- Replace Clerk with self-hosted JWT auth (register/login/verify, bcrypt passwords, Gmail OTP with console fallback) - Add lib/db.ts pg pool + transaction helpers; seed script migrates legacy Clerk-era schema (drop clerk_id, enforce UUID ids and unique email) - Add owner-gated admin API: stats, users, drivers CRUD, rides - Add dashboard/ Vite React owner dashboard (login, overview, users, fleet, rides) with dev-server proxy to avoid Expo CORS middleware - Add scripts/set-owner.mjs for role management
76 lines
1.8 KiB
TypeScript
76 lines
1.8 KiB
TypeScript
import { requireAuth } from "@/lib/jwt";
|
|
import { sql } from "@/lib/db";
|
|
|
|
export async function POST(request: Request) {
|
|
const auth = requireAuth(request);
|
|
if ("error" in auth) return auth.error;
|
|
|
|
try {
|
|
const body = await request.json();
|
|
const {
|
|
origin_address,
|
|
destination_address,
|
|
origin_latitude,
|
|
origin_longitude,
|
|
destination_latitude,
|
|
destination_longitude,
|
|
ride_time,
|
|
fare_price,
|
|
payment_status,
|
|
driver_id,
|
|
} = body;
|
|
|
|
if (
|
|
!origin_address ||
|
|
!destination_address ||
|
|
!origin_latitude ||
|
|
!origin_longitude ||
|
|
!destination_latitude ||
|
|
!destination_longitude ||
|
|
!ride_time ||
|
|
!fare_price ||
|
|
!payment_status ||
|
|
!driver_id
|
|
) {
|
|
return Response.json(
|
|
{ error: "Missing required fields" },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
|
|
const response = await sql`
|
|
INSERT INTO rides (
|
|
origin_address,
|
|
destination_address,
|
|
origin_latitude,
|
|
origin_longitude,
|
|
destination_latitude,
|
|
destination_longitude,
|
|
ride_time,
|
|
fare_price,
|
|
payment_status,
|
|
driver_id,
|
|
user_id
|
|
) VALUES (
|
|
${origin_address},
|
|
${destination_address},
|
|
${origin_latitude},
|
|
${origin_longitude},
|
|
${destination_latitude},
|
|
${destination_longitude},
|
|
${ride_time},
|
|
${fare_price},
|
|
${payment_status},
|
|
${driver_id},
|
|
${auth.userId}
|
|
)
|
|
RETURNING *;
|
|
`;
|
|
|
|
return Response.json({ data: response[0] }, { status: 201 });
|
|
} catch (error) {
|
|
console.error("[CREATE_RIDES]: ", error);
|
|
return Response.json({ error: "Internal Server Error" }, { status: 500 });
|
|
}
|
|
}
|