42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { z } from "zod";
|
|
import { loginSelectEmployee } from "@/apicalls/custom/login/login";
|
|
import { NextResponse } from "next/server";
|
|
|
|
const loginSchemaEmployee = z.object({
|
|
company_uu_id: z.string(),
|
|
});
|
|
|
|
export async function POST(req: Request): Promise<NextResponse> {
|
|
try {
|
|
const headers = req.headers;
|
|
console.log("headers", Object.entries(headers));
|
|
const body = await req.json();
|
|
const dataValidated = {
|
|
company_uu_id: body.company_uu_id,
|
|
};
|
|
const validatedLoginBody = loginSchemaEmployee.safeParse(body);
|
|
if (!validatedLoginBody.success) {
|
|
return NextResponse.json({
|
|
status: 422,
|
|
message: validatedLoginBody.error.message,
|
|
});
|
|
}
|
|
|
|
const userLogin = await loginSelectEmployee(dataValidated);
|
|
if (userLogin.status === 200 || userLogin.status === 202) {
|
|
return NextResponse.json({
|
|
status: 200,
|
|
message: "Selection successfully completed",
|
|
data: userLogin.data,
|
|
});
|
|
} else {
|
|
return NextResponse.json({
|
|
status: userLogin.status,
|
|
message: userLogin.message,
|
|
});
|
|
}
|
|
} catch (error) {
|
|
return NextResponse.json({ status: 401, message: "Invalid credentials" });
|
|
}
|
|
}
|