diff --git a/src/app/api/id360/CustomerController.ts b/src/app/api/id360/CustomerController.ts index 49abb8fb..fc234983 100644 --- a/src/app/api/id360/CustomerController.ts +++ b/src/app/api/id360/CustomerController.ts @@ -35,13 +35,11 @@ export default class CustomerController extends ApiController { } try { const enrollment = await this.id360Service.getEnrollment(callbackToken); - console.log("enrollment", enrollment); if (enrollment.status !== "OK") { this.httpUnauthorized(response, "Enrollment status is not OK"); return; } const customerData = await this.id360Service.getReport(enrollment.id); - console.log(customerData.external_methods.france_connect.results); const customer = await this.customerService.get({ where: { contact: { @@ -55,7 +53,6 @@ export default class CustomerController extends ApiController { contact: true, } }); - console.log(customer); // const contact = await this.customerService.getByEmail( // customerData.external_methods.france_connect.results.france_connect_out_userinfo[0].email, // ); diff --git a/src/app/api/id360/DocumentController.ts b/src/app/api/id360/DocumentController.ts index 73cd6d5b..1b8d43ca 100644 --- a/src/app/api/id360/DocumentController.ts +++ b/src/app/api/id360/DocumentController.ts @@ -50,10 +50,7 @@ export default class DocumentController extends ApiController { this.httpBadRequest(response, "Missing document id"); return; } - - const enrl = await this.id360Service.createEnrollment(documentId!); - console.log(enrl) - + await this.id360Service.createEnrollment(documentId!); //success this.httpSuccess(response); } catch (error) { diff --git a/src/services/common/Id360Service/Id360Service.ts b/src/services/common/Id360Service/Id360Service.ts index 531bd1e0..0271396d 100644 --- a/src/services/common/Id360Service/Id360Service.ts +++ b/src/services/common/Id360Service/Id360Service.ts @@ -110,7 +110,6 @@ export default class Id360Service extends BaseService { ); const resJson = (await res.json()) as EnrollmentResponse; - console.log(resJson.id); return { franceConnectUrl: `${this.variables.DOCAPOST_BASE_URL}static/process_ui/index.html#/enrollment/${resJson.api_key}`, processId: resJson.id, @@ -139,10 +138,8 @@ export default class Id360Service extends BaseService { ); const resJson = (await res.json()) as EnrollmentResponse; - console.log(resJson); const route = await this.getRouteId(resJson.api_key); await this.selectRoute(resJson.api_key, route); - console.log(route); await this.uploadDocument(resJson.api_key, documentUid); return await this.getReport(resJson.id); diff --git a/src/services/common/IdNotService/IdNotService.ts b/src/services/common/IdNotService/IdNotService.ts index 281dc7c0..079c06bb 100644 --- a/src/services/common/IdNotService/IdNotService.ts +++ b/src/services/common/IdNotService/IdNotService.ts @@ -355,39 +355,34 @@ export default class IdNotService extends BaseService { updated_at: null, }, }; + let userHydrated = User.hydrate(userToAdd); const user = await this.userService.create(userHydrated); + const userOffice = await this.officeService.getByUid(user.office_uid); 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 documentTypes = await this.documentTypesService.get({ where: { office: { idNot: "0000" } }, include: { office: 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 documentTypesHydrated = DocumentType.hydrateArray(documentTypes); const deedTypesHydrated = DeedType.hydrateArray(deedTypes); + const documentTypesHydrated = DocumentType.hydrateArray(documentTypes); - officeRolesHydrated.forEach(async (officeRole) => { - officeRole.office.uid = user.office_uid; - await this.officeRolesService.create(officeRole); - }); - documentTypesHydrated.forEach(async (documentType) => { - documentType.office!.uid = user.office_uid; - await this.documentTypesService.create(documentType); - }); - deedTypesHydrated.forEach(async (deedType) => { - deedType.office!.uid = user.office_uid; - deedType.document_types!.forEach((documentType) => { - documentType.office!.uid = user.office_uid; - }); - await this.deedTypesService.create(deedType); - }); + + 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); @@ -402,6 +397,38 @@ export default class IdNotService extends BaseService { return user; } + public async duplicateDocumentTypes(documentTypes: DocumentType[], office: Office): Promise { + let newDocumentTypes: DocumentType[] = []; + for(const documentType of documentTypes) { + documentType.office = office; + const documentTypeCreated = await this.documentTypesService.create(documentType); + newDocumentTypes.push(DocumentType.hydrate(documentTypeCreated)); + }; + return newDocumentTypes; + } + + public async duplicateDeedTypes(deedTypes: DeedType[], documentTypes: DocumentType[], office: Office) { + for (const deedType of deedTypes) { + let newDocumentTypes: DocumentType[] = []; + for (const document of deedType.document_types!) { + const newDocumentType = documentTypes.find((documentType) => documentType.name === document.name); + newDocumentTypes.push(newDocumentType!); + }; + deedType.document_types = newDocumentTypes; + deedType.office = office; + await this.deedTypesService.create(deedType); + }; + } + + public async duplicateOfficeRoles(officeRoles: OfficeRole[], office: Office){ + for(const officeRole of officeRoles) { + officeRole.office = office; + await this.officeRolesService.create(officeRole); + }; + } + + + public async updateUsers() { const usersReq = await this.userService.getUsersToBeChecked(); const users = User.hydrateArray(usersReq);