Compare commits
3 Commits
5f9742f8b2
...
b82ba08f72
Author | SHA1 | Date | |
---|---|---|---|
![]() |
b82ba08f72 | ||
![]() |
f01141896a | ||
![]() |
8a50939f95 |
@ -90,7 +90,6 @@ export default class UsersRepository extends BaseRepository {
|
||||
*/
|
||||
|
||||
public async update(uid: string, user: User): Promise<Users> {
|
||||
console.log("Updating user", JSON.stringify(user));
|
||||
const updateArgs: Prisma.UsersUpdateArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
@ -142,8 +141,6 @@ export default class UsersRepository extends BaseRepository {
|
||||
};
|
||||
}
|
||||
|
||||
console.log("updateArgs", JSON.stringify(updateArgs));
|
||||
|
||||
return this.model.update({ ...updateArgs, include: { contact: true, office_membership: { include: { address: true } } } });
|
||||
}
|
||||
|
||||
|
@ -222,7 +222,6 @@ export default class IdNotService extends BaseService {
|
||||
public async updateUser(userId: string) {
|
||||
const userInfos = await this.userService.getByUid(userId, { contact: true, role: true, office_membership: true });
|
||||
const user = User.hydrate<User>(userInfos!);
|
||||
console.log("Got user from db:", JSON.stringify(user));
|
||||
const searchParams = new URLSearchParams({
|
||||
key: this.variables.IDNOT_API_KEY,
|
||||
});
|
||||
@ -251,12 +250,9 @@ export default class IdNotService extends BaseService {
|
||||
|
||||
let userData = (await userRawData.json()) as IRattachementData;
|
||||
|
||||
console.log("Got userData from idnot", JSON.stringify(userData));
|
||||
|
||||
if (userData.deleted) {
|
||||
let rattachements: any;
|
||||
|
||||
console.log("Fetching rattachements for user", user.uid);
|
||||
try {
|
||||
const res = await fetch(`${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/personnes/${user.idNot}/rattachements?` + searchParams, {
|
||||
method: "GET",
|
||||
@ -275,8 +271,6 @@ export default class IdNotService extends BaseService {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("rattachements", JSON.stringify(rattachements));
|
||||
|
||||
if (rattachements && rattachements.totalResultCount === 0 && rattachements.result.length === 0) {
|
||||
console.warn("User has no valid rattachements", user.uid);
|
||||
await this.userService.updateCheckedAt(user.uid!);
|
||||
@ -289,7 +283,6 @@ export default class IdNotService extends BaseService {
|
||||
|
||||
for (const rattachement of rattachementsResults) {
|
||||
if (rattachement.statutDuRattachement && !rattachement.deleted) {
|
||||
console.log("rattachementsResults", JSON.stringify(rattachementsResults));
|
||||
let officeData: IOfficeData;
|
||||
|
||||
try {
|
||||
@ -303,12 +296,9 @@ export default class IdNotService extends BaseService {
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log("officeData", JSON.stringify(officeData));
|
||||
|
||||
if (officeData.typeEntite.name === "office") {
|
||||
userData = rattachement;
|
||||
userData.entite = officeData;
|
||||
console.log("Updated userData", JSON.stringify(userData));
|
||||
break; // Found the first valid office, no need to continue
|
||||
}
|
||||
}
|
||||
@ -318,7 +308,6 @@ export default class IdNotService extends BaseService {
|
||||
let update = false;
|
||||
|
||||
if (user.office_membership!.idNot !== userData.entite.ou) {
|
||||
console.log("Updating user.office_membership");
|
||||
update = true;
|
||||
let officeData = (await this.officeService.get({ where: { idNot: userData.entite.ou } }))[0];
|
||||
if (!officeData) {
|
||||
@ -353,20 +342,21 @@ export default class IdNotService extends BaseService {
|
||||
officeData = await this.officeService.create(office);
|
||||
}
|
||||
user.office_membership = officeData;
|
||||
console.log("Updated user.office_membership", JSON.stringify(user.office_membership));
|
||||
console.log("New office_membership found", JSON.stringify(user.office_membership));
|
||||
}
|
||||
|
||||
if (userData.mailRattachement && (user.contact!.email === null || user.contact!.email === undefined || user.contact!.email !== userData.mailRattachement)) {
|
||||
update = true;
|
||||
user.contact!.email = userData.mailRattachement;
|
||||
console.log("Updated user.contact.email", JSON.stringify(user.contact!.email));
|
||||
console.log("New email found", JSON.stringify(user.contact!.email));
|
||||
}
|
||||
if (userData.numeroMobile && (user.contact!.cell_phone_number === null || user.contact!.cell_phone_number === undefined || user.contact!.cell_phone_number !== userData.numeroMobile)) {
|
||||
update = true;
|
||||
user.contact!.cell_phone_number = userData.numeroMobile;
|
||||
console.log("Updated user.contact.cell_phone_number", JSON.stringify(user.contact!.cell_phone_number));
|
||||
console.log("New cell phone number found", JSON.stringify(user.contact!.cell_phone_number));
|
||||
}
|
||||
if (update) {
|
||||
console.log("Found updates for user", user.uid!);
|
||||
// Filter out null values before updating to prevent Prisma errors
|
||||
const convertedUser = this.convertNullToUndefined(user);
|
||||
await this.userService.update(user.uid!, convertedUser);
|
||||
|
Loading…
x
Reference in New Issue
Block a user