Compare commits

..

4 Commits

Author SHA1 Message Date
6fe5540784 Merge pull request 'preprod' (#5) from preprod into main
All checks were successful
Prod - Build & Deploy to Scaleway / build-and-push-images-lecoffre (push) Successful in 20s
Prod - Build & Deploy to Scaleway / deploy-back-lecoffre (push) Successful in 3s
Prod - Build & Deploy to Scaleway / deploy-cron-lecoffre (push) Successful in 3s
Reviewed-on: #5
2025-07-21 23:39:59 +00:00
Sosthene
5717bd2f51 Merge branch 'staging' into preprod
All checks were successful
Preprod - Build & Deploy to Scaleway / build-and-push-images-lecoffre (push) Successful in 19s
Preprod - Build & Deploy to Scaleway / deploy-back-lecoffre (push) Successful in 4s
Preprod - Build & Deploy to Scaleway / deploy-cron-lecoffre (push) Successful in 3s
2025-07-18 19:28:58 +02:00
Sosthene
c1770518a8 Merge branch 'legacy_dev' into staging
All checks were successful
Staging - Build & Deploy to Scaleway / build-and-push-images-lecoffre (push) Successful in 22s
Staging - Build & Deploy to Scaleway / deploy-back-lecoffre (push) Successful in 3s
Staging - Build & Deploy to Scaleway / deploy-cron-lecoffre (push) Successful in 3s
2025-07-18 19:27:42 +02:00
2da5e5fa51 Actualiser .github/workflows/ppd.yml
All checks were successful
Preprod - Build & Deploy to Scaleway / build-and-push-images-lecoffre (push) Successful in 17s
Preprod - Build & Deploy to Scaleway / deploy-back-lecoffre (push) Successful in 4s
Preprod - Build & Deploy to Scaleway / deploy-cron-lecoffre (push) Successful in 4s
2025-06-17 14:48:13 +00:00
3 changed files with 44 additions and 107 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

@ -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,
@ -101,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 === 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,
email: user.contact?.email,
phone_number: user.contact?.phone_number,
cell_phone_number: user.contact?.cell_phone_number,
civility: ECivility[user.contact?.civility as keyof typeof ECivility],
},
},
@ -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 } } } });
}

View File

@ -50,7 +50,6 @@ interface IRattachementData {
numeroTelephone: string;
statutDuRattachement: boolean;
mailRattachement: string;
deleted: boolean;
}
interface IOfficeData {
@ -222,74 +221,49 @@ 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,
});
let userRawData: Response;
let userData: IRattachementData;
try {
userRawData = await fetch(
userData = (await (
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 for ${user.uid}: ${error}`);
return;
}
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}`);
console.error("Error fetching user data", error);
return;
}
let userData = (await userRawData.json()) as IRattachementData;
console.log("Got userData from idnot", JSON.stringify(userData));
if (userData.deleted) {
if (!userData.statutDuRattachement) {
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",
});
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();
rattachements = (await (
await fetch(`${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/personnes/${user.idNot}/rattachements?` + searchParams, {
method: "GET",
})
).json()) as any;
} catch (error) {
console.error("Error fetching rattachements", error);
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);
if (rattachements.totalResultCount === 0) {
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;
for (const rattachement of rattachementsResults) {
if (rattachement.statutDuRattachement && !rattachement.deleted) {
console.log("rattachementsResults", JSON.stringify(rattachementsResults));
rattachementsResults.forEach(async (rattachement) => {
if (rattachement.statutDuRattachement) {
let officeData: IOfficeData;
try {
@ -300,26 +274,20 @@ export default class IdNotService extends BaseService {
).json()) as IOfficeData;
} catch (error) {
console.error("Error fetching office data", error);
continue;
return;
}
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
}
}
}
});
}
let update = false;
let updates = 0;
if (user.office_membership!.idNot !== userData.entite.ou) {
console.log("Updating user.office_membership");
update = true;
updates++;
let officeData = (await this.officeService.get({ where: { idNot: userData.entite.ou } }))[0];
if (!officeData) {
let officeLocationData: IOfficeLocation;
@ -353,24 +321,17 @@ 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));
}
if (userData.mailRattachement && (user.contact!.email === null || user.contact!.email === undefined || user.contact!.email !== userData.mailRattachement)) {
update = true;
if (user.contact!.email !== userData.mailRattachement) {
updates++;
user.contact!.email = userData.mailRattachement;
console.log("Updated user.contact.email", 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;
if (user.contact!.cell_phone_number !== userData.numeroMobile) {
updates++;
user.contact!.cell_phone_number = userData.numeroMobile;
console.log("Updated user.contact.cell_phone_number", JSON.stringify(user.contact!.cell_phone_number));
}
if (update) {
// 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!);
}
@ -398,20 +359,19 @@ 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!);
@ -581,36 +541,16 @@ export default class IdNotService extends BaseService {
public async updateUsers() {
const usersReq = await this.userService.getUsersToBeChecked();
const users = User.hydrateArray<User>(usersReq);
for (const user of users) {
users.forEach(async (user) => {
await this.updateUser(user.uid!);
}
});
}
public async updateOffices() {
const officesReq = await this.officeService.getOfficesToBeChecked();
const offices = Office.hydrateArray<Office>(officesReq);
console.log(`Updating ${offices.length} offices`);
for (const office of offices) {
offices.forEach(async (office) => {
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;
});
}
}