select employee tested

This commit is contained in:
berkay 2025-04-07 13:52:02 +03:00
parent e4d50306ac
commit 7eadadbd1d
6 changed files with 57 additions and 21 deletions

View File

@ -8,7 +8,7 @@ from ApiServices.AuthService.config import api_config
from ApiServices.AuthService.validations.request.authentication.login_post import ( from ApiServices.AuthService.validations.request.authentication.login_post import (
RequestLogin, RequestLogin,
RequestSelectLiving, RequestSelectLiving,
RequestSelectOccupant, RequestSelectEmployee,
RequestCreatePassword, RequestCreatePassword,
RequestChangePassword, RequestChangePassword,
RequestForgotPasswordPhone, RequestForgotPasswordPhone,
@ -67,7 +67,7 @@ def authentication_login_post(
) )
def authentication_select_post( def authentication_select_post(
request: Request, request: Request,
data: Union[RequestSelectOccupant, RequestSelectLiving], data: Union[RequestSelectEmployee, RequestSelectLiving],
language: str = Header(None, alias="language"), language: str = Header(None, alias="language"),
domain: str = Header(None, alias="domain"), domain: str = Header(None, alias="domain"),
tz: str = Header(None, alias="timezone"), tz: str = Header(None, alias="timezone"),

View File

@ -18,7 +18,7 @@ class RequestApplication(BaseModel):
page: str # /building/create page: str # /building/create
class RequestSelectOccupant(BaseModel): class RequestSelectEmployee(BaseModel):
company_uu_id: str company_uu_id: str

View File

@ -24,9 +24,7 @@ interface LoginSelectEmployee {
} }
interface LoginSelectOccupant { interface LoginSelectOccupant {
selectedBuilding: any; build_living_space_uu_id: any;
build_part_uu_id: string;
occupant_uu_id: string;
} }
async function loginViaAccessKeys(payload: LoginViaAccessKeys) { async function loginViaAccessKeys(payload: LoginViaAccessKeys) {
@ -51,7 +49,7 @@ async function loginViaAccessKeys(payload: LoginViaAccessKeys) {
const accessObject = await nextCrypto.encrypt( const accessObject = await nextCrypto.encrypt(
JSON.stringify({ JSON.stringify({
userType: loginRespone.user_type, userType: loginRespone.user_type,
selectionList:loginRespone.selection_list selectionList: loginRespone.selection_list,
}) })
); );
const userProfile = await nextCrypto.encrypt( const userProfile = await nextCrypto.encrypt(
@ -122,7 +120,7 @@ async function loginSelectEmployee(payload: LoginSelectEmployee) {
"POST", "POST",
false false
); );
if (selectResponse.status === 200) { if (selectResponse.status === 200 || selectResponse.status === 202) {
const usersSelection = await nextCrypto.encrypt( const usersSelection = await nextCrypto.encrypt(
JSON.stringify({ JSON.stringify({
company_uu_id: payload.company_uu_id, company_uu_id: payload.company_uu_id,
@ -139,14 +137,13 @@ async function loginSelectEmployee(payload: LoginSelectEmployee) {
} }
async function loginSelectOccupant(payload: LoginSelectOccupant) { async function loginSelectOccupant(payload: LoginSelectOccupant) {
const selectedBuilding = payload.selectedBuilding; const build_living_space_uu_id = payload.build_living_space_uu_id;
const cookieStore = await cookies(); const cookieStore = await cookies();
const nextCrypto = new NextCrypto(tokenSecret); const nextCrypto = new NextCrypto(tokenSecret);
const selectResponse: any = await fetchDataWithToken( const selectResponse: any = await fetchDataWithToken(
loginSelectEndpoint, loginSelectEndpoint,
{ {
build_part_uu_id: payload.build_part_uu_id, build_living_space_uu_id: build_living_space_uu_id,
occupant_uu_id: payload.occupant_uu_id,
}, },
"POST", "POST",
false false
@ -155,11 +152,12 @@ async function loginSelectOccupant(payload: LoginSelectOccupant) {
if (selectResponse.status === 200) { if (selectResponse.status === 200) {
const usersSelection = await nextCrypto.encrypt( const usersSelection = await nextCrypto.encrypt(
JSON.stringify({ JSON.stringify({
company_uu_id: { // company_uu_id: {
build_part_uu_id: payload.build_part_uu_id, // build_part_uu_id: payload.build_part_uu_id,
occupant_uu_id: payload.occupant_uu_id, // occupant_uu_id: payload.occupant_uu_id,
build_id: selectedBuilding, // build_id: selectedBuilding,
}, // },
build_living_space_uu_id: build_living_space_uu_id,
user_type: "occupant", user_type: "occupant",
}) })
); );

View File

@ -16,7 +16,7 @@ async function SelectPage() {
const selectionList = selection?.selectionList; const selectionList = selection?.selectionList;
if (!selectionList || !token_is_valid) { if (!selectionList || !token_is_valid) {
redirect("/login/email"); redirect("/auth/login");
} }
return ( return (
<> <>

View File

@ -0,0 +1,14 @@
import React from "react";
import { checkAccessTokenIsValid } from "@/apicalls/cookies/token";
import { redirect } from "next/navigation";
async function DashboardPage() {
const token_is_valid = await checkAccessTokenIsValid();
if (!token_is_valid) {
redirect("/auth/login");
}
return <div>You have arrived to Dashboard Page</div>;
}
export default DashboardPage;

View File

@ -1,7 +1,12 @@
"use client"; "use client";
import React from "react"; import React from "react";
import {
loginSelectEmployee,
loginSelectOccupant,
} from "@/apicalls/login/login";
import { useRouter } from "next/navigation";
function SelectList({ function SelectList({
selectionList, selectionList,
isEmployee, isEmployee,
@ -16,11 +21,31 @@ function SelectList({
isEmployee: boolean; isEmployee: boolean;
isOccupant: boolean; isOccupant: boolean;
}) { }) {
const handleClick = (uu_id: string) => { const router = useRouter();
const setSelectionHandler = (uu_id: string) => {
if (isEmployee) { if (isEmployee) {
console.log("Selected isEmployee uu_id:", uu_id); console.log("Selected isEmployee uu_id:", uu_id);
loginSelectEmployee({ company_uu_id: uu_id })
.then((responseData: any) => {
if (responseData?.status === 200 || responseData?.status === 202) {
router.push("/dashboard");
}
})
.catch((error) => {
console.error(error);
});
} else if (isOccupant) { } else if (isOccupant) {
console.log("Selected isOccupant uu_id:", uu_id); console.log("Selected isOccupant uu_id:", uu_id);
loginSelectOccupant({ build_living_space_uu_id: uu_id })
.then((responseData: any) => {
if (responseData?.status === 200 || responseData?.status === 202) {
router.push("/dashboard");
}
})
.catch((error) => {
console.error(error);
});
} }
}; };
@ -30,12 +55,11 @@ function SelectList({
<div <div
key={index} key={index}
className="w-full p-4 m-2 bg-emerald-300 hover:bg-emerald-500 rounded-lg transition-colors duration-200 cursor-pointer" className="w-full p-4 m-2 bg-emerald-300 hover:bg-emerald-500 rounded-lg transition-colors duration-200 cursor-pointer"
onClick={() => handleClick(item.uu_id)} onClick={() => setSelectionHandler(item.uu_id)}
> >
<div className="flex flex-col items-center md:items-start"> <div className="flex flex-col items-center md:items-start">
<div> <div>
<span className="text-2xl font-medium">{item.public_name}</span> <span className="text-2xl font-medium">{item.public_name}</span>
{""}
<span className="font-medium text-sky-500"> <span className="font-medium text-sky-500">
{item.company_type} {item.company_type}
</span> </span>