diff --git a/src/services/common/IdNotService/IdNotService.ts b/src/services/common/IdNotService/IdNotService.ts index ac047428..ccb5c164 100644 --- a/src/services/common/IdNotService/IdNotService.ts +++ b/src/services/common/IdNotService/IdNotService.ts @@ -371,8 +371,11 @@ export default class IdNotService extends BaseService { user.contact!.cell_phone_number = userData.numeroMobile; console.log("Updated user.contact.cell_phone_number", JSON.stringify(user.contact!.cell_phone_number)); } - console.log("updates", updates); - if (updates != 0) await this.userService.update(user.uid!, user); + if (updates != 0) { + // Filter out null values before updating to prevent Prisma errors + const convertedUser = this.convertNullToUndefined(user); + await this.userService.update(user.uid!, convertedUser); + } await this.userService.updateCheckedAt(user.uid!); } @@ -583,17 +586,35 @@ export default class IdNotService extends BaseService { public async updateUsers() { const usersReq = await this.userService.getUsersToBeChecked(); const users = User.hydrateArray(usersReq); - users.forEach(async (user) => { + for (const user of users) { await this.updateUser(user.uid!); - }); + } } public async updateOffices() { const officesReq = await this.officeService.getOfficesToBeChecked(); const offices = Office.hydrateArray(officesReq); console.log(`Updating ${offices.length} offices`); - offices.forEach(async (office) => { + for (const office of offices) { await this.updateOffice(office.uid!); - }); + } + } + + /** + * Utility function to convert null values to undefined + * This prevents Prisma from throwing errors about null values + */ + private convertNullToUndefined>(obj: T): T { + const converted = { ...obj }; + + for (const [key, value] of Object.entries(converted)) { + if (value === null) { + (converted as any)[key] = undefined; + } else if (typeof value === 'object' && !Array.isArray(value)) { + (converted as any)[key] = this.convertNullToUndefined(value); + } + } + + return converted; } }