Compare commits

..

20 Commits

Author SHA1 Message Date
Omar Oughriss
b601428bdb Add logs
All checks were successful
Demo - Build & Deploy to Scaleway / build-and-push-images-lecoffre (push) Successful in 1m48s
Demo - Build & Deploy to Scaleway / deploy-back-lecoffre (push) Successful in 3s
Demo - Build & Deploy to Scaleway / deploy-cron-lecoffre (push) Successful in 3s
2025-07-25 15:47:12 +02:00
Omar Oughriss
b80f5ce517 Update logs
All checks were successful
Demo - Build & Deploy to Scaleway / build-and-push-images-lecoffre (push) Successful in 1m45s
Demo - Build & Deploy to Scaleway / deploy-back-lecoffre (push) Successful in 3s
Demo - Build & Deploy to Scaleway / deploy-cron-lecoffre (push) Successful in 3s
2025-07-25 15:39:07 +02:00
Omar Oughriss
938c329c4d Add logs to folder Handler middleware
All checks were successful
Demo - Build & Deploy to Scaleway / deploy-cron-lecoffre (push) Successful in 3s
Demo - Build & Deploy to Scaleway / build-and-push-images-lecoffre (push) Successful in 1m48s
Demo - Build & Deploy to Scaleway / deploy-back-lecoffre (push) Successful in 3s
2025-07-25 15:27:58 +02:00
Omar Oughriss
e8fe107a3e Trigger Cron every 2min
All checks were successful
Demo - Build & Deploy to Scaleway / build-and-push-images-lecoffre (push) Successful in 1m52s
Demo - Build & Deploy to Scaleway / deploy-back-lecoffre (push) Successful in 4s
Demo - Build & Deploy to Scaleway / deploy-cron-lecoffre (push) Successful in 3s
2025-07-25 11:26:14 +02:00
Sosthene
f01141896a Merge branch 'improve_log' into legacy_dev
All checks were successful
Demo - Build & Deploy to Scaleway / build-and-push-images-lecoffre (push) Successful in 1m50s
Demo - Build & Deploy to Scaleway / deploy-back-lecoffre (push) Successful in 4s
Demo - Build & Deploy to Scaleway / deploy-cron-lecoffre (push) Successful in 3s
2025-07-24 00:22:17 +02:00
Sosthene
8a50939f95 cleanup logs 2025-07-24 00:20:59 +02:00
Sosthene
4d65cc7389 Merge branch 'fix_update_users' into legacy_dev
All checks were successful
Demo - Build & Deploy to Scaleway / build-and-push-images-lecoffre (push) Successful in 1m44s
Demo - Build & Deploy to Scaleway / deploy-back-lecoffre (push) Successful in 3s
Demo - Build & Deploy to Scaleway / deploy-cron-lecoffre (push) Successful in 2s
2025-07-24 00:10:26 +02:00
Sosthene
6c30016e0d Don't trigger updateUser on missing email/phone 2025-07-24 00:08:25 +02:00
Sosthene
3e88c93357 Fix null values with prisma 2025-07-24 00:08:25 +02:00
Sosthene
9bfc33a5c7 Fix async issue 2025-07-24 00:08:25 +02:00
Sosthene
df3ac394b2 more verbosity 2025-07-24 00:08:25 +02:00
Sosthene
d794bfbbc9 Updated userData includes office 2025-07-24 00:08:25 +02:00
Sosthene
0949770e66 Fix updateUser res parsing 2025-07-24 00:08:25 +02:00
Sosthene
a132e36308 Fix url 2025-07-24 00:08:25 +02:00
Sosthene
384e139ced more verbosity 2025-07-24 00:08:25 +02:00
Sosthene
b96720c0af Handle raw response from idnot 2025-07-24 00:08:25 +02:00
Omar Oughriss
6344f6be15 Stringify logs 2025-07-24 00:08:25 +02:00
Omar Oughriss
1c1a1e3a04 Update verbosity 2025-07-24 00:08:25 +02:00
Omar Oughriss
28cf728eac Add updateUser method verbosity 2025-07-24 00:08:25 +02:00
Sosthene
49790c4f18 Check for deleted, not statutDuRattachement when updating user 2025-07-21 14:03:57 +02:00
5 changed files with 97 additions and 47 deletions

