fix data copy (#98)

This commit is contained in:
Arnaud D. Natali 2023-09-28 20:43:11 +02:00 committed by GitHub
commit 8e974ed50b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 27 deletions

View File

@ -35,13 +35,11 @@ export default class CustomerController extends ApiController {
} }
try { try {
const enrollment = await this.id360Service.getEnrollment(callbackToken); const enrollment = await this.id360Service.getEnrollment(callbackToken);
console.log("enrollment", enrollment);
if (enrollment.status !== "OK") { if (enrollment.status !== "OK") {
this.httpUnauthorized(response, "Enrollment status is not OK"); this.httpUnauthorized(response, "Enrollment status is not OK");
return; return;
} }
const customerData = await this.id360Service.getReport(enrollment.id); const customerData = await this.id360Service.getReport(enrollment.id);
console.log(customerData.external_methods.france_connect.results);
const customer = await this.customerService.get({ const customer = await this.customerService.get({
where: { where: {
contact: { contact: {
@ -55,7 +53,6 @@ export default class CustomerController extends ApiController {
contact: true, contact: true,
} }
}); });
console.log(customer);
// const contact = await this.customerService.getByEmail( // const contact = await this.customerService.getByEmail(
// customerData.external_methods.france_connect.results.france_connect_out_userinfo[0].email, // customerData.external_methods.france_connect.results.france_connect_out_userinfo[0].email,
// ); // );

View File

@ -50,10 +50,7 @@ export default class DocumentController extends ApiController {
this.httpBadRequest(response, "Missing document id"); this.httpBadRequest(response, "Missing document id");
return; return;
} }
await this.id360Service.createEnrollment(documentId!);
const enrl = await this.id360Service.createEnrollment(documentId!);
console.log(enrl)
//success //success
this.httpSuccess(response); this.httpSuccess(response);
} catch (error) { } catch (error) {

View File

@ -110,7 +110,6 @@ export default class Id360Service extends BaseService {
); );
const resJson = (await res.json()) as EnrollmentResponse; const resJson = (await res.json()) as EnrollmentResponse;
console.log(resJson.id);
return { return {
franceConnectUrl: `${this.variables.DOCAPOST_BASE_URL}static/process_ui/index.html#/enrollment/${resJson.api_key}`, franceConnectUrl: `${this.variables.DOCAPOST_BASE_URL}static/process_ui/index.html#/enrollment/${resJson.api_key}`,
processId: resJson.id, processId: resJson.id,
@ -139,10 +138,8 @@ export default class Id360Service extends BaseService {
); );
const resJson = (await res.json()) as EnrollmentResponse; const resJson = (await res.json()) as EnrollmentResponse;
console.log(resJson);
const route = await this.getRouteId(resJson.api_key); const route = await this.getRouteId(resJson.api_key);
await this.selectRoute(resJson.api_key, route); await this.selectRoute(resJson.api_key, route);
console.log(route);
await this.uploadDocument(resJson.api_key, documentUid); await this.uploadDocument(resJson.api_key, documentUid);
return await this.getReport(resJson.id); return await this.getReport(resJson.id);

View File

@ -355,39 +355,34 @@ export default class IdNotService extends BaseService {
updated_at: null, updated_at: null,
}, },
}; };
let userHydrated = User.hydrate<User>(userToAdd); let userHydrated = User.hydrate<User>(userToAdd);
const user = await this.userService.create(userHydrated); const user = await this.userService.create(userHydrated);
const userOffice = await this.officeService.getByUid(user.office_uid);
userHydrated = User.hydrate<User>(user); userHydrated = User.hydrate<User>(user);
const userOfficeHydrated = Office.hydrate<Office>(userOffice!);
const officeRoles = await this.officeRolesService.get({ const officeRoles = await this.officeRolesService.get({
where: { office: { idNot: "0000" } }, where: { office: { idNot: "0000" } },
include: { office: true, rules: true }, include: { office: true, rules: true },
}); });
const documentTypes = await this.documentTypesService.get({ where: { office: { idNot: "0000" } }, include: { office: true } });
const deedTypes = await this.deedTypesService.get({ const deedTypes = await this.deedTypesService.get({
where: { office: { idNot: "0000" } }, where: { office: { idNot: "0000" } },
include: { office: true, document_types: { include: { office: true } } }, 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<OfficeRole>(officeRoles); const officeRolesHydrated = OfficeRole.hydrateArray<OfficeRole>(officeRoles);
const documentTypesHydrated = DocumentType.hydrateArray<DocumentType>(documentTypes);
const deedTypesHydrated = DeedType.hydrateArray<DeedType>(deedTypes); const deedTypesHydrated = DeedType.hydrateArray<DeedType>(deedTypes);
const documentTypesHydrated = DocumentType.hydrateArray<DocumentType>(documentTypes);
officeRolesHydrated.forEach(async (officeRole) => {
officeRole.office.uid = user.office_uid; await this.duplicateOfficeRoles(officeRolesHydrated, userOfficeHydrated);
await this.officeRolesService.create(officeRole); const documentTypesCreated = await this.duplicateDocumentTypes(documentTypesHydrated, userOfficeHydrated);
}); await this.duplicateDeedTypes(deedTypesHydrated, documentTypesCreated, userOfficeHydrated);
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);
});
const officeRole = await this.getOfficeRole(userData.typeLien.name, user.office_uid); const officeRole = await this.getOfficeRole(userData.typeLien.name, user.office_uid);
@ -402,6 +397,38 @@ export default class IdNotService extends BaseService {
return user; return user;
} }
public async duplicateDocumentTypes(documentTypes: DocumentType[], office: Office): Promise<DocumentType[]> {
let newDocumentTypes: DocumentType[] = [];
for(const documentType of documentTypes) {
documentType.office = office;
const documentTypeCreated = await this.documentTypesService.create(documentType);
newDocumentTypes.push(DocumentType.hydrate<DocumentType>(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() { public async updateUsers() {
const usersReq = await this.userService.getUsersToBeChecked(); const usersReq = await this.userService.getUsersToBeChecked();
const users = User.hydrateArray<User>(usersReq); const users = User.hydrateArray<User>(usersReq);