diff --git a/src/app/api/customer/DocumentsController.ts b/src/app/api/customer/DocumentsController.ts index d802ba36..966b613a 100644 --- a/src/app/api/customer/DocumentsController.ts +++ b/src/app/api/customer/DocumentsController.ts @@ -24,13 +24,14 @@ export default class DocumentsController extends ApiController { protected async get(req: Request, response: Response) { try { //get query - let query: Prisma.CustomersFindManyArgs = {}; + let query: Prisma.DocumentsFindManyArgs = {}; if (req.query["q"]) { query = JSON.parse(req.query["q"] as string); } - const customerId: string = req.body.user.customerId; - const customerWhereInput: Prisma.DocumentsWhereInput ={ depositor: { uid: customerId } }; + if(query.where?.depositor) delete query.where.depositor; + if(query.where?.depositor_uid) delete query.where.depositor_uid; + const customerWhereInput: Prisma.DocumentsWhereInput = { ...query.where, depositor: { uid: customerId } }; query.where = customerWhereInput; diff --git a/src/app/middlewares/OfficeMembershipHandlers/DocumentHandler.ts b/src/app/middlewares/OfficeMembershipHandlers/DocumentHandler.ts index 9d684de0..f6b9714f 100644 --- a/src/app/middlewares/OfficeMembershipHandlers/DocumentHandler.ts +++ b/src/app/middlewares/OfficeMembershipHandlers/DocumentHandler.ts @@ -45,12 +45,12 @@ export default async function documentHandler(req: Request, response: Response, const document = await documentService.getByUidWithOffice(uid!); if (!document) { - response.sendStatus(HttpCodes.NOT_FOUND); + response.sendStatus(HttpCodes.NOT_FOUND).send("Document not found"); return; } - if (document.document_type.office.uid != officeId) { - response.sendStatus(HttpCodes.UNAUTHORIZED); + if (document.folder.office.uid != officeId) { + response.sendStatus(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office"); return; } } diff --git a/src/common/databases/seeders/seeder.ts b/src/common/databases/seeders/seeder.ts index 6c144e8e..54db8b54 100644 --- a/src/common/databases/seeders/seeder.ts +++ b/src/common/databases/seeders/seeder.ts @@ -171,15 +171,15 @@ export default async function main() { const contacts: Contact[] = [ { address: addresses[0], - first_name: "Arnaud", - last_name: "Daubernatali", - email: "arnaud.daubernatali@smart-chain.fr", + first_name: "Angela", + last_name: "Dubois", + email: "angela.dubois@gmail.com", phone_number: "06 12 34 56 78", cell_phone_number: "06 12 34 56 78", birthdate: null, created_at: new Date(), updated_at: new Date(), - civility: ECivility.MALE, + civility: ECivility.FEMALE, }, { address: addresses[1], @@ -1039,10 +1039,10 @@ export default async function main() { }, { archived_at: null, - name: "Other", + name: "Autres documents", office: offices[0], - private_description: "Other", - public_description: "Other", + private_description: "Document ajouté à l'initiative du client", + public_description: "Documents annexes pour compléter le dossier", created_at: new Date(), updated_at: new Date(), }, diff --git a/src/services/common/IdNotService/IdNotService.ts b/src/services/common/IdNotService/IdNotService.ts index 87d6c9cc..281dc7c0 100644 --- a/src/services/common/IdNotService/IdNotService.ts +++ b/src/services/common/IdNotService/IdNotService.ts @@ -33,7 +33,7 @@ interface IRattachementData { name: string; }; locationsUrl: string; - } + }; personne: { numeroTelephonePro: string; prenom: string; @@ -67,7 +67,7 @@ interface IOfficeData { }; typeEntite: { name: string; - } + }; } interface IOfficeLocation { @@ -124,7 +124,7 @@ export default class IdNotService extends BaseService { const token = await fetch(this.variables.IDNOT_BASE_URL + this.variables.IDNOT_CONNEXION_URL + "?" + query, { method: "POST" }); const decodedToken = (await token.json()) as IIdNotToken; const decodedIdToken = jwt.decode(decodedToken.id_token) as IdNotJwtPayload; - + return decodedIdToken; } @@ -152,19 +152,19 @@ export default class IdNotService extends BaseService { public async getOfficeRole(roleName: string, officeUid: string) { switch (roleName) { case EIdnotRole.NOTAIRE_TITULAIRE: - return (await this.officeRolesService.get({ where: {AND:[{ name: "Notaire" }, {office_uid: officeUid}]}}))[0]!; + return (await this.officeRolesService.get({ where: { AND: [{ name: "Notaire" }, { office_uid: officeUid }] } }))[0]!; case EIdnotRole.NOTAIRE_ASSOCIE: - return (await this.officeRolesService.get({ where: {AND:[{ name: "Notaire" }, {office_uid: officeUid}]}}))[0]!; + return (await this.officeRolesService.get({ where: { AND: [{ name: "Notaire" }, { office_uid: officeUid }] } }))[0]!; case EIdnotRole.NOTAIRE_SALARIE: - return (await this.officeRolesService.get({ where: {AND:[{ name: "Notaire" }, {office_uid: officeUid}]}}))[0]!; + return (await this.officeRolesService.get({ where: { AND: [{ name: "Notaire" }, { office_uid: officeUid }] } }))[0]!; case EIdnotRole.COLLABORATEUR: - return (await this.officeRolesService.get({ where: {AND:[{ name: "Collaborateur" }, {office_uid: officeUid}]}}))[0]!; + return (await this.officeRolesService.get({ where: { AND: [{ name: "Collaborateur" }, { office_uid: officeUid }] } }))[0]!; case EIdnotRole.SUPPLEANT: - return (await this.officeRolesService.get({ where: {AND:[{ name: "Collaborateur" }, {office_uid: officeUid}]}}))[0]!; + return (await this.officeRolesService.get({ where: { AND: [{ name: "Collaborateur" }, { office_uid: officeUid }] } }))[0]!; case EIdnotRole.ADMINISTRATEUR: - return (await this.officeRolesService.get({ where: {AND:[{ name: "Collaborateur" }, {office_uid: officeUid}]}}))[0]!; + return (await this.officeRolesService.get({ where: { AND: [{ name: "Collaborateur" }, { office_uid: officeUid }] } }))[0]!; case EIdnotRole.CURATEUR: - return (await this.officeRolesService.get({ where: {AND:[{ name: "Collaborateur" }, {office_uid: officeUid}]}}))[0]!; + return (await this.officeRolesService.get({ where: { AND: [{ name: "Collaborateur" }, { office_uid: officeUid }] } }))[0]!; default: return; } @@ -193,39 +193,37 @@ export default class IdNotService extends BaseService { const searchParams = new URLSearchParams({ key: this.variables.IDNOT_API_KEY, }); - let 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; - - if (!userData.statutDuRattachement) { - const rattachements = await (await fetch( - `${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/personnes/${user.idNot}/rattachements?` + + let 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 any; + ) + ).json()) as IRattachementData; + + if (!userData.statutDuRattachement) { + const rattachements = (await ( + await fetch(`${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/personnes/${user.idNot}/rattachements?` + searchParams, { + method: "GET", + }) + ).json()) as any; if (rattachements.totalResultCount === 0) { await this.userService.updateCheckedAt(user.uid!); //await this.userService.delete(user.uid!); return; } const rattachementsResults = rattachements.result as IRattachementData[]; - if(!rattachementsResults) return; + if (!rattachementsResults) return; rattachementsResults.forEach(async (rattachement) => { if (rattachement.statutDuRattachement) { - const officeData = await (await fetch( - `${this.variables.IDNOT_API_BASE_URL + rattachement.entiteUrl}?` + - searchParams, - { + const officeData = (await ( + await fetch(`${this.variables.IDNOT_API_BASE_URL + rattachement.entiteUrl}?` + searchParams, { method: "GET", - }, - )).json() as IOfficeData; - if(officeData.typeEntite.name === "office") { + }) + ).json()) as IOfficeData; + if (officeData.typeEntite.name === "office") { userData = rattachement; } } @@ -236,7 +234,7 @@ export default class IdNotService extends BaseService { if (user.office_membership!.idNot !== userData.entite.ou) { updates++; - let officeData = (await this.officeService.get({ where: { idNot:userData.entite.ou } }))[0]; + let officeData = (await this.officeService.get({ where: { idNot: userData.entite.ou } }))[0]; if (!officeData) { const officeLocationData = (await ( await fetch(`${this.variables.IDNOT_API_BASE_URL + userData.entite.locationsUrl}?` + searchParams, { method: "GET" }) @@ -248,7 +246,7 @@ export default class IdNotService extends BaseService { office_status: this.getOfficeStatus(userData.entite.statutEntite.name), address: { address: officeLocationData.result[0]!.adrGeo4, - city: officeLocationData.result[0]!.adrGeoVille.split(" ")[0] ?? officeLocationData.result[0]!.adrGeoVille, + city: officeLocationData.result[0]!.adrGeoVille.split(" ")[0] ?? officeLocationData.result[0]!.adrGeoVille, zip_code: Number(officeLocationData.result[0]!.adrGeoCodePostal), created_at: null, updated_at: null, @@ -279,13 +277,9 @@ export default class IdNotService extends BaseService { const searchParams = new URLSearchParams({ key: this.variables.IDNOT_API_KEY, }); - const officeRawData = await fetch( - `${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/entities/${office.idNot}?` + - searchParams, - { - method: "GET", - }, - ); + const officeRawData = await fetch(`${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/entities/${office.idNot}?` + searchParams, { + method: "GET", + }); if (officeRawData.status === 404) { await this.officeService.updateCheckedAt(office.uid!); //await this.officeService.delete(office.uid!); @@ -293,15 +287,15 @@ export default class IdNotService extends BaseService { } const officeData = (await officeRawData.json()) as IOfficeData; let updates = 0; - if(office.name !== officeData.denominationSociale) { + if (office.name !== officeData.denominationSociale) { updates++; office.name = officeData.denominationSociale; } - if(office.office_status !== this.getOfficeStatus(officeData.statutEntite.name)) { + if (office.office_status !== this.getOfficeStatus(officeData.statutEntite.name)) { updates++; office.office_status = this.getOfficeStatus(officeData.statutEntite.name); } - if(updates != 0) await this.officeService.update(office.uid!, office); + if (updates != 0) await this.officeService.update(office.uid!, office); await this.officeService.updateCheckedAt(office.uid!); } @@ -318,8 +312,7 @@ export default class IdNotService extends BaseService { }) ).json()) as IRattachementData; - - if(!userData.statutDuRattachement || userData.entite.typeEntite.name !== "office") { + if (!userData.statutDuRattachement || userData.entite.typeEntite.name !== "office") { return null; } @@ -342,7 +335,7 @@ export default class IdNotService extends BaseService { office_status: this.getOfficeStatus(userData.entite.statutEntite.name), address: { address: officeLocationData.result[0]!.adrGeo4, - city: officeLocationData.result[0]!.adrGeoVille.split(" ")[0] ?? officeLocationData.result[0]!.adrGeoVille, //officeLocationData.result[0]!.adrPostaleVille, + city: officeLocationData.result[0]!.adrGeoVille.split(" ")[0] ?? officeLocationData.result[0]!.adrGeoVille, //officeLocationData.result[0]!.adrPostaleVille, zip_code: Number(officeLocationData.result[0]!.adrGeoCodePostal), created_at: null, updated_at: null, @@ -366,9 +359,15 @@ export default class IdNotService extends BaseService { const user = await this.userService.create(userHydrated); userHydrated = User.hydrate(user); - 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: true } }); + 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 officeRolesHydrated = OfficeRole.hydrateArray(officeRoles); const documentTypesHydrated = DocumentType.hydrateArray(documentTypes); @@ -384,12 +383,15 @@ export default class IdNotService extends BaseService { }); 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); - if(officeRole) { + if (officeRole) { const officeRoleHydrated = OfficeRole.hydrate(officeRole!); userHydrated.office_role = officeRoleHydrated; await this.userService.update(user.uid, userHydrated); @@ -405,7 +407,6 @@ export default class IdNotService extends BaseService { const users = User.hydrateArray(usersReq); users.forEach(async (user) => { await this.updateUser(user.uid!); - }); } diff --git a/src/services/customer/DocumentsService/DocumentsService.ts b/src/services/customer/DocumentsService/DocumentsService.ts index fb6d925c..b162f5dc 100644 --- a/src/services/customer/DocumentsService/DocumentsService.ts +++ b/src/services/customer/DocumentsService/DocumentsService.ts @@ -24,9 +24,9 @@ export default class DocumentsService extends BaseService { * @throws {Error} If document cannot be created */ public async create(document: Document): Promise { - const otherDocumentType = await this.documentTypeService.get({ where: { name: "Other" } }); + const otherDocumentType = await this.documentTypeService.get({ where: { name: "Autres documents" } }); - if(otherDocumentType.length < 1) throw new Error("Other document type not found"); + if(otherDocumentType.length < 1) throw new Error("Autres documents document type not found"); document.document_type = otherDocumentType[0]; document.document_status = "DEPOSITED";