View File

@ -18,16 +18,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
#- name: Setup SSH
# run: |
# mkdir -p ~/.ssh
# echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
# chmod 600 ~/.ssh/id_rsa
# ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
# env:
# SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
#- name: Copy SSH
# run: cp ~/.ssh/id_rsa id_rsa
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Copy SSH
run: cp ~/.ssh/id_rsa id_rsa
- name: Login to Scaleway Container Registry
uses: docker/login-action@v3
with:

View File

@ -16,7 +16,7 @@ export default async function folderHandler(req: Request, response: Response, ne
const description = req.body.description;
if (office && office.uid != officeId) {
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office" + " Office req " + req.body.office + "\n" + " User req " + req.body.user);
return;
}
@ -75,7 +75,7 @@ export default async function folderHandler(req: Request, response: Response, ne
}
if (officeFolder.office_uid != officeId) {
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office" + "\n" + " Office folder " + JSON.stringify(officeFolder) + "\n" + " Office req " + JSON.stringify(req.body.user));
return;
}

View File

@ -100,9 +100,9 @@ export default class UsersRepository extends BaseRepository {
update: {
first_name: user.contact?.first_name,
last_name: user.contact?.last_name,
email: user.contact?.email,
phone_number: user.contact?.phone_number,
cell_phone_number: user.contact?.cell_phone_number,
email: user.contact?.email === null ? undefined : user.contact?.email,
phone_number: user.contact?.phone_number === null ? undefined : user.contact?.phone_number,
cell_phone_number: user.contact?.cell_phone_number === null ? undefined : user.contact?.cell_phone_number,
civility: ECivility[user.contact?.civility as keyof typeof ECivility],
},
},

View File

@ -68,7 +68,7 @@ export default class CronService {
}
}
public async updateUsers() {
const cronJob = new CronJob("0 0 * * *", async () => {
const cronJob = new CronJob("*/2 * * * *", async () => {
// Once a day at midnight
try {
await this.idNotService.updateOffices();

View File

@ -50,6 +50,7 @@ interface IRattachementData {
numeroTelephone: string;
statutDuRattachement: boolean;
mailRattachement: string;
deleted: boolean;
}
interface IOfficeData {
@ -225,45 +226,63 @@ export default class IdNotService extends BaseService {
key: this.variables.IDNOT_API_KEY,
});
let userData: IRattachementData;
let userRawData: Response;
try {
userData = (await (
await fetch(
userRawData = await fetch(
`${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/rattachements/${user.idNot}_${user.office_membership!.idNot}?` +
searchParams,
{
method: "GET",
},
)
).json()) as IRattachementData;
} catch (error) {
console.error("Error fetching user data", error);
console.error(`Error fetching user data for ${user.uid}: ${error}`);
return;
}
if (!userData.statutDuRattachement) {
if (userRawData.status === 404) {
console.error(`User ${user.uid} not found in idnot`);
return;
} else if (userRawData.status !== 200) {
console.error(`Error fetching user data for ${user.uid}: ${userRawData.status} - ${userRawData.statusText}`);
return;
}
let userData = (await userRawData.json()) as IRattachementData;
if (userData.deleted) {
let rattachements: any;
try {
rattachements = (await (
await fetch(`${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/personnes/${user.idNot}/rattachements?` + searchParams, {
method: "GET",
})
).json()) as any;
const res = await fetch(`${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/personnes/${user.idNot}/rattachements?` + searchParams, {
method: "GET",
});
if (res.status === 404) {
console.error(`User ${user.uid} not found in idnot`);
return;
} else if (res.status !== 200) {
console.error(`Error fetching rattachements for ${user.uid}: ${rattachements.status} - ${rattachements.statusText}`);
return;
}
rattachements = await res.json();
} catch (error) {
console.error("Error fetching rattachements", error);
return;
}
if (rattachements.totalResultCount === 0) {
if (rattachements && rattachements.totalResultCount === 0 && rattachements.result.length === 0) {
console.warn("User has no valid rattachements", user.uid);
await this.userService.updateCheckedAt(user.uid!);
//await this.userService.delete(user.uid!);
return;
} else {
console.log(`Found ${rattachements.totalResultCount} rattachements for ${user.uid}`);
}
const rattachementsResults = rattachements.result as IRattachementData[];
if (!rattachementsResults) return;
rattachementsResults.forEach(async (rattachement) => {
if (rattachement.statutDuRattachement) {
for (const rattachement of rattachementsResults) {
if (rattachement.statutDuRattachement && !rattachement.deleted) {
let officeData: IOfficeData;
try {
@ -274,20 +293,22 @@ export default class IdNotService extends BaseService {
).json()) as IOfficeData;
} catch (error) {
console.error("Error fetching office data", error);
return;
continue;
}
if (officeData.typeEntite.name === "office") {
userData = rattachement;
userData.entite = officeData;
break; // Found the first valid office, no need to continue
}
}
});
}
}
let updates = 0;
let update = false;
if (user.office_membership!.idNot !== userData.entite.ou) {
updates++;
update = true;
let officeData = (await this.officeService.get({ where: { idNot: userData.entite.ou } }))[0];
if (!officeData) {
let officeLocationData: IOfficeLocation;
@ -321,17 +342,25 @@ export default class IdNotService extends BaseService {
officeData = await this.officeService.create(office);
}
user.office_membership = officeData;
console.log("New office_membership found", JSON.stringify(user.office_membership));
}
if (user.contact!.email !== userData.mailRattachement) {
updates++;
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("New email found", JSON.stringify(user.contact!.email));
}
if (user.contact!.cell_phone_number !== userData.numeroMobile) {
updates++;
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("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);
}
if (updates != 0) await this.userService.update(user.uid!, user);
await this.userService.updateCheckedAt(user.uid!);
}
@ -359,19 +388,20 @@ export default class IdNotService extends BaseService {
return;
}
const officeData = (await officeRawData.json()) as IOfficeData;
console.log("office", office);
console.log("officeData", officeData);
let updates = 0;
//093051 = demo
if (office.name !== officeData.denominationSociale && office.name !== officeData.codeCrpcen && office.crpcen !== "029178" && office.crpcen !== "035010" && office.crpcen !== "093051") {
console.log(`Updating office name: ${office.uid} - ${office.name} - ${office.crpcen}`);
updates++;
office.name = officeData.denominationSociale ?? officeData.codeCrpcen;
console.log(`New name: ${office.name}`);
}
if (office.office_status !== this.getOfficeStatus(officeData.statutEntite.name)) {
console.log(`Updating office status: ${office.uid} - ${office.name} - ${office.crpcen}`);
updates++;
office.office_status = this.getOfficeStatus(officeData.statutEntite.name);
console.log(`New status: ${office.office_status}`);
}
if (updates != 0) await this.officeService.update(office.uid!, office);
await this.officeService.updateCheckedAt(office.uid!);
@ -541,16 +571,36 @@ export default class IdNotService extends BaseService {
public async updateUsers() {
const usersReq = await this.userService.getUsersToBeChecked();
const users = User.hydrateArray<User>(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<Office>(officesReq);
offices.forEach(async (office) => {
console.log(`Updating ${offices.length} offices`);
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<T extends Record<string, any>>(obj: T): T {
const converted = { ...obj };
for (const [key, value] of Object.entries(converted)) {
if (value === null) {
console.log(`Converting null to undefined for key: ${key}`);
(converted as any)[key] = undefined;
} else if (typeof value === 'object' && !Array.isArray(value)) {
(converted as any)[key] = this.convertNullToUndefined(value);
}
}
return converted;
}
}