updated occupant and employee login completed
This commit is contained in:
parent
9fb517fa15
commit
57c2696bcb
|
|
@ -288,8 +288,7 @@ class LoginHandler:
|
||||||
list_of_returns = (
|
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,
|
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,
|
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,
|
Duties.id, Duties.uu_id, Addresses.letter_address
|
||||||
OccupantTypes.id, OccupantTypes.uu_id, OccupantTypes.occupant_type, OccupantTypes.occupant_description, Addresses.letter_address
|
|
||||||
)
|
)
|
||||||
|
|
||||||
selected_company_query = db_session.query(*list_of_returns
|
selected_company_query = db_session.query(*list_of_returns
|
||||||
|
|
|
||||||
|
|
@ -8,34 +8,17 @@ import { NextResponse } from "next/server";
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
try {
|
try {
|
||||||
const selection = await getSelectionFromRedis();
|
const selection = await getSelectionFromRedis();
|
||||||
return NextResponse.json({
|
return NextResponse.json({ status: 200, data: selection || null });
|
||||||
status: 200,
|
|
||||||
data: selection || null,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof AuthError) {
|
if (error instanceof AuthError) {
|
||||||
// Return 401 Unauthorized for authentication errors
|
|
||||||
return new NextResponse(
|
return new NextResponse(
|
||||||
JSON.stringify({
|
JSON.stringify({ status: 401, error: error.message }),
|
||||||
status: 401,
|
{ status: 401, headers: { "Content-Type": "application/json" } }
|
||||||
error: error.message,
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
status: 401,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// For other errors, return 500 Internal Server Error
|
|
||||||
return new NextResponse(
|
return new NextResponse(
|
||||||
JSON.stringify({
|
JSON.stringify({ status: 500, error: "Internal server error" }),
|
||||||
status: 500,
|
{ status: 500, headers: { "Content-Type": "application/json" } }
|
||||||
error: "Internal server error",
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
status: 500,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -44,33 +27,17 @@ export async function POST(request: Request) {
|
||||||
try {
|
try {
|
||||||
const selection = await request.json();
|
const selection = await request.json();
|
||||||
await setActiveSelectionToRedis(selection);
|
await setActiveSelectionToRedis(selection);
|
||||||
|
return NextResponse.json({ status: 200, data: selection || null });
|
||||||
return NextResponse.json({
|
|
||||||
status: 200,
|
|
||||||
data: selection || null,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof AuthError) {
|
if (error instanceof AuthError) {
|
||||||
return new NextResponse(
|
return new NextResponse(
|
||||||
JSON.stringify({
|
JSON.stringify({ status: 401, error: error.message }),
|
||||||
status: 401,
|
{ status: 401, headers: { "Content-Type": "application/json" } }
|
||||||
error: error.message,
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
status: 401,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return new NextResponse(
|
return new NextResponse(
|
||||||
JSON.stringify({
|
JSON.stringify({ status: 500, error: "Internal server error" }),
|
||||||
status: 500,
|
{ status: 500, headers: { "Content-Type": "application/json" } }
|
||||||
error: "Internal server error",
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
status: 500,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,10 @@ const setActiveSelectionToRedis = async (selectionObject: any) => {
|
||||||
activeSelection: selectionObject
|
activeSelection: selectionObject
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
console.log("oldData", oldData)
|
||||||
if (oldData.online.userType.toUpperCase() === "EMPLOYEE") {
|
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") {
|
} else if (oldData.online.userType.toUpperCase() === "OCCUPANT") {
|
||||||
await loginSelectOccupant({ uuid: selectionObject.build_living_space_uu_id });
|
await loginSelectOccupant({ uuid: selectionObject.build_living_space_uu_id });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,6 @@ async function logoutActiveSession() {
|
||||||
|
|
||||||
async function initRedis(loginRespone: any, firstSelection: any, accessToken: string, redisKey: string) {
|
async function initRedis(loginRespone: any, firstSelection: any, accessToken: string, redisKey: string) {
|
||||||
let alreadyAtRedis = null
|
let alreadyAtRedis = null
|
||||||
console.log("loginRespone", loginRespone)
|
|
||||||
console.log("firstSelection", firstSelection)
|
|
||||||
console.log("accessToken", accessToken)
|
|
||||||
console.log("redisKey", redisKey)
|
|
||||||
if (!alreadyAtRedis) {
|
if (!alreadyAtRedis) {
|
||||||
if (loginRespone.user_type.toUpperCase() === "EMPLOYEE") {
|
if (loginRespone.user_type.toUpperCase() === "EMPLOYEE") {
|
||||||
const loginObjectToRedis = {
|
const loginObjectToRedis = {
|
||||||
|
|
@ -64,7 +60,7 @@ async function initRedis(loginRespone: any, firstSelection: any, accessToken: st
|
||||||
|
|
||||||
async function initFirstSelection(firstSelection: any, userType: string) {
|
async function initFirstSelection(firstSelection: any, userType: string) {
|
||||||
if (userType === "EMPLOYEE") {
|
if (userType === "EMPLOYEE") {
|
||||||
const uuid = firstSelection.uuid;
|
const uuid = firstSelection.uu_id;
|
||||||
await loginSelectEmployee({ uuid });
|
await loginSelectEmployee({ uuid });
|
||||||
} else if (userType === "OCCUPANT") {
|
} else if (userType === "OCCUPANT") {
|
||||||
const uuid = firstSelection.build_living_space_uu_id;
|
const uuid = firstSelection.build_living_space_uu_id;
|
||||||
|
|
@ -87,13 +83,10 @@ async function loginViaAccessKeys(payload: LoginViaAccessKeys) {
|
||||||
);
|
);
|
||||||
await deleteAllCookies()
|
await deleteAllCookies()
|
||||||
if (response.status === 200 || response.status === 202) {
|
if (response.status === 200 || response.status === 202) {
|
||||||
|
|
||||||
const loginRespone: any = response?.data;
|
const loginRespone: any = response?.data;
|
||||||
|
|
||||||
let firstSelection = null
|
let firstSelection = null
|
||||||
|
|
||||||
if (loginRespone.user_type.toUpperCase() === "EMPLOYEE") {
|
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") {
|
} else if (loginRespone.user_type.toUpperCase() === "OCCUPANT") {
|
||||||
const firstKeyOfSelectionList = Object.keys(loginRespone.selection_list)[0];
|
const firstKeyOfSelectionList = Object.keys(loginRespone.selection_list)[0];
|
||||||
firstSelection = loginRespone.selection_list[firstKeyOfSelectionList].occupants[0];
|
firstSelection = loginRespone.selection_list[firstKeyOfSelectionList].occupants[0];
|
||||||
|
|
@ -165,6 +158,7 @@ async function loginViaAccessKeys(payload: LoginViaAccessKeys) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loginSelectEmployee(payload: LoginSelect) {
|
async function loginSelectEmployee(payload: LoginSelect) {
|
||||||
|
console.log("payload", payload)
|
||||||
const employeeUUID = payload.uuid;
|
const employeeUUID = payload.uuid;
|
||||||
const selectResponse: any = await fetchDataWithToken(urlLoginSelectEndpoint, { uuid: employeeUUID }, "POST", false);
|
const selectResponse: any = await fetchDataWithToken(urlLoginSelectEndpoint, { uuid: employeeUUID }, "POST", false);
|
||||||
console.log("selectResponse", selectResponse)
|
console.log("selectResponse", selectResponse)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue