updated postgres and mongo updated
This commit is contained in:
@@ -23,9 +23,7 @@ async function retrievePageList() {
|
||||
: null;
|
||||
}
|
||||
|
||||
|
||||
async function retrievePagebyUrl(pageUrl: string) {
|
||||
|
||||
const response = await fetchDataWithToken(
|
||||
pageValid,
|
||||
{
|
||||
@@ -66,50 +64,56 @@ async function retrieveAccessObjects() {
|
||||
async function retrieveUserSelection() {
|
||||
const cookieStore = await cookies();
|
||||
const encrpytUserSelection = cookieStore.get("userSelection")?.value || "";
|
||||
|
||||
let objectUserSelection = {};
|
||||
let decrpytUserSelection: any = await nextCrypto.decrypt(
|
||||
encrpytUserSelection
|
||||
);
|
||||
decrpytUserSelection = decrpytUserSelection
|
||||
? JSON.parse(decrpytUserSelection)
|
||||
: null;
|
||||
|
||||
const userSelection = decrpytUserSelection?.company_uu_id;
|
||||
|
||||
let objectUserSelection = {};
|
||||
console.log("decrpytUserSelection", decrpytUserSelection);
|
||||
const userSelection = decrpytUserSelection?.selected;
|
||||
const accessObjects = (await retrieveAccessObjects()) || {};
|
||||
console.log("accessObjects", accessObjects);
|
||||
|
||||
if (decrpytUserSelection?.user_type === "employee") {
|
||||
const accessObjects = (await retrieveAccessObjects()) || {};
|
||||
const companyList = accessObjects?.companies_list;
|
||||
const companyList = accessObjects?.selectionList;
|
||||
const selectedCompany = companyList.find(
|
||||
(company: any) => company.uu_id === userSelection
|
||||
);
|
||||
if (selectedCompany) {
|
||||
objectUserSelection = {
|
||||
occupantName: `${selectedCompany?.public_name}`,
|
||||
};
|
||||
objectUserSelection = { userType: "employee", selected: selectedCompany };
|
||||
}
|
||||
} else if (decrpytUserSelection?.user_type === "occupant") {
|
||||
const buildPartUUID = userSelection?.build_part_uu_id;
|
||||
const occupantUUID = userSelection?.occupant_uu_id;
|
||||
const build_id = userSelection?.build_id;
|
||||
const accessObjects = (await retrieveAccessObjects()) || {};
|
||||
const availableOccupants = accessObjects?.available_occupants[build_id];
|
||||
const buildName = availableOccupants?.build_name;
|
||||
const buildNo = availableOccupants?.build_no;
|
||||
let selectedOccupant: any = null;
|
||||
const occupants = availableOccupants?.occupants;
|
||||
if (occupants) {
|
||||
selectedOccupant = occupants.find(
|
||||
(occupant: any) =>
|
||||
occupant.part_uu_id === buildPartUUID &&
|
||||
occupant.uu_id === occupantUUID
|
||||
);
|
||||
}
|
||||
if (selectedOccupant) {
|
||||
objectUserSelection = {
|
||||
buildName: `${buildName} - No:${buildNo}`,
|
||||
occupantName: `${selectedOccupant?.description} ${selectedOccupant?.part_name}`,
|
||||
};
|
||||
const buildingsList = accessObjects?.selectionList;
|
||||
|
||||
// Iterate through all buildings
|
||||
if (buildingsList) {
|
||||
// Loop through each building
|
||||
for (const buildKey in buildingsList) {
|
||||
const building = buildingsList[buildKey];
|
||||
|
||||
// Check if the building has occupants
|
||||
if (building.occupants && building.occupants.length > 0) {
|
||||
// Find the occupant with the matching build_living_space_uu_id
|
||||
const occupant = building.occupants.find(
|
||||
(occ: any) => occ.build_living_space_uu_id === userSelection
|
||||
);
|
||||
|
||||
if (occupant) {
|
||||
objectUserSelection = {
|
||||
userType: "occupant",
|
||||
selected: {
|
||||
...occupant,
|
||||
buildName: building.build_name,
|
||||
buildNo: building.build_no,
|
||||
},
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user