ci: docker_tag=ext - Fix: fetch entite/personne data separately v1.1.0
All checks were successful
build-and-push-ext / build_push (push) Successful in 22s

This commit is contained in:
dev4 2025-09-19 12:24:55 +00:00
parent c4d8676b55
commit 9d7c11a2b7
3 changed files with 87 additions and 10 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "lecoffre-back-mini", "name": "lecoffre-back-mini",
"version": "1.0.9", "version": "1.1.0",
"description": "Mini serveur avec une route /api/ping", "description": "Mini serveur avec une route /api/ping",
"main": "dist/server.js", "main": "dist/server.js",
"scripts": { "scripts": {

View File

@ -113,12 +113,33 @@ export class IdNotController {
Logger.info('IdNot using rattachements API with sub', { sub: payload.sub }); Logger.info('IdNot using rattachements API with sub', { sub: payload.sub });
const rattachementsJson = await IdNotService.getUserRattachements(payload.sub); const rattachementsJson = await IdNotService.getUserRattachements(payload.sub);
const results: any[] = Array.isArray(rattachementsJson?.result) ? rattachementsJson.result : []; const results: any[] = Array.isArray(rattachementsJson?.result) ? rattachementsJson.result : [];
// pick first office rattachement with a defined entite
const candidate = results.find((r: any) => r?.entite?.typeEntite?.name === 'office') || results[0]; if (results.length === 0) {
if (!candidate) {
throw new ForbiddenError('User not attached to an office'); throw new ForbiddenError('User not attached to an office');
} }
const userData = candidate;
// Get the first rattachement
const rattachement = results[0];
// Fetch entite and personne data separately if not present
let entiteData = rattachement.entite;
let personneData = rattachement.personne;
if (!entiteData && rattachement.entiteUrl) {
Logger.info('IdNot fetching entite data', { entiteUrl: rattachement.entiteUrl });
entiteData = await IdNotService.getEntiteData(rattachement.entiteUrl);
}
if (!personneData && rattachement.personneUrl) {
Logger.info('IdNot fetching personne data', { personneUrl: rattachement.personneUrl });
personneData = await IdNotService.getPersonneData(rattachement.personneUrl);
}
const userData = {
...rattachement,
entite: entiteData,
personne: personneData
};
// Log d'analyse (non sensible) pour diagnostiquer les cas de rattachement // Log d'analyse (non sensible) pour diagnostiquer les cas de rattachement
Logger.info('IdNot userData summary', { Logger.info('IdNot userData summary', {

View File

@ -231,18 +231,74 @@ export class IdNotService {
throw new ExternalServiceError('IdNot', 'Failed to fetch user data after all attempts'); throw new ExternalServiceError('IdNot', 'Failed to fetch user data after all attempts');
} }
static async getOfficeLocationData(locationsUrl: string) { static async getEntiteData(entiteUrl: string) {
const { IDNOT_API_KEY, IDNOT_API_BASE_URL } = process.env; const { IDNOT_API_KEY, IDNOT_ANNUARY_BASE_URL } = process.env;
if (!IDNOT_API_KEY || !IDNOT_API_BASE_URL) { if (!IDNOT_API_KEY || !IDNOT_ANNUARY_BASE_URL) {
throw new Error('Missing IDnot API key or base URL'); throw new Error('Missing IDnot API key or annuary base URL');
} }
const searchParams = new URLSearchParams({ const searchParams = new URLSearchParams({
key: IDNOT_API_KEY key: IDNOT_API_KEY
}); });
const locUrl = `${IDNOT_API_BASE_URL}${locationsUrl}?` + searchParams; const url = `${IDNOT_ANNUARY_BASE_URL}${entiteUrl}?${searchParams}`;
const response = await fetch(url, { method: 'GET' });
if (!response.ok) {
const text = await response.text().catch(() => '');
Logger.error('IdNot getEntiteData failed', {
url,
status: response.status,
statusText: response.statusText,
bodySnippet: text?.substring(0, 500)
});
throw new Error(`Failed to fetch entite data: ${response.status} ${response.statusText}`);
}
return response.json();
}
static async getPersonneData(personneUrl: string) {
const { IDNOT_API_KEY, IDNOT_ANNUARY_BASE_URL } = process.env;
if (!IDNOT_API_KEY || !IDNOT_ANNUARY_BASE_URL) {
throw new Error('Missing IDnot API key or annuary base URL');
}
const searchParams = new URLSearchParams({
key: IDNOT_API_KEY
});
const url = `${IDNOT_ANNUARY_BASE_URL}${personneUrl}?${searchParams}`;
const response = await fetch(url, { method: 'GET' });
if (!response.ok) {
const text = await response.text().catch(() => '');
Logger.error('IdNot getPersonneData failed', {
url,
status: response.status,
statusText: response.statusText,
bodySnippet: text?.substring(0, 500)
});
throw new Error(`Failed to fetch personne data: ${response.status} ${response.statusText}`);
}
return response.json();
}
static async getOfficeLocationData(locationsUrl: string) {
const { IDNOT_API_KEY, IDNOT_ANNUARY_BASE_URL } = process.env;
if (!IDNOT_API_KEY || !IDNOT_ANNUARY_BASE_URL) {
throw new Error('Missing IDnot API key or annuary base URL');
}
const searchParams = new URLSearchParams({
key: IDNOT_API_KEY
});
const locUrl = `${IDNOT_ANNUARY_BASE_URL}${locationsUrl}?${searchParams}`;
const locResp = await fetch(locUrl, { method: 'GET' }); const locResp = await fetch(locUrl, { method: 'GET' });
if (!locResp.ok) { if (!locResp.ok) {
const text = await locResp.text().catch(() => ''); const text = await locResp.text().catch(() => '');