From 57c2696bcb8439a34358792c4b176b86ce68f391 Mon Sep 17 00:00:00 2001 From: Berkay Date: Sun, 15 Jun 2025 20:25:50 +0300 Subject: [PATCH] updated occupant and employee login completed --- ServicesApi/Builds/Auth/events/auth/events.py | 3 +- .../app/api/context/dash/selection/route.ts | 53 ++++--------------- .../custom/context/dash/selection/fetch.tsx | 4 +- .../src/fetchers/custom/login/login.tsx | 12 ++--- 4 files changed, 17 insertions(+), 55 deletions(-) diff --git a/ServicesApi/Builds/Auth/events/auth/events.py b/ServicesApi/Builds/Auth/events/auth/events.py index b30f36d..8978c82 100644 --- a/ServicesApi/Builds/Auth/events/auth/events.py +++ b/ServicesApi/Builds/Auth/events/auth/events.py @@ -288,8 +288,7 @@ class LoginHandler: list_of_returns = ( Employees.id, Employees.uu_id, People.id, People.uu_id, Users.id, Users.uu_id, Companies.id, Companies.uu_id, Companies.public_name, Companies.company_type, Departments.id, Departments.uu_id, Duty.id, Duty.uu_id, Addresses.id, Addresses.letter_address, Staff.id, Staff.uu_id, Duty.duty_name, - Duties.id, Duties.uu_id, BuildParts.id, BuildParts.uu_id, BuildParts.part_name, BuildParts.part_level, BuildParts.part_code, - OccupantTypes.id, OccupantTypes.uu_id, OccupantTypes.occupant_type, OccupantTypes.occupant_description, Addresses.letter_address + Duties.id, Duties.uu_id, Addresses.letter_address ) selected_company_query = db_session.query(*list_of_returns diff --git a/ServicesWeb/customer/src/app/api/context/dash/selection/route.ts b/ServicesWeb/customer/src/app/api/context/dash/selection/route.ts index 2afe97a..c6e3259 100644 --- a/ServicesWeb/customer/src/app/api/context/dash/selection/route.ts +++ b/ServicesWeb/customer/src/app/api/context/dash/selection/route.ts @@ -8,34 +8,17 @@ import { NextResponse } from "next/server"; export async function GET() { try { const selection = await getSelectionFromRedis(); - return NextResponse.json({ - status: 200, - data: selection || null, - }); + return NextResponse.json({ status: 200, data: selection || null }); } catch (error) { if (error instanceof AuthError) { - // Return 401 Unauthorized for authentication errors return new NextResponse( - JSON.stringify({ - status: 401, - error: error.message, - }), - { - status: 401, - headers: { "Content-Type": "application/json" }, - } + JSON.stringify({ status: 401, error: error.message }), + { status: 401, headers: { "Content-Type": "application/json" } } ); } - // For other errors, return 500 Internal Server Error return new NextResponse( - JSON.stringify({ - status: 500, - error: "Internal server error", - }), - { - status: 500, - headers: { "Content-Type": "application/json" }, - } + JSON.stringify({ status: 500, error: "Internal server error" }), + { status: 500, headers: { "Content-Type": "application/json" } } ); } } @@ -44,33 +27,17 @@ export async function POST(request: Request) { try { const selection = await request.json(); await setActiveSelectionToRedis(selection); - - return NextResponse.json({ - status: 200, - data: selection || null, - }); + return NextResponse.json({ status: 200, data: selection || null }); } catch (error) { if (error instanceof AuthError) { return new NextResponse( - JSON.stringify({ - status: 401, - error: error.message, - }), - { - status: 401, - headers: { "Content-Type": "application/json" }, - } + JSON.stringify({ status: 401, error: error.message }), + { status: 401, headers: { "Content-Type": "application/json" } } ); } return new NextResponse( - JSON.stringify({ - status: 500, - error: "Internal server error", - }), - { - status: 500, - headers: { "Content-Type": "application/json" }, - } + JSON.stringify({ status: 500, error: "Internal server error" }), + { status: 500, headers: { "Content-Type": "application/json" } } ); } } diff --git a/ServicesWeb/customer/src/fetchers/custom/context/dash/selection/fetch.tsx b/ServicesWeb/customer/src/fetchers/custom/context/dash/selection/fetch.tsx index ab5fd21..42eeada 100644 --- a/ServicesWeb/customer/src/fetchers/custom/context/dash/selection/fetch.tsx +++ b/ServicesWeb/customer/src/fetchers/custom/context/dash/selection/fetch.tsx @@ -37,8 +37,10 @@ const setActiveSelectionToRedis = async (selectionObject: any) => { activeSelection: selectionObject } }) + console.log("oldData", oldData) if (oldData.online.userType.toUpperCase() === "EMPLOYEE") { - await loginSelectEmployee({ uuid: selectionObject.uuid }); + console.log("selectionObject", selectionObject) + await loginSelectEmployee({ uuid: selectionObject.uu_id }); } else if (oldData.online.userType.toUpperCase() === "OCCUPANT") { await loginSelectOccupant({ uuid: selectionObject.build_living_space_uu_id }); } diff --git a/ServicesWeb/customer/src/fetchers/custom/login/login.tsx b/ServicesWeb/customer/src/fetchers/custom/login/login.tsx index ee22545..746d194 100644 --- a/ServicesWeb/customer/src/fetchers/custom/login/login.tsx +++ b/ServicesWeb/customer/src/fetchers/custom/login/login.tsx @@ -25,10 +25,6 @@ async function logoutActiveSession() { async function initRedis(loginRespone: any, firstSelection: any, accessToken: string, redisKey: string) { let alreadyAtRedis = null - console.log("loginRespone", loginRespone) - console.log("firstSelection", firstSelection) - console.log("accessToken", accessToken) - console.log("redisKey", redisKey) if (!alreadyAtRedis) { if (loginRespone.user_type.toUpperCase() === "EMPLOYEE") { const loginObjectToRedis = { @@ -64,7 +60,7 @@ async function initRedis(loginRespone: any, firstSelection: any, accessToken: st async function initFirstSelection(firstSelection: any, userType: string) { if (userType === "EMPLOYEE") { - const uuid = firstSelection.uuid; + const uuid = firstSelection.uu_id; await loginSelectEmployee({ uuid }); } else if (userType === "OCCUPANT") { const uuid = firstSelection.build_living_space_uu_id; @@ -87,13 +83,10 @@ async function loginViaAccessKeys(payload: LoginViaAccessKeys) { ); await deleteAllCookies() if (response.status === 200 || response.status === 202) { - const loginRespone: any = response?.data; - let firstSelection = null - if (loginRespone.user_type.toUpperCase() === "EMPLOYEE") { - firstSelection = loginRespone.selection_list.find((item: any) => item.uu_id === loginRespone.selection_list[0].uu_id); + firstSelection = loginRespone.selection_list[0]; } else if (loginRespone.user_type.toUpperCase() === "OCCUPANT") { const firstKeyOfSelectionList = Object.keys(loginRespone.selection_list)[0]; firstSelection = loginRespone.selection_list[firstKeyOfSelectionList].occupants[0]; @@ -165,6 +158,7 @@ async function loginViaAccessKeys(payload: LoginViaAccessKeys) { } async function loginSelectEmployee(payload: LoginSelect) { + console.log("payload", payload) const employeeUUID = payload.uuid; const selectResponse: any = await fetchDataWithToken(urlLoginSelectEndpoint, { uuid: employeeUUID }, "POST", false); console.log("selectResponse", selectResponse)