diff --git a/src/app/api/idnot/UserController.ts b/src/app/api/idnot/UserController.ts index 2106276a..102af93a 100644 --- a/src/app/api/idnot/UserController.ts +++ b/src/app/api/idnot/UserController.ts @@ -37,30 +37,7 @@ export default class UserController extends ApiController { const payload = await this.authService.getUserJwtPayload(user.idNot); const accessToken = this.authService.generateAccessToken(payload); const refreshToken = this.authService.generateRefreshToken(payload); - - this.httpSuccess(response, { accessToken, refreshToken }); - } catch (error) { - console.log(error); - this.httpInternalError(response); - return; - } - } - - @Post("/api/v1/idnot/user/login/:idnot") - protected async login(req: Request, response: Response) { - try { - const id = req.params["idnot"]; - if (!id) throw new Error("idnot is required"); - - const payload = await this.authService.getUserJwtPayload(id); - if (!payload) { - this.httpNotFoundRequest(response); - return; - } - const accessToken = this.authService.generateAccessToken(payload); - const refreshToken = this.authService.generateRefreshToken(payload); - - //success + this.httpSuccess(response, { accessToken, refreshToken }); } catch (error) { console.log(error); diff --git a/src/services/common/IdNotService/IdNotService.ts b/src/services/common/IdNotService/IdNotService.ts index 079c06bb..7b403836 100644 --- a/src/services/common/IdNotService/IdNotService.ts +++ b/src/services/common/IdNotService/IdNotService.ts @@ -319,6 +319,8 @@ export default class IdNotService extends BaseService { const officeLocationData = (await ( await fetch(`${this.variables.IDNOT_API_BASE_URL + userData.entite.locationsUrl}?` + searchParams, { method: "GET" }) ).json()) as IOfficeLocation; + + const office = await this.officeService.get({ where: { idNot: decodedToken.entity_idn } }); // if(officeLocationData.result[0]!.adrGeoCodePostal.slice(0,2) !== "35") { // return null; @@ -362,28 +364,30 @@ export default class IdNotService extends BaseService { userHydrated = User.hydrate(user); const userOfficeHydrated = Office.hydrate(userOffice!); - const officeRoles = await this.officeRolesService.get({ - where: { office: { idNot: "0000" } }, - include: { office: true, rules: true }, - }); - const deedTypes = await this.deedTypesService.get({ - where: { office: { idNot: "0000" } }, - include: { office: true, document_types: { include: { office: true } } }, - }); - const documentTypes = await this.documentTypesService.get({ - where: { office: { idNot: "0000" } }, - include: { office: true }, - }); - - const officeRolesHydrated = OfficeRole.hydrateArray(officeRoles); - const deedTypesHydrated = DeedType.hydrateArray(deedTypes); - const documentTypesHydrated = DocumentType.hydrateArray(documentTypes); - - - await this.duplicateOfficeRoles(officeRolesHydrated, userOfficeHydrated); - const documentTypesCreated = await this.duplicateDocumentTypes(documentTypesHydrated, userOfficeHydrated); - await this.duplicateDeedTypes(deedTypesHydrated, documentTypesCreated, userOfficeHydrated); - + if(office.length === 0) { + const officeRoles = await this.officeRolesService.get({ + where: { office: { idNot: "0000" } }, + include: { office: true, rules: true }, + }); + const deedTypes = await this.deedTypesService.get({ + where: { office: { idNot: "0000" } }, + include: { office: true, document_types: { include: { office: true } } }, + }); + const documentTypes = await this.documentTypesService.get({ + where: { office: { idNot: "0000" } }, + include: { office: true }, + }); + + const officeRolesHydrated = OfficeRole.hydrateArray(officeRoles); + const deedTypesHydrated = DeedType.hydrateArray(deedTypes); + const documentTypesHydrated = DocumentType.hydrateArray(documentTypes); + + + await this.duplicateOfficeRoles(officeRolesHydrated, userOfficeHydrated); + const documentTypesCreated = await this.duplicateDocumentTypes(documentTypesHydrated, userOfficeHydrated); + await this.duplicateDeedTypes(deedTypesHydrated, documentTypesCreated, userOfficeHydrated); + } + const officeRole = await this.getOfficeRole(userData.typeLien.name, user.office_uid); if (officeRole) { @@ -412,6 +416,7 @@ export default class IdNotService extends BaseService { let newDocumentTypes: DocumentType[] = []; for (const document of deedType.document_types!) { const newDocumentType = documentTypes.find((documentType) => documentType.name === document.name); + if(!newDocumentType) continue; newDocumentTypes.push(newDocumentType!); }; deedType.document_types = newDocumentTypes;