-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ignacio López-Amor
committed
Sep 24, 2024
1 parent
8e7af9d
commit 62f79b5
Showing
130 changed files
with
16,311 additions
and
5,262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/.expo | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// https://docs.expo.dev/guides/using-eslint/ | ||
module.exports = { | ||
extends: ["expo", "prettier"], | ||
plugins: ["prettier", "import"], | ||
rules: { | ||
"prettier/prettier": "error", | ||
"import/order": [ | ||
"error", | ||
{ | ||
groups: [ | ||
"builtin", | ||
"external", | ||
"internal", | ||
"parent", | ||
"sibling", | ||
"index", | ||
"object", | ||
"type", | ||
], | ||
"newlines-between": "always", | ||
alphabetize: { | ||
order: "asc", | ||
caseInsensitive: true, | ||
}, | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["prettier-plugin-tailwindcss"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
"editor.formatOnPaste": true, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"[typescriptreact]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
"[typescript]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
"cSpell.words": ["Lngs"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// { | ||
// "ignore_dirs": ["node_modules", ".git", ".expo"] | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Stripe } from "stripe"; | ||
|
||
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!); | ||
|
||
export async function POST(request: Request) { | ||
const body = await request.json(); | ||
const { name, email, amount } = body; | ||
|
||
if (!name || !email || !amount) { | ||
return new Response(JSON.stringify({ error: "Missing required fields" }), { | ||
status: 400, | ||
}); | ||
} | ||
|
||
let customer; | ||
|
||
const existingCustomer = await stripe.customers.list({ | ||
email, | ||
}); | ||
|
||
if (existingCustomer.data.length > 0) { | ||
customer = existingCustomer.data[0]; | ||
} else { | ||
const newCustomer = await stripe.customers.create({ | ||
name, | ||
email, | ||
}); | ||
|
||
customer = newCustomer; | ||
} | ||
|
||
const ephemeralKey = await stripe.ephemeralKeys.create( | ||
{ customer: customer.id }, | ||
{ apiVersion: "2024-06-20" }, | ||
); | ||
|
||
const paymentIntent = await stripe.paymentIntents.create({ | ||
amount: parseInt(amount) * 100, | ||
currency: "eur", | ||
customer: customer.id, | ||
automatic_payment_methods: { | ||
enabled: true, | ||
allow_redirects: "never", | ||
}, | ||
}); | ||
|
||
return new Response( | ||
JSON.stringify({ | ||
paymentIntent: paymentIntent, | ||
ephemeralKey: ephemeralKey, | ||
customer: customer.id, | ||
}), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Stripe } from "stripe"; | ||
|
||
const apiKey = process.env.STRIPE_SECRET_KEY as string; | ||
|
||
const stripe = new Stripe(apiKey); | ||
|
||
export async function POST(request: Request) { | ||
try { | ||
const body = await request.json(); | ||
const { payment_method_id, payment_intent_id, customer_id } = body; | ||
|
||
if (!payment_method_id || !payment_intent_id || !customer_id) { | ||
return new Response( | ||
JSON.stringify({ error: "Missing required payment information" }), | ||
{ | ||
status: 400, | ||
}, | ||
); | ||
} | ||
|
||
const paymentMethod = await stripe.paymentMethods.attach( | ||
payment_method_id, | ||
{ | ||
customer: customer_id, | ||
}, | ||
); | ||
|
||
const result = await stripe.paymentIntents.confirm(payment_intent_id, { | ||
payment_method: paymentMethod.id, | ||
}); | ||
|
||
return new Response( | ||
JSON.stringify({ | ||
success: true, | ||
message: "Payment confirmed successfully", | ||
result, | ||
}), | ||
); | ||
} catch (error) { | ||
console.log(error); | ||
|
||
return new Response( | ||
JSON.stringify({ | ||
success: false, | ||
message: "Payment failed", | ||
status: 500, | ||
error, | ||
}), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { neon } from "@neondatabase/serverless"; | ||
|
||
export async function GET() { | ||
try { | ||
const sql = neon(`${process.env.DATABASE_URL}`); | ||
|
||
const response = await sql`SELECT * FROM drivers`; | ||
|
||
return Response.json({ data: response }, { status: 201 }); | ||
} catch (error) { | ||
console.log(error); | ||
return Response.json({ error }, { status: 500 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { neon } from "@neondatabase/serverless"; | ||
|
||
export async function GET(request: Request, { id }: { id: string }) { | ||
if (!id) | ||
return Response.json({ error: "Missing required fields" }, { status: 400 }); | ||
|
||
try { | ||
const sql = neon(`${process.env.DATABASE_URL}`); | ||
const response = await sql` | ||
SELECT | ||
rides.ride_id, | ||
rides.origin_address, | ||
rides.destination_address, | ||
rides.origin_latitude, | ||
rides.origin_longitude, | ||
rides.destination_latitude, | ||
rides.destination_longitude, | ||
rides.ride_time, | ||
rides.fare_price, | ||
rides.payment_status, | ||
rides.created_at, | ||
'driver', json_build_object( | ||
'driver_id', drivers.id, | ||
'first_name', drivers.first_name, | ||
'last_name', drivers.last_name, | ||
'profile_image_url', drivers.profile_image_url, | ||
'car_image_url', drivers.car_image_url, | ||
'car_seats', drivers.car_seats, | ||
'rating', drivers.rating | ||
) AS driver | ||
FROM | ||
rides | ||
INNER JOIN | ||
drivers ON rides.driver_id = drivers.id | ||
WHERE | ||
rides.user_id = ${id} | ||
ORDER BY | ||
rides.created_at DESC; | ||
`; | ||
|
||
return Response.json({ data: response }); | ||
} catch (error) { | ||
console.error("Error fetching recent rides:", error); | ||
return Response.json({ error: "Internal Server Error" }, { status: 500 }); | ||
} | ||
} |
Oops, something went wrong.