Fix/objectHydratation (#28)
- fix hydratation of resources with prisma entities
This commit is contained in:
commit
d29e066495
@ -22,10 +22,9 @@
|
||||
"start": "tsc && node ./dist/entries/App.js",
|
||||
"api:start": "npm run migrate && npm run start",
|
||||
"dev": "nodemon -V",
|
||||
"build:test": "tsc && mocha ./dist/entries/Test.js",
|
||||
"format": "prettier --write src",
|
||||
"migrate": "npx prisma migrate deploy",
|
||||
"migrate:test": "dotenv -e .env.test -- npx prisma migrate deploy",
|
||||
"migrate": "npx prisma migrate deploy",
|
||||
"docker:up:test": "docker-compose -f docker-compose-test.yml up -d",
|
||||
"docker:down:test": "docker-compose down",
|
||||
"test": "tsc && npm run docker:up:test && npm run migrate:test && dotenv -e .env.test -- jest -i --verbose ./dist/test/* && npm run docker:down:test"
|
||||
@ -48,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",
|
||||
|
@ -3,7 +3,6 @@ import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import CustomersService from "@Services/super-admin/CustomersService/CustomersService";
|
||||
import { Service } from "typedi";
|
||||
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
||||
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { Customers } from "@prisma/client";
|
||||
import { validateOrReject } from "class-validator";
|
||||
@ -25,10 +24,10 @@ export default class CustomersController extends ApiController {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
|
||||
//call service to get prisma entity
|
||||
const customersEntity: Customers[] = await this.customersService.get(query);
|
||||
const customersEntity = await this.customersService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const customers = ObjectHydrate.map<Customer>(Customer, customersEntity, { strategy: "exposeAll" });
|
||||
const customers = Customer.map<Customer>(Customer, customersEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, customers);
|
||||
@ -46,17 +45,17 @@ export default class CustomersController extends ApiController {
|
||||
try {
|
||||
//init IUser resource with request body values
|
||||
const customerEntity = new Customer();
|
||||
ObjectHydrate.hydrate(customerEntity, req.body);
|
||||
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);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const customerEntityCreated = ObjectHydrate.hydrate<Customer>(new Customer(), prismaEntityCreated, {
|
||||
strategy: "exposeAll",
|
||||
const customerEntityCreated = Customer.hydrate<Customer>(prismaEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
@ -79,16 +78,16 @@ export default class CustomersController extends ApiController {
|
||||
}
|
||||
//init IUser resource with request body values
|
||||
const customerEntity = new Customer();
|
||||
ObjectHydrate.hydrate(customerEntity, req.body);
|
||||
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 = ObjectHydrate.hydrate<Customer>(new Customer(), prismaEntityUpdated, {
|
||||
strategy: "exposeAll",
|
||||
const customerEntityUpdated = Customer.hydrate<Customer>(prismaEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
@ -121,7 +120,7 @@ export default class CustomersController extends ApiController {
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const customer = ObjectHydrate.hydrate<Customer>(new Customer(), customerEntity, { strategy: "exposeAll" });
|
||||
const customer = Customer.hydrate<Customer>(customerEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, customer);
|
||||
|
@ -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>(DeedType, prismaEntity, { strategy: "exposeAll" });
|
||||
const DeedTypes = DeedType.map<DeedType>(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<DeedType>(new DeedType(), prismaEntityCreated, {
|
||||
strategy: "exposeAll",
|
||||
const deedTypeEntityCreated = DeedType.hydrate<DeedType>(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<DeedType>(new DeedType(), prismaEntityUpdated, {
|
||||
strategy: "exposeAll",
|
||||
const deedTypeEntityUpdated = DeedType.hydrate<DeedType>(prismaEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
@ -125,7 +125,7 @@ export default class DeedTypesController extends ApiController {
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deedType = ObjectHydrate.hydrate<DeedType>(new DeedType(), deedTypeEntity, { strategy: "exposeAll" });
|
||||
const deedType = DeedType.hydrate<DeedType>(deedTypeEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deedType);
|
||||
|
@ -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>(Deed, prismaEntity, { strategy: "exposeAll" });
|
||||
const deeds = Deed.map<Deed>(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<Deed>(new Deed(), deedEntity, { strategy: "exposeAll" });
|
||||
const deed = Deed.hydrate<Deed>(deedEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deed);
|
||||
|
@ -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>(DocumentType, prismaEntity, {
|
||||
strategy: "exposeAll",
|
||||
const documentTypes = DocumentType.map<DocumentType>(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<DocumentType>(new DocumentType(), prismaEntityCreated, {
|
||||
strategy: "exposeAll",
|
||||
const userEntityCreated = DocumentType.hydrate<DocumentType>(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<DocumentType>(new DocumentType(), prismaEntityUpdated, {
|
||||
strategy: "exposeAll",
|
||||
const documentTypeEntityUpdated = DocumentType.hydrate<DocumentType>(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<DocumentType>(new DocumentType(), documentTypeEntity, { strategy: "exposeAll" });
|
||||
const user = ObjectHydrate.hydrate<DocumentType>(new DocumentType(), documentTypeEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, user);
|
||||
|
@ -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>(Document, prismaEntity, { strategy: "exposeAll" });
|
||||
const documents = Document.map<Document>(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<Document>(new Document(), prismaEntityCreated, {
|
||||
strategy: "exposeAll",
|
||||
const documentEntityCreated = Document.hydrate<Document>(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<Document>(new Document(), prismaEntityUpdated, { strategy: "exposeAll" });
|
||||
const document = Document.hydrate<Document>(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<Document>(new Document(), documentEntity, { strategy: "exposeAll" });
|
||||
const document = Document.hydrate<Document>(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<Document>(new Document(), documentEntity, { strategy: "exposeAll" });
|
||||
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
|
@ -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>(OfficeFolder, prismaEntity, {
|
||||
strategy: "exposeAll", enableImplicitConversion: true
|
||||
const officeFolders = OfficeFolder.map<OfficeFolder>(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<OfficeFolder>(new OfficeFolder(), prismaEntityCreated, {
|
||||
strategy: "exposeAll", enableImplicitConversion: true
|
||||
const officeFolderEntityCreated = OfficeFolder.hydrate<OfficeFolder>(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<OfficeFolder>(new OfficeFolder(), prismaEntityUpdated, {
|
||||
strategy: "exposeAll",
|
||||
const officeFolderEntityUpdated = OfficeFolder.hydrate<OfficeFolder>(prismaEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
@ -119,7 +119,7 @@ export default class OfficeFoldersController extends ApiController {
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolder = ObjectHydrate.hydrate<OfficeFolder>(new OfficeFolder(), officeFolderEntity, { strategy: "exposeAll" });
|
||||
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeFolder);
|
||||
|
@ -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>(OfficeRessource, officesEntity, { strategy: "exposeAll" });
|
||||
const offices = OfficeResource.map<OfficeResource>(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<OfficeRessource>(new OfficeRessource(), prismaEntityCreated, {
|
||||
strategy: "exposeAll",
|
||||
const officeEntityCreated = OfficeResource.hydrate<OfficeResource>(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<OfficeRessource>(new OfficeRessource(), prismaEntityUpdated, {
|
||||
strategy: "exposeAll",
|
||||
const officeEntityUpdated = OfficeResource.hydrate<OfficeResource>(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<OfficeRessource>(new OfficeRessource(), officeEntity, { strategy: "exposeAll" });
|
||||
const office = OfficeResource.hydrate<OfficeResource>(officeEntity, { strategy: "excludeAll" });
|
||||
//success
|
||||
this.httpSuccess(response, office);
|
||||
} catch (error) {
|
||||
|
@ -7,7 +7,6 @@ import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import User from "le-coffre-resources/dist/Notary";
|
||||
import { Users } from "@prisma/client";
|
||||
import { plainToInstance } from "class-transformer";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -26,13 +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 = plainToInstance<User, Users[]>(User, usersEntity, {
|
||||
enableImplicitConversion: true,
|
||||
excludeExtraneousValues: false,
|
||||
});
|
||||
const users = User.map<User>(User, usersEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, users);
|
||||
@ -53,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<User>(new User(), prismaEntityCreated, {
|
||||
strategy: "exposeAll",
|
||||
const userEntityCreated = User.hydrate<User>(prismaEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
@ -92,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<User>(new User(), prismaEntityUpdated, {
|
||||
strategy: "exposeAll",
|
||||
const userEntityUpdated = User.hydrate<User>(prismaEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
@ -125,7 +121,7 @@ export default class UsersController extends ApiController {
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const user = ObjectHydrate.hydrate<User>(new User(), userEntity, { strategy: "exposeAll" });
|
||||
const user = User.hydrate<User>(userEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, user);
|
||||
|
@ -443,3 +443,4 @@ ALTER TABLE "deed_type_has_document_types" ADD CONSTRAINT "deed_type_has_documen
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "deed_type_has_document_types" ADD CONSTRAINT "deed_type_has_document_types_deed_type_uid_fkey" FOREIGN KEY ("deed_type_uid") REFERENCES "deed_types"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
|
@ -18,7 +18,7 @@ datasource db {
|
||||
// id String @unique @default(auto()) @map("_id") @db.ObjectId // @map de la table checker le naming avec le tiret
|
||||
|
||||
model Addresses {
|
||||
uid String @id @unique @default(uuid())
|
||||
uid String @id @unique @default(uuid())
|
||||
address String @db.VarChar(255)
|
||||
city String @db.VarChar(255)
|
||||
zip_code Int
|
||||
@ -31,15 +31,15 @@ model Addresses {
|
||||
}
|
||||
|
||||
model Contacts {
|
||||
uid String @id @unique @default(uuid())
|
||||
uid String @id @unique @default(uuid())
|
||||
first_name String @db.VarChar(255)
|
||||
last_name String @db.VarChar(255)
|
||||
email String @unique @db.VarChar(255)
|
||||
phone_number String? @db.VarChar(50)
|
||||
cell_phone_number String? @unique @db.VarChar(50)
|
||||
cell_phone_number String @unique @db.VarChar(50)
|
||||
civility ECivility @default(MALE)
|
||||
address Addresses? @relation(fields: [address_uid], references: [uid], onDelete: Cascade)
|
||||
address_uid String @unique @db.VarChar(255)
|
||||
address Addresses? @relation(fields: [address_uid], references: [uid], onDelete: Cascade)
|
||||
address_uid String @unique @db.VarChar(255)
|
||||
birthdate DateTime?
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
@ -50,14 +50,14 @@ model Contacts {
|
||||
}
|
||||
|
||||
model Users {
|
||||
uid String @id @unique @default(uuid()) @map("uid")
|
||||
uid String @id @unique @default(uuid()) @map("uid")
|
||||
idNot String @unique @db.VarChar(255)
|
||||
contact Contacts @relation(fields: [contact_uid], references: [uid], onDelete: Cascade)
|
||||
contact_uid String @unique @db.VarChar(255)
|
||||
contact_uid String @unique @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
office_membership Offices @relation(fields: [office_uid], references: [uid], onDelete: Cascade)
|
||||
office_uid String @db.VarChar(255)
|
||||
office_uid String @db.VarChar(255)
|
||||
user_has_notifications UserHasNotifications[]
|
||||
office_folder_has_stakeholder OfficeFolderHasStakeholders[]
|
||||
|
||||
@ -65,28 +65,28 @@ model Users {
|
||||
}
|
||||
|
||||
model Offices {
|
||||
uid String @id @unique @default(uuid())
|
||||
uid String @id @unique @default(uuid())
|
||||
idNot String @unique @db.VarChar(255)
|
||||
name String @db.VarChar(255)
|
||||
crpcen String @unique @db.VarChar(255)
|
||||
address Addresses @relation(fields: [address_uid], references: [uid], onDelete: Cascade)
|
||||
address_uid String @unique @db.VarChar(255)
|
||||
address_uid String @unique @db.VarChar(255)
|
||||
office_status EOfficeStatus @default(DESACTIVATED)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
deed_types DeedTypes[]
|
||||
users Users[]
|
||||
office_folders OfficeFolders[]
|
||||
document_types DocumentTypes[]
|
||||
document_types DocumentTypes[]
|
||||
|
||||
@@map("offices")
|
||||
}
|
||||
|
||||
model Customers {
|
||||
uid String @id @unique @default(uuid())
|
||||
uid String @id @unique @default(uuid())
|
||||
status ECustomerStatus @default(PENDING)
|
||||
contact Contacts @relation(fields: [contact_uid], references: [uid], onDelete: Cascade)
|
||||
contact_uid String @unique @db.VarChar(255)
|
||||
contact_uid String @unique @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
office_folder_has_customers OfficeFolderHasCustomers[]
|
||||
@ -96,11 +96,11 @@ model Customers {
|
||||
}
|
||||
|
||||
model UserHasNotifications {
|
||||
uid String @id @unique @default(uuid())
|
||||
uid String @id @unique @default(uuid())
|
||||
user Users @relation(fields: [user_uid], references: [uid])
|
||||
user_uid String @db.VarChar(255)
|
||||
user_uid String @db.VarChar(255)
|
||||
notification Notifications @relation(fields: [notification_uid], references: [uid], onDelete: Cascade)
|
||||
notification_uid String @db.VarChar(255)
|
||||
notification_uid String @db.VarChar(255)
|
||||
notification_status ENotificationStatus @default(UNREAD)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
@ -110,7 +110,7 @@ model UserHasNotifications {
|
||||
}
|
||||
|
||||
model Notifications {
|
||||
uid String @id @unique @default(uuid())
|
||||
uid String @id @unique @default(uuid())
|
||||
message String @db.VarChar(255)
|
||||
redirection_url String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
@ -121,16 +121,16 @@ model Notifications {
|
||||
}
|
||||
|
||||
model OfficeFolders {
|
||||
uid String @id @unique @default(uuid())
|
||||
uid String @id @unique @default(uuid())
|
||||
folder_number String @db.VarChar(255)
|
||||
name String @db.VarChar(255)
|
||||
description String? @db.VarChar(255)
|
||||
archived_description String? @db.VarChar(255)
|
||||
status EFolderStatus @default(LIVE)
|
||||
deed Deeds @relation(fields: [deed_uid], references: [uid], onDelete: Cascade)
|
||||
deed_uid String @unique @db.VarChar(255)
|
||||
deed_uid String @unique @db.VarChar(255)
|
||||
office Offices @relation(fields: [office_uid], references: [uid], onDelete: Cascade)
|
||||
office_uid String @db.VarChar(255)
|
||||
office_uid String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
office_folder_has_customers OfficeFolderHasCustomers[]
|
||||
@ -143,12 +143,12 @@ model OfficeFolders {
|
||||
|
||||
model OfficeFolderHasCustomers {
|
||||
uid String @id @unique @default(uuid())
|
||||
customer Customers @relation(fields: [customer_uid], references: [uid], onDelete: Cascade)
|
||||
customer Customers @relation(fields: [customer_uid], references: [uid], onDelete: Cascade)
|
||||
customer_uid String @db.VarChar(255)
|
||||
office_folder OfficeFolders @relation(fields: [office_folder_uid], references: [uid], onDelete: Cascade)
|
||||
office_folder OfficeFolders @relation(fields: [office_folder_uid], references: [uid], onDelete: Cascade)
|
||||
office_folder_uid String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
|
||||
@@unique([office_folder_uid, customer_uid])
|
||||
@@map("office_folder_has_customers")
|
||||
@ -156,12 +156,12 @@ model OfficeFolderHasCustomers {
|
||||
|
||||
model OfficeFolderHasStakeholders {
|
||||
uid String @id @unique @default(uuid())
|
||||
office_folder OfficeFolders @relation(fields: [office_folder_uid], references: [uid], onDelete: Cascade)
|
||||
office_folder OfficeFolders @relation(fields: [office_folder_uid], references: [uid], onDelete: Cascade)
|
||||
office_folder_uid String @db.VarChar(255)
|
||||
user_stakeholder Users @relation(fields: [user_stakeholder_uid], references: [uid], onDelete: Cascade)
|
||||
user_stakeholder Users @relation(fields: [user_stakeholder_uid], references: [uid], onDelete: Cascade)
|
||||
user_stakeholder_uid String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
|
||||
@@unique([office_folder_uid, user_stakeholder_uid])
|
||||
@@map("office_folder_has_stakeholder")
|
||||
@ -169,29 +169,29 @@ model OfficeFolderHasStakeholders {
|
||||
|
||||
model Documents {
|
||||
uid String @id @unique @default(uuid())
|
||||
document_status EDocumentStatus @default(ASKED)
|
||||
document_type DocumentTypes @relation(fields: [document_type_uid], references: [uid])
|
||||
document_status EDocumentStatus @default(ASKED)
|
||||
document_type DocumentTypes @relation(fields: [document_type_uid], references: [uid])
|
||||
document_type_uid String @db.VarChar(255)
|
||||
blockchain_anchor BlockchainAnchors? @relation(fields: [blockchain_anchor_uid], references: [uid])
|
||||
blockchain_anchor BlockchainAnchors? @relation(fields: [blockchain_anchor_uid], references: [uid])
|
||||
blockchain_anchor_uid String? @db.VarChar(255)
|
||||
folder OfficeFolders @relation(fields: [folder_uid], references: [uid])
|
||||
folder OfficeFolders @relation(fields: [folder_uid], references: [uid])
|
||||
folder_uid String @db.VarChar(255)
|
||||
depositor Customers @relation(fields: [depositor_uid], references: [uid], onDelete: Cascade)
|
||||
depositor Customers @relation(fields: [depositor_uid], references: [uid], onDelete: Cascade)
|
||||
depositor_uid String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
files Files[]
|
||||
document_history DocumentHistory[]
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
files Files[]
|
||||
document_history DocumentHistory[]
|
||||
|
||||
@@map("documents")
|
||||
}
|
||||
|
||||
model DocumentHistory {
|
||||
uid String @id @unique @default(uuid())
|
||||
uid String @id @unique @default(uuid())
|
||||
document_status EDocumentStatus @default(ASKED)
|
||||
refused_reason String? @db.VarChar(255)
|
||||
document Documents @relation(fields: [document_uid], references: [uid], onDelete: Cascade)
|
||||
document_uid String @db.VarChar(255)
|
||||
document_uid String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
|
||||
@ -200,17 +200,17 @@ model DocumentHistory {
|
||||
|
||||
model Files {
|
||||
uid String @id @unique @default(uuid())
|
||||
document Documents @relation(fields: [document_uid], references: [uid], onDelete: Cascade)
|
||||
document Documents @relation(fields: [document_uid], references: [uid], onDelete: Cascade)
|
||||
document_uid String @db.VarChar(255)
|
||||
file_path String @unique @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
file_path String @unique @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
|
||||
@@map("files")
|
||||
}
|
||||
|
||||
model BlockchainAnchors {
|
||||
uid String @id @unique @default(uuid())
|
||||
uid String @id @unique @default(uuid())
|
||||
smartSigJobId String @unique @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
@ -220,12 +220,12 @@ model BlockchainAnchors {
|
||||
}
|
||||
|
||||
model DocumentTypes {
|
||||
uid String @id @unique @default(uuid())
|
||||
uid String @id @unique @default(uuid())
|
||||
name String @db.VarChar(255)
|
||||
public_description String @db.VarChar(255)
|
||||
private_description String? @db.VarChar(255)
|
||||
office Offices @relation(fields: [office_uid], references: [uid], onDelete: Cascade)
|
||||
office_uid String @db.VarChar(255)
|
||||
office_uid String @db.VarChar(255)
|
||||
archived_at DateTime?
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
@ -239,21 +239,21 @@ model DocumentTypes {
|
||||
|
||||
model DeedHasDocumentTypes {
|
||||
uid String @id @unique @default(uuid())
|
||||
document_type DocumentTypes @relation(fields: [document_type_uid], references: [uid], onDelete: Cascade)
|
||||
document_type DocumentTypes @relation(fields: [document_type_uid], references: [uid], onDelete: Cascade)
|
||||
document_type_uid String @db.VarChar(255)
|
||||
deed Deeds @relation(fields: [deed_uid], references: [uid], onDelete: Cascade)
|
||||
deed Deeds @relation(fields: [deed_uid], references: [uid], onDelete: Cascade)
|
||||
deed_uid String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
|
||||
@@unique([deed_uid, document_type_uid])
|
||||
@@map("deed_has_document_types")
|
||||
}
|
||||
|
||||
model Deeds {
|
||||
uid String @id @unique @default(uuid())
|
||||
uid String @id @unique @default(uuid())
|
||||
deed_type DeedTypes @relation(fields: [deed_type_uid], references: [uid], onDelete: Cascade)
|
||||
deed_type_uid String @db.VarChar(255)
|
||||
deed_type_uid String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
deed_has_document_types DeedHasDocumentTypes[]
|
||||
@ -263,12 +263,12 @@ model Deeds {
|
||||
}
|
||||
|
||||
model DeedTypes {
|
||||
uid String @id @unique @default(uuid())
|
||||
uid String @id @unique @default(uuid())
|
||||
name String @db.VarChar(255)
|
||||
description String @db.VarChar(255)
|
||||
archived_at DateTime?
|
||||
office Offices @relation(fields: [office_uid], references: [uid], onDelete: Cascade)
|
||||
office_uid String @db.VarChar(255)
|
||||
office_uid String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
deed Deeds[]
|
||||
@ -280,12 +280,12 @@ model DeedTypes {
|
||||
|
||||
model DeedTypeHasDocumentTypes {
|
||||
uid String @id @unique @default(uuid())
|
||||
document_type DocumentTypes @relation(fields: [document_type_uid], references: [uid], onDelete: Cascade)
|
||||
document_type DocumentTypes @relation(fields: [document_type_uid], references: [uid], onDelete: Cascade)
|
||||
document_type_uid String @db.VarChar(255)
|
||||
deed_type DeedTypes @relation(fields: [deed_type_uid], references: [uid], onDelete: Cascade)
|
||||
deed_type DeedTypes @relation(fields: [deed_type_uid], references: [uid], onDelete: Cascade)
|
||||
deed_type_uid String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
|
||||
@@unique([deed_type_uid, document_type_uid])
|
||||
@@map("deed_type_has_document_types")
|
||||
|
@ -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();
|
||||
|
||||
@ -256,7 +255,7 @@ import {
|
||||
office_uid: uidOffice2,
|
||||
description: null,
|
||||
archived_description: null,
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
const deeds: Deeds[] = [
|
||||
@ -289,7 +288,7 @@ import {
|
||||
deed_type_uid: uidDeedType2,
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
const deedTypes: DeedTypes[] = [
|
||||
@ -446,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!");
|
||||
})();
|
||||
})();
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { Customers, ECivility, ECustomerStatus, Prisma } from "@prisma/client";
|
||||
import { Contacts, Customers, ECivility, ECustomerStatus, Prisma } from "@prisma/client";
|
||||
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
||||
|
||||
@Service()
|
||||
@ -19,46 +19,62 @@ export default class CustomersRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find many customers
|
||||
*/
|
||||
public async findMany(query: any): Promise<Customers[]> {
|
||||
public async findMany(query: Prisma.CustomersFindManyArgs): Promise<
|
||||
(Customers & {
|
||||
contact: Contacts;
|
||||
})[]
|
||||
> {
|
||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||
return this.model.findMany(query);
|
||||
if (!query.include) return this.model.findMany({ ...query, include: { contact: true } });
|
||||
return this.model.findMany({ ...query, include: { contact: { include: { address: true } } } });
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a customer
|
||||
*/
|
||||
public async create(customer: Customer): Promise<Customers> {
|
||||
public async create(customer: Customer): Promise<
|
||||
Customers & {
|
||||
contact: Contacts;
|
||||
}
|
||||
> {
|
||||
const createArgs: Prisma.CustomersCreateArgs = {
|
||||
data: {
|
||||
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],
|
||||
address: {}
|
||||
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);
|
||||
return this.model.create({ ...createArgs, include: { contact: true } });
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Update data from a customer
|
||||
*/
|
||||
public async update(uid: string, customer: Customer): Promise<Customers> {
|
||||
public async update(
|
||||
uid: string,
|
||||
customer: Customer,
|
||||
): Promise<
|
||||
Customers & {
|
||||
contact: Contacts;
|
||||
}
|
||||
> {
|
||||
const updateArgs: Prisma.CustomersUpdateArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
@ -67,40 +83,44 @@ 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],
|
||||
address: {}
|
||||
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);
|
||||
return this.model.update({ ...updateArgs, include: { contact: true } });
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find unique customer
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<Customers> {
|
||||
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");
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 },
|
||||
});
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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<Prisma.BatchPayload> {
|
||||
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) {
|
||||
|
@ -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<Files> {
|
||||
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<Files> {
|
||||
return this.model.delete({
|
||||
where: {
|
||||
uid: uid,
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { ECivility, Prisma, Users } from "@prisma/client";
|
||||
import { Addresses, Contacts, ECivility, Offices, Prisma, Users } from "@prisma/client";
|
||||
import User from "le-coffre-resources/dist/SuperAdmin";
|
||||
|
||||
@Service()
|
||||
@ -19,7 +19,7 @@ export default class UsersRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find many users
|
||||
*/
|
||||
public async findMany(query: any): Promise<Users[]> {
|
||||
public async findMany(query: Prisma.UsersFindManyArgs): Promise<Users[]> {
|
||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||
return this.model.findMany(query);
|
||||
}
|
||||
@ -34,17 +34,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,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -52,31 +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);
|
||||
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<Users> {
|
||||
public async update(
|
||||
uid: string,
|
||||
user: User,
|
||||
): Promise<
|
||||
Users & {
|
||||
contact: Contacts;
|
||||
office_membership: Offices & {
|
||||
address: Addresses;
|
||||
};
|
||||
}
|
||||
> {
|
||||
const updateArgs: Prisma.UsersUpdateArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
@ -86,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,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -104,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],
|
||||
address: {}
|
||||
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);
|
||||
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<Users> {
|
||||
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");
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { 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,7 +14,7 @@ export default class CustomersService extends BaseService {
|
||||
* @description : Get all Customers
|
||||
* @throws {Error} If Customers cannot be get
|
||||
*/
|
||||
public async get(query: any) {
|
||||
public async get(query: Prisma.CustomersFindManyArgs): Promise<Customers[]> {
|
||||
return this.customerRepository.findMany(query);
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ export default class OfficeFoldersService extends BaseService {
|
||||
* @throws {Error} If folder cannot be created
|
||||
*/
|
||||
public async create(officeFolderEntity: OfficeFolder): Promise<OfficeFolders> {
|
||||
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);
|
||||
}
|
||||
|
@ -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 { Users } from "@prisma/client";
|
||||
import {Prisma, Users } from "@prisma/client";
|
||||
|
||||
@Service()
|
||||
export default class UsersService extends BaseService {
|
||||
@ -15,7 +15,7 @@ export default class UsersService extends BaseService {
|
||||
* @description : Get all users
|
||||
* @throws {Error} If users cannot be get
|
||||
*/
|
||||
public get(query: any): Promise<Users[]> {
|
||||
public get(query: Prisma.UsersFindManyArgs): Promise<Users[]> {
|
||||
return this.userRepository.findMany(query);
|
||||
}
|
||||
|
||||
|
@ -11,9 +11,9 @@ export const initOffice = (office: Office): Promise<Offices> => {
|
||||
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<Customers> => {
|
||||
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<Users> => {
|
||||
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<Users> => {
|
||||
},
|
||||
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,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -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() {
|
||||
|
@ -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 },
|
||||
|
@ -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_);
|
||||
|
@ -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);
|
||||
|
@ -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 () => {
|
||||
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user