diff --git a/package.json b/package.json index 84e273fa..bee4740a 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "cors": "^2.8.5", "express": "^4.18.2", "jsonwebtoken": "^9.0.0", - "le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.24", + "le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.29", "module-alias": "^2.2.2", "next": "^13.1.5", "node-cache": "^5.1.2", diff --git a/src/app/api/super-admin/CustomersController.ts b/src/app/api/super-admin/CustomersController.ts index 9066c904..9e4a1732 100644 --- a/src/app/api/super-admin/CustomersController.ts +++ b/src/app/api/super-admin/CustomersController.ts @@ -7,7 +7,6 @@ import { Customer } from "le-coffre-resources/dist/SuperAdmin"; import { Customers } from "@prisma/client"; import { validateOrReject } from "class-validator"; - @Controller() @Service() export default class CustomersController extends ApiController { @@ -23,7 +22,7 @@ export default class CustomersController extends ApiController { try { //get query const query = JSON.parse(req.query["q"] as string); - + //call service to get prisma entity const customersEntity = await this.customersService.get(query); @@ -49,7 +48,7 @@ export default class CustomersController extends ApiController { Customer.hydrate(customerEntity, req.body); //validate user - await validateOrReject(customerEntity, { groups: ["createCustomer"], forbidUnknownValues: false}); + await validateOrReject(customerEntity, { groups: ["createCustomer"], forbidUnknownValues: false }); //call service to get prisma entity const prismaEntityCreated = await this.customersService.create(customerEntity); @@ -81,14 +80,14 @@ export default class CustomersController extends ApiController { const customerEntity = new Customer(); Customer.hydrate(customerEntity, req.body); //validate user - await validateOrReject(customerEntity, { groups: ["updateCustomer"] , forbidUnknownValues: false}); + await validateOrReject(customerEntity, { groups: ["updateCustomer"], forbidUnknownValues: false }); //call service to get prisma entity const prismaEntityUpdated = await this.customersService.update(uid, customerEntity); //Hydrate ressource with prisma entity const customerEntityUpdated = Customer.hydrate(prismaEntityUpdated, { - strategy: "exposeAll", + strategy: "excludeAll", }); //success @@ -121,7 +120,7 @@ export default class CustomersController extends ApiController { } //Hydrate ressource with prisma entity - const customer = Customer.hydrate(customerEntity, { strategy: "exposeAll" }); + const customer = Customer.hydrate(customerEntity, { strategy: "excludeAll" }); //success this.httpSuccess(response, customer); diff --git a/src/app/api/super-admin/DeedTypesController.ts b/src/app/api/super-admin/DeedTypesController.ts index 0ef3b83b..1a5f1a0d 100644 --- a/src/app/api/super-admin/DeedTypesController.ts +++ b/src/app/api/super-admin/DeedTypesController.ts @@ -28,7 +28,7 @@ export default class DeedTypesController extends ApiController { const prismaEntity: DeedTypes[] = await this.deedTypesService.get(query); //Hydrate ressource with prisma entity - const DeedTypes = ObjectHydrate.map(DeedType, prismaEntity, { strategy: "exposeAll" }); + const DeedTypes = DeedType.map(DeedType, prismaEntity, { strategy: "excludeAll" }); //success this.httpSuccess(response, DeedTypes); @@ -56,8 +56,8 @@ export default class DeedTypesController extends ApiController { const prismaEntityCreated = await this.deedTypesService.create(deedTypeEntity); //Hydrate ressource with prisma entity - const deedTypeEntityCreated = ObjectHydrate.hydrate(new DeedType(), prismaEntityCreated, { - strategy: "exposeAll", + const deedTypeEntityCreated = DeedType.hydrate(prismaEntityCreated, { + strategy: "excludeAll", }); //success @@ -84,14 +84,14 @@ export default class DeedTypesController extends ApiController { ObjectHydrate.hydrate(deedTypeEntity, req.body); //validate deed type - await validateOrReject(deedTypeEntity, { groups: ["update"] }); + await validateOrReject(deedTypeEntity, { groups: ["updateDeedType"] }); //call service to get prisma entity const prismaEntityUpdated = await this.deedTypesService.update(uid, deedTypeEntity); //Hydrate ressource with prisma entity - const deedTypeEntityUpdated = ObjectHydrate.hydrate(new DeedType(), prismaEntityUpdated, { - strategy: "exposeAll", + const deedTypeEntityUpdated = DeedType.hydrate(prismaEntityUpdated, { + strategy: "excludeAll", }); //success @@ -125,7 +125,7 @@ export default class DeedTypesController extends ApiController { } //Hydrate ressource with prisma entity - const deedType = ObjectHydrate.hydrate(new DeedType(), deedTypeEntity, { strategy: "exposeAll" }); + const deedType = DeedType.hydrate(deedTypeEntity, { strategy: "excludeAll" }); //success this.httpSuccess(response, deedType); diff --git a/src/app/api/super-admin/DeedsController.ts b/src/app/api/super-admin/DeedsController.ts index df6a836d..382c9e7d 100644 --- a/src/app/api/super-admin/DeedsController.ts +++ b/src/app/api/super-admin/DeedsController.ts @@ -4,8 +4,7 @@ import ApiController from "@Common/system/controller-pattern/ApiController"; import DeedsService from "@Services/super-admin/DeedsService/DeedsService"; import { Service } from "typedi"; import { Deeds } from "@prisma/client"; -import Deed from "le-coffre-resources/dist/SuperAdmin"; -import ObjectHydrate from "@Common/helpers/ObjectHydrate"; +import { Deed } from "le-coffre-resources/dist/SuperAdmin"; @Controller() @Service() @@ -27,7 +26,7 @@ export default class DeedsController extends ApiController { const prismaEntity: Deeds[] = await this.deedsService.get(query); //Hydrate ressource with prisma entity - const deeds = ObjectHydrate.map(Deed, prismaEntity, { strategy: "exposeAll" }); + const deeds = Deed.map(Deed, prismaEntity, { strategy: "excludeAll" }); //success this.httpSuccess(response, deeds); @@ -53,7 +52,7 @@ export default class DeedsController extends ApiController { const deedEntity: Deeds = await this.deedsService.getByUid(uid); //Hydrate ressource with prisma entity - const deed = ObjectHydrate.hydrate(new Deed(), deedEntity, { strategy: "exposeAll" }); + const deed = Deed.hydrate(deedEntity, { strategy: "excludeAll" }); //success this.httpSuccess(response, deed); diff --git a/src/app/api/super-admin/DocumentTypesController.ts b/src/app/api/super-admin/DocumentTypesController.ts index a862e697..e5ebfa64 100644 --- a/src/app/api/super-admin/DocumentTypesController.ts +++ b/src/app/api/super-admin/DocumentTypesController.ts @@ -29,8 +29,8 @@ export default class DocumentTypesController extends ApiController { const prismaEntity: DocumentTypes[] = await this.documentTypesService.get(query); //Hydrate ressource with prisma entity - const documentTypes = ObjectHydrate.map(DocumentType, prismaEntity, { - strategy: "exposeAll", + const documentTypes = DocumentType.map(DocumentType, prismaEntity, { + strategy: "excludeAll", }); //success @@ -51,12 +51,12 @@ export default class DocumentTypesController extends ApiController { const documentTypeEntity = new DocumentType(); ObjectHydrate.hydrate(documentTypeEntity, req.body); //validate user - await validateOrReject(documentTypeEntity, { groups: ["createDocumentType"] , forbidUnknownValues: false}); + await validateOrReject(documentTypeEntity, { groups: ["createDocumentType"], forbidUnknownValues: false }); //call service to get prisma entity const prismaEntityCreated = await this.documentTypesService.create(documentTypeEntity); //Hydrate ressource with prisma entity - const userEntityCreated = ObjectHydrate.hydrate(new DocumentType(), prismaEntityCreated, { - strategy: "exposeAll", + const userEntityCreated = DocumentType.hydrate(prismaEntityCreated, { + strategy: "excludeAll", }); //success this.httpSuccess(response, userEntityCreated); @@ -87,8 +87,8 @@ export default class DocumentTypesController extends ApiController { const prismaEntityUpdated = await this.documentTypesService.update(uid, documentTypeEntity); //Hydrate ressource with prisma entity - const documentTypeEntityUpdated = ObjectHydrate.hydrate(new DocumentType(), prismaEntityUpdated, { - strategy: "exposeAll", + const documentTypeEntityUpdated = DocumentType.hydrate(prismaEntityUpdated, { + strategy: "excludeAll", }); //success @@ -119,9 +119,9 @@ export default class DocumentTypesController extends ApiController { //call service to get prisma entity documentTypeEntity = await this.documentTypesService.getByUid(uid); } - + //Hydrate ressource with prisma entity - const user = ObjectHydrate.hydrate(new DocumentType(), documentTypeEntity, { strategy: "exposeAll" }); + const user = ObjectHydrate.hydrate(new DocumentType(), documentTypeEntity, { strategy: "excludeAll" }); //success this.httpSuccess(response, user); diff --git a/src/app/api/super-admin/DocumentsController.ts b/src/app/api/super-admin/DocumentsController.ts index aa9af242..74122d25 100644 --- a/src/app/api/super-admin/DocumentsController.ts +++ b/src/app/api/super-admin/DocumentsController.ts @@ -29,7 +29,7 @@ export default class DocumentsController extends ApiController { const prismaEntity: Documents[] = await this.documentsService.get(query); //Hydrate ressource with prisma entity - const documents = ObjectHydrate.map(Document, prismaEntity, { strategy: "exposeAll" }); + const documents = Document.map(Document, prismaEntity, { strategy: "excludeAll" }); //success this.httpSuccess(response, documents); @@ -51,14 +51,14 @@ export default class DocumentsController extends ApiController { ObjectHydrate.hydrate(documentEntity, req.body); //validate document - await validateOrReject(documentEntity, { groups: ["createDocument"] , forbidUnknownValues: false}); + await validateOrReject(documentEntity, { groups: ["createDocument"], forbidUnknownValues: false }); //call service to get prisma entity const prismaEntityCreated = await this.documentsService.create(documentEntity); //Hydrate ressource with prisma entity - const documentEntityCreated = ObjectHydrate.hydrate(new Document(), prismaEntityCreated, { - strategy: "exposeAll", + const documentEntityCreated = Document.hydrate(prismaEntityCreated, { + strategy: "excludeAll", }); //success @@ -91,7 +91,7 @@ export default class DocumentsController extends ApiController { const prismaEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity); //Hydrate ressource with prisma entity - const document = ObjectHydrate.hydrate(new Document(), prismaEntityUpdated, { strategy: "exposeAll" }); + const document = Document.hydrate(prismaEntityUpdated, { strategy: "excludeAll" }); //success this.httpSuccess(response, document); @@ -116,7 +116,7 @@ export default class DocumentsController extends ApiController { const documentEntity: Documents = await this.documentsService.delete(uid); //Hydrate ressource with prisma entity - const document = ObjectHydrate.hydrate(new Document(), documentEntity, { strategy: "exposeAll" }); + const document = Document.hydrate(documentEntity, { strategy: "excludeAll" }); //success this.httpSuccess(response, document); @@ -148,7 +148,7 @@ export default class DocumentsController extends ApiController { } //Hydrate ressource with prisma entity - const document = ObjectHydrate.hydrate(new Document(), documentEntity, { strategy: "exposeAll" }); + const document = Document.hydrate(documentEntity, { strategy: "excludeAll" }); //success this.httpSuccess(response, document); diff --git a/src/app/api/super-admin/OfficeFoldersController.ts b/src/app/api/super-admin/OfficeFoldersController.ts index 100f85a3..94265252 100644 --- a/src/app/api/super-admin/OfficeFoldersController.ts +++ b/src/app/api/super-admin/OfficeFoldersController.ts @@ -26,8 +26,8 @@ export default class OfficeFoldersController extends ApiController { //call service to get prisma entity const prismaEntity: OfficeFolders[] = await this.officeFoldersService.get(query); //Hydrate ressource with prisma entity - const officeFolders = ObjectHydrate.map(OfficeFolder, prismaEntity, { - strategy: "exposeAll", enableImplicitConversion: true + const officeFolders = OfficeFolder.map(OfficeFolder, prismaEntity, { + strategy: "excludeAll", }); //success this.httpSuccess(response, officeFolders); @@ -52,8 +52,8 @@ export default class OfficeFoldersController extends ApiController { //call service to get prisma entity const prismaEntityCreated = await this.officeFoldersService.create(officeFolderEntity); //Hydrate ressource with prisma entity - const officeFolderEntityCreated = ObjectHydrate.hydrate(new OfficeFolder(), prismaEntityCreated, { - strategy: "exposeAll", enableImplicitConversion: true + const officeFolderEntityCreated = OfficeFolder.hydrate(prismaEntityCreated, { + strategy: "excludeAll", }); //success this.httpSuccess(response, officeFolderEntityCreated); @@ -84,8 +84,8 @@ export default class OfficeFoldersController extends ApiController { const prismaEntityUpdated = await this.officeFoldersService.update(uid, officeFolderEntity); //Hydrate ressource with prisma entity - const officeFolderEntityUpdated = ObjectHydrate.hydrate(new OfficeFolder(), prismaEntityUpdated, { - strategy: "exposeAll", + const officeFolderEntityUpdated = OfficeFolder.hydrate(prismaEntityUpdated, { + strategy: "excludeAll", }); //success @@ -119,7 +119,7 @@ export default class OfficeFoldersController extends ApiController { } //Hydrate ressource with prisma entity - const officeFolder = ObjectHydrate.hydrate(new OfficeFolder(), officeFolderEntity, { strategy: "exposeAll" }); + const officeFolder = OfficeFolder.hydrate(officeFolderEntity, { strategy: "excludeAll" }); //success this.httpSuccess(response, officeFolder); diff --git a/src/app/api/super-admin/OfficesController.ts b/src/app/api/super-admin/OfficesController.ts index dc4e52d8..05b3af1b 100644 --- a/src/app/api/super-admin/OfficesController.ts +++ b/src/app/api/super-admin/OfficesController.ts @@ -5,7 +5,7 @@ import OfficesService from "@Services/super-admin/OfficesService/OfficesService" import { Service } from "typedi"; import { Offices } from "@prisma/client"; import ObjectHydrate from "@Common/helpers/ObjectHydrate"; -import { Office as OfficeRessource } from "le-coffre-resources/dist/SuperAdmin"; +import { Office as OfficeResource } from "le-coffre-resources/dist/SuperAdmin"; import { validateOrReject } from "class-validator"; @Controller() @@ -25,7 +25,7 @@ export default class OfficesController extends ApiController { //call service to get prisma entity const officesEntity: Offices[] = await this.officesService.get(query); //Hydrate ressource with prisma entity - const offices = ObjectHydrate.map(OfficeRessource, officesEntity, { strategy: "exposeAll" }); + const offices = OfficeResource.map(OfficeResource, officesEntity, { strategy: "excludeAll" }); //success this.httpSuccess(response, offices); } catch (error) { @@ -40,15 +40,15 @@ export default class OfficesController extends ApiController { protected async post(req: Request, response: Response) { try { //init IUser resource with request body values - const officeEntity = new OfficeRessource(); + const officeEntity = new OfficeResource(); ObjectHydrate.hydrate(officeEntity, req.body); //validate user await validateOrReject(officeEntity, { groups: ["createOffice"], forbidUnknownValues: false }); //call service to get prisma entity const prismaEntityCreated = await this.officesService.create(officeEntity); //Hydrate ressource with prisma entity - const officeEntityCreated = ObjectHydrate.hydrate(new OfficeRessource(), prismaEntityCreated, { - strategy: "exposeAll", + const officeEntityCreated = OfficeResource.hydrate(prismaEntityCreated, { + strategy: "excludeAll", }); //success this.httpSuccess(response, officeEntityCreated); @@ -68,15 +68,15 @@ export default class OfficesController extends ApiController { throw new Error("No uid provided"); } //init IUser resource with request body values - const officeEntity = new OfficeRessource(); + const officeEntity = new OfficeResource(); ObjectHydrate.hydrate(officeEntity, req.body); //validate user await validateOrReject(officeEntity, { groups: ["update"] }); //call service to get prisma entity const prismaEntityUpdated = await this.officesService.update(uid, officeEntity); //Hydrate ressource with prisma entity - const officeEntityUpdated = ObjectHydrate.hydrate(new OfficeRessource(), prismaEntityUpdated, { - strategy: "exposeAll", + const officeEntityUpdated = OfficeResource.hydrate(prismaEntityUpdated, { + strategy: "excludeAll", }); //success this.httpSuccess(response, officeEntityUpdated); @@ -105,7 +105,7 @@ export default class OfficesController extends ApiController { officeEntity = await this.officesService.getByUid(uid); } //Hydrate ressource with prisma entity - const office = ObjectHydrate.hydrate(new OfficeRessource(), officeEntity, { strategy: "exposeAll" }); + const office = OfficeResource.hydrate(officeEntity, { strategy: "excludeAll" }); //success this.httpSuccess(response, office); } catch (error) { diff --git a/src/app/api/super-admin/UsersController.ts b/src/app/api/super-admin/UsersController.ts index 0ed184d0..13b2c8c3 100644 --- a/src/app/api/super-admin/UsersController.ts +++ b/src/app/api/super-admin/UsersController.ts @@ -25,10 +25,10 @@ export default class UsersController extends ApiController { const query = JSON.parse(req.query["q"] as string); //call service to get prisma entity - const usersEntity: Users[] = await this.usersService.get(query); - + const usersEntity = await this.usersService.get(query); + //Hydrate ressource with prisma entity - const users = User.map(User, usersEntity, {excludeExtraneousValues: true}) + const users = User.map(User, usersEntity, { strategy: "excludeAll" }); //success this.httpSuccess(response, users); @@ -49,14 +49,14 @@ export default class UsersController extends ApiController { ObjectHydrate.hydrate(userEntity, req.body); //validate user - await validateOrReject(userEntity, { groups: ["create"] }); + await validateOrReject(userEntity, { groups: ["createUser"] }); //call service to get prisma entity const prismaEntityCreated = await this.usersService.create(userEntity); //Hydrate ressource with prisma entity - const userEntityCreated = ObjectHydrate.hydrate(new User(), prismaEntityCreated, { - strategy: "exposeAll", + const userEntityCreated = User.hydrate(prismaEntityCreated, { + strategy: "excludeAll", }); //success @@ -88,8 +88,8 @@ export default class UsersController extends ApiController { const prismaEntityUpdated = await this.usersService.update(uid, userEntity); //Hydrate ressource with prisma entity - const userEntityUpdated = ObjectHydrate.hydrate(new User(), prismaEntityUpdated, { - strategy: "exposeAll", + const userEntityUpdated = User.hydrate(prismaEntityUpdated, { + strategy: "excludeAll", }); //success @@ -121,7 +121,7 @@ export default class UsersController extends ApiController { } //Hydrate ressource with prisma entity - const user = ObjectHydrate.hydrate(new User(), userEntity, { strategy: "exposeAll" }); + const user = User.hydrate(userEntity, { strategy: "excludeAll" }); //success this.httpSuccess(response, user); diff --git a/src/common/databases/seeders/seeder.ts b/src/common/databases/seeders/seeder.ts index 577511ca..35df0bbd 100644 --- a/src/common/databases/seeders/seeder.ts +++ b/src/common/databases/seeders/seeder.ts @@ -1,7 +1,7 @@ import { Addresses, Contacts, - Customers, + Customers, DeedHasDocumentTypes, DeedTypeHasDocumentTypes, DeedTypes, @@ -17,27 +17,26 @@ import { OfficeFolders, Offices, Users, - ECivility, - ECustomerStatus, - PrismaClient + ECivility, + ECustomerStatus, + PrismaClient, } from "@prisma/client"; (async () => { - const prisma = new PrismaClient(); - const existingData = await prisma.contacts.findFirst({ where: { email: "john.doe@example.com" } }); - if (existingData) { - console.log('Seed data already exists. Skipping seeding process.'); - return; - } + const existingData = await prisma.contacts.findFirst({ where: { email: "john.doe@example.com" } }); + if (existingData) { + console.log("Seed data already exists. Skipping seeding process."); + return; + } - const randomString = () => { - const chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - let result = ""; - for (let i = 10; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)]; - return result; - }; + const randomString = () => { + const chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + let result = ""; + for (let i = 10; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)]; + return result; + }; const uidCustomer1: string = randomString(); const uidCustomer2: string = randomString(); @@ -55,7 +54,6 @@ import { const uidOfficeFolder1: string = randomString(); const uidOfficeFolder2: string = randomString(); -<<<<<<< HEAD const uidOfficeFolder3: string = randomString(); const uidOfficeFolder4: string = randomString(); const uidOfficeFolder5: string = randomString(); @@ -65,11 +63,6 @@ import { const uidDeed3: string = randomString(); const uidDeed4: string = randomString(); const uidDeed5: string = randomString(); -======= - - const uidDeed1: string = randomString(); - const uidDeed2: string = randomString(); ->>>>>>> 7122ff1 (uuid --> uid) const uidDeedType1: string = randomString(); const uidDeedType2: string = randomString(); @@ -205,13 +198,8 @@ import { const officeFolders: OfficeFolders[] = [ { uid: uidOfficeFolder1, -<<<<<<< HEAD folder_number: "0001", name: "Dossier", -======= - folder_number: randomString(), - name: "0001", ->>>>>>> 7122ff1 (uuid --> uid) deed_uid: uidDeed1, status: EFolderStatus.LIVE, created_at: new Date(), @@ -222,13 +210,8 @@ import { }, { uid: uidOfficeFolder2, -<<<<<<< HEAD folder_number: "0002", name: "Dossier", -======= - folder_number: randomString(), - name: "0001", ->>>>>>> 7122ff1 (uuid --> uid) deed_uid: uidDeed2, status: EFolderStatus.LIVE, created_at: new Date(), @@ -272,31 +255,24 @@ import { office_uid: uidOffice2, description: null, archived_description: null, - } + }, ]; const deeds: Deeds[] = [ { uid: uidDeed1, deed_type_uid: uidDeedType1, -<<<<<<< HEAD created_at: new Date(), updated_at: new Date(), }, { uid: uidDeed2, deed_type_uid: uidDeedType2, -======= ->>>>>>> 7122ff1 (uuid --> uid) created_at: new Date(), updated_at: new Date(), }, { -<<<<<<< HEAD uid: uidDeed3, -======= - uid: uidDeed2, ->>>>>>> 7122ff1 (uuid --> uid) deed_type_uid: uidDeedType2, created_at: new Date(), updated_at: new Date(), @@ -312,7 +288,7 @@ import { deed_type_uid: uidDeedType2, created_at: new Date(), updated_at: new Date(), - } + }, ]; const deedTypes: DeedTypes[] = [ @@ -469,67 +445,64 @@ import { }, ]; - for (const address of addresses) { - await prisma.addresses.create({data: address}); + await prisma.addresses.create({ data: address }); } for (const contact of contacts) { await prisma.contacts.create({ data: contact }); } - - for (const office of offices) { - await prisma.offices.create({ data: office }); - } + + for (const office of offices) { + await prisma.offices.create({ data: office }); + } for (const user of users) { await prisma.users.create({ data: user }); } - for (const customer of customers) { await prisma.customers.create({ data: customer }); } - for (const deedType of deedTypes) { - await prisma.deedTypes.create({ data: deedType }); - } + for (const deedType of deedTypes) { + await prisma.deedTypes.create({ data: deedType }); + } - for (const deed of deeds) { - await prisma.deeds.create({ data: deed }); - - } - for (const officeFolder of officeFolders) { - await prisma.officeFolders.create({ data: officeFolder }); - } + for (const deed of deeds) { + await prisma.deeds.create({ data: deed }); + } + for (const officeFolder of officeFolders) { + await prisma.officeFolders.create({ data: officeFolder }); + } - for (const documentType of documentTypes) { - await prisma.documentTypes.create({ data: documentType }); - } + for (const documentType of documentTypes) { + await prisma.documentTypes.create({ data: documentType }); + } - for (const document of documents) { - await prisma.documents.create({ data: document }); - } + for (const document of documents) { + await prisma.documents.create({ data: document }); + } - for (const file of files) { - await prisma.files.create({ data: file }); - } + for (const file of files) { + await prisma.files.create({ data: file }); + } - for (const documentHistory of documentHistories) { - await prisma.documentHistory.create({ data: documentHistory }); - } + for (const documentHistory of documentHistories) { + await prisma.documentHistory.create({ data: documentHistory }); + } - for (const officeFolderHasCustomer of officeFolderHasCustomers) { - await prisma.officeFolderHasCustomers.create({ data: officeFolderHasCustomer }); - } + for (const officeFolderHasCustomer of officeFolderHasCustomers) { + await prisma.officeFolderHasCustomers.create({ data: officeFolderHasCustomer }); + } - for (const deedHasDocumentType of deedHasDocumentTypes) { - await prisma.deedHasDocumentTypes.create({ data: deedHasDocumentType }); - } + for (const deedHasDocumentType of deedHasDocumentTypes) { + await prisma.deedHasDocumentTypes.create({ data: deedHasDocumentType }); + } - for (const deedTypeHasDocumentType of deedTypeHasDocumentTypes) { - await prisma.deedTypeHasDocumentTypes.create({ data: deedTypeHasDocumentType }); - } + for (const deedTypeHasDocumentType of deedTypeHasDocumentTypes) { + await prisma.deedTypeHasDocumentTypes.create({ data: deedTypeHasDocumentType }); + } console.log(">MOCK DATA - Seeding completed!"); -})(); \ No newline at end of file +})(); diff --git a/src/common/repositories/CustomersRepository.ts b/src/common/repositories/CustomersRepository.ts index e4414f65..ddca2087 100644 --- a/src/common/repositories/CustomersRepository.ts +++ b/src/common/repositories/CustomersRepository.ts @@ -42,23 +42,23 @@ export default class CustomersRepository extends BaseRepository { status: ECustomerStatus.PENDING, contact: { create: { - first_name: customer.contact.first_name, - last_name: customer.contact.last_name, - email: customer.contact.email, - phone_number: customer.contact.phone_number, - cell_phone_number: customer.contact?.cell_phone_number, - civility: ECivility[customer.contact.civility as keyof typeof ECivility], + first_name: customer.contact!.first_name, + last_name: customer.contact!.last_name, + email: customer.contact!.email, + phone_number: customer.contact!.phone_number, + cell_phone_number: customer.contact!?.cell_phone_number, + civility: ECivility[customer.contact!.civility as keyof typeof ECivility], address: {}, }, }, }, }; - if (customer.contact.address) { + if (customer.contact!.address) { createArgs.data.contact!.create!.address!.create = { - address: customer.contact.address!.address, - zip_code: customer.contact.address!.zip_code, - city: customer.contact.address!.city, + address: customer.contact!.address!.address, + zip_code: customer.contact!.address!.zip_code, + city: customer.contact!.address!.city, }; } return this.model.create({ ...createArgs, include: { contact: true } }); @@ -83,22 +83,22 @@ export default class CustomersRepository extends BaseRepository { status: ECustomerStatus[customer.status as keyof typeof ECustomerStatus], contact: { update: { - first_name: customer.contact.first_name, - last_name: customer.contact.last_name, - email: customer.contact.email, - phone_number: customer.contact.phone_number, - cell_phone_number: customer.contact.cell_phone_number, - civility: ECivility[customer.contact.civility as keyof typeof ECivility], + first_name: customer.contact!.first_name, + last_name: customer.contact!.last_name, + email: customer.contact!.email, + phone_number: customer.contact!.phone_number, + cell_phone_number: customer.contact!.cell_phone_number, + civility: ECivility[customer.contact!.civility as keyof typeof ECivility], address: {}, }, }, }, }; - if (customer.contact.address) { + if (customer.contact!.address) { updateArgs.data.contact!.update!.address!.update = { - address: customer.contact.address!.address, - zip_code: customer.contact.address!.zip_code, - city: customer.contact.address!.city, + address: customer.contact!.address!.address, + zip_code: customer.contact!.address!.zip_code, + city: customer.contact!.address!.city, }; } return this.model.update({ ...updateArgs, include: { contact: true } }); @@ -107,16 +107,20 @@ export default class CustomersRepository extends BaseRepository { /** * @description : Find unique customer */ - public async findOneByUid(uid: string, query?: any): Promise { + public async findOneByUid( + uid: string, + query?: any, + ): Promise< + Customers & { + contact: Contacts; + } + > { const findOneArgs: Prisma.CustomersFindUniqueArgs = { where: { uid: uid, - } + }, }; - if(query) { - findOneArgs.include = query - } - const customerEntity = await this.model.findUnique(findOneArgs); + const customerEntity = await this.model.findUnique({ ...findOneArgs, include: { contact: true } }); if (!customerEntity) { throw new Error("Customer not found"); diff --git a/src/common/repositories/DeedTypesRepository.ts b/src/common/repositories/DeedTypesRepository.ts index 47ea54c1..6f38421d 100644 --- a/src/common/repositories/DeedTypesRepository.ts +++ b/src/common/repositories/DeedTypesRepository.ts @@ -34,10 +34,10 @@ export default class DeedTypesRepository extends BaseRepository { description: deedType.description, office: { connect: { - uid: deedType.office.uid, + uid: deedType.office!.uid, }, }, - } + }, }; if (deedType.deed_type_has_document_types) { createArgs.data.deed_type_has_document_types = { @@ -66,7 +66,7 @@ export default class DeedTypesRepository extends BaseRepository { archived_at: deedType.archived_at, office: { connect: { - uid: deedType.office.uid, + uid: deedType.office!.uid, }, }, }, @@ -95,10 +95,10 @@ export default class DeedTypesRepository extends BaseRepository { const findOneArgs: Prisma.DeedTypesFindUniqueArgs = { where: { uid: uid, - } + }, }; - if(query) { - findOneArgs.include = query + if (query) { + findOneArgs.include = query; } const deedTypeEntity = await this.model.findUnique(findOneArgs); diff --git a/src/common/repositories/DeedsRepository.ts b/src/common/repositories/DeedsRepository.ts index 71c37b47..dcbe3203 100644 --- a/src/common/repositories/DeedsRepository.ts +++ b/src/common/repositories/DeedsRepository.ts @@ -32,14 +32,14 @@ export default class DeedsRepository extends BaseRepository { data: { deed_type: { connect: { - uid: deed.deed_type.uid, + uid: deed.deed_type!.uid, }, }, }, }; const deedTypeWithDocumentTypes = await this.instanceDb.deedTypes.findUniqueOrThrow({ where: { - uid: deed.deed_type.uid, + uid: deed.deed_type!.uid, }, include: { deed_type_has_document_types: true }, }); diff --git a/src/common/repositories/DocumentTypesRepository.ts b/src/common/repositories/DocumentTypesRepository.ts index d29259cb..e9cb3fef 100644 --- a/src/common/repositories/DocumentTypesRepository.ts +++ b/src/common/repositories/DocumentTypesRepository.ts @@ -35,7 +35,7 @@ export default class DocumentTypesRepository extends BaseRepository { private_description: documentType.private_description, office: { connect: { - uid: documentType.office.uid, + uid: documentType.office!.uid, }, }, }, @@ -57,7 +57,7 @@ export default class DocumentTypesRepository extends BaseRepository { archived_at: documentType.archived_at, office: { connect: { - uid: documentType.office.uid, + uid: documentType.office!.uid, }, }, }, @@ -71,10 +71,10 @@ export default class DocumentTypesRepository extends BaseRepository { const findOneArgs: Prisma.DocumentTypesFindUniqueArgs = { where: { uid: uid, - } + }, }; - if(query) { - findOneArgs.include = query + if (query) { + findOneArgs.include = query; } const documentTypeEntity = await this.model.findUnique(findOneArgs); diff --git a/src/common/repositories/DocumentsRepository.ts b/src/common/repositories/DocumentsRepository.ts index e9c631f2..f48a0030 100644 --- a/src/common/repositories/DocumentsRepository.ts +++ b/src/common/repositories/DocumentsRepository.ts @@ -32,17 +32,17 @@ export default class DocumentsRepository extends BaseRepository { data: { folder: { connect: { - uid: document.folder.uid, + uid: document.folder!.uid, }, }, depositor: { connect: { - uid: document.depositor.uid, + uid: document.depositor!.uid, }, }, document_type: { connect: { - uid: document.document_type.uid, + uid: document.document_type!.uid, }, }, }, @@ -67,9 +67,9 @@ export default class DocumentsRepository extends BaseRepository { public async createMany(documents: Document[]): Promise { return this.model.createMany({ data: documents.map((document) => ({ - folder_uid: document.folder.uid!, - depositor_uid: document.depositor.uid!, - document_type_uid: document.document_type.uid!, + folder_uid: document.folder!.uid!, + depositor_uid: document.depositor!.uid!, + document_type_uid: document.document_type!.uid!, })), skipDuplicates: true, }); @@ -93,7 +93,7 @@ export default class DocumentsRepository extends BaseRepository { }, depositor: { connect: { - uid: document.depositor.uid, + uid: document.depositor!.uid, }, }, }, @@ -118,10 +118,10 @@ export default class DocumentsRepository extends BaseRepository { const findOneArgs: Prisma.DocumentsFindUniqueArgs = { where: { uid: uid, - } + }, }; - if(query) { - findOneArgs.include = query + if (query) { + findOneArgs.include = query; } const documentEntity = await this.model.findUnique(findOneArgs); if (!documentEntity) { diff --git a/src/common/repositories/FilesRepository.ts b/src/common/repositories/FilesRepository.ts index d91da097..ebc0fb77 100644 --- a/src/common/repositories/FilesRepository.ts +++ b/src/common/repositories/FilesRepository.ts @@ -2,7 +2,7 @@ import Database from "@Common/databases/database"; import BaseRepository from "@Repositories/BaseRepository"; import { Service } from "typedi"; import { Files } from "@prisma/client"; -import { File } from "le-coffre-resources/dist/SuperAdmin" +import { File } from "le-coffre-resources/dist/SuperAdmin"; @Service() export default class FilesRepository extends BaseRepository { @@ -32,16 +32,16 @@ export default class FilesRepository extends BaseRepository { data: { document: { connect: { - uid: file.document.uid - } + uid: file.document.uid, + }, }, - file_path: file.file_path + file_path: file.file_path, }, }); } /** - * @description : Update data of a file + * @description : Update data of a file */ public async update(uid: string, file: File): Promise { return this.model.update({ @@ -49,19 +49,19 @@ export default class FilesRepository extends BaseRepository { uid: uid, }, data: { - file_path: file.file_path + file_path: file.file_path, }, }); } /** - * @description : Delete a file + * @description : Delete a file */ public async delete(uid: string): Promise { return this.model.delete({ where: { uid: uid, - } + }, }); } diff --git a/src/common/repositories/OfficeFoldersHasCustomerRepository.ts b/src/common/repositories/OfficeFoldersHasCustomerRepository.ts index aa83e947..2d4b403d 100644 --- a/src/common/repositories/OfficeFoldersHasCustomerRepository.ts +++ b/src/common/repositories/OfficeFoldersHasCustomerRepository.ts @@ -23,7 +23,6 @@ export default class OfficeFoldersHasCustomerRepository extends BaseRepository { return this.model.findMany(query); } - /** * @description : Find a unique relation between an office folder and customers */ diff --git a/src/common/repositories/OfficeFoldersRepository.ts b/src/common/repositories/OfficeFoldersRepository.ts index e09ad3d2..2a752d7f 100644 --- a/src/common/repositories/OfficeFoldersRepository.ts +++ b/src/common/repositories/OfficeFoldersRepository.ts @@ -38,20 +38,20 @@ export default class OfficeFoldersRepository extends BaseRepository { create: { deed_type: { connect: { - uid: officeFolder.deed.deed_type.uid, + uid: officeFolder.deed!.deed_type!.uid, }, }, }, }, office: { connect: { - uid: officeFolder.office.uid, + uid: officeFolder.office!.uid, }, }, }, include: { office_folder_has_stakeholder: true, - } + }, }; if (officeFolder.office_folder_has_stakeholder) { createArgs.data.office_folder_has_stakeholder = { @@ -59,7 +59,7 @@ export default class OfficeFoldersRepository extends BaseRepository { data: officeFolder.office_folder_has_stakeholder.map((relation) => ({ user_stakeholder_uid: relation.user_stakeholder.uid!, })), - skipDuplicates: true + skipDuplicates: true, }, }; } @@ -85,7 +85,7 @@ export default class OfficeFoldersRepository extends BaseRepository { office_folder_has_stakeholder: true, office_folder_has_customers: true, documents: true, - } + }, }; if (officeFolder.office_folder_has_stakeholder) { updateArgs.data.office_folder_has_stakeholder = { @@ -94,9 +94,9 @@ export default class OfficeFoldersRepository extends BaseRepository { data: officeFolder.office_folder_has_stakeholder.map((relation) => ({ user_stakeholder_uid: relation.user_stakeholder.uid!, })), - skipDuplicates: true + skipDuplicates: true, }, - } + }; } if (officeFolder.office_folder_has_customers) { updateArgs.data.office_folder_has_customers = { @@ -105,20 +105,20 @@ export default class OfficeFoldersRepository extends BaseRepository { data: officeFolder.office_folder_has_customers.map((relation) => ({ customer_uid: relation.customer.uid!, })), - skipDuplicates: true + skipDuplicates: true, }, - } + }; } if (officeFolder.documents) { updateArgs.data.documents = { createMany: { data: officeFolder.documents.map((relation) => ({ - document_type_uid: relation.document_type.uid!, - depositor_uid: relation.depositor.uid! + document_type_uid: relation.document_type!.uid!, + depositor_uid: relation.depositor!.uid!, })), - skipDuplicates: true + skipDuplicates: true, }, - } + }; } return this.model.update(updateArgs); } @@ -130,10 +130,10 @@ export default class OfficeFoldersRepository extends BaseRepository { const findOneArgs: Prisma.OfficeFoldersFindUniqueArgs = { where: { uid: uid, - } + }, }; - if(query) { - findOneArgs.include = query + if (query) { + findOneArgs.include = query; } const officeFolderEntity = await this.model.findUnique(findOneArgs); diff --git a/src/common/repositories/OfficesRepository.ts b/src/common/repositories/OfficesRepository.ts index 1bd11cf0..7595a1f5 100644 --- a/src/common/repositories/OfficesRepository.ts +++ b/src/common/repositories/OfficesRepository.ts @@ -36,9 +36,9 @@ export default class OfficesRepository extends BaseRepository { crpcen: office.crpcen, address: { create: { - address: office.address.address, - zip_code: office.address.zip_code, - city: office.address.city, + address: office.address!.address, + zip_code: office.address!.zip_code, + city: office.address!.city, }, }, office_status: EOfficeStatus.DESACTIVATED, @@ -58,9 +58,9 @@ export default class OfficesRepository extends BaseRepository { name: office.name, address: { create: { - address: office.address.address, - zip_code: office.address.zip_code, - city: office.address.city, + address: office.address!.address, + zip_code: office.address!.zip_code, + city: office.address!.city, }, }, office_status: EOfficeStatus[office.office_status as keyof typeof EOfficeStatus], @@ -75,14 +75,13 @@ export default class OfficesRepository extends BaseRepository { const findOneArgs: Prisma.OfficesFindUniqueArgs = { where: { uid: uid, - } + }, }; - if(query) { - findOneArgs.include = query + if (query) { + findOneArgs.include = query; } const officeEntity = await this.model.findUnique(findOneArgs); - if (!officeEntity) { throw new Error("office not found"); } diff --git a/src/common/repositories/UsersRepository.ts b/src/common/repositories/UsersRepository.ts index 90240e3a..f59c2385 100644 --- a/src/common/repositories/UsersRepository.ts +++ b/src/common/repositories/UsersRepository.ts @@ -19,43 +19,32 @@ export default class UsersRepository extends BaseRepository { /** * @description : Find many users */ - public async findMany(query: Prisma.UsersFindManyArgs): Promise< - (Users & { - contact: Contacts; - office_membership: Offices & { - address: Addresses - }; - })[] - > { + public async findMany(query: Prisma.UsersFindManyArgs): Promise { query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows); - if (!query.include) return this.model.findMany({ ...query, include: { contact: true, office_membership: { include: { address: true } } } }); - return this.model.findMany({ ...query, include: { contact: { include: { address: true } }, office_membership: { include: { address: true } } } }); + return this.model.findMany(query); } /** * @description : Create a user */ - public async create(user: User): Promise { + public async create(user: User): Promise { const createArgs: Prisma.UsersCreateArgs = { data: { idNot: user.idNot, office_membership: { connectOrCreate: { where: { - idNot: user.office_membership.idNot, + idNot: user.office_membership!.idNot, }, create: { - idNot: user.office_membership.idNot, - name: user.office_membership.name, - crpcen: user.office_membership.crpcen, + idNot: user.office_membership!.idNot, + name: user.office_membership!.name, + crpcen: user.office_membership!.crpcen, address: { create: { - address: user.office_membership.address.address, - zip_code: user.office_membership.address.zip_code, - city: user.office_membership.address.city, + address: user.office_membership!.address!.address, + zip_code: user.office_membership!.address!.zip_code, + city: user.office_membership!.address!.city, }, }, }, @@ -63,34 +52,41 @@ export default class UsersRepository extends BaseRepository { }, contact: { create: { - first_name: user.contact.first_name, - last_name: user.contact.last_name, - email: user.contact.email, - phone_number: user.contact.phone_number, - cell_phone_number: user.contact.cell_phone_number, - civility: ECivility[user.contact.civility as keyof typeof ECivility], + first_name: user.contact!.first_name, + last_name: user.contact!.last_name, + email: user.contact!.email, + phone_number: user.contact!.phone_number, + cell_phone_number: user.contact!.cell_phone_number, + civility: ECivility[user.contact!.civility as keyof typeof ECivility], address: {}, }, }, }, }; - if (user.contact.address) { + if (user.contact!.address) { createArgs.data.contact!.create!.address!.create = { - address: user.contact.address!.address, - zip_code: user.contact.address!.zip_code, - city: user.contact.address!.city, + address: user.contact!.address.address, + zip_code: user.contact!.address.zip_code, + city: user.contact!.address.city, }; } - return this.model.create({...createArgs, include : { contact: true, office_membership: true}}); + return this.model.create({ ...createArgs, include: { contact: true, office_membership: { include: { address: true } } } }); } /** * @description : Update data from a user */ - public async update(uid: string, user: User): Promise { + public async update( + uid: string, + user: User, + ): Promise< + Users & { + contact: Contacts; + office_membership: Offices & { + address: Addresses; + }; + } + > { const updateArgs: Prisma.UsersUpdateArgs = { where: { uid: uid, @@ -100,17 +96,17 @@ export default class UsersRepository extends BaseRepository { office_membership: { connectOrCreate: { where: { - idNot: user.office_membership.idNot, + idNot: user.office_membership!.idNot, }, create: { - idNot: user.office_membership.idNot, - name: user.office_membership.name, - crpcen: user.office_membership.crpcen, + idNot: user.office_membership!.idNot, + name: user.office_membership!.name, + crpcen: user.office_membership!.crpcen, address: { create: { - address: user.office_membership.address.address, - zip_code: user.office_membership.address.zip_code, - city: user.office_membership.address.city, + address: user.office_membership!.address!.address, + zip_code: user.office_membership!.address!.zip_code, + city: user.office_membership!.address!.city, }, }, }, @@ -118,40 +114,50 @@ export default class UsersRepository extends BaseRepository { }, contact: { update: { - first_name: user.contact.first_name, - last_name: user.contact.last_name, - email: user.contact.email, - phone_number: user.contact.phone_number, - cell_phone_number: user.contact.cell_phone_number, - civility: ECivility[user.contact.civility as keyof typeof ECivility], + first_name: user.contact!.first_name, + last_name: user.contact!.last_name, + email: user.contact!.email, + phone_number: user.contact!.phone_number, + cell_phone_number: user.contact!.cell_phone_number, + civility: ECivility[user.contact!.civility as keyof typeof ECivility], address: {}, }, }, }, }; - if (user.contact.address) { + if (user.contact!.address) { updateArgs.data.contact!.update!.address!.update = { - address: user.contact.address!.address, - zip_code: user.contact.address!.zip_code, - city: user.contact.address!.city, + address: user.contact!.address!.address, + zip_code: user.contact!.address!.zip_code, + city: user.contact!.address!.city, }; } - return this.model.update({...updateArgs, include : { contact: true, office_membership: true}}); + return this.model.update({ ...updateArgs, include: { contact: true, office_membership: { include: { address: true } } } }); } /** * @description : Find one user */ - public async findOneByUid(uid: string, query?: any): Promise { + public async findOneByUid( + uid: string, + query?: any, + ): Promise< + Users & { + contact: Contacts; + office_membership: Offices & { + address: Addresses; + }; + } + > { const findOneArgs: Prisma.UsersFindUniqueArgs = { where: { uid: uid, - } + }, }; - if(query) { - findOneArgs.include = query - } - const userEntity = await this.model.findUnique(findOneArgs); + const userEntity = await this.model.findUnique({ + ...findOneArgs, + include: { contact: true, office_membership: { include: { address: true } } }, + }); if (!userEntity) { throw new Error("User not found"); diff --git a/src/services/super-admin/CustomersService/CustomersService.ts b/src/services/super-admin/CustomersService/CustomersService.ts index 10ee7231..80765051 100644 --- a/src/services/super-admin/CustomersService/CustomersService.ts +++ b/src/services/super-admin/CustomersService/CustomersService.ts @@ -1,4 +1,4 @@ -import { Contacts, Customers } from "@prisma/client"; +import { Customers, Prisma } from "@prisma/client"; import CustomersRepository from "@Repositories/CustomersRepository"; import BaseService from "@Services/BaseService"; import { Customer } from "le-coffre-resources/dist/SuperAdmin"; @@ -14,11 +14,7 @@ export default class CustomersService extends BaseService { * @description : Get all Customers * @throws {Error} If Customers cannot be get */ - public async get(query: any): Promise< - (Customers & { - contact: Contacts; - })[] - > { + public async get(query: Prisma.CustomersFindManyArgs): Promise { return this.customerRepository.findMany(query); } @@ -26,11 +22,7 @@ export default class CustomersService extends BaseService { * @description : Create a new customer * @throws {Error} If customer cannot be created */ - public async create(customerEntity: Customer): Promise< - Customers & { - contact: Contacts; - } - > { + public async create(customerEntity: Customer): Promise { return this.customerRepository.create(customerEntity); } @@ -38,14 +30,7 @@ export default class CustomersService extends BaseService { * @description : Modify a customer * @throws {Error} If customer cannot be modified */ - public async update( - uid: string, - customerEntity: Customer, - ): Promise< - Customers & { - contact: Contacts; - } - > { + public async update(uid: string, customerEntity: Customer): Promise { return this.customerRepository.update(uid, customerEntity); } diff --git a/src/services/super-admin/OfficeFoldersService/OfficeFoldersService.ts b/src/services/super-admin/OfficeFoldersService/OfficeFoldersService.ts index 06388662..78e86a84 100644 --- a/src/services/super-admin/OfficeFoldersService/OfficeFoldersService.ts +++ b/src/services/super-admin/OfficeFoldersService/OfficeFoldersService.ts @@ -28,7 +28,7 @@ export default class OfficeFoldersService extends BaseService { * @throws {Error} If folder cannot be created */ public async create(officeFolderEntity: OfficeFolder): Promise { - const deedType = await this.deedTypeService.getByUid(officeFolderEntity.deed.deed_type.uid!); + const deedType = await this.deedTypeService.getByUid(officeFolderEntity.deed!.deed_type!.uid!); if(deedType.archived_at) throw new Error('deed type is archived'); return this.officeFoldersRepository.create(officeFolderEntity); } diff --git a/src/services/super-admin/UsersService/UsersService.ts b/src/services/super-admin/UsersService/UsersService.ts index f8e914a2..fcdbf428 100644 --- a/src/services/super-admin/UsersService/UsersService.ts +++ b/src/services/super-admin/UsersService/UsersService.ts @@ -3,7 +3,7 @@ import "reflect-metadata"; import { Service } from "typedi"; import UsersRepository from "@Repositories/UsersRepository"; import User from "le-coffre-resources/dist/SuperAdmin"; -import { Contacts, Offices, Prisma, Users } from "@prisma/client"; +import {Prisma, Users } from "@prisma/client"; @Service() export default class UsersService extends BaseService { @@ -15,10 +15,7 @@ export default class UsersService extends BaseService { * @description : Get all users * @throws {Error} If users cannot be get */ - public get(query: Prisma.UsersFindManyArgs): Promise<(Users & { - contact: Contacts; - office_membership: Offices; - })[]> { + public get(query: Prisma.UsersFindManyArgs): Promise { return this.userRepository.findMany(query); } @@ -26,10 +23,7 @@ export default class UsersService extends BaseService { * @description : Create a user * @throws {Error} If user couldn't be created */ - public create(userEntity: User): Promise { + public create(userEntity: User): Promise { return this.userRepository.create(userEntity); } @@ -37,10 +31,7 @@ export default class UsersService extends BaseService { * @description : Modify a user * @throws {Error} If user modification failed */ - public update(uid: string, userEntity: User): Promise { + public update(uid: string, userEntity: User): Promise { return this.userRepository.update(uid, userEntity); } diff --git a/src/test/config/Init.ts b/src/test/config/Init.ts index 8be002d5..033fc8f1 100644 --- a/src/test/config/Init.ts +++ b/src/test/config/Init.ts @@ -11,9 +11,9 @@ export const initOffice = (office: Office): Promise => { crpcen: office.crpcen, address: { create: { - address: office.address.address, - zip_code: office.address.zip_code, - city: office.address.city, + address: office.address!.address, + zip_code: office.address!.zip_code, + city: office.address!.city, }, }, }, @@ -57,17 +57,17 @@ export const initCustomers = (customer: Customer): Promise => { status: ECustomerStatus.PENDING, contact: { create: { - first_name: customer.contact.first_name, - last_name: customer.contact.last_name, - email: customer.contact.email, - phone_number: customer.contact.phone_number, - cell_phone_number: customer.contact?.cell_phone_number, - civility: ECivility[customer.contact.civility as keyof typeof ECivility], + first_name: customer.contact!.first_name, + last_name: customer.contact!.last_name, + email: customer.contact!.email, + phone_number: customer.contact!.phone_number, + cell_phone_number: customer.contact!?.cell_phone_number, + civility: ECivility[customer.contact!.civility as keyof typeof ECivility], address: { create: { - address: customer.contact.address!.address, - zip_code: customer.contact.address!.zip_code, - city: customer.contact.address!.city, + address: customer.contact!.address!.address, + zip_code: customer.contact!.address!.zip_code, + city: customer.contact!.address!.city, }, }, }, @@ -83,17 +83,17 @@ export const initUsers = (user: User): Promise => { office_membership: { connectOrCreate: { where: { - idNot: user.office_membership.idNot, + idNot: user.office_membership!.idNot, }, create: { - idNot: user.office_membership.idNot, - name: user.office_membership.name, - crpcen: user.office_membership.crpcen, + idNot: user.office_membership!.idNot, + name: user.office_membership!.name, + crpcen: user.office_membership!.crpcen, address: { create: { - address: user.office_membership.address.address, - zip_code: user.office_membership.address.zip_code, - city: user.office_membership.address.city, + address: user.office_membership!.address!.address, + zip_code: user.office_membership!.address!.zip_code, + city: user.office_membership!.address!.city, }, }, }, @@ -101,17 +101,17 @@ export const initUsers = (user: User): Promise => { }, contact: { create: { - first_name: user.contact.first_name, - last_name: user.contact.last_name, - email: user.contact.email, - phone_number: user.contact.phone_number, - cell_phone_number: user.contact.cell_phone_number, - civility: ECivility[user.contact.civility as keyof typeof ECivility], + first_name: user.contact!.first_name, + last_name: user.contact!.last_name, + email: user.contact!.email, + phone_number: user.contact!.phone_number, + cell_phone_number: user.contact!.cell_phone_number, + civility: ECivility[user.contact!.civility as keyof typeof ECivility], address: { create: { - address: user.contact.address!.address, - zip_code: user.contact.address!.zip_code, - city: user.contact.address!.city, + address: user.contact!.address!.address, + zip_code: user.contact!.address!.zip_code, + city: user.contact!.address!.city, }, }, }, diff --git a/src/test/services/super-admin/CustomersService.test.ts b/src/test/services/super-admin/CustomersService.test.ts index 1ebccd55..84172325 100644 --- a/src/test/services/super-admin/CustomersService.test.ts +++ b/src/test/services/super-admin/CustomersService.test.ts @@ -29,18 +29,18 @@ describe("test create function", () => { // verify if customer contact is created in db const contactCreated = await prisma.contacts.findUnique({ where: { uid: customerCreated.contact_uid } }); - expect(contactCreated?.first_name).toEqual(customer.contact.first_name); - expect(contactCreated?.last_name).toEqual(customer.contact.last_name); - expect(contactCreated?.cell_phone_number).toEqual(customer.contact.cell_phone_number); - expect(contactCreated?.phone_number).toEqual(customer.contact.phone_number); - expect(contactCreated?.civility).toEqual(customer.contact.civility); - expect(contactCreated?.email).toEqual(customer.contact.email); + expect(contactCreated?.first_name).toEqual(customer.contact!.first_name); + expect(contactCreated?.last_name).toEqual(customer.contact!.last_name); + expect(contactCreated?.cell_phone_number).toEqual(customer.contact!.cell_phone_number); + expect(contactCreated?.phone_number).toEqual(customer.contact!.phone_number); + expect(contactCreated?.civility).toEqual(customer.contact!.civility); + expect(contactCreated?.email).toEqual(customer.contact!.email); // verify if customer address is created in db const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid } }); - expect(addressForContactCreated?.address).toEqual(customer.contact.address?.address); - expect(addressForContactCreated?.zip_code).toEqual(customer.contact.address?.zip_code); - expect(addressForContactCreated?.city).toEqual(customer.contact.address?.city); + expect(addressForContactCreated?.address).toEqual(customer.contact!.address?.address); + expect(addressForContactCreated?.zip_code).toEqual(customer.contact!.address?.zip_code); + expect(addressForContactCreated?.city).toEqual(customer.contact!.address?.city); }); it("should not create an customer already created", async () => { @@ -53,7 +53,7 @@ describe("test create function", () => { it("should not create an new customer with an email already created", async () => { let newCustomer: Customer = JSON.parse(JSON.stringify(customer_)); - newCustomer.contact.email = customerContact.email; + newCustomer.contact!.email = customerContact.email; // try to create a new customer with already used email async function createCustomerWithDuplicateEmail() { @@ -64,7 +64,7 @@ describe("test create function", () => { it("should not create an customer with an phone number already created", async () => { let newCustomer: Customer = JSON.parse(JSON.stringify(customer_)); - newCustomer.contact.cell_phone_number = customerContact.cell_phone_number; + newCustomer.contact!.cell_phone_number = customerContact.cell_phone_number; // try to create a new customer with already used cellphone number async function duplicateCustomer() { @@ -75,8 +75,8 @@ describe("test create function", () => { it("should create an new customer if unique attributes differ from existing customers", async () => { let newCustomer: Customer = JSON.parse(JSON.stringify(customer)); - newCustomer.contact.email = customerContact_.email; - newCustomer.contact.cell_phone_number = customerContact_.cell_phone_number; + newCustomer.contact!.email = customerContact_.email; + newCustomer.contact!.cell_phone_number = customerContact_.cell_phone_number; const customerCreated = await CustomersServiceTest.create(newCustomer); @@ -84,24 +84,24 @@ describe("test create function", () => { // verify if customer_ contact is created in db const contactCreated = await prisma.contacts.findUnique({ where: { uid: customerCreated.contact_uid } }); - expect(contactCreated?.first_name).toEqual(customer.contact.first_name); - expect(contactCreated?.last_name).toEqual(customer.contact.last_name); - expect(contactCreated?.cell_phone_number).toEqual(customer_.contact.cell_phone_number); - expect(contactCreated?.phone_number).toEqual(customer.contact.phone_number); - expect(contactCreated?.civility).toEqual(customer.contact.civility); - expect(contactCreated?.email).toEqual(customer_.contact.email); + expect(contactCreated?.first_name).toEqual(customer.contact!.first_name); + expect(contactCreated?.last_name).toEqual(customer.contact!.last_name); + expect(contactCreated?.cell_phone_number).toEqual(customer_.contact!.cell_phone_number); + expect(contactCreated?.phone_number).toEqual(customer.contact!.phone_number); + expect(contactCreated?.civility).toEqual(customer.contact!.civility); + expect(contactCreated?.email).toEqual(customer_.contact!.email); // verify if customer_ address is created in db const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid } }); - expect(addressForContactCreated?.address).toEqual(customer.contact.address?.address); - expect(addressForContactCreated?.zip_code).toEqual(customer.contact.address?.zip_code); - expect(addressForContactCreated?.city).toEqual(customer.contact.address?.city); + expect(addressForContactCreated?.address).toEqual(customer.contact!.address?.address); + expect(addressForContactCreated?.zip_code).toEqual(customer.contact!.address?.zip_code); + expect(addressForContactCreated?.city).toEqual(customer.contact!.address?.city); }); }); describe("test update function", () => { it("should update an customer's data", async () => { - const customerCreated = await prisma.customers.findFirstOrThrow({ where: { contact: { email: customer_.contact.email } } }); + const customerCreated = await prisma.customers.findFirstOrThrow({ where: { contact: { email: customer_.contact!.email } } }); // update the last customer created with his own new office and own contact const updatedCustomer = await CustomersServiceTest.update(customerCreated.uid, customer_); @@ -110,24 +110,24 @@ describe("test update function", () => { // verify if customer_ contact is created in db const existingContact = await prisma.contacts.findUnique({ where: { uid: updatedCustomer.contact_uid } }); - expect(existingContact?.first_name).toEqual(customer_.contact.first_name); - expect(existingContact?.last_name).toEqual(customer_.contact.last_name); - expect(existingContact?.cell_phone_number).toEqual(customer_.contact.cell_phone_number); - expect(existingContact?.phone_number).toEqual(customer_.contact.phone_number); - expect(existingContact?.civility).toEqual(customer_.contact.civility); - expect(existingContact?.email).toEqual(customer_.contact.email); + expect(existingContact?.first_name).toEqual(customer_.contact!.first_name); + expect(existingContact?.last_name).toEqual(customer_.contact!.last_name); + expect(existingContact?.cell_phone_number).toEqual(customer_.contact!.cell_phone_number); + expect(existingContact?.phone_number).toEqual(customer_.contact!.phone_number); + expect(existingContact?.civility).toEqual(customer_.contact!.civility); + expect(existingContact?.email).toEqual(customer_.contact!.email); // verify if customer_ address is created in db const addressForExistingContact = await prisma.addresses.findUnique({ where: { uid: existingContact?.address_uid } }); - expect(addressForExistingContact?.address).toEqual(customer_.contact.address?.address); - expect(addressForExistingContact?.zip_code).toEqual(customer_.contact.address?.zip_code); - expect(addressForExistingContact?.city).toEqual(customer_.contact.address?.city); + expect(addressForExistingContact?.address).toEqual(customer_.contact!.address?.address); + expect(addressForExistingContact?.zip_code).toEqual(customer_.contact!.address?.zip_code); + expect(addressForExistingContact?.city).toEqual(customer_.contact!.address?.city); }); it("should not update an customer with an email already used", async () => { - const customerUid = (await prisma.customers.findFirstOrThrow({ where: { contact: { email: customer_.contact.email } } })).uid; + const customerUid = (await prisma.customers.findFirstOrThrow({ where: { contact: { email: customer_.contact!.email } } })).uid; let updatedCustomer: Customer = JSON.parse(JSON.stringify(customer_)); - updatedCustomer.contact.email = customerContact.email; + updatedCustomer.contact!.email = customerContact.email; // try to create a new customer with already used email async function updateCustomerWithDuplicateEmail() { @@ -137,9 +137,9 @@ describe("test update function", () => { }); it("should not update an customer with an phone number already used", async () => { - const customerUid = (await prisma.customers.findFirstOrThrow({ where: { contact: { email: customer_.contact.email } } })).uid; + const customerUid = (await prisma.customers.findFirstOrThrow({ where: { contact: { email: customer_.contact!.email } } })).uid; let updatedCustomer: Customer = JSON.parse(JSON.stringify(customer_)); - updatedCustomer.contact.cell_phone_number = customerContact.cell_phone_number; + updatedCustomer.contact!.cell_phone_number = customerContact.cell_phone_number; // try to create a new customer with already used email async function updateCustomerWithDuplicateEmail() { diff --git a/src/test/services/super-admin/DeedService.test.ts b/src/test/services/super-admin/DeedService.test.ts index 58511ebb..6e67e3fd 100644 --- a/src/test/services/super-admin/DeedService.test.ts +++ b/src/test/services/super-admin/DeedService.test.ts @@ -29,7 +29,7 @@ afterAll(async () => { describe("test create function", () => { it("should not create a new deed if deed type is unknown", async () => { let deedWithoutDeedTypeUid: Deed = JSON.parse(JSON.stringify(deed)); - deedWithoutDeedTypeUid.deed_type.uid = "random uid"; + deedWithoutDeedTypeUid.deed_type!.uid = "random uid"; // try to create a new deed with unknown deed type async function createDeedWithUnknownDeedType() { await DeedServiceTest.create(deedWithoutDeedTypeUid); @@ -39,7 +39,7 @@ describe("test create function", () => { it("should create a new deed based on existing deed type", async () => { let deedWithDeedTypeUid: Deed = JSON.parse(JSON.stringify(deed)); - deedWithDeedTypeUid.deed_type.uid = deedType.uid; + deedWithDeedTypeUid.deed_type!.uid = deedType.uid; const deedCreated = await DeedServiceTest.create(deedWithDeedTypeUid); expect(deedCreated.deed_type_uid).toEqual(deedType.uid); @@ -53,7 +53,7 @@ describe("test create function", () => { it("should create a the same deed based on existing deed type", async () => { let deedWithDeedTypeUid: Deed = JSON.parse(JSON.stringify(deed)); - deedWithDeedTypeUid.deed_type.uid = deedType.uid; + deedWithDeedTypeUid.deed_type!.uid = deedType.uid; const deedCreated = await DeedServiceTest.create(deedWithDeedTypeUid); expect(deedCreated.deed_type_uid).toEqual(deedType.uid); @@ -61,7 +61,7 @@ describe("test create function", () => { it("should not create a new deed based on archivated deed type", async () => { let deedArchivated: Deed = JSON.parse(JSON.stringify(deed)); - deedArchivated.deed_type.uid = deedType.uid; + deedArchivated.deed_type!.uid = deedType.uid; await prisma.deedTypes.update({ where: { uid: deedType.uid }, diff --git a/src/test/services/super-admin/DeedTypesService.test.ts b/src/test/services/super-admin/DeedTypesService.test.ts index 5cf11f7f..af923ad1 100644 --- a/src/test/services/super-admin/DeedTypesService.test.ts +++ b/src/test/services/super-admin/DeedTypesService.test.ts @@ -29,7 +29,7 @@ afterAll(async () => { describe("test create function", () => { it("should not create a new deed type if office is unknown", async () => { let deedTypeWithoutOfficeUid: DeedType = JSON.parse(JSON.stringify(deedType)); - deedTypeWithoutOfficeUid.office.uid = "random uid"; + deedTypeWithoutOfficeUid.office!.uid = "random uid"; // try to create a new deed type with unknown office async function createDeedTypeWithUnknownOffice() { await DeedTypeServiceTest.create(deedTypeWithoutOfficeUid); @@ -48,7 +48,7 @@ describe("test create function", () => { it("should not create a new deed type with a name already used for a given office", async () => { let deedTypeWithSameNameAndOffice: DeedType = JSON.parse(JSON.stringify(deedType_)); - deedTypeWithSameNameAndOffice.office = office; + deedTypeWithSameNameAndOffice.office! = office; deedTypeWithSameNameAndOffice.name = deedType.name; async function createDeedTypeWithSameNameAndOffice() { @@ -59,7 +59,7 @@ describe("test create function", () => { it("should create the same deed type for a different office", async () => { let deedTypeDuplicatedForNewOffice: DeedType = JSON.parse(JSON.stringify(deedType)); - deedTypeDuplicatedForNewOffice.office = office_; + deedTypeDuplicatedForNewOffice.office! = office_; const deedTypeCreated = await DeedTypeServiceTest.create(deedTypeDuplicatedForNewOffice); @@ -89,10 +89,10 @@ describe("test update function", () => { expect(deedTypeCreated.name).toEqual(deedType_.name); expect(deedTypeCreated.description).toEqual(deedType.description); expect(deedTypeCreated.archived_at).toBeNull(); - expect(deedTypeCreated.office_uid).toEqual(deedType.office.uid); + expect(deedTypeCreated.office_uid).toEqual(deedType.office!.uid); let deedTypeWithNewDescription: DeedType = JSON.parse(JSON.stringify(deedType_)); - deedTypeWithNewDescription.office = office; + deedTypeWithNewDescription.office! = office; // update the last deed type created with his the right description const deedTypeUpdated = await DeedTypeServiceTest.update(deedTypeCreated.uid, deedTypeWithNewDescription); @@ -100,13 +100,13 @@ describe("test update function", () => { expect(deedTypeUpdated.name).toEqual(deedType_.name); expect(deedTypeUpdated.description).toEqual(deedType_.description); expect(deedTypeUpdated.archived_at).toBeNull(); - expect(deedTypeUpdated.office_uid).toEqual(deedType.office.uid); + expect(deedTypeUpdated.office_uid).toEqual(deedType.office!.uid); }); it("should not update a deed type name with an already used name for given office", async () => { const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uid: office.uid } })).uid; let deedTypeWithSameNameAndOffice: DeedType = JSON.parse(JSON.stringify(deedType_)); - deedTypeWithSameNameAndOffice.office.uid = office.uid; + deedTypeWithSameNameAndOffice.office!.uid = office.uid; deedTypeWithSameNameAndOffice.name = deedType.name; // update the last deed type created with his the right description @@ -119,7 +119,7 @@ describe("test update function", () => { it("should not update a deed type office membership if the office already have this document type", async () => { const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uid: office.uid } })).uid; let deedTypeWithSameNameAndOffice: DeedType = JSON.parse(JSON.stringify(deedType_)); - deedTypeWithSameNameAndOffice.office.uid = office.uid; + deedTypeWithSameNameAndOffice.office!.uid = office.uid; deedTypeWithSameNameAndOffice.name = deedType.name; // try to duplicate deed type in a given office @@ -143,7 +143,7 @@ describe("test update function", () => { expect(deedTypeUpdated.name).toEqual(deedType_.name); expect(deedTypeUpdated.description).toEqual(deedType_.description); expect(deedTypeUpdated.archived_at).toBeNull(); - expect(deedTypeUpdated.office_uid).toEqual(deedType_.office.uid); + expect(deedTypeUpdated.office_uid).toEqual(deedType_.office!.uid); }); it("should archivate a deed type", async () => { @@ -152,7 +152,7 @@ describe("test update function", () => { expect(deedTypeCreated.name).toEqual(deedType_.name); expect(deedTypeCreated.description).toEqual(deedType_.description); expect(deedTypeCreated.archived_at).toBeNull(); - expect(deedTypeCreated.office_uid).toEqual(deedType_.office.uid); + expect(deedTypeCreated.office_uid).toEqual(deedType_.office!.uid); let deedTypeArchivated: DeedType = JSON.parse(JSON.stringify(deedType_)); const currentDate = new Date(Date.now()); @@ -173,7 +173,7 @@ describe("test update function", () => { expect(deedTypeCreated.name).toEqual(deedType_.name); expect(deedTypeCreated.description).toEqual(deedType_.description); expect(deedTypeCreated.archived_at).not.toBeNull(); - expect(deedTypeCreated.office_uid).toEqual(deedType_.office.uid); + expect(deedTypeCreated.office_uid).toEqual(deedType_.office!.uid); // unarchivate a deed type by giving a null date for archivated_at attribute const deedTypeUpdated = await DeedTypeServiceTest.update(deedTypeCreated.uid, deedType_); diff --git a/src/test/services/super-admin/DocumentTypesService.test.ts b/src/test/services/super-admin/DocumentTypesService.test.ts index e8c88d17..b6d98045 100644 --- a/src/test/services/super-admin/DocumentTypesService.test.ts +++ b/src/test/services/super-admin/DocumentTypesService.test.ts @@ -27,7 +27,7 @@ afterAll(async () => { describe("test create function", () => { it("should not create a new document type if office is unknown", async () => { let documentTypeWithoutOfficeUid: DocumentType = JSON.parse(JSON.stringify(documentType)); - documentTypeWithoutOfficeUid.office.uid = "random uid"; + documentTypeWithoutOfficeUid.office!.uid = "random uid"; // try to create a new document type with unknown office async function createDocumentTypeWithUnknownOffice() { await DocumentTypesServiceTest.create(documentTypeWithoutOfficeUid); @@ -37,7 +37,7 @@ describe("test create function", () => { it("should create a new document type", async () => { let documentTypeWithOfficeUid: DocumentType = JSON.parse(JSON.stringify(documentType)); - documentTypeWithOfficeUid.office.uid = office.uid; + documentTypeWithOfficeUid.office!.uid = office.uid; const documentTypeCreated = await DocumentTypesServiceTest.create(documentTypeWithOfficeUid); expect(documentTypeCreated.name).toEqual(documentType.name); @@ -49,7 +49,7 @@ describe("test create function", () => { it("should not create a new document type with a name already used for a given office", async () => { let documentTypeWithSameNameAndOffice: DocumentType = JSON.parse(JSON.stringify(documentType_)); - documentTypeWithSameNameAndOffice.office.uid = office.uid; + documentTypeWithSameNameAndOffice.office!.uid = office.uid; documentTypeWithSameNameAndOffice.name = documentType.name; async function createDocumentTypeWithSameNameAndOffice() { @@ -60,7 +60,7 @@ describe("test create function", () => { it("should create the same document type for a different office", async () => { let documentTypeDuplicatedForNewOffice: DocumentType = JSON.parse(JSON.stringify(documentType)); - documentTypeDuplicatedForNewOffice.office.uid = office_.uid; + documentTypeDuplicatedForNewOffice.office!.uid = office_.uid; const documentTypeCreated = await DocumentTypesServiceTest.create(documentTypeDuplicatedForNewOffice); @@ -73,7 +73,7 @@ describe("test create function", () => { it("should create a new document type version with a different name for a given office", async () => { let documentTypeWithSameDescription: DocumentType = JSON.parse(JSON.stringify(documentType)); - documentTypeWithSameDescription.office.uid = office.uid; + documentTypeWithSameDescription.office!.uid = office.uid; documentTypeWithSameDescription.name = documentType_.name; const documentTypeCreated = await DocumentTypesServiceTest.create(documentTypeWithSameDescription); @@ -98,7 +98,7 @@ describe("test update function", () => { expect(documentTypeCreated.office_uid).toEqual(office.uid); let documentTypeWithNewDescription: DocumentType = JSON.parse(JSON.stringify(documentType_)); - documentTypeWithNewDescription.office.uid = office.uid; + documentTypeWithNewDescription.office!.uid = office.uid; // update the last document type created with his the right descriptions const documentTypeUpdated = await DocumentTypesServiceTest.update(documentTypeCreated.uid, documentTypeWithNewDescription); @@ -114,7 +114,7 @@ describe("test update function", () => { await prisma.documentTypes.findFirstOrThrow({ where: { name: documentType_.name, office_uid: office.uid } }) ).uid; let documentTypeWithSameNameAndOffice: DocumentType = JSON.parse(JSON.stringify(documentType_)); - documentTypeWithSameNameAndOffice.office.uid = office.uid; + documentTypeWithSameNameAndOffice.office!.uid = office.uid; documentTypeWithSameNameAndOffice.name = documentType.name; // update the last document type created with his the right description @@ -129,7 +129,7 @@ describe("test update function", () => { await prisma.documentTypes.findFirstOrThrow({ where: { name: documentType_.name, office_uid: office.uid } }) ).uid; let documentTypeWithSameNameAndOffice: DocumentType = JSON.parse(JSON.stringify(documentType_)); - documentTypeWithSameNameAndOffice.office.uid = office.uid; + documentTypeWithSameNameAndOffice.office!.uid = office.uid; documentTypeWithSameNameAndOffice.name = documentType.name; // try to duplicate document type in a given office @@ -151,7 +151,7 @@ describe("test update function", () => { expect(documentTypeCreated.office_uid).toEqual(office.uid); let documentTypeTransferedToNewOffice: DocumentType = JSON.parse(JSON.stringify(documentType_)); - documentTypeTransferedToNewOffice.office.uid = office_.uid; + documentTypeTransferedToNewOffice.office!.uid = office_.uid; // update the last document type updated with a new office membership const documentTypeUpdated = await DocumentTypesServiceTest.update(documentTypeCreated.uid, documentTypeTransferedToNewOffice); @@ -175,7 +175,7 @@ describe("test update function", () => { expect(documentTypeCreated.office_uid).toEqual(office_.uid); let documentTypeArchivated: DocumentType = JSON.parse(JSON.stringify(documentType_)); - documentTypeArchivated.office.uid = office_.uid; + documentTypeArchivated.office!.uid = office_.uid; const currentDate = new Date(Date.now()); documentTypeArchivated.archived_at = currentDate; // archivate a document type by giving a non null date for archivated_at attribute @@ -199,7 +199,7 @@ describe("test update function", () => { expect(documentTypeCreated.office_uid).toEqual(office_.uid); let documentTypeUnarchivated: DocumentType = JSON.parse(JSON.stringify(documentType_)); - documentTypeUnarchivated.office.uid = office_.uid; + documentTypeUnarchivated.office!.uid = office_.uid; // unarchivate a document type by giving a null date for archivated_at attribute const documentTypeUpdated = await DocumentTypesServiceTest.update(documentTypeCreated.uid, documentTypeUnarchivated); diff --git a/src/test/services/super-admin/OfficeFolderService.test.ts b/src/test/services/super-admin/OfficeFolderService.test.ts index 6011f30e..8c8394a1 100644 --- a/src/test/services/super-admin/OfficeFolderService.test.ts +++ b/src/test/services/super-admin/OfficeFolderService.test.ts @@ -38,7 +38,7 @@ afterAll(async () => { describe("test create function", () => { it("should not create a new office folder if deed type is unknown", async () => { let officeFolderWithoutDeedTypeUid: OfficeFolder = JSON.parse(JSON.stringify(officeFolder)); - officeFolderWithoutDeedTypeUid.deed.deed_type.uid = "random uid"; + officeFolderWithoutDeedTypeUid.deed!.deed_type!.uid = "random uid"; // try to create a new deed with unknown deed type async function createOfficeFolderWithUnknownDeedType() { await OfficeFolderServiceTest.create(officeFolderWithoutDeedTypeUid); @@ -65,8 +65,8 @@ describe("test create function", () => { expect(officeFolderCreated.description).toEqual(officeFolder.description); expect(officeFolderCreated.archived_description).toEqual(null); expect(officeFolderCreated.status).toEqual("LIVE"); - expect(officeFolderCreated.office_uid).toEqual(officeFolder.office.uid); - expect(deedCreated.deed_type_uid).toEqual(officeFolder.deed.deed_type.uid); + expect(officeFolderCreated.office_uid).toEqual(officeFolder.office!.uid); + expect(deedCreated.deed_type_uid).toEqual(officeFolder.deed!.deed_type!.uid); }); it("should contains stakeholders", async () => { diff --git a/src/test/services/super-admin/UsersService.test.ts b/src/test/services/super-admin/UsersService.test.ts index a4ce6f06..a6255c4c 100644 --- a/src/test/services/super-admin/UsersService.test.ts +++ b/src/test/services/super-admin/UsersService.test.ts @@ -29,31 +29,31 @@ describe("test create function", () => { // verify if user contact is created in db const contactCreated = await prisma.contacts.findUnique({ where: { uid: userCreated.contact_uid } }); - expect(contactCreated?.first_name).toEqual(user.contact.first_name); - expect(contactCreated?.last_name).toEqual(user.contact.last_name); - expect(contactCreated?.cell_phone_number).toEqual(user.contact.cell_phone_number); - expect(contactCreated?.phone_number).toEqual(user.contact.phone_number); - expect(contactCreated?.civility).toEqual(user.contact.civility); - expect(contactCreated?.email).toEqual(user.contact.email); + expect(contactCreated?.first_name).toEqual(user.contact!.first_name); + expect(contactCreated?.last_name).toEqual(user.contact!.last_name); + expect(contactCreated?.cell_phone_number).toEqual(user.contact!.cell_phone_number); + expect(contactCreated?.phone_number).toEqual(user.contact!.phone_number); + expect(contactCreated?.civility).toEqual(user.contact!.civility); + expect(contactCreated?.email).toEqual(user.contact!.email); // verify if user address is created in db const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid } }); - expect(addressForContactCreated?.address).toEqual(user.contact.address?.address); - expect(addressForContactCreated?.zip_code).toEqual(user.contact.address?.zip_code); - expect(addressForContactCreated?.city).toEqual(user.contact.address?.city); + expect(addressForContactCreated?.address).toEqual(user.contact!.address?.address); + expect(addressForContactCreated?.zip_code).toEqual(user.contact!.address?.zip_code); + expect(addressForContactCreated?.city).toEqual(user.contact!.address?.city); // verify if user office is created in db const officeCreated = await prisma.offices.findUnique({ where: { uid: userCreated.office_uid } }); - expect(officeCreated?.idNot).toEqual(user.office_membership.idNot); - expect(officeCreated?.name).toEqual(user.office_membership.name); - expect(officeCreated?.crpcen).toEqual(user.office_membership.crpcen); + expect(officeCreated?.idNot).toEqual(user.office_membership!!.idNot); + expect(officeCreated?.name).toEqual(user.office_membership!!.name); + expect(officeCreated?.crpcen).toEqual(user.office_membership!!.crpcen); expect(officeCreated?.office_status).toEqual("DESACTIVATED"); // verify if user office's address is created in db const addressForOfficeCreated = await prisma.addresses.findUnique({ where: { uid: officeCreated?.address_uid } }); - expect(addressForOfficeCreated?.address).toEqual(user.office_membership.address.address); - expect(addressForOfficeCreated?.zip_code).toEqual(user.office_membership.address.zip_code); - expect(addressForOfficeCreated?.city).toEqual(user.office_membership.address.city); + expect(addressForOfficeCreated?.address).toEqual(user.office_membership!.address!.address); + expect(addressForOfficeCreated?.zip_code).toEqual(user.office_membership!.address!.zip_code); + expect(addressForOfficeCreated?.city).toEqual(user.office_membership!.address!.city); }); it("should not create an user already created", async () => { @@ -66,7 +66,7 @@ describe("test create function", () => { it("should not create an new user with an email already created", async () => { let newUser: User = JSON.parse(JSON.stringify(user_)); - newUser.contact.email = userContact.email; + newUser.contact!.email = userContact.email; // try to create a new user with already used email async function createUserWithDuplicateEmail() { @@ -77,7 +77,7 @@ describe("test create function", () => { it("should not create an user with an phone number already created", async () => { let newUser: User = JSON.parse(JSON.stringify(user_)); - newUser.contact.cell_phone_number = userContact.cell_phone_number; + newUser.contact!.cell_phone_number = userContact.cell_phone_number; // try to create a new user with already used cellphone number async function duplicateUser() { @@ -89,8 +89,8 @@ describe("test create function", () => { it("should create an new user if unique attributes differ from existing users", async () => { let newUser: User = JSON.parse(JSON.stringify(user)); newUser.idNot = user_.idNot; - newUser.contact.email = userContact_.email; - newUser.contact.cell_phone_number = userContact_.cell_phone_number; + newUser.contact!.email = userContact_.email; + newUser.contact!.cell_phone_number = userContact_.cell_phone_number; const userCreated = await UsersServiceTest.create(newUser); @@ -98,24 +98,24 @@ describe("test create function", () => { // verify if user_ contact is created in db const contactCreated = await prisma.contacts.findUnique({ where: { uid: userCreated.contact_uid } }); - expect(contactCreated?.first_name).toEqual(user.contact.first_name); - expect(contactCreated?.last_name).toEqual(user.contact.last_name); - expect(contactCreated?.cell_phone_number).toEqual(user_.contact.cell_phone_number); - expect(contactCreated?.phone_number).toEqual(user.contact.phone_number); - expect(contactCreated?.civility).toEqual(user.contact.civility); - expect(contactCreated?.email).toEqual(user_.contact.email); + expect(contactCreated?.first_name).toEqual(user.contact!.first_name); + expect(contactCreated?.last_name).toEqual(user.contact!.last_name); + expect(contactCreated?.cell_phone_number).toEqual(user_.contact!.cell_phone_number); + expect(contactCreated?.phone_number).toEqual(user.contact!.phone_number); + expect(contactCreated?.civility).toEqual(user.contact!.civility); + expect(contactCreated?.email).toEqual(user_.contact!.email); // verify if user_ address is created in db const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid } }); - expect(addressForContactCreated?.address).toEqual(user.contact.address?.address); - expect(addressForContactCreated?.zip_code).toEqual(user.contact.address?.zip_code); - expect(addressForContactCreated?.city).toEqual(user.contact.address?.city); + expect(addressForContactCreated?.address).toEqual(user.contact!.address?.address); + expect(addressForContactCreated?.zip_code).toEqual(user.contact!.address?.zip_code); + expect(addressForContactCreated?.city).toEqual(user.contact!.address?.city); // verify if user joined the existing office const officeJoined = await prisma.offices.findUnique({ where: { uid: userCreated.office_uid } }); - expect(officeJoined?.idNot).toEqual(user.office_membership.idNot); - expect(officeJoined?.name).toEqual(user.office_membership.name); - expect(officeJoined?.crpcen).toEqual(user.office_membership.crpcen); + expect(officeJoined?.idNot).toEqual(user.office_membership!!.idNot); + expect(officeJoined?.name).toEqual(user.office_membership!!.name); + expect(officeJoined?.crpcen).toEqual(user.office_membership!!.crpcen); expect(officeJoined?.office_status).toEqual("DESACTIVATED"); }); }); @@ -125,9 +125,9 @@ describe("test update function", () => { const userCreated = await prisma.users.findFirstOrThrow({ where: { idNot: user_.idNot } }); const officeJoined = await prisma.offices.findUnique({ where: { uid: userCreated.office_uid } }); - expect(officeJoined?.idNot).toEqual(user.office_membership.idNot); - expect(officeJoined?.name).toEqual(user.office_membership.name); - expect(officeJoined?.crpcen).toEqual(user.office_membership.crpcen); + expect(officeJoined?.idNot).toEqual(user.office_membership!!.idNot); + expect(officeJoined?.name).toEqual(user.office_membership!!.name); + expect(officeJoined?.crpcen).toEqual(user.office_membership!!.crpcen); expect(officeJoined?.office_status).toEqual("DESACTIVATED"); // update the last user created with his own new office and own contact @@ -137,37 +137,37 @@ describe("test update function", () => { // verify if user_ contact is created in db const existingContact = await prisma.contacts.findUnique({ where: { uid: updatedUser.contact_uid } }); - expect(existingContact?.first_name).toEqual(user_.contact.first_name); - expect(existingContact?.last_name).toEqual(user_.contact.last_name); - expect(existingContact?.cell_phone_number).toEqual(user_.contact.cell_phone_number); - expect(existingContact?.phone_number).toEqual(user_.contact.phone_number); - expect(existingContact?.civility).toEqual(user_.contact.civility); - expect(existingContact?.email).toEqual(user_.contact.email); + expect(existingContact?.first_name).toEqual(user_.contact!.first_name); + expect(existingContact?.last_name).toEqual(user_.contact!.last_name); + expect(existingContact?.cell_phone_number).toEqual(user_.contact!.cell_phone_number); + expect(existingContact?.phone_number).toEqual(user_.contact!.phone_number); + expect(existingContact?.civility).toEqual(user_.contact!.civility); + expect(existingContact?.email).toEqual(user_.contact!.email); // verify if user_ address is created in db const addressForExistingContact = await prisma.addresses.findUnique({ where: { uid: existingContact?.address_uid } }); - expect(addressForExistingContact?.address).toEqual(user_.contact.address?.address); - expect(addressForExistingContact?.zip_code).toEqual(user_.contact.address?.zip_code); - expect(addressForExistingContact?.city).toEqual(user_.contact.address?.city); + expect(addressForExistingContact?.address).toEqual(user_.contact!.address?.address); + expect(addressForExistingContact?.zip_code).toEqual(user_.contact!.address?.zip_code); + expect(addressForExistingContact?.city).toEqual(user_.contact!.address?.city); // verify if user_ joined the new office const officeCreated = await prisma.offices.findUnique({ where: { uid: updatedUser.office_uid } }); - expect(officeCreated?.idNot).toEqual(user_.office_membership.idNot); - expect(officeCreated?.name).toEqual(user_.office_membership.name); - expect(officeCreated?.crpcen).toEqual(user_.office_membership.crpcen); + expect(officeCreated?.idNot).toEqual(user_.office_membership!.idNot); + expect(officeCreated?.name).toEqual(user_.office_membership!.name); + expect(officeCreated?.crpcen).toEqual(user_.office_membership!.crpcen); expect(officeCreated?.office_status).toEqual("DESACTIVATED"); // verify is user_ office's address is created in db const addressForOfficeCreated = await prisma.addresses.findUnique({ where: { uid: officeCreated?.address_uid } }); - expect(addressForOfficeCreated?.address).toEqual(user_.office_membership.address.address); - expect(addressForOfficeCreated?.zip_code).toEqual(user_.office_membership.address.zip_code); - expect(addressForOfficeCreated?.city).toEqual(user_.office_membership.address.city); + expect(addressForOfficeCreated?.address).toEqual(user_.office_membership!.address!.address); + expect(addressForOfficeCreated?.zip_code).toEqual(user_.office_membership!.address!.zip_code); + expect(addressForOfficeCreated?.city).toEqual(user_.office_membership!.address!.city); }); it("should not update an user with an email already used", async () => { const userUid = (await prisma.users.findFirstOrThrow({ where: { idNot: user_.idNot } })).uid; let updatedUser: User = JSON.parse(JSON.stringify(user_)); - updatedUser.contact.email = userContact.email; + updatedUser.contact!.email = userContact.email; // try to create a new user with already used email async function updateUserWithDuplicateEmail() { @@ -179,7 +179,7 @@ describe("test update function", () => { it("should not update an user with an phone number already used", async () => { const userUid = (await prisma.users.findFirstOrThrow({ where: { idNot: user_.idNot } })).uid; let updatedUser: User = JSON.parse(JSON.stringify(user_)); - updatedUser.contact.cell_phone_number = userContact.cell_phone_number; + updatedUser.contact!.cell_phone_number = userContact.cell_phone_number; // try to create a new user with already used email async function updateUserWithDuplicateEmail() {