management frontend menu and content get tested

This commit is contained in:
2025-05-15 11:07:54 +03:00
parent 1560d6e68b
commit f73b54613e
38 changed files with 1459 additions and 22 deletions

View File

@@ -0,0 +1,20 @@
import { retrieveUserSelection } from "@/apicalls/cookies/token";
import { NextResponse } from "next/server";
export async function POST(): Promise<NextResponse> {
try {
const userSelection = await retrieveUserSelection();
console.log("userSelection", userSelection);
if (userSelection) {
return NextResponse.json({
status: 200,
message: "User selection found",
data: userSelection,
});
}
} catch (error) {}
return NextResponse.json({
status: 500,
message: "User selection not found",
});
}

View File

@@ -0,0 +1,39 @@
import { loginViaAccessKeys } from "@/apicalls/custom/login/login";
import { NextResponse } from "next/server";
import { loginSchemaEmail } from "@/webPages/auth/login/schemas";
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 = {
accessKey: body.email,
password: body.password,
rememberMe: body.rememberMe,
};
const validatedLoginBody = loginSchemaEmail.safeParse(body);
if (!validatedLoginBody.success) {
return NextResponse.json({
status: 422,
message: validatedLoginBody.error.message,
});
}
const userLogin = await loginViaAccessKeys(dataValidated);
if (userLogin.status === 200 || userLogin.status === 202) {
return NextResponse.json({
status: 200,
message: "Login 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" });
}
}

View File

@@ -0,0 +1,41 @@
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" });
}
}

View File

@@ -0,0 +1,41 @@
import { z } from "zod";
import { loginSelectOccupant } from "@/apicalls/custom/login/login";
import { NextResponse } from "next/server";
const loginSchemaOccupant = z.object({
build_living_space_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 = {
build_living_space_uu_id: body.build_living_space_uu_id,
};
const validatedLoginBody = loginSchemaOccupant.safeParse(body);
if (!validatedLoginBody.success) {
return NextResponse.json({
status: 422,
message: validatedLoginBody.error.message,
});
}
const userLogin = await loginSelectOccupant(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" });
}
}