Compare commits
2 Commits
1e7ac2521c
...
eb45cb3fb8
Author | SHA1 | Date | |
---|---|---|---|
![]() |
eb45cb3fb8 | ||
![]() |
98f3ff5dab |
@ -95,7 +95,7 @@ export default class NotificationBuilder {
|
|||||||
redirection_url: "",
|
redirection_url: "",
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
user: user ? [user] : [],
|
user: [user] || [],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ export default class NotificationBuilder {
|
|||||||
redirection_url: "",
|
redirection_url: "",
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
user: user ? [user] : [],
|
user: [user] || [],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,157 +227,134 @@ export default class IdNotService extends BaseService {
|
|||||||
key: this.variables.IDNOT_API_KEY,
|
key: this.variables.IDNOT_API_KEY,
|
||||||
});
|
});
|
||||||
|
|
||||||
let rattachmentRawData: Response;
|
let userRawData: Response;
|
||||||
try {
|
try {
|
||||||
const url = `${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/personnes/${user.idNot}/rattachements?` + searchParams;
|
userRawData = await fetch(
|
||||||
console.log("Fetching rattachements data for", url);
|
`${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/rattachements/${user.idNot}_${user.office_membership!.idNot}?` +
|
||||||
rattachmentRawData = await fetch(
|
searchParams,
|
||||||
url,
|
|
||||||
{
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
}
|
},
|
||||||
);
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error fetching rattachments data for ${user.uid}: ${error}`);
|
console.error(`Error fetching user data for ${user.uid}: ${error}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rattachmentRawData.status === 404) {
|
if (userRawData.status === 404) {
|
||||||
console.error(`User ${user.uid} not found in idnot`);
|
console.error(`User ${user.uid} not found in idnot`);
|
||||||
return;
|
return;
|
||||||
} else if (rattachmentRawData.status !== 200) {
|
} else if (userRawData.status !== 200) {
|
||||||
console.error(`Error fetching rattachements data for ${user.uid}: ${rattachmentRawData.status}`);
|
console.error(`Error fetching user data for ${user.uid}: ${userRawData.status} - ${userRawData.statusText}`);
|
||||||
|
console.error(await userRawData.text());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let rattachements = (await rattachmentRawData.json()) as IRattachementData[];
|
let userData = (await userRawData.json()) as IRattachementData;
|
||||||
|
|
||||||
console.log("Got rattachements from idnot", JSON.stringify(rattachements));
|
console.log("Got userData from idnot", JSON.stringify(userData));
|
||||||
// if (!rattachements) return;
|
|
||||||
// rattachements.forEach(async (rattachement) => {
|
|
||||||
// if (rattachement.statutDuRattachement && !rattachement.deleted) {
|
|
||||||
// let officeData: IOfficeData;
|
|
||||||
|
|
||||||
// try {
|
if (userData.deleted) {
|
||||||
// officeData = (await (
|
let rattachements: any;
|
||||||
// await fetch(`${this.variables.IDNOT_API_BASE_URL + rattachement.entiteUrl}?` + searchParams, {
|
|
||||||
// method: "GET",
|
|
||||||
// })
|
|
||||||
// ).json()) as IOfficeData;
|
|
||||||
// } catch (error) {
|
|
||||||
// console.error("Error fetching office data", error);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (officeData.typeEntite.name === "office") {
|
console.log("Fetching rattachements for user", user.uid);
|
||||||
// // userData = rattachement;
|
console.log(searchParams.toString());
|
||||||
// console.log("Updated userData", JSON.stringify(rattachement));
|
try {
|
||||||
// }
|
rattachements = await fetch(`${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/personnes/${user.idNot}/rattachements?` + searchParams, {
|
||||||
// }
|
method: "GET",
|
||||||
// });
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching rattachements", error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// if (rattachements.deleted) {
|
if (rattachements.status === 404) {
|
||||||
// let rattachements: any;
|
console.error(`User ${user.uid} not found in idnot`);
|
||||||
|
return;
|
||||||
|
} else if (rattachements.status !== 200) {
|
||||||
|
console.error(`Error fetching rattachements for ${user.uid}: ${rattachements.status} - ${rattachements.statusText}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// console.log("Fetching rattachements for user", user.uid);
|
if (rattachements.totalResultCount === 0) {
|
||||||
// try {
|
console.warn("User has no valid rattachements", user.uid);
|
||||||
// rattachements = await fetch(`${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/personnes/${user.idNot}/rattachements?deleted=false` + searchParams, {
|
await this.userService.updateCheckedAt(user.uid!);
|
||||||
// method: "GET",
|
return;
|
||||||
// });
|
}
|
||||||
// } catch (error) {
|
const rattachementsResults = rattachements.result as IRattachementData[];
|
||||||
// console.error("Error fetching rattachements", error);
|
console.log("rattachementsResults", JSON.stringify(rattachementsResults));
|
||||||
// return;
|
if (!rattachementsResults) return;
|
||||||
// }
|
rattachementsResults.forEach(async (rattachement) => {
|
||||||
|
if (rattachement.statutDuRattachement && !rattachement.deleted) {
|
||||||
|
let officeData: IOfficeData;
|
||||||
|
|
||||||
// if (rattachements.status === 404) {
|
try {
|
||||||
// console.error(`User ${user.uid} not found in idnot`);
|
officeData = (await (
|
||||||
// return;
|
await fetch(`${this.variables.IDNOT_API_BASE_URL + rattachement.entiteUrl}?` + searchParams, {
|
||||||
// } else if (rattachements.status !== 200) {
|
method: "GET",
|
||||||
// console.error(`Error fetching rattachements for ${user.uid}: ${rattachements.status} - ${await rattachements.text()}`);
|
})
|
||||||
// return;
|
).json()) as IOfficeData;
|
||||||
// }
|
} catch (error) {
|
||||||
|
console.error("Error fetching office data", error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// if (rattachements.totalResultCount === 0) {
|
if (officeData.typeEntite.name === "office") {
|
||||||
// console.warn("User has no valid rattachements", user.uid);
|
userData = rattachement;
|
||||||
// await this.userService.updateCheckedAt(user.uid!);
|
console.log("Updated userData", JSON.stringify(userData));
|
||||||
// return;
|
}
|
||||||
// }
|
}
|
||||||
// const rattachementsResults = rattachements.result as IRattachementData[];
|
});
|
||||||
|
}
|
||||||
// console.log("rattachementsResults", JSON.stringify(rattachementsResults));
|
|
||||||
|
|
||||||
// if (!rattachementsResults) return;
|
|
||||||
// rattachementsResults.forEach(async (rattachement) => {
|
|
||||||
// if (rattachement.statutDuRattachement && !rattachement.deleted) {
|
|
||||||
// let officeData: IOfficeData;
|
|
||||||
|
|
||||||
// try {
|
|
||||||
// officeData = (await (
|
|
||||||
// await fetch(`${this.variables.IDNOT_API_BASE_URL + rattachement.entiteUrl}?` + searchParams, {
|
|
||||||
// method: "GET",
|
|
||||||
// })
|
|
||||||
// ).json()) as IOfficeData;
|
|
||||||
// } catch (error) {
|
|
||||||
// console.error("Error fetching office data", error);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (officeData.typeEntite.name === "office") {
|
|
||||||
// userData = rattachement;
|
|
||||||
// console.log("Updated userData", JSON.stringify(userData));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
let updates = 0;
|
let updates = 0;
|
||||||
|
|
||||||
|
|
||||||
// if (user.office_membership!.idNot !== userData.entite.ou) {
|
if (user.office_membership!.idNot !== userData.entite.ou) {
|
||||||
// updates++;
|
updates++;
|
||||||
// let officeData = (await this.officeService.get({ where: { idNot: userData.entite.ou } }))[0];
|
let officeData = (await this.officeService.get({ where: { idNot: userData.entite.ou } }))[0];
|
||||||
// if (!officeData) {
|
if (!officeData) {
|
||||||
// let officeLocationData: IOfficeLocation;
|
let officeLocationData: IOfficeLocation;
|
||||||
|
|
||||||
// try {
|
try {
|
||||||
// officeLocationData = (await (
|
officeLocationData = (await (
|
||||||
// await fetch(`${this.variables.IDNOT_API_BASE_URL + userData.entite.locationsUrl}?` + searchParams, {
|
await fetch(`${this.variables.IDNOT_API_BASE_URL + userData.entite.locationsUrl}?` + searchParams, {
|
||||||
// method: "GET",
|
method: "GET",
|
||||||
// })
|
})
|
||||||
// ).json()) as IOfficeLocation;
|
).json()) as IOfficeLocation;
|
||||||
// } catch (error) {
|
} catch (error) {
|
||||||
// console.error("Error fetching office location data", error);
|
console.error("Error fetching office location data", error);
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// const office = {
|
const office = {
|
||||||
// idNot: userData.entite.ou,
|
idNot: userData.entite.ou,
|
||||||
// name: userData.entite.denominationSociale ?? userData.entite.codeCrpcen,
|
name: userData.entite.denominationSociale ?? userData.entite.codeCrpcen,
|
||||||
// crpcen: userData.entite.codeCrpcen,
|
crpcen: userData.entite.codeCrpcen,
|
||||||
// office_status: this.getOfficeStatus(userData.entite.statutEntite.name),
|
office_status: this.getOfficeStatus(userData.entite.statutEntite.name),
|
||||||
// address: {
|
address: {
|
||||||
// address: officeLocationData.result[0]!.adrGeo4,
|
address: officeLocationData.result[0]!.adrGeo4,
|
||||||
// city: officeLocationData.result[0]!.adrGeoVille.split(" ")[0] ?? officeLocationData.result[0]!.adrGeoVille,
|
city: officeLocationData.result[0]!.adrGeoVille.split(" ")[0] ?? officeLocationData.result[0]!.adrGeoVille,
|
||||||
// zip_code: Number(officeLocationData.result[0]!.adrGeoCodePostal),
|
zip_code: Number(officeLocationData.result[0]!.adrGeoCodePostal),
|
||||||
// created_at: null,
|
created_at: null,
|
||||||
// updated_at: null,
|
updated_at: null,
|
||||||
// },
|
},
|
||||||
// created_at: null,
|
created_at: null,
|
||||||
// updated_at: null,
|
updated_at: null,
|
||||||
// };
|
};
|
||||||
// officeData = await this.officeService.create(office);
|
officeData = await this.officeService.create(office);
|
||||||
// }
|
}
|
||||||
// user.office_membership = officeData;
|
user.office_membership = officeData;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (user.contact!.email !== userData.mailRattachement) {
|
if (user.contact!.email !== userData.mailRattachement) {
|
||||||
// updates++;
|
updates++;
|
||||||
// user.contact!.email = userData.mailRattachement;
|
user.contact!.email = userData.mailRattachement;
|
||||||
// }
|
}
|
||||||
// if (user.contact!.cell_phone_number !== userData.numeroMobile) {
|
if (user.contact!.cell_phone_number !== userData.numeroMobile) {
|
||||||
// updates++;
|
updates++;
|
||||||
// user.contact!.cell_phone_number = userData.numeroMobile;
|
user.contact!.cell_phone_number = userData.numeroMobile;
|
||||||
// }
|
}
|
||||||
if (updates != 0) await this.userService.update(user.uid!, user);
|
if (updates != 0) await this.userService.update(user.uid!, user);
|
||||||
await this.userService.updateCheckedAt(user.uid!);
|
await this.userService.updateCheckedAt(user.uid!);
|
||||||
}
|
}
|
||||||
@ -589,23 +566,17 @@ export default class IdNotService extends BaseService {
|
|||||||
public async updateUsers() {
|
public async updateUsers() {
|
||||||
const usersReq = await this.userService.getUsersToBeChecked();
|
const usersReq = await this.userService.getUsersToBeChecked();
|
||||||
const users = User.hydrateArray<User>(usersReq);
|
const users = User.hydrateArray<User>(usersReq);
|
||||||
for (const user of users) {
|
users.forEach(async (user) => {
|
||||||
await this.updateUser(user.uid!);
|
await this.updateUser(user.uid!);
|
||||||
await this.delay(500);
|
});
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateOffices() {
|
public async updateOffices() {
|
||||||
const officesReq = await this.officeService.getOfficesToBeChecked();
|
const officesReq = await this.officeService.getOfficesToBeChecked();
|
||||||
const offices = Office.hydrateArray<Office>(officesReq);
|
const offices = Office.hydrateArray<Office>(officesReq);
|
||||||
console.log(`Updating ${offices.length} offices`);
|
console.log(`Updating ${offices.length} offices`);
|
||||||
for (const office of offices) {
|
offices.forEach(async (office) => {
|
||||||
await this.updateOffice(office.uid!);
|
await this.updateOffice(office.uid!);
|
||||||
await this.delay(500);
|
});
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private async delay(ms: number) {
|
|
||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user