add resources hydratation (#29)
This commit is contained in:
commit
77ae3ceb10
@ -22,10 +22,9 @@
|
|||||||
"start": "tsc && node ./dist/entries/App.js",
|
"start": "tsc && node ./dist/entries/App.js",
|
||||||
"api:start": "npm run migrate && npm run start",
|
"api:start": "npm run migrate && npm run start",
|
||||||
"dev": "nodemon -V",
|
"dev": "nodemon -V",
|
||||||
"build:test": "tsc && mocha ./dist/entries/Test.js",
|
|
||||||
"format": "prettier --write src",
|
"format": "prettier --write src",
|
||||||
"migrate": "npx prisma migrate deploy",
|
|
||||||
"migrate:test": "dotenv -e .env.test -- 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:up:test": "docker-compose -f docker-compose-test.yml up -d",
|
||||||
"docker:down:test": "docker-compose down",
|
"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"
|
"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",
|
"cors": "^2.8.5",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"jsonwebtoken": "^9.0.0",
|
"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",
|
"module-alias": "^2.2.2",
|
||||||
"next": "^13.1.5",
|
"next": "^13.1.5",
|
||||||
"node-cache": "^5.1.2",
|
"node-cache": "^5.1.2",
|
||||||
|
159
src/app/api/customer/DocumentsController.ts
Normal file
159
src/app/api/customer/DocumentsController.ts
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
import { Response, Request } from "express";
|
||||||
|
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||||
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||||
|
import { Service } from "typedi";
|
||||||
|
import DocumentsService from "@Services/customer/DocumentsService/DocumentsService";
|
||||||
|
import { Documents } from "@prisma/client";
|
||||||
|
import { Document } from "le-coffre-resources/dist/Customer";
|
||||||
|
import { validateOrReject } from "class-validator";
|
||||||
|
|
||||||
|
@Controller()
|
||||||
|
@Service()
|
||||||
|
export default class DocumentsController extends ApiController {
|
||||||
|
constructor(private documentsService: DocumentsService) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Get all documents
|
||||||
|
* @returns IDocument[] list of documents
|
||||||
|
*/
|
||||||
|
@Get("/api/v1/customer/documents")
|
||||||
|
protected async get(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
//get query
|
||||||
|
const query = JSON.parse(req.query["q"] as string);
|
||||||
|
|
||||||
|
//call service to get prisma entity
|
||||||
|
const prismaEntity: Documents[] = await this.documentsService.get(query);
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const documents = Document.map<Document>(Document, prismaEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, documents);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpBadRequest(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Create a new document
|
||||||
|
* @returns IDocument created
|
||||||
|
*/
|
||||||
|
@Post("/api/v1/customer/documents")
|
||||||
|
protected async post(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
//init Document resource with request body values
|
||||||
|
const documentEntity = new Document();
|
||||||
|
Document.hydrate(documentEntity, req.body);
|
||||||
|
|
||||||
|
//validate document
|
||||||
|
await validateOrReject(documentEntity, { groups: ["createDocument"] });
|
||||||
|
|
||||||
|
//call service to get prisma entity
|
||||||
|
const prismaEntityCreated = await this.documentsService.create(documentEntity);
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const documentEntityCreated = Document.hydrate<Document>(prismaEntityCreated, {
|
||||||
|
strategy: "excludeAll",
|
||||||
|
});
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, documentEntityCreated);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpBadRequest(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Update a specific document
|
||||||
|
*/
|
||||||
|
@Put("/api/v1/customer/documents/:uid")
|
||||||
|
protected async update(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
const uid = req.params["uid"];
|
||||||
|
if (!uid) {
|
||||||
|
throw new Error("No uid provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
//init Document resource with request body values
|
||||||
|
const documentEntity = new Document();
|
||||||
|
Document.hydrate(documentEntity, req.body);
|
||||||
|
|
||||||
|
//validate document
|
||||||
|
await validateOrReject(documentEntity, { groups: ["createDocument"] });
|
||||||
|
|
||||||
|
//call service to get prisma entity
|
||||||
|
const prismaEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity);
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const document = Document.hydrate<Document>(prismaEntityUpdated, { strategy: "excludeAll" });
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, document);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpBadRequest(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Delete a specific document
|
||||||
|
*/
|
||||||
|
@Delete("/api/v1/customer/documents/:uid")
|
||||||
|
protected async delete(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
const uid = req.params["uid"];
|
||||||
|
if (!uid) {
|
||||||
|
throw new Error("No uid provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
//call service to get prisma entity
|
||||||
|
const documentEntity: Documents = await this.documentsService.delete(uid);
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, document);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpBadRequest(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Get a specific document by uid
|
||||||
|
*/
|
||||||
|
@Get("/api/v1/customer/documents/:uid")
|
||||||
|
protected async getOneByUid(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
const uid = req.params["uid"];
|
||||||
|
if (!uid) {
|
||||||
|
throw new Error("No uid provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
let documentEntity: Documents;
|
||||||
|
//get query
|
||||||
|
if (req.query["q"]) {
|
||||||
|
const query = JSON.parse(req.query["q"] as string);
|
||||||
|
documentEntity = await this.documentsService.getByUid(uid, query);
|
||||||
|
} else {
|
||||||
|
//call service to get prisma entity
|
||||||
|
documentEntity = await this.documentsService.getByUid(uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, document);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpBadRequest(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,6 @@ import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
|||||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||||
import CustomersService from "@Services/super-admin/CustomersService/CustomersService";
|
import CustomersService from "@Services/super-admin/CustomersService/CustomersService";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
|
||||||
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
import { Customers } from "@prisma/client";
|
import { Customers } from "@prisma/client";
|
||||||
import { validateOrReject } from "class-validator";
|
import { validateOrReject } from "class-validator";
|
||||||
@ -25,10 +24,10 @@ export default class CustomersController extends ApiController {
|
|||||||
const query = JSON.parse(req.query["q"] as string);
|
const query = JSON.parse(req.query["q"] as string);
|
||||||
|
|
||||||
//call service to get prisma entity
|
//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
|
//Hydrate ressource with prisma entity
|
||||||
const customers = ObjectHydrate.map<Customer>(Customer, customersEntity, { strategy: "exposeAll" });
|
const customers = Customer.map<Customer>(Customer, customersEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, customers);
|
this.httpSuccess(response, customers);
|
||||||
@ -46,17 +45,17 @@ export default class CustomersController extends ApiController {
|
|||||||
try {
|
try {
|
||||||
//init IUser resource with request body values
|
//init IUser resource with request body values
|
||||||
const customerEntity = new Customer();
|
const customerEntity = new Customer();
|
||||||
ObjectHydrate.hydrate(customerEntity, req.body);
|
Customer.hydrate(customerEntity, req.body);
|
||||||
|
|
||||||
//validate user
|
//validate user
|
||||||
await validateOrReject(customerEntity, { groups: ["create"] });
|
await validateOrReject(customerEntity, { groups: ["createCustomer"], forbidUnknownValues: false });
|
||||||
|
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const prismaEntityCreated = await this.customersService.create(customerEntity);
|
const prismaEntityCreated = await this.customersService.create(customerEntity);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const customerEntityCreated = ObjectHydrate.hydrate<Customer>(new Customer(), prismaEntityCreated, {
|
const customerEntityCreated = Customer.hydrate<Customer>(prismaEntityCreated, {
|
||||||
strategy: "exposeAll",
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
|
|
||||||
//success
|
//success
|
||||||
@ -79,16 +78,16 @@ export default class CustomersController extends ApiController {
|
|||||||
}
|
}
|
||||||
//init IUser resource with request body values
|
//init IUser resource with request body values
|
||||||
const customerEntity = new Customer();
|
const customerEntity = new Customer();
|
||||||
ObjectHydrate.hydrate(customerEntity, req.body);
|
Customer.hydrate(customerEntity, req.body);
|
||||||
//validate user
|
//validate user
|
||||||
await validateOrReject(customerEntity, { groups: ["update"] });
|
await validateOrReject(customerEntity, { groups: ["updateCustomer"], forbidUnknownValues: false });
|
||||||
|
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const prismaEntityUpdated = await this.customersService.update(uid, customerEntity);
|
const prismaEntityUpdated = await this.customersService.update(uid, customerEntity);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const customerEntityUpdated = ObjectHydrate.hydrate<Customer>(new Customer(), prismaEntityUpdated, {
|
const customerEntityUpdated = Customer.hydrate<Customer>(prismaEntityUpdated, {
|
||||||
strategy: "exposeAll",
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
|
|
||||||
//success
|
//success
|
||||||
@ -121,7 +120,7 @@ export default class CustomersController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const customer = ObjectHydrate.hydrate<Customer>(new Customer(), customerEntity, { strategy: "exposeAll" });
|
const customer = Customer.hydrate<Customer>(customerEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, customer);
|
this.httpSuccess(response, customer);
|
||||||
|
@ -28,7 +28,7 @@ export default class DeedTypesController extends ApiController {
|
|||||||
const prismaEntity: DeedTypes[] = await this.deedTypesService.get(query);
|
const prismaEntity: DeedTypes[] = await this.deedTypesService.get(query);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const DeedTypes = ObjectHydrate.map<DeedType>(DeedType, prismaEntity, { strategy: "exposeAll" });
|
const DeedTypes = DeedType.map<DeedType>(DeedType, prismaEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, DeedTypes);
|
this.httpSuccess(response, DeedTypes);
|
||||||
@ -50,14 +50,14 @@ export default class DeedTypesController extends ApiController {
|
|||||||
ObjectHydrate.hydrate(deedTypeEntity, req.body);
|
ObjectHydrate.hydrate(deedTypeEntity, req.body);
|
||||||
|
|
||||||
//validate deed type
|
//validate deed type
|
||||||
await validateOrReject(deedTypeEntity, { groups: ["create"] });
|
await validateOrReject(deedTypeEntity, { groups: ["createDeedType"], forbidUnknownValues: false });
|
||||||
|
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const prismaEntityCreated = await this.deedTypesService.create(deedTypeEntity);
|
const prismaEntityCreated = await this.deedTypesService.create(deedTypeEntity);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const deedTypeEntityCreated = ObjectHydrate.hydrate<DeedType>(new DeedType(), prismaEntityCreated, {
|
const deedTypeEntityCreated = DeedType.hydrate<DeedType>(prismaEntityCreated, {
|
||||||
strategy: "exposeAll",
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
|
|
||||||
//success
|
//success
|
||||||
@ -84,14 +84,14 @@ export default class DeedTypesController extends ApiController {
|
|||||||
ObjectHydrate.hydrate(deedTypeEntity, req.body);
|
ObjectHydrate.hydrate(deedTypeEntity, req.body);
|
||||||
|
|
||||||
//validate deed type
|
//validate deed type
|
||||||
await validateOrReject(deedTypeEntity, { groups: ["update"] });
|
await validateOrReject(deedTypeEntity, { groups: ["updateDeedType"] });
|
||||||
|
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const prismaEntityUpdated = await this.deedTypesService.update(uid, deedTypeEntity);
|
const prismaEntityUpdated = await this.deedTypesService.update(uid, deedTypeEntity);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const deedTypeEntityUpdated = ObjectHydrate.hydrate<DeedType>(new DeedType(), prismaEntityUpdated, {
|
const deedTypeEntityUpdated = DeedType.hydrate<DeedType>(prismaEntityUpdated, {
|
||||||
strategy: "exposeAll",
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
|
|
||||||
//success
|
//success
|
||||||
@ -125,7 +125,7 @@ export default class DeedTypesController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const deedType = ObjectHydrate.hydrate<DeedType>(new DeedType(), deedTypeEntity, { strategy: "exposeAll" });
|
const deedType = DeedType.hydrate<DeedType>(deedTypeEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, deedType);
|
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 DeedsService from "@Services/super-admin/DeedsService/DeedsService";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import { Deeds } from "@prisma/client";
|
import { Deeds } from "@prisma/client";
|
||||||
import Deed from "le-coffre-resources/dist/SuperAdmin";
|
import { Deed } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@Service()
|
@Service()
|
||||||
@ -27,7 +26,7 @@ export default class DeedsController extends ApiController {
|
|||||||
const prismaEntity: Deeds[] = await this.deedsService.get(query);
|
const prismaEntity: Deeds[] = await this.deedsService.get(query);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const deeds = ObjectHydrate.map<Deed>(Deed, prismaEntity, { strategy: "exposeAll" });
|
const deeds = Deed.map<Deed>(Deed, prismaEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, deeds);
|
this.httpSuccess(response, deeds);
|
||||||
@ -53,7 +52,7 @@ export default class DeedsController extends ApiController {
|
|||||||
const deedEntity: Deeds = await this.deedsService.getByUid(uid);
|
const deedEntity: Deeds = await this.deedsService.getByUid(uid);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const deed = ObjectHydrate.hydrate<Deed>(new Deed(), deedEntity, { strategy: "exposeAll" });
|
const deed = Deed.hydrate<Deed>(deedEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, deed);
|
this.httpSuccess(response, deed);
|
||||||
|
@ -29,8 +29,8 @@ export default class DocumentTypesController extends ApiController {
|
|||||||
const prismaEntity: DocumentTypes[] = await this.documentTypesService.get(query);
|
const prismaEntity: DocumentTypes[] = await this.documentTypesService.get(query);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const documentTypes = ObjectHydrate.map<DocumentType>(DocumentType, prismaEntity, {
|
const documentTypes = DocumentType.map<DocumentType>(DocumentType, prismaEntity, {
|
||||||
strategy: "exposeAll",
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
|
|
||||||
//success
|
//success
|
||||||
@ -51,12 +51,12 @@ export default class DocumentTypesController extends ApiController {
|
|||||||
const documentTypeEntity = new DocumentType();
|
const documentTypeEntity = new DocumentType();
|
||||||
ObjectHydrate.hydrate(documentTypeEntity, req.body);
|
ObjectHydrate.hydrate(documentTypeEntity, req.body);
|
||||||
//validate user
|
//validate user
|
||||||
await validateOrReject(documentTypeEntity, { groups: ["create"] });
|
await validateOrReject(documentTypeEntity, { groups: ["createDocumentType"], forbidUnknownValues: false });
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const prismaEntityCreated = await this.documentTypesService.create(documentTypeEntity);
|
const prismaEntityCreated = await this.documentTypesService.create(documentTypeEntity);
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const userEntityCreated = ObjectHydrate.hydrate<DocumentType>(new DocumentType(), prismaEntityCreated, {
|
const userEntityCreated = DocumentType.hydrate<DocumentType>(prismaEntityCreated, {
|
||||||
strategy: "exposeAll",
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, userEntityCreated);
|
this.httpSuccess(response, userEntityCreated);
|
||||||
@ -87,8 +87,8 @@ export default class DocumentTypesController extends ApiController {
|
|||||||
const prismaEntityUpdated = await this.documentTypesService.update(uid, documentTypeEntity);
|
const prismaEntityUpdated = await this.documentTypesService.update(uid, documentTypeEntity);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const documentTypeEntityUpdated = ObjectHydrate.hydrate<DocumentType>(new DocumentType(), prismaEntityUpdated, {
|
const documentTypeEntityUpdated = DocumentType.hydrate<DocumentType>(prismaEntityUpdated, {
|
||||||
strategy: "exposeAll",
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
|
|
||||||
//success
|
//success
|
||||||
@ -119,9 +119,9 @@ export default class DocumentTypesController extends ApiController {
|
|||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
documentTypeEntity = await this.documentTypesService.getByUid(uid);
|
documentTypeEntity = await this.documentTypesService.getByUid(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//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
|
//success
|
||||||
this.httpSuccess(response, user);
|
this.httpSuccess(response, user);
|
||||||
|
@ -29,7 +29,7 @@ export default class DocumentsController extends ApiController {
|
|||||||
const prismaEntity: Documents[] = await this.documentsService.get(query);
|
const prismaEntity: Documents[] = await this.documentsService.get(query);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const documents = ObjectHydrate.map<Document>(Document, prismaEntity, { strategy: "exposeAll" });
|
const documents = Document.map<Document>(Document, prismaEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, documents);
|
this.httpSuccess(response, documents);
|
||||||
@ -51,14 +51,14 @@ export default class DocumentsController extends ApiController {
|
|||||||
ObjectHydrate.hydrate(documentEntity, req.body);
|
ObjectHydrate.hydrate(documentEntity, req.body);
|
||||||
|
|
||||||
//validate document
|
//validate document
|
||||||
await validateOrReject(documentEntity, { groups: ["create"] });
|
await validateOrReject(documentEntity, { groups: ["createDocument"], forbidUnknownValues: false });
|
||||||
|
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const prismaEntityCreated = await this.documentsService.create(documentEntity);
|
const prismaEntityCreated = await this.documentsService.create(documentEntity);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const documentEntityCreated = ObjectHydrate.hydrate<Document>(new Document(), prismaEntityCreated, {
|
const documentEntityCreated = Document.hydrate<Document>(prismaEntityCreated, {
|
||||||
strategy: "exposeAll",
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
|
|
||||||
//success
|
//success
|
||||||
@ -85,13 +85,13 @@ export default class DocumentsController extends ApiController {
|
|||||||
ObjectHydrate.hydrate(documentEntity, req.body);
|
ObjectHydrate.hydrate(documentEntity, req.body);
|
||||||
|
|
||||||
//validate document
|
//validate document
|
||||||
await validateOrReject(documentEntity, { groups: ["create"] });
|
await validateOrReject(documentEntity, { groups: ["createDocument"] });
|
||||||
|
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const prismaEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity);
|
const prismaEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const document = ObjectHydrate.hydrate<Document>(new Document(), prismaEntityUpdated, { strategy: "exposeAll" });
|
const document = Document.hydrate<Document>(prismaEntityUpdated, { strategy: "excludeAll" });
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, document);
|
this.httpSuccess(response, document);
|
||||||
@ -116,7 +116,7 @@ export default class DocumentsController extends ApiController {
|
|||||||
const documentEntity: Documents = await this.documentsService.delete(uid);
|
const documentEntity: Documents = await this.documentsService.delete(uid);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const document = ObjectHydrate.hydrate<Document>(new Document(), documentEntity, { strategy: "exposeAll" });
|
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, document);
|
this.httpSuccess(response, document);
|
||||||
@ -148,7 +148,7 @@ export default class DocumentsController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const document = ObjectHydrate.hydrate<Document>(new Document(), documentEntity, { strategy: "exposeAll" });
|
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, document);
|
this.httpSuccess(response, document);
|
||||||
|
@ -26,8 +26,8 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const prismaEntity: OfficeFolders[] = await this.officeFoldersService.get(query);
|
const prismaEntity: OfficeFolders[] = await this.officeFoldersService.get(query);
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const officeFolders = ObjectHydrate.map<OfficeFolder>(OfficeFolder, prismaEntity, {
|
const officeFolders = OfficeFolder.map<OfficeFolder>(OfficeFolder, prismaEntity, {
|
||||||
strategy: "exposeAll", enableImplicitConversion: true
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, officeFolders);
|
this.httpSuccess(response, officeFolders);
|
||||||
@ -52,8 +52,8 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const prismaEntityCreated = await this.officeFoldersService.create(officeFolderEntity);
|
const prismaEntityCreated = await this.officeFoldersService.create(officeFolderEntity);
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const officeFolderEntityCreated = ObjectHydrate.hydrate<OfficeFolder>(new OfficeFolder(), prismaEntityCreated, {
|
const officeFolderEntityCreated = OfficeFolder.hydrate<OfficeFolder>(prismaEntityCreated, {
|
||||||
strategy: "exposeAll", enableImplicitConversion: true
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, officeFolderEntityCreated);
|
this.httpSuccess(response, officeFolderEntityCreated);
|
||||||
@ -78,14 +78,14 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
ObjectHydrate.hydrate(officeFolderEntity, req.body);
|
ObjectHydrate.hydrate(officeFolderEntity, req.body);
|
||||||
|
|
||||||
//validate user
|
//validate user
|
||||||
await validateOrReject(officeFolderEntity, { groups: ["update"] });
|
await validateOrReject(officeFolderEntity, { groups: ["updateFolder"], forbidUnknownValues: false });
|
||||||
|
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const prismaEntityUpdated = await this.officeFoldersService.update(uid, officeFolderEntity);
|
const prismaEntityUpdated = await this.officeFoldersService.update(uid, officeFolderEntity);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const officeFolderEntityUpdated = ObjectHydrate.hydrate<OfficeFolder>(new OfficeFolder(), prismaEntityUpdated, {
|
const officeFolderEntityUpdated = OfficeFolder.hydrate<OfficeFolder>(prismaEntityUpdated, {
|
||||||
strategy: "exposeAll",
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
|
|
||||||
//success
|
//success
|
||||||
@ -119,7 +119,7 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const officeFolder = ObjectHydrate.hydrate<OfficeFolder>(new OfficeFolder(), officeFolderEntity, { strategy: "exposeAll" });
|
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, officeFolder);
|
this.httpSuccess(response, officeFolder);
|
||||||
|
@ -5,7 +5,7 @@ import OfficesService from "@Services/super-admin/OfficesService/OfficesService"
|
|||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import { Offices } from "@prisma/client";
|
import { Offices } from "@prisma/client";
|
||||||
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
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";
|
import { validateOrReject } from "class-validator";
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@ -25,7 +25,7 @@ export default class OfficesController extends ApiController {
|
|||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const officesEntity: Offices[] = await this.officesService.get(query);
|
const officesEntity: Offices[] = await this.officesService.get(query);
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const offices = ObjectHydrate.map<OfficeRessource>(OfficeRessource, officesEntity, { strategy: "exposeAll" });
|
const offices = OfficeResource.map<OfficeResource>(OfficeResource, officesEntity, { strategy: "excludeAll" });
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, offices);
|
this.httpSuccess(response, offices);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -40,15 +40,15 @@ export default class OfficesController extends ApiController {
|
|||||||
protected async post(req: Request, response: Response) {
|
protected async post(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
//init IUser resource with request body values
|
//init IUser resource with request body values
|
||||||
const officeEntity = new OfficeRessource();
|
const officeEntity = new OfficeResource();
|
||||||
ObjectHydrate.hydrate(officeEntity, req.body);
|
ObjectHydrate.hydrate(officeEntity, req.body);
|
||||||
//validate user
|
//validate user
|
||||||
await validateOrReject(officeEntity, { groups: ["create"] });
|
await validateOrReject(officeEntity, { groups: ["createOffice"], forbidUnknownValues: false });
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const prismaEntityCreated = await this.officesService.create(officeEntity);
|
const prismaEntityCreated = await this.officesService.create(officeEntity);
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const officeEntityCreated = ObjectHydrate.hydrate<OfficeRessource>(new OfficeRessource(), prismaEntityCreated, {
|
const officeEntityCreated = OfficeResource.hydrate<OfficeResource>(prismaEntityCreated, {
|
||||||
strategy: "exposeAll",
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, officeEntityCreated);
|
this.httpSuccess(response, officeEntityCreated);
|
||||||
@ -68,15 +68,15 @@ export default class OfficesController extends ApiController {
|
|||||||
throw new Error("No uid provided");
|
throw new Error("No uid provided");
|
||||||
}
|
}
|
||||||
//init IUser resource with request body values
|
//init IUser resource with request body values
|
||||||
const officeEntity = new OfficeRessource();
|
const officeEntity = new OfficeResource();
|
||||||
ObjectHydrate.hydrate(officeEntity, req.body);
|
ObjectHydrate.hydrate(officeEntity, req.body);
|
||||||
//validate user
|
//validate user
|
||||||
await validateOrReject(officeEntity, { groups: ["update"] });
|
await validateOrReject(officeEntity, { groups: ["update"] });
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const prismaEntityUpdated = await this.officesService.update(uid, officeEntity);
|
const prismaEntityUpdated = await this.officesService.update(uid, officeEntity);
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const officeEntityUpdated = ObjectHydrate.hydrate<OfficeRessource>(new OfficeRessource(), prismaEntityUpdated, {
|
const officeEntityUpdated = OfficeResource.hydrate<OfficeResource>(prismaEntityUpdated, {
|
||||||
strategy: "exposeAll",
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, officeEntityUpdated);
|
this.httpSuccess(response, officeEntityUpdated);
|
||||||
@ -105,7 +105,7 @@ export default class OfficesController extends ApiController {
|
|||||||
officeEntity = await this.officesService.getByUid(uid);
|
officeEntity = await this.officesService.getByUid(uid);
|
||||||
}
|
}
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const office = ObjectHydrate.hydrate<OfficeRessource>(new OfficeRessource(), officeEntity, { strategy: "exposeAll" });
|
const office = OfficeResource.hydrate<OfficeResource>(officeEntity, { strategy: "excludeAll" });
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, office);
|
this.httpSuccess(response, office);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -7,7 +7,6 @@ import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
|||||||
import { validateOrReject } from "class-validator";
|
import { validateOrReject } from "class-validator";
|
||||||
import User from "le-coffre-resources/dist/Notary";
|
import User from "le-coffre-resources/dist/Notary";
|
||||||
import { Users } from "@prisma/client";
|
import { Users } from "@prisma/client";
|
||||||
import { plainToInstance } from "class-transformer";
|
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@Service()
|
@Service()
|
||||||
@ -26,13 +25,10 @@ export default class UsersController extends ApiController {
|
|||||||
const query = JSON.parse(req.query["q"] as string);
|
const query = JSON.parse(req.query["q"] as string);
|
||||||
|
|
||||||
//call service to get prisma entity
|
//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
|
//Hydrate ressource with prisma entity
|
||||||
const users = plainToInstance<User, Users[]>(User, usersEntity, {
|
const users = User.map<User>(User, usersEntity, { strategy: "excludeAll" });
|
||||||
enableImplicitConversion: true,
|
|
||||||
excludeExtraneousValues: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, users);
|
this.httpSuccess(response, users);
|
||||||
@ -53,14 +49,14 @@ export default class UsersController extends ApiController {
|
|||||||
ObjectHydrate.hydrate(userEntity, req.body);
|
ObjectHydrate.hydrate(userEntity, req.body);
|
||||||
|
|
||||||
//validate user
|
//validate user
|
||||||
await validateOrReject(userEntity, { groups: ["create"] });
|
await validateOrReject(userEntity, { groups: ["createUser"] });
|
||||||
|
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const prismaEntityCreated = await this.usersService.create(userEntity);
|
const prismaEntityCreated = await this.usersService.create(userEntity);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const userEntityCreated = ObjectHydrate.hydrate<User>(new User(), prismaEntityCreated, {
|
const userEntityCreated = User.hydrate<User>(prismaEntityCreated, {
|
||||||
strategy: "exposeAll",
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
|
|
||||||
//success
|
//success
|
||||||
@ -92,8 +88,8 @@ export default class UsersController extends ApiController {
|
|||||||
const prismaEntityUpdated = await this.usersService.update(uid, userEntity);
|
const prismaEntityUpdated = await this.usersService.update(uid, userEntity);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const userEntityUpdated = ObjectHydrate.hydrate<User>(new User(), prismaEntityUpdated, {
|
const userEntityUpdated = User.hydrate<User>(prismaEntityUpdated, {
|
||||||
strategy: "exposeAll",
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
|
|
||||||
//success
|
//success
|
||||||
@ -125,7 +121,7 @@ export default class UsersController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const user = ObjectHydrate.hydrate<User>(new User(), userEntity, { strategy: "exposeAll" });
|
const user = User.hydrate<User>(userEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, user);
|
this.httpSuccess(response, user);
|
||||||
|
@ -10,6 +10,9 @@ import DocumentsController from "./api/super-admin/DocumentsController";
|
|||||||
import DocumentTypesController from "./api/super-admin/DocumentTypesController";
|
import DocumentTypesController from "./api/super-admin/DocumentTypesController";
|
||||||
import IdNotUserInfoController from "./api/idnot-user/UserInfoController";
|
import IdNotUserInfoController from "./api/idnot-user/UserInfoController";
|
||||||
|
|
||||||
|
import DocumentsControllerCustomer from "./api/customer/DocumentsController";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description This allow to declare all controllers used in the application
|
* @description This allow to declare all controllers used in the application
|
||||||
*/
|
*/
|
||||||
@ -25,5 +28,7 @@ export default {
|
|||||||
Container.get(DocumentsController);
|
Container.get(DocumentsController);
|
||||||
Container.get(DocumentTypesController);
|
Container.get(DocumentTypesController);
|
||||||
Container.get(IdNotUserInfoController);
|
Container.get(IdNotUserInfoController);
|
||||||
|
|
||||||
|
Container.get(DocumentsControllerCustomer);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -443,3 +443,4 @@ ALTER TABLE "deed_type_has_document_types" ADD CONSTRAINT "deed_type_has_documen
|
|||||||
|
|
||||||
-- AddForeignKey
|
-- 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;
|
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
|
// id String @unique @default(auto()) @map("_id") @db.ObjectId // @map de la table checker le naming avec le tiret
|
||||||
|
|
||||||
model Addresses {
|
model Addresses {
|
||||||
uid String @id @unique @default(uuid())
|
uid String @id @unique @default(uuid())
|
||||||
address String @db.VarChar(255)
|
address String @db.VarChar(255)
|
||||||
city String @db.VarChar(255)
|
city String @db.VarChar(255)
|
||||||
zip_code Int
|
zip_code Int
|
||||||
@ -31,15 +31,15 @@ model Addresses {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model Contacts {
|
model Contacts {
|
||||||
uid String @id @unique @default(uuid())
|
uid String @id @unique @default(uuid())
|
||||||
first_name String @db.VarChar(255)
|
first_name String @db.VarChar(255)
|
||||||
last_name String @db.VarChar(255)
|
last_name String @db.VarChar(255)
|
||||||
email String @unique @db.VarChar(255)
|
email String @unique @db.VarChar(255)
|
||||||
phone_number String? @db.VarChar(50)
|
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)
|
civility ECivility @default(MALE)
|
||||||
address Addresses? @relation(fields: [address_uid], references: [uid], onDelete: Cascade)
|
address Addresses? @relation(fields: [address_uid], references: [uid], onDelete: Cascade)
|
||||||
address_uid String @unique @db.VarChar(255)
|
address_uid String @unique @db.VarChar(255)
|
||||||
birthdate DateTime?
|
birthdate DateTime?
|
||||||
created_at DateTime? @default(now())
|
created_at DateTime? @default(now())
|
||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
@ -50,14 +50,14 @@ model Contacts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model Users {
|
model Users {
|
||||||
uid String @id @unique @default(uuid()) @map("uid")
|
uid String @id @unique @default(uuid()) @map("uid")
|
||||||
idNot String @unique @db.VarChar(255)
|
idNot String @unique @db.VarChar(255)
|
||||||
contact Contacts @relation(fields: [contact_uid], references: [uid], onDelete: Cascade)
|
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())
|
created_at DateTime? @default(now())
|
||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
office_membership Offices @relation(fields: [office_uid], references: [uid], onDelete: Cascade)
|
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[]
|
user_has_notifications UserHasNotifications[]
|
||||||
office_folder_has_stakeholder OfficeFolderHasStakeholders[]
|
office_folder_has_stakeholder OfficeFolderHasStakeholders[]
|
||||||
|
|
||||||
@ -65,28 +65,28 @@ model Users {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model Offices {
|
model Offices {
|
||||||
uid String @id @unique @default(uuid())
|
uid String @id @unique @default(uuid())
|
||||||
idNot String @unique @db.VarChar(255)
|
idNot String @unique @db.VarChar(255)
|
||||||
name String @db.VarChar(255)
|
name String @db.VarChar(255)
|
||||||
crpcen String @unique @db.VarChar(255)
|
crpcen String @unique @db.VarChar(255)
|
||||||
address Addresses @relation(fields: [address_uid], references: [uid], onDelete: Cascade)
|
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)
|
office_status EOfficeStatus @default(DESACTIVATED)
|
||||||
created_at DateTime? @default(now())
|
created_at DateTime? @default(now())
|
||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
deed_types DeedTypes[]
|
deed_types DeedTypes[]
|
||||||
users Users[]
|
users Users[]
|
||||||
office_folders OfficeFolders[]
|
office_folders OfficeFolders[]
|
||||||
document_types DocumentTypes[]
|
document_types DocumentTypes[]
|
||||||
|
|
||||||
@@map("offices")
|
@@map("offices")
|
||||||
}
|
}
|
||||||
|
|
||||||
model Customers {
|
model Customers {
|
||||||
uid String @id @unique @default(uuid())
|
uid String @id @unique @default(uuid())
|
||||||
status ECustomerStatus @default(PENDING)
|
status ECustomerStatus @default(PENDING)
|
||||||
contact Contacts @relation(fields: [contact_uid], references: [uid], onDelete: Cascade)
|
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())
|
created_at DateTime? @default(now())
|
||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
office_folder_has_customers OfficeFolderHasCustomers[]
|
office_folder_has_customers OfficeFolderHasCustomers[]
|
||||||
@ -96,11 +96,11 @@ model Customers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model UserHasNotifications {
|
model UserHasNotifications {
|
||||||
uid String @id @unique @default(uuid())
|
uid String @id @unique @default(uuid())
|
||||||
user Users @relation(fields: [user_uid], references: [uid])
|
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 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)
|
notification_status ENotificationStatus @default(UNREAD)
|
||||||
created_at DateTime? @default(now())
|
created_at DateTime? @default(now())
|
||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
@ -110,7 +110,7 @@ model UserHasNotifications {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model Notifications {
|
model Notifications {
|
||||||
uid String @id @unique @default(uuid())
|
uid String @id @unique @default(uuid())
|
||||||
message String @db.VarChar(255)
|
message String @db.VarChar(255)
|
||||||
redirection_url String @db.VarChar(255)
|
redirection_url String @db.VarChar(255)
|
||||||
created_at DateTime? @default(now())
|
created_at DateTime? @default(now())
|
||||||
@ -121,16 +121,16 @@ model Notifications {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model OfficeFolders {
|
model OfficeFolders {
|
||||||
uid String @id @unique @default(uuid())
|
uid String @id @unique @default(uuid())
|
||||||
folder_number String @db.VarChar(255)
|
folder_number String @db.VarChar(255)
|
||||||
name String @db.VarChar(255)
|
name String @db.VarChar(255)
|
||||||
description String? @db.VarChar(255)
|
description String? @db.VarChar(255)
|
||||||
archived_description String? @db.VarChar(255)
|
archived_description String? @db.VarChar(255)
|
||||||
status EFolderStatus @default(LIVE)
|
status EFolderStatus @default(LIVE)
|
||||||
deed Deeds @relation(fields: [deed_uid], references: [uid], onDelete: Cascade)
|
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 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())
|
created_at DateTime? @default(now())
|
||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
office_folder_has_customers OfficeFolderHasCustomers[]
|
office_folder_has_customers OfficeFolderHasCustomers[]
|
||||||
@ -143,12 +143,12 @@ model OfficeFolders {
|
|||||||
|
|
||||||
model OfficeFolderHasCustomers {
|
model OfficeFolderHasCustomers {
|
||||||
uid String @id @unique @default(uuid())
|
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)
|
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)
|
office_folder_uid String @db.VarChar(255)
|
||||||
created_at DateTime? @default(now())
|
created_at DateTime? @default(now())
|
||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
|
|
||||||
@@unique([office_folder_uid, customer_uid])
|
@@unique([office_folder_uid, customer_uid])
|
||||||
@@map("office_folder_has_customers")
|
@@map("office_folder_has_customers")
|
||||||
@ -156,12 +156,12 @@ model OfficeFolderHasCustomers {
|
|||||||
|
|
||||||
model OfficeFolderHasStakeholders {
|
model OfficeFolderHasStakeholders {
|
||||||
uid String @id @unique @default(uuid())
|
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)
|
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)
|
user_stakeholder_uid String @db.VarChar(255)
|
||||||
created_at DateTime? @default(now())
|
created_at DateTime? @default(now())
|
||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
|
|
||||||
@@unique([office_folder_uid, user_stakeholder_uid])
|
@@unique([office_folder_uid, user_stakeholder_uid])
|
||||||
@@map("office_folder_has_stakeholder")
|
@@map("office_folder_has_stakeholder")
|
||||||
@ -169,29 +169,29 @@ model OfficeFolderHasStakeholders {
|
|||||||
|
|
||||||
model Documents {
|
model Documents {
|
||||||
uid String @id @unique @default(uuid())
|
uid String @id @unique @default(uuid())
|
||||||
document_status EDocumentStatus @default(ASKED)
|
document_status EDocumentStatus @default(ASKED)
|
||||||
document_type DocumentTypes @relation(fields: [document_type_uid], references: [uid])
|
document_type DocumentTypes @relation(fields: [document_type_uid], references: [uid])
|
||||||
document_type_uid String @db.VarChar(255)
|
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)
|
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)
|
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)
|
depositor_uid String @db.VarChar(255)
|
||||||
created_at DateTime? @default(now())
|
created_at DateTime? @default(now())
|
||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
files Files[]
|
files Files[]
|
||||||
document_history DocumentHistory[]
|
document_history DocumentHistory[]
|
||||||
|
|
||||||
@@map("documents")
|
@@map("documents")
|
||||||
}
|
}
|
||||||
|
|
||||||
model DocumentHistory {
|
model DocumentHistory {
|
||||||
uid String @id @unique @default(uuid())
|
uid String @id @unique @default(uuid())
|
||||||
document_status EDocumentStatus @default(ASKED)
|
document_status EDocumentStatus @default(ASKED)
|
||||||
refused_reason String? @db.VarChar(255)
|
refused_reason String? @db.VarChar(255)
|
||||||
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)
|
document_uid String @db.VarChar(255)
|
||||||
created_at DateTime? @default(now())
|
created_at DateTime? @default(now())
|
||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
|
|
||||||
@ -200,17 +200,17 @@ model DocumentHistory {
|
|||||||
|
|
||||||
model Files {
|
model Files {
|
||||||
uid String @id @unique @default(uuid())
|
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)
|
document_uid String @db.VarChar(255)
|
||||||
file_path String @unique @db.VarChar(255)
|
file_path String @unique @db.VarChar(255)
|
||||||
created_at DateTime? @default(now())
|
created_at DateTime? @default(now())
|
||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
|
|
||||||
@@map("files")
|
@@map("files")
|
||||||
}
|
}
|
||||||
|
|
||||||
model BlockchainAnchors {
|
model BlockchainAnchors {
|
||||||
uid String @id @unique @default(uuid())
|
uid String @id @unique @default(uuid())
|
||||||
smartSigJobId String @unique @db.VarChar(255)
|
smartSigJobId String @unique @db.VarChar(255)
|
||||||
created_at DateTime? @default(now())
|
created_at DateTime? @default(now())
|
||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
@ -220,12 +220,12 @@ model BlockchainAnchors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model DocumentTypes {
|
model DocumentTypes {
|
||||||
uid String @id @unique @default(uuid())
|
uid String @id @unique @default(uuid())
|
||||||
name String @db.VarChar(255)
|
name String @db.VarChar(255)
|
||||||
public_description String @db.VarChar(255)
|
public_description String @db.VarChar(255)
|
||||||
private_description String? @db.VarChar(255)
|
private_description String? @db.VarChar(255)
|
||||||
office Offices @relation(fields: [office_uid], references: [uid], onDelete: Cascade)
|
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?
|
archived_at DateTime?
|
||||||
created_at DateTime? @default(now())
|
created_at DateTime? @default(now())
|
||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
@ -239,21 +239,21 @@ model DocumentTypes {
|
|||||||
|
|
||||||
model DeedHasDocumentTypes {
|
model DeedHasDocumentTypes {
|
||||||
uid String @id @unique @default(uuid())
|
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)
|
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)
|
deed_uid String @db.VarChar(255)
|
||||||
created_at DateTime? @default(now())
|
created_at DateTime? @default(now())
|
||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
|
|
||||||
@@unique([deed_uid, document_type_uid])
|
@@unique([deed_uid, document_type_uid])
|
||||||
@@map("deed_has_document_types")
|
@@map("deed_has_document_types")
|
||||||
}
|
}
|
||||||
|
|
||||||
model Deeds {
|
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 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())
|
created_at DateTime? @default(now())
|
||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
deed_has_document_types DeedHasDocumentTypes[]
|
deed_has_document_types DeedHasDocumentTypes[]
|
||||||
@ -263,12 +263,12 @@ model Deeds {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model DeedTypes {
|
model DeedTypes {
|
||||||
uid String @id @unique @default(uuid())
|
uid String @id @unique @default(uuid())
|
||||||
name String @db.VarChar(255)
|
name String @db.VarChar(255)
|
||||||
description String @db.VarChar(255)
|
description String @db.VarChar(255)
|
||||||
archived_at DateTime?
|
archived_at DateTime?
|
||||||
office Offices @relation(fields: [office_uid], references: [uid], onDelete: Cascade)
|
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())
|
created_at DateTime? @default(now())
|
||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
deed Deeds[]
|
deed Deeds[]
|
||||||
@ -280,12 +280,12 @@ model DeedTypes {
|
|||||||
|
|
||||||
model DeedTypeHasDocumentTypes {
|
model DeedTypeHasDocumentTypes {
|
||||||
uid String @id @unique @default(uuid())
|
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)
|
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)
|
deed_type_uid String @db.VarChar(255)
|
||||||
created_at DateTime? @default(now())
|
created_at DateTime? @default(now())
|
||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
|
|
||||||
@@unique([deed_type_uid, document_type_uid])
|
@@unique([deed_type_uid, document_type_uid])
|
||||||
@@map("deed_type_has_document_types")
|
@@map("deed_type_has_document_types")
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
Addresses,
|
Addresses,
|
||||||
Contacts,
|
Contacts,
|
||||||
Customers,
|
Customers,
|
||||||
DeedHasDocumentTypes,
|
DeedHasDocumentTypes,
|
||||||
DeedTypeHasDocumentTypes,
|
DeedTypeHasDocumentTypes,
|
||||||
DeedTypes,
|
DeedTypes,
|
||||||
@ -17,27 +17,26 @@ import {
|
|||||||
OfficeFolders,
|
OfficeFolders,
|
||||||
Offices,
|
Offices,
|
||||||
Users,
|
Users,
|
||||||
ECivility,
|
ECivility,
|
||||||
ECustomerStatus,
|
ECustomerStatus,
|
||||||
PrismaClient
|
PrismaClient,
|
||||||
} from "@prisma/client";
|
} from "@prisma/client";
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
const existingData = await prisma.contacts.findFirst({ where: { email: "john.doe@example.com" } });
|
const existingData = await prisma.contacts.findFirst({ where: { email: "john.doe@example.com" } });
|
||||||
if (existingData) {
|
if (existingData) {
|
||||||
console.log('Seed data already exists. Skipping seeding process.');
|
console.log("Seed data already exists. Skipping seeding process.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const randomString = () => {
|
const randomString = () => {
|
||||||
const chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
const chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
let result = "";
|
let result = "";
|
||||||
for (let i = 10; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
|
for (let i = 10; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
const uidCustomer1: string = randomString();
|
const uidCustomer1: string = randomString();
|
||||||
const uidCustomer2: string = randomString();
|
const uidCustomer2: string = randomString();
|
||||||
|
|
||||||
@ -256,7 +255,7 @@ import {
|
|||||||
office_uid: uidOffice2,
|
office_uid: uidOffice2,
|
||||||
description: null,
|
description: null,
|
||||||
archived_description: null,
|
archived_description: null,
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const deeds: Deeds[] = [
|
const deeds: Deeds[] = [
|
||||||
@ -289,7 +288,7 @@ import {
|
|||||||
deed_type_uid: uidDeedType2,
|
deed_type_uid: uidDeedType2,
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const deedTypes: DeedTypes[] = [
|
const deedTypes: DeedTypes[] = [
|
||||||
@ -446,67 +445,64 @@ import {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
for (const address of addresses) {
|
for (const address of addresses) {
|
||||||
await prisma.addresses.create({data: address});
|
await prisma.addresses.create({ data: address });
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const contact of contacts) {
|
for (const contact of contacts) {
|
||||||
await prisma.contacts.create({ data: contact });
|
await prisma.contacts.create({ data: contact });
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const office of offices) {
|
for (const office of offices) {
|
||||||
await prisma.offices.create({ data: office });
|
await prisma.offices.create({ data: office });
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const user of users) {
|
for (const user of users) {
|
||||||
await prisma.users.create({ data: user });
|
await prisma.users.create({ data: user });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (const customer of customers) {
|
for (const customer of customers) {
|
||||||
await prisma.customers.create({ data: customer });
|
await prisma.customers.create({ data: customer });
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const deedType of deedTypes) {
|
for (const deedType of deedTypes) {
|
||||||
await prisma.deedTypes.create({ data: deedType });
|
await prisma.deedTypes.create({ data: deedType });
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const deed of deeds) {
|
for (const deed of deeds) {
|
||||||
await prisma.deeds.create({ data: deed });
|
await prisma.deeds.create({ data: deed });
|
||||||
|
}
|
||||||
}
|
for (const officeFolder of officeFolders) {
|
||||||
for (const officeFolder of officeFolders) {
|
await prisma.officeFolders.create({ data: officeFolder });
|
||||||
await prisma.officeFolders.create({ data: officeFolder });
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (const documentType of documentTypes) {
|
for (const documentType of documentTypes) {
|
||||||
await prisma.documentTypes.create({ data: documentType });
|
await prisma.documentTypes.create({ data: documentType });
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const document of documents) {
|
for (const document of documents) {
|
||||||
await prisma.documents.create({ data: document });
|
await prisma.documents.create({ data: document });
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
await prisma.files.create({ data: file });
|
await prisma.files.create({ data: file });
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const documentHistory of documentHistories) {
|
for (const documentHistory of documentHistories) {
|
||||||
await prisma.documentHistory.create({ data: documentHistory });
|
await prisma.documentHistory.create({ data: documentHistory });
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const officeFolderHasCustomer of officeFolderHasCustomers) {
|
for (const officeFolderHasCustomer of officeFolderHasCustomers) {
|
||||||
await prisma.officeFolderHasCustomers.create({ data: officeFolderHasCustomer });
|
await prisma.officeFolderHasCustomers.create({ data: officeFolderHasCustomer });
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const deedHasDocumentType of deedHasDocumentTypes) {
|
for (const deedHasDocumentType of deedHasDocumentTypes) {
|
||||||
await prisma.deedHasDocumentTypes.create({ data: deedHasDocumentType });
|
await prisma.deedHasDocumentTypes.create({ data: deedHasDocumentType });
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const deedTypeHasDocumentType of deedTypeHasDocumentTypes) {
|
for (const deedTypeHasDocumentType of deedTypeHasDocumentTypes) {
|
||||||
await prisma.deedTypeHasDocumentTypes.create({ data: deedTypeHasDocumentType });
|
await prisma.deedTypeHasDocumentTypes.create({ data: deedTypeHasDocumentType });
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(">MOCK DATA - Seeding completed!");
|
console.log(">MOCK DATA - Seeding completed!");
|
||||||
})();
|
})();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import Database from "@Common/databases/database";
|
import Database from "@Common/databases/database";
|
||||||
import BaseRepository from "@Repositories/BaseRepository";
|
import BaseRepository from "@Repositories/BaseRepository";
|
||||||
import { Service } from "typedi";
|
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";
|
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
@ -19,46 +19,62 @@ export default class CustomersRepository extends BaseRepository {
|
|||||||
/**
|
/**
|
||||||
* @description : Find many customers
|
* @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);
|
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
|
* @description : Create a customer
|
||||||
*/
|
*/
|
||||||
public async create(customer: Customer): Promise<Customers> {
|
public async create(customer: Customer): Promise<
|
||||||
|
Customers & {
|
||||||
|
contact: Contacts;
|
||||||
|
}
|
||||||
|
> {
|
||||||
const createArgs: Prisma.CustomersCreateArgs = {
|
const createArgs: Prisma.CustomersCreateArgs = {
|
||||||
data: {
|
data: {
|
||||||
status: ECustomerStatus.PENDING,
|
status: ECustomerStatus.PENDING,
|
||||||
contact: {
|
contact: {
|
||||||
create: {
|
create: {
|
||||||
first_name: customer.contact.first_name,
|
first_name: customer.contact!.first_name,
|
||||||
last_name: customer.contact.last_name,
|
last_name: customer.contact!.last_name,
|
||||||
email: customer.contact.email,
|
email: customer.contact!.email,
|
||||||
phone_number: customer.contact.phone_number,
|
phone_number: customer.contact!.phone_number,
|
||||||
cell_phone_number: customer.contact?.cell_phone_number,
|
cell_phone_number: customer.contact!?.cell_phone_number,
|
||||||
civility: ECivility[customer.contact.civility as keyof typeof ECivility],
|
civility: ECivility[customer.contact!.civility as keyof typeof ECivility],
|
||||||
address: {}
|
address: {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (customer.contact.address) {
|
if (customer.contact!.address) {
|
||||||
createArgs.data.contact!.create!.address!.create = {
|
createArgs.data.contact!.create!.address!.create = {
|
||||||
address: customer.contact.address!.address,
|
address: customer.contact!.address!.address,
|
||||||
zip_code: customer.contact.address!.zip_code,
|
zip_code: customer.contact!.address!.zip_code,
|
||||||
city: customer.contact.address!.city,
|
city: customer.contact!.address!.city,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return this.model.create(createArgs);
|
return this.model.create({ ...createArgs, include: { contact: true } });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Update data from a customer
|
* @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 = {
|
const updateArgs: Prisma.CustomersUpdateArgs = {
|
||||||
where: {
|
where: {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
@ -67,40 +83,44 @@ export default class CustomersRepository extends BaseRepository {
|
|||||||
status: ECustomerStatus[customer.status as keyof typeof ECustomerStatus],
|
status: ECustomerStatus[customer.status as keyof typeof ECustomerStatus],
|
||||||
contact: {
|
contact: {
|
||||||
update: {
|
update: {
|
||||||
first_name: customer.contact.first_name,
|
first_name: customer.contact!.first_name,
|
||||||
last_name: customer.contact.last_name,
|
last_name: customer.contact!.last_name,
|
||||||
email: customer.contact.email,
|
email: customer.contact!.email,
|
||||||
phone_number: customer.contact.phone_number,
|
phone_number: customer.contact!.phone_number,
|
||||||
cell_phone_number: customer.contact.cell_phone_number,
|
cell_phone_number: customer.contact!.cell_phone_number,
|
||||||
civility: ECivility[customer.contact.civility as keyof typeof ECivility],
|
civility: ECivility[customer.contact!.civility as keyof typeof ECivility],
|
||||||
address: {}
|
address: {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
if (customer.contact.address) {
|
if (customer.contact!.address) {
|
||||||
updateArgs.data.contact!.update!.address!.update = {
|
updateArgs.data.contact!.update!.address!.update = {
|
||||||
address: customer.contact.address!.address,
|
address: customer.contact!.address!.address,
|
||||||
zip_code: customer.contact.address!.zip_code,
|
zip_code: customer.contact!.address!.zip_code,
|
||||||
city: customer.contact.address!.city,
|
city: customer.contact!.address!.city,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return this.model.update(updateArgs);
|
return this.model.update({ ...updateArgs, include: { contact: true } });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Find unique customer
|
* @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 = {
|
const findOneArgs: Prisma.CustomersFindUniqueArgs = {
|
||||||
where: {
|
where: {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
if(query) {
|
const customerEntity = await this.model.findUnique({ ...findOneArgs, include: { contact: true } });
|
||||||
findOneArgs.include = query
|
|
||||||
}
|
|
||||||
const customerEntity = await this.model.findUnique(findOneArgs);
|
|
||||||
|
|
||||||
if (!customerEntity) {
|
if (!customerEntity) {
|
||||||
throw new Error("Customer not found");
|
throw new Error("Customer not found");
|
||||||
|
@ -34,10 +34,10 @@ export default class DeedTypesRepository extends BaseRepository {
|
|||||||
description: deedType.description,
|
description: deedType.description,
|
||||||
office: {
|
office: {
|
||||||
connect: {
|
connect: {
|
||||||
uid: deedType.office.uid,
|
uid: deedType.office!.uid,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
if (deedType.deed_type_has_document_types) {
|
if (deedType.deed_type_has_document_types) {
|
||||||
createArgs.data.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,
|
archived_at: deedType.archived_at,
|
||||||
office: {
|
office: {
|
||||||
connect: {
|
connect: {
|
||||||
uid: deedType.office.uid,
|
uid: deedType.office!.uid,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -95,10 +95,10 @@ export default class DeedTypesRepository extends BaseRepository {
|
|||||||
const findOneArgs: Prisma.DeedTypesFindUniqueArgs = {
|
const findOneArgs: Prisma.DeedTypesFindUniqueArgs = {
|
||||||
where: {
|
where: {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
if(query) {
|
if (query) {
|
||||||
findOneArgs.include = query
|
findOneArgs.include = query;
|
||||||
}
|
}
|
||||||
const deedTypeEntity = await this.model.findUnique(findOneArgs);
|
const deedTypeEntity = await this.model.findUnique(findOneArgs);
|
||||||
|
|
||||||
|
@ -32,14 +32,14 @@ export default class DeedsRepository extends BaseRepository {
|
|||||||
data: {
|
data: {
|
||||||
deed_type: {
|
deed_type: {
|
||||||
connect: {
|
connect: {
|
||||||
uid: deed.deed_type.uid,
|
uid: deed.deed_type!.uid,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const deedTypeWithDocumentTypes = await this.instanceDb.deedTypes.findUniqueOrThrow({
|
const deedTypeWithDocumentTypes = await this.instanceDb.deedTypes.findUniqueOrThrow({
|
||||||
where: {
|
where: {
|
||||||
uid: deed.deed_type.uid,
|
uid: deed.deed_type!.uid,
|
||||||
},
|
},
|
||||||
include: { deed_type_has_document_types: true },
|
include: { deed_type_has_document_types: true },
|
||||||
});
|
});
|
||||||
|
@ -35,7 +35,7 @@ export default class DocumentTypesRepository extends BaseRepository {
|
|||||||
private_description: documentType.private_description,
|
private_description: documentType.private_description,
|
||||||
office: {
|
office: {
|
||||||
connect: {
|
connect: {
|
||||||
uid: documentType.office.uid,
|
uid: documentType.office!.uid,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -57,7 +57,7 @@ export default class DocumentTypesRepository extends BaseRepository {
|
|||||||
archived_at: documentType.archived_at,
|
archived_at: documentType.archived_at,
|
||||||
office: {
|
office: {
|
||||||
connect: {
|
connect: {
|
||||||
uid: documentType.office.uid,
|
uid: documentType.office!.uid,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -71,10 +71,10 @@ export default class DocumentTypesRepository extends BaseRepository {
|
|||||||
const findOneArgs: Prisma.DocumentTypesFindUniqueArgs = {
|
const findOneArgs: Prisma.DocumentTypesFindUniqueArgs = {
|
||||||
where: {
|
where: {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
if(query) {
|
if (query) {
|
||||||
findOneArgs.include = query
|
findOneArgs.include = query;
|
||||||
}
|
}
|
||||||
const documentTypeEntity = await this.model.findUnique(findOneArgs);
|
const documentTypeEntity = await this.model.findUnique(findOneArgs);
|
||||||
|
|
||||||
|
@ -32,17 +32,17 @@ export default class DocumentsRepository extends BaseRepository {
|
|||||||
data: {
|
data: {
|
||||||
folder: {
|
folder: {
|
||||||
connect: {
|
connect: {
|
||||||
uid: document.folder.uid,
|
uid: document.folder!.uid,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
depositor: {
|
depositor: {
|
||||||
connect: {
|
connect: {
|
||||||
uid: document.depositor.uid,
|
uid: document.depositor!.uid,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
document_type: {
|
document_type: {
|
||||||
connect: {
|
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> {
|
public async createMany(documents: Document[]): Promise<Prisma.BatchPayload> {
|
||||||
return this.model.createMany({
|
return this.model.createMany({
|
||||||
data: documents.map((document) => ({
|
data: documents.map((document) => ({
|
||||||
folder_uid: document.folder.uid!,
|
folder_uid: document.folder!.uid!,
|
||||||
depositor_uid: document.depositor.uid!,
|
depositor_uid: document.depositor!.uid!,
|
||||||
document_type_uid: document.document_type.uid!,
|
document_type_uid: document.document_type!.uid!,
|
||||||
})),
|
})),
|
||||||
skipDuplicates: true,
|
skipDuplicates: true,
|
||||||
});
|
});
|
||||||
@ -93,7 +93,7 @@ export default class DocumentsRepository extends BaseRepository {
|
|||||||
},
|
},
|
||||||
depositor: {
|
depositor: {
|
||||||
connect: {
|
connect: {
|
||||||
uid: document.depositor.uid,
|
uid: document.depositor!.uid,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -118,10 +118,10 @@ export default class DocumentsRepository extends BaseRepository {
|
|||||||
const findOneArgs: Prisma.DocumentsFindUniqueArgs = {
|
const findOneArgs: Prisma.DocumentsFindUniqueArgs = {
|
||||||
where: {
|
where: {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
if(query) {
|
if (query) {
|
||||||
findOneArgs.include = query
|
findOneArgs.include = query;
|
||||||
}
|
}
|
||||||
const documentEntity = await this.model.findUnique(findOneArgs);
|
const documentEntity = await this.model.findUnique(findOneArgs);
|
||||||
if (!documentEntity) {
|
if (!documentEntity) {
|
||||||
|
@ -2,7 +2,7 @@ import Database from "@Common/databases/database";
|
|||||||
import BaseRepository from "@Repositories/BaseRepository";
|
import BaseRepository from "@Repositories/BaseRepository";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import { Files } from "@prisma/client";
|
import { Files } from "@prisma/client";
|
||||||
import { File } from "le-coffre-resources/dist/SuperAdmin"
|
import { File } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class FilesRepository extends BaseRepository {
|
export default class FilesRepository extends BaseRepository {
|
||||||
@ -32,16 +32,16 @@ export default class FilesRepository extends BaseRepository {
|
|||||||
data: {
|
data: {
|
||||||
document: {
|
document: {
|
||||||
connect: {
|
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> {
|
public async update(uid: string, file: File): Promise<Files> {
|
||||||
return this.model.update({
|
return this.model.update({
|
||||||
@ -49,19 +49,19 @@ export default class FilesRepository extends BaseRepository {
|
|||||||
uid: uid,
|
uid: uid,
|
||||||
},
|
},
|
||||||
data: {
|
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> {
|
public async delete(uid: string): Promise<Files> {
|
||||||
return this.model.delete({
|
return this.model.delete({
|
||||||
where: {
|
where: {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@ export default class OfficeFoldersHasCustomerRepository extends BaseRepository {
|
|||||||
return this.model.findMany(query);
|
return this.model.findMany(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Find a unique relation between an office folder and customers
|
* @description : Find a unique relation between an office folder and customers
|
||||||
*/
|
*/
|
||||||
|
@ -38,20 +38,20 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
|||||||
create: {
|
create: {
|
||||||
deed_type: {
|
deed_type: {
|
||||||
connect: {
|
connect: {
|
||||||
uid: officeFolder.deed.deed_type.uid,
|
uid: officeFolder.deed!.deed_type!.uid,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
office: {
|
office: {
|
||||||
connect: {
|
connect: {
|
||||||
idNot: officeFolder.office.idNot,
|
uid: officeFolder.office!.uid,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
office_folder_has_stakeholder: true,
|
office_folder_has_stakeholder: true,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
if (officeFolder.office_folder_has_stakeholder) {
|
if (officeFolder.office_folder_has_stakeholder) {
|
||||||
createArgs.data.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) => ({
|
data: officeFolder.office_folder_has_stakeholder.map((relation) => ({
|
||||||
user_stakeholder_uid: relation.user_stakeholder.uid!,
|
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_stakeholder: true,
|
||||||
office_folder_has_customers: true,
|
office_folder_has_customers: true,
|
||||||
documents: true,
|
documents: true,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
if (officeFolder.office_folder_has_stakeholder) {
|
if (officeFolder.office_folder_has_stakeholder) {
|
||||||
updateArgs.data.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) => ({
|
data: officeFolder.office_folder_has_stakeholder.map((relation) => ({
|
||||||
user_stakeholder_uid: relation.user_stakeholder.uid!,
|
user_stakeholder_uid: relation.user_stakeholder.uid!,
|
||||||
})),
|
})),
|
||||||
skipDuplicates: true
|
skipDuplicates: true,
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
if (officeFolder.office_folder_has_customers) {
|
if (officeFolder.office_folder_has_customers) {
|
||||||
updateArgs.data.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) => ({
|
data: officeFolder.office_folder_has_customers.map((relation) => ({
|
||||||
customer_uid: relation.customer.uid!,
|
customer_uid: relation.customer.uid!,
|
||||||
})),
|
})),
|
||||||
skipDuplicates: true
|
skipDuplicates: true,
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
if (officeFolder.documents) {
|
if (officeFolder.documents) {
|
||||||
updateArgs.data.documents = {
|
updateArgs.data.documents = {
|
||||||
createMany: {
|
createMany: {
|
||||||
data: officeFolder.documents.map((relation) => ({
|
data: officeFolder.documents.map((relation) => ({
|
||||||
document_type_uid: relation.document_type.uid!,
|
document_type_uid: relation.document_type!.uid!,
|
||||||
depositor_uid: relation.depositor.uid!
|
depositor_uid: relation.depositor!.uid!,
|
||||||
})),
|
})),
|
||||||
skipDuplicates: true
|
skipDuplicates: true,
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
return this.model.update(updateArgs);
|
return this.model.update(updateArgs);
|
||||||
}
|
}
|
||||||
@ -130,10 +130,10 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
|||||||
const findOneArgs: Prisma.OfficeFoldersFindUniqueArgs = {
|
const findOneArgs: Prisma.OfficeFoldersFindUniqueArgs = {
|
||||||
where: {
|
where: {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
if(query) {
|
if (query) {
|
||||||
findOneArgs.include = query
|
findOneArgs.include = query;
|
||||||
}
|
}
|
||||||
const officeFolderEntity = await this.model.findUnique(findOneArgs);
|
const officeFolderEntity = await this.model.findUnique(findOneArgs);
|
||||||
|
|
||||||
|
@ -36,9 +36,9 @@ export default class OfficesRepository extends BaseRepository {
|
|||||||
crpcen: office.crpcen,
|
crpcen: office.crpcen,
|
||||||
address: {
|
address: {
|
||||||
create: {
|
create: {
|
||||||
address: office.address.address,
|
address: office.address!.address,
|
||||||
zip_code: office.address.zip_code,
|
zip_code: office.address!.zip_code,
|
||||||
city: office.address.city,
|
city: office.address!.city,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
office_status: EOfficeStatus.DESACTIVATED,
|
office_status: EOfficeStatus.DESACTIVATED,
|
||||||
@ -58,9 +58,9 @@ export default class OfficesRepository extends BaseRepository {
|
|||||||
name: office.name,
|
name: office.name,
|
||||||
address: {
|
address: {
|
||||||
create: {
|
create: {
|
||||||
address: office.address.address,
|
address: office.address!.address,
|
||||||
zip_code: office.address.zip_code,
|
zip_code: office.address!.zip_code,
|
||||||
city: office.address.city,
|
city: office.address!.city,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
office_status: EOfficeStatus[office.office_status as keyof typeof EOfficeStatus],
|
office_status: EOfficeStatus[office.office_status as keyof typeof EOfficeStatus],
|
||||||
@ -75,14 +75,13 @@ export default class OfficesRepository extends BaseRepository {
|
|||||||
const findOneArgs: Prisma.OfficesFindUniqueArgs = {
|
const findOneArgs: Prisma.OfficesFindUniqueArgs = {
|
||||||
where: {
|
where: {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
if(query) {
|
if (query) {
|
||||||
findOneArgs.include = query
|
findOneArgs.include = query;
|
||||||
}
|
}
|
||||||
const officeEntity = await this.model.findUnique(findOneArgs);
|
const officeEntity = await this.model.findUnique(findOneArgs);
|
||||||
|
|
||||||
|
|
||||||
if (!officeEntity) {
|
if (!officeEntity) {
|
||||||
throw new Error("office not found");
|
throw new Error("office not found");
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import Database from "@Common/databases/database";
|
import Database from "@Common/databases/database";
|
||||||
import BaseRepository from "@Repositories/BaseRepository";
|
import BaseRepository from "@Repositories/BaseRepository";
|
||||||
import { Service } from "typedi";
|
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";
|
import User from "le-coffre-resources/dist/SuperAdmin";
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
@ -19,7 +19,7 @@ export default class UsersRepository extends BaseRepository {
|
|||||||
/**
|
/**
|
||||||
* @description : Find many users
|
* @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);
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||||
return this.model.findMany(query);
|
return this.model.findMany(query);
|
||||||
}
|
}
|
||||||
@ -34,17 +34,17 @@ export default class UsersRepository extends BaseRepository {
|
|||||||
office_membership: {
|
office_membership: {
|
||||||
connectOrCreate: {
|
connectOrCreate: {
|
||||||
where: {
|
where: {
|
||||||
idNot: user.office_membership.idNot,
|
idNot: user.office_membership!.idNot,
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
idNot: user.office_membership.idNot,
|
idNot: user.office_membership!.idNot,
|
||||||
name: user.office_membership.name,
|
name: user.office_membership!.name,
|
||||||
crpcen: user.office_membership.crpcen,
|
crpcen: user.office_membership!.crpcen,
|
||||||
address: {
|
address: {
|
||||||
create: {
|
create: {
|
||||||
address: user.office_membership.address.address,
|
address: user.office_membership!.address!.address,
|
||||||
zip_code: user.office_membership.address.zip_code,
|
zip_code: user.office_membership!.address!.zip_code,
|
||||||
city: user.office_membership.address.city,
|
city: user.office_membership!.address!.city,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -52,31 +52,41 @@ export default class UsersRepository extends BaseRepository {
|
|||||||
},
|
},
|
||||||
contact: {
|
contact: {
|
||||||
create: {
|
create: {
|
||||||
first_name: user.contact.first_name,
|
first_name: user.contact!.first_name,
|
||||||
last_name: user.contact.last_name,
|
last_name: user.contact!.last_name,
|
||||||
email: user.contact.email,
|
email: user.contact!.email,
|
||||||
phone_number: user.contact.phone_number,
|
phone_number: user.contact!.phone_number,
|
||||||
cell_phone_number: user.contact.cell_phone_number,
|
cell_phone_number: user.contact!.cell_phone_number,
|
||||||
civility: ECivility[user.contact.civility as keyof typeof ECivility],
|
civility: ECivility[user.contact!.civility as keyof typeof ECivility],
|
||||||
address: {},
|
address: {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
if (user.contact.address) {
|
if (user.contact!.address) {
|
||||||
createArgs.data.contact!.create!.address!.create = {
|
createArgs.data.contact!.create!.address!.create = {
|
||||||
address: user.contact.address!.address,
|
address: user.contact!.address.address,
|
||||||
zip_code: user.contact.address!.zip_code,
|
zip_code: user.contact!.address.zip_code,
|
||||||
city: user.contact.address!.city,
|
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
|
* @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 = {
|
const updateArgs: Prisma.UsersUpdateArgs = {
|
||||||
where: {
|
where: {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
@ -86,17 +96,17 @@ export default class UsersRepository extends BaseRepository {
|
|||||||
office_membership: {
|
office_membership: {
|
||||||
connectOrCreate: {
|
connectOrCreate: {
|
||||||
where: {
|
where: {
|
||||||
idNot: user.office_membership.idNot,
|
idNot: user.office_membership!.idNot,
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
idNot: user.office_membership.idNot,
|
idNot: user.office_membership!.idNot,
|
||||||
name: user.office_membership.name,
|
name: user.office_membership!.name,
|
||||||
crpcen: user.office_membership.crpcen,
|
crpcen: user.office_membership!.crpcen,
|
||||||
address: {
|
address: {
|
||||||
create: {
|
create: {
|
||||||
address: user.office_membership.address.address,
|
address: user.office_membership!.address!.address,
|
||||||
zip_code: user.office_membership.address.zip_code,
|
zip_code: user.office_membership!.address!.zip_code,
|
||||||
city: user.office_membership.address.city,
|
city: user.office_membership!.address!.city,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -104,25 +114,25 @@ export default class UsersRepository extends BaseRepository {
|
|||||||
},
|
},
|
||||||
contact: {
|
contact: {
|
||||||
update: {
|
update: {
|
||||||
first_name: user.contact.first_name,
|
first_name: user.contact!.first_name,
|
||||||
last_name: user.contact.last_name,
|
last_name: user.contact!.last_name,
|
||||||
email: user.contact.email,
|
email: user.contact!.email,
|
||||||
phone_number: user.contact.phone_number,
|
phone_number: user.contact!.phone_number,
|
||||||
cell_phone_number: user.contact.cell_phone_number,
|
cell_phone_number: user.contact!.cell_phone_number,
|
||||||
civility: ECivility[user.contact.civility as keyof typeof ECivility],
|
civility: ECivility[user.contact!.civility as keyof typeof ECivility],
|
||||||
address: {}
|
address: {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if (user.contact.address) {
|
if (user.contact!.address) {
|
||||||
updateArgs.data.contact!.update!.address!.update = {
|
updateArgs.data.contact!.update!.address!.update = {
|
||||||
address: user.contact.address!.address,
|
address: user.contact!.address!.address,
|
||||||
zip_code: user.contact.address!.zip_code,
|
zip_code: user.contact!.address!.zip_code,
|
||||||
city: user.contact.address!.city,
|
city: user.contact!.address!.city,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return this.model.update(updateArgs);
|
return this.model.update({ ...updateArgs, include: { contact: true, office_membership: { include: { address: true } } } });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -132,10 +142,10 @@ export default class UsersRepository extends BaseRepository {
|
|||||||
const findOneArgs: Prisma.UsersFindUniqueArgs = {
|
const findOneArgs: Prisma.UsersFindUniqueArgs = {
|
||||||
where: {
|
where: {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
if(query) {
|
if (query) {
|
||||||
findOneArgs.include = query
|
findOneArgs.include = query;
|
||||||
}
|
}
|
||||||
const userEntity = await this.model.findUnique(findOneArgs);
|
const userEntity = await this.model.findUnique(findOneArgs);
|
||||||
|
|
||||||
|
60
src/services/customer/DocumentsService/DocumentsService.ts
Normal file
60
src/services/customer/DocumentsService/DocumentsService.ts
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import { Documents, Prisma } from "@prisma/client";
|
||||||
|
import { Document } from "le-coffre-resources/dist/Customer";
|
||||||
|
import DocumentsRepository from "@Repositories/DocumentsRepository";
|
||||||
|
import BaseService from "@Services/BaseService";
|
||||||
|
import { Service } from "typedi";
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export default class DocumentsService extends BaseService {
|
||||||
|
constructor(private documentsRepository: DocumentsRepository) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Get all documents
|
||||||
|
* @throws {Error} If documents cannot be get
|
||||||
|
*/
|
||||||
|
public async get(query: any) {
|
||||||
|
return this.documentsRepository.findMany(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Create a new document
|
||||||
|
* @throws {Error} If document cannot be created
|
||||||
|
*/
|
||||||
|
public async create(document: Document): Promise<Documents> {
|
||||||
|
return this.documentsRepository.create(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Create new documents
|
||||||
|
* @throws {Error} If documents or one of them cannot be created
|
||||||
|
*/
|
||||||
|
public async createMany(documents: Document[]): Promise<Prisma.BatchPayload> {
|
||||||
|
return this.documentsRepository.createMany(documents);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Modify a document
|
||||||
|
* @throws {Error} If document cannot be modified
|
||||||
|
*/
|
||||||
|
public async update(uid: string, document: Document): Promise<Documents> {
|
||||||
|
return this.documentsRepository.update(uid, document);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Delete a document
|
||||||
|
* @throws {Error} If document cannot be deleted
|
||||||
|
*/
|
||||||
|
public async delete(uid: string): Promise<Documents> {
|
||||||
|
return this.documentsRepository.delete(uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Get a document by uid
|
||||||
|
* @throws {Error} If document cannot be get by uid
|
||||||
|
*/
|
||||||
|
public async getByUid(uid: string, query?: any) {
|
||||||
|
return this.documentsRepository.findOneByUid(uid, query);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import { Customers } from "@prisma/client";
|
import { Customers, Prisma } from "@prisma/client";
|
||||||
import CustomersRepository from "@Repositories/CustomersRepository";
|
import CustomersRepository from "@Repositories/CustomersRepository";
|
||||||
import BaseService from "@Services/BaseService";
|
import BaseService from "@Services/BaseService";
|
||||||
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
@ -14,7 +14,7 @@ export default class CustomersService extends BaseService {
|
|||||||
* @description : Get all Customers
|
* @description : Get all Customers
|
||||||
* @throws {Error} If Customers cannot be get
|
* @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);
|
return this.customerRepository.findMany(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ export default class OfficeFoldersService extends BaseService {
|
|||||||
* @throws {Error} If folder cannot be created
|
* @throws {Error} If folder cannot be created
|
||||||
*/
|
*/
|
||||||
public async create(officeFolderEntity: OfficeFolder): Promise<OfficeFolders> {
|
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');
|
if(deedType.archived_at) throw new Error('deed type is archived');
|
||||||
return this.officeFoldersRepository.create(officeFolderEntity);
|
return this.officeFoldersRepository.create(officeFolderEntity);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import "reflect-metadata";
|
|||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import UsersRepository from "@Repositories/UsersRepository";
|
import UsersRepository from "@Repositories/UsersRepository";
|
||||||
import User from "le-coffre-resources/dist/SuperAdmin";
|
import User from "le-coffre-resources/dist/SuperAdmin";
|
||||||
import { Users } from "@prisma/client";
|
import {Prisma, Users } from "@prisma/client";
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class UsersService extends BaseService {
|
export default class UsersService extends BaseService {
|
||||||
@ -15,7 +15,7 @@ export default class UsersService extends BaseService {
|
|||||||
* @description : Get all users
|
* @description : Get all users
|
||||||
* @throws {Error} If users cannot be get
|
* @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);
|
return this.userRepository.findMany(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,9 +11,9 @@ export const initOffice = (office: Office): Promise<Offices> => {
|
|||||||
crpcen: office.crpcen,
|
crpcen: office.crpcen,
|
||||||
address: {
|
address: {
|
||||||
create: {
|
create: {
|
||||||
address: office.address.address,
|
address: office.address!.address,
|
||||||
zip_code: office.address.zip_code,
|
zip_code: office.address!.zip_code,
|
||||||
city: office.address.city,
|
city: office.address!.city,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -57,17 +57,17 @@ export const initCustomers = (customer: Customer): Promise<Customers> => {
|
|||||||
status: ECustomerStatus.PENDING,
|
status: ECustomerStatus.PENDING,
|
||||||
contact: {
|
contact: {
|
||||||
create: {
|
create: {
|
||||||
first_name: customer.contact.first_name,
|
first_name: customer.contact!.first_name,
|
||||||
last_name: customer.contact.last_name,
|
last_name: customer.contact!.last_name,
|
||||||
email: customer.contact.email,
|
email: customer.contact!.email,
|
||||||
phone_number: customer.contact.phone_number,
|
phone_number: customer.contact!.phone_number,
|
||||||
cell_phone_number: customer.contact?.cell_phone_number,
|
cell_phone_number: customer.contact!?.cell_phone_number,
|
||||||
civility: ECivility[customer.contact.civility as keyof typeof ECivility],
|
civility: ECivility[customer.contact!.civility as keyof typeof ECivility],
|
||||||
address: {
|
address: {
|
||||||
create: {
|
create: {
|
||||||
address: customer.contact.address!.address,
|
address: customer.contact!.address!.address,
|
||||||
zip_code: customer.contact.address!.zip_code,
|
zip_code: customer.contact!.address!.zip_code,
|
||||||
city: customer.contact.address!.city,
|
city: customer.contact!.address!.city,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -83,17 +83,17 @@ export const initUsers = (user: User): Promise<Users> => {
|
|||||||
office_membership: {
|
office_membership: {
|
||||||
connectOrCreate: {
|
connectOrCreate: {
|
||||||
where: {
|
where: {
|
||||||
idNot: user.office_membership.idNot,
|
idNot: user.office_membership!.idNot,
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
idNot: user.office_membership.idNot,
|
idNot: user.office_membership!.idNot,
|
||||||
name: user.office_membership.name,
|
name: user.office_membership!.name,
|
||||||
crpcen: user.office_membership.crpcen,
|
crpcen: user.office_membership!.crpcen,
|
||||||
address: {
|
address: {
|
||||||
create: {
|
create: {
|
||||||
address: user.office_membership.address.address,
|
address: user.office_membership!.address!.address,
|
||||||
zip_code: user.office_membership.address.zip_code,
|
zip_code: user.office_membership!.address!.zip_code,
|
||||||
city: user.office_membership.address.city,
|
city: user.office_membership!.address!.city,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -101,17 +101,17 @@ export const initUsers = (user: User): Promise<Users> => {
|
|||||||
},
|
},
|
||||||
contact: {
|
contact: {
|
||||||
create: {
|
create: {
|
||||||
first_name: user.contact.first_name,
|
first_name: user.contact!.first_name,
|
||||||
last_name: user.contact.last_name,
|
last_name: user.contact!.last_name,
|
||||||
email: user.contact.email,
|
email: user.contact!.email,
|
||||||
phone_number: user.contact.phone_number,
|
phone_number: user.contact!.phone_number,
|
||||||
cell_phone_number: user.contact.cell_phone_number,
|
cell_phone_number: user.contact!.cell_phone_number,
|
||||||
civility: ECivility[user.contact.civility as keyof typeof ECivility],
|
civility: ECivility[user.contact!.civility as keyof typeof ECivility],
|
||||||
address: {
|
address: {
|
||||||
create: {
|
create: {
|
||||||
address: user.contact.address!.address,
|
address: user.contact!.address!.address,
|
||||||
zip_code: user.contact.address!.zip_code,
|
zip_code: user.contact!.address!.zip_code,
|
||||||
city: user.contact.address!.city,
|
city: user.contact!.address!.city,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -29,18 +29,18 @@ describe("test create function", () => {
|
|||||||
|
|
||||||
// verify if customer contact is created in db
|
// verify if customer contact is created in db
|
||||||
const contactCreated = await prisma.contacts.findUnique({ where: { uid: customerCreated.contact_uid } });
|
const contactCreated = await prisma.contacts.findUnique({ where: { uid: customerCreated.contact_uid } });
|
||||||
expect(contactCreated?.first_name).toEqual(customer.contact.first_name);
|
expect(contactCreated?.first_name).toEqual(customer.contact!.first_name);
|
||||||
expect(contactCreated?.last_name).toEqual(customer.contact.last_name);
|
expect(contactCreated?.last_name).toEqual(customer.contact!.last_name);
|
||||||
expect(contactCreated?.cell_phone_number).toEqual(customer.contact.cell_phone_number);
|
expect(contactCreated?.cell_phone_number).toEqual(customer.contact!.cell_phone_number);
|
||||||
expect(contactCreated?.phone_number).toEqual(customer.contact.phone_number);
|
expect(contactCreated?.phone_number).toEqual(customer.contact!.phone_number);
|
||||||
expect(contactCreated?.civility).toEqual(customer.contact.civility);
|
expect(contactCreated?.civility).toEqual(customer.contact!.civility);
|
||||||
expect(contactCreated?.email).toEqual(customer.contact.email);
|
expect(contactCreated?.email).toEqual(customer.contact!.email);
|
||||||
|
|
||||||
// verify if customer address is created in db
|
// verify if customer address is created in db
|
||||||
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid } });
|
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid } });
|
||||||
expect(addressForContactCreated?.address).toEqual(customer.contact.address?.address);
|
expect(addressForContactCreated?.address).toEqual(customer.contact!.address?.address);
|
||||||
expect(addressForContactCreated?.zip_code).toEqual(customer.contact.address?.zip_code);
|
expect(addressForContactCreated?.zip_code).toEqual(customer.contact!.address?.zip_code);
|
||||||
expect(addressForContactCreated?.city).toEqual(customer.contact.address?.city);
|
expect(addressForContactCreated?.city).toEqual(customer.contact!.address?.city);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not create an customer already created", async () => {
|
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 () => {
|
it("should not create an new customer with an email already created", async () => {
|
||||||
let newCustomer: Customer = JSON.parse(JSON.stringify(customer_));
|
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
|
// try to create a new customer with already used email
|
||||||
async function createCustomerWithDuplicateEmail() {
|
async function createCustomerWithDuplicateEmail() {
|
||||||
@ -64,7 +64,7 @@ describe("test create function", () => {
|
|||||||
|
|
||||||
it("should not create an customer with an phone number already created", async () => {
|
it("should not create an customer with an phone number already created", async () => {
|
||||||
let newCustomer: Customer = JSON.parse(JSON.stringify(customer_));
|
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
|
// try to create a new customer with already used cellphone number
|
||||||
async function duplicateCustomer() {
|
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 () => {
|
it("should create an new customer if unique attributes differ from existing customers", async () => {
|
||||||
let newCustomer: Customer = JSON.parse(JSON.stringify(customer));
|
let newCustomer: Customer = JSON.parse(JSON.stringify(customer));
|
||||||
newCustomer.contact.email = customerContact_.email;
|
newCustomer.contact!.email = customerContact_.email;
|
||||||
newCustomer.contact.cell_phone_number = customerContact_.cell_phone_number;
|
newCustomer.contact!.cell_phone_number = customerContact_.cell_phone_number;
|
||||||
|
|
||||||
const customerCreated = await CustomersServiceTest.create(newCustomer);
|
const customerCreated = await CustomersServiceTest.create(newCustomer);
|
||||||
|
|
||||||
@ -84,24 +84,24 @@ describe("test create function", () => {
|
|||||||
|
|
||||||
// verify if customer_ contact is created in db
|
// verify if customer_ contact is created in db
|
||||||
const contactCreated = await prisma.contacts.findUnique({ where: { uid: customerCreated.contact_uid } });
|
const contactCreated = await prisma.contacts.findUnique({ where: { uid: customerCreated.contact_uid } });
|
||||||
expect(contactCreated?.first_name).toEqual(customer.contact.first_name);
|
expect(contactCreated?.first_name).toEqual(customer.contact!.first_name);
|
||||||
expect(contactCreated?.last_name).toEqual(customer.contact.last_name);
|
expect(contactCreated?.last_name).toEqual(customer.contact!.last_name);
|
||||||
expect(contactCreated?.cell_phone_number).toEqual(customer_.contact.cell_phone_number);
|
expect(contactCreated?.cell_phone_number).toEqual(customer_.contact!.cell_phone_number);
|
||||||
expect(contactCreated?.phone_number).toEqual(customer.contact.phone_number);
|
expect(contactCreated?.phone_number).toEqual(customer.contact!.phone_number);
|
||||||
expect(contactCreated?.civility).toEqual(customer.contact.civility);
|
expect(contactCreated?.civility).toEqual(customer.contact!.civility);
|
||||||
expect(contactCreated?.email).toEqual(customer_.contact.email);
|
expect(contactCreated?.email).toEqual(customer_.contact!.email);
|
||||||
|
|
||||||
// verify if customer_ address is created in db
|
// verify if customer_ address is created in db
|
||||||
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid } });
|
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid } });
|
||||||
expect(addressForContactCreated?.address).toEqual(customer.contact.address?.address);
|
expect(addressForContactCreated?.address).toEqual(customer.contact!.address?.address);
|
||||||
expect(addressForContactCreated?.zip_code).toEqual(customer.contact.address?.zip_code);
|
expect(addressForContactCreated?.zip_code).toEqual(customer.contact!.address?.zip_code);
|
||||||
expect(addressForContactCreated?.city).toEqual(customer.contact.address?.city);
|
expect(addressForContactCreated?.city).toEqual(customer.contact!.address?.city);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("test update function", () => {
|
describe("test update function", () => {
|
||||||
it("should update an customer's data", async () => {
|
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
|
// update the last customer created with his own new office and own contact
|
||||||
const updatedCustomer = await CustomersServiceTest.update(customerCreated.uid, customer_);
|
const updatedCustomer = await CustomersServiceTest.update(customerCreated.uid, customer_);
|
||||||
@ -110,24 +110,24 @@ describe("test update function", () => {
|
|||||||
|
|
||||||
// verify if customer_ contact is created in db
|
// verify if customer_ contact is created in db
|
||||||
const existingContact = await prisma.contacts.findUnique({ where: { uid: updatedCustomer.contact_uid } });
|
const existingContact = await prisma.contacts.findUnique({ where: { uid: updatedCustomer.contact_uid } });
|
||||||
expect(existingContact?.first_name).toEqual(customer_.contact.first_name);
|
expect(existingContact?.first_name).toEqual(customer_.contact!.first_name);
|
||||||
expect(existingContact?.last_name).toEqual(customer_.contact.last_name);
|
expect(existingContact?.last_name).toEqual(customer_.contact!.last_name);
|
||||||
expect(existingContact?.cell_phone_number).toEqual(customer_.contact.cell_phone_number);
|
expect(existingContact?.cell_phone_number).toEqual(customer_.contact!.cell_phone_number);
|
||||||
expect(existingContact?.phone_number).toEqual(customer_.contact.phone_number);
|
expect(existingContact?.phone_number).toEqual(customer_.contact!.phone_number);
|
||||||
expect(existingContact?.civility).toEqual(customer_.contact.civility);
|
expect(existingContact?.civility).toEqual(customer_.contact!.civility);
|
||||||
expect(existingContact?.email).toEqual(customer_.contact.email);
|
expect(existingContact?.email).toEqual(customer_.contact!.email);
|
||||||
|
|
||||||
// verify if customer_ address is created in db
|
// verify if customer_ address is created in db
|
||||||
const addressForExistingContact = await prisma.addresses.findUnique({ where: { uid: existingContact?.address_uid } });
|
const addressForExistingContact = await prisma.addresses.findUnique({ where: { uid: existingContact?.address_uid } });
|
||||||
expect(addressForExistingContact?.address).toEqual(customer_.contact.address?.address);
|
expect(addressForExistingContact?.address).toEqual(customer_.contact!.address?.address);
|
||||||
expect(addressForExistingContact?.zip_code).toEqual(customer_.contact.address?.zip_code);
|
expect(addressForExistingContact?.zip_code).toEqual(customer_.contact!.address?.zip_code);
|
||||||
expect(addressForExistingContact?.city).toEqual(customer_.contact.address?.city);
|
expect(addressForExistingContact?.city).toEqual(customer_.contact!.address?.city);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not update an customer with an email already used", async () => {
|
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_));
|
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
|
// try to create a new customer with already used email
|
||||||
async function updateCustomerWithDuplicateEmail() {
|
async function updateCustomerWithDuplicateEmail() {
|
||||||
@ -137,9 +137,9 @@ describe("test update function", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should not update an customer with an phone number already used", async () => {
|
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_));
|
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
|
// try to create a new customer with already used email
|
||||||
async function updateCustomerWithDuplicateEmail() {
|
async function updateCustomerWithDuplicateEmail() {
|
||||||
|
@ -29,7 +29,7 @@ afterAll(async () => {
|
|||||||
describe("test create function", () => {
|
describe("test create function", () => {
|
||||||
it("should not create a new deed if deed type is unknown", async () => {
|
it("should not create a new deed if deed type is unknown", async () => {
|
||||||
let deedWithoutDeedTypeUid: Deed = JSON.parse(JSON.stringify(deed));
|
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
|
// try to create a new deed with unknown deed type
|
||||||
async function createDeedWithUnknownDeedType() {
|
async function createDeedWithUnknownDeedType() {
|
||||||
await DeedServiceTest.create(deedWithoutDeedTypeUid);
|
await DeedServiceTest.create(deedWithoutDeedTypeUid);
|
||||||
@ -39,7 +39,7 @@ describe("test create function", () => {
|
|||||||
|
|
||||||
it("should create a new deed based on existing deed type", async () => {
|
it("should create a new deed based on existing deed type", async () => {
|
||||||
let deedWithDeedTypeUid: Deed = JSON.parse(JSON.stringify(deed));
|
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);
|
const deedCreated = await DeedServiceTest.create(deedWithDeedTypeUid);
|
||||||
|
|
||||||
expect(deedCreated.deed_type_uid).toEqual(deedType.uid);
|
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 () => {
|
it("should create a the same deed based on existing deed type", async () => {
|
||||||
let deedWithDeedTypeUid: Deed = JSON.parse(JSON.stringify(deed));
|
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);
|
const deedCreated = await DeedServiceTest.create(deedWithDeedTypeUid);
|
||||||
|
|
||||||
expect(deedCreated.deed_type_uid).toEqual(deedType.uid);
|
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 () => {
|
it("should not create a new deed based on archivated deed type", async () => {
|
||||||
let deedArchivated: Deed = JSON.parse(JSON.stringify(deed));
|
let deedArchivated: Deed = JSON.parse(JSON.stringify(deed));
|
||||||
deedArchivated.deed_type.uid = deedType.uid;
|
deedArchivated.deed_type!.uid = deedType.uid;
|
||||||
|
|
||||||
await prisma.deedTypes.update({
|
await prisma.deedTypes.update({
|
||||||
where: { uid: deedType.uid },
|
where: { uid: deedType.uid },
|
||||||
|
@ -29,7 +29,7 @@ afterAll(async () => {
|
|||||||
describe("test create function", () => {
|
describe("test create function", () => {
|
||||||
it("should not create a new deed type if office is unknown", async () => {
|
it("should not create a new deed type if office is unknown", async () => {
|
||||||
let deedTypeWithoutOfficeUid: DeedType = JSON.parse(JSON.stringify(deedType));
|
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
|
// try to create a new deed type with unknown office
|
||||||
async function createDeedTypeWithUnknownOffice() {
|
async function createDeedTypeWithUnknownOffice() {
|
||||||
await DeedTypeServiceTest.create(deedTypeWithoutOfficeUid);
|
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 () => {
|
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_));
|
let deedTypeWithSameNameAndOffice: DeedType = JSON.parse(JSON.stringify(deedType_));
|
||||||
deedTypeWithSameNameAndOffice.office = office;
|
deedTypeWithSameNameAndOffice.office! = office;
|
||||||
deedTypeWithSameNameAndOffice.name = deedType.name;
|
deedTypeWithSameNameAndOffice.name = deedType.name;
|
||||||
|
|
||||||
async function createDeedTypeWithSameNameAndOffice() {
|
async function createDeedTypeWithSameNameAndOffice() {
|
||||||
@ -59,7 +59,7 @@ describe("test create function", () => {
|
|||||||
|
|
||||||
it("should create the same deed type for a different office", async () => {
|
it("should create the same deed type for a different office", async () => {
|
||||||
let deedTypeDuplicatedForNewOffice: DeedType = JSON.parse(JSON.stringify(deedType));
|
let deedTypeDuplicatedForNewOffice: DeedType = JSON.parse(JSON.stringify(deedType));
|
||||||
deedTypeDuplicatedForNewOffice.office = office_;
|
deedTypeDuplicatedForNewOffice.office! = office_;
|
||||||
|
|
||||||
const deedTypeCreated = await DeedTypeServiceTest.create(deedTypeDuplicatedForNewOffice);
|
const deedTypeCreated = await DeedTypeServiceTest.create(deedTypeDuplicatedForNewOffice);
|
||||||
|
|
||||||
@ -89,10 +89,10 @@ describe("test update function", () => {
|
|||||||
expect(deedTypeCreated.name).toEqual(deedType_.name);
|
expect(deedTypeCreated.name).toEqual(deedType_.name);
|
||||||
expect(deedTypeCreated.description).toEqual(deedType.description);
|
expect(deedTypeCreated.description).toEqual(deedType.description);
|
||||||
expect(deedTypeCreated.archived_at).toBeNull();
|
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_));
|
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
|
// update the last deed type created with his the right description
|
||||||
const deedTypeUpdated = await DeedTypeServiceTest.update(deedTypeCreated.uid, deedTypeWithNewDescription);
|
const deedTypeUpdated = await DeedTypeServiceTest.update(deedTypeCreated.uid, deedTypeWithNewDescription);
|
||||||
@ -100,13 +100,13 @@ describe("test update function", () => {
|
|||||||
expect(deedTypeUpdated.name).toEqual(deedType_.name);
|
expect(deedTypeUpdated.name).toEqual(deedType_.name);
|
||||||
expect(deedTypeUpdated.description).toEqual(deedType_.description);
|
expect(deedTypeUpdated.description).toEqual(deedType_.description);
|
||||||
expect(deedTypeUpdated.archived_at).toBeNull();
|
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 () => {
|
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;
|
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uid: office.uid } })).uid;
|
||||||
let deedTypeWithSameNameAndOffice: DeedType = JSON.parse(JSON.stringify(deedType_));
|
let deedTypeWithSameNameAndOffice: DeedType = JSON.parse(JSON.stringify(deedType_));
|
||||||
deedTypeWithSameNameAndOffice.office.uid = office.uid;
|
deedTypeWithSameNameAndOffice.office!.uid = office.uid;
|
||||||
deedTypeWithSameNameAndOffice.name = deedType.name;
|
deedTypeWithSameNameAndOffice.name = deedType.name;
|
||||||
|
|
||||||
// update the last deed type created with his the right description
|
// 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 () => {
|
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;
|
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uid: office.uid } })).uid;
|
||||||
let deedTypeWithSameNameAndOffice: DeedType = JSON.parse(JSON.stringify(deedType_));
|
let deedTypeWithSameNameAndOffice: DeedType = JSON.parse(JSON.stringify(deedType_));
|
||||||
deedTypeWithSameNameAndOffice.office.uid = office.uid;
|
deedTypeWithSameNameAndOffice.office!.uid = office.uid;
|
||||||
deedTypeWithSameNameAndOffice.name = deedType.name;
|
deedTypeWithSameNameAndOffice.name = deedType.name;
|
||||||
|
|
||||||
// try to duplicate deed type in a given office
|
// 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.name).toEqual(deedType_.name);
|
||||||
expect(deedTypeUpdated.description).toEqual(deedType_.description);
|
expect(deedTypeUpdated.description).toEqual(deedType_.description);
|
||||||
expect(deedTypeUpdated.archived_at).toBeNull();
|
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 () => {
|
it("should archivate a deed type", async () => {
|
||||||
@ -152,7 +152,7 @@ describe("test update function", () => {
|
|||||||
expect(deedTypeCreated.name).toEqual(deedType_.name);
|
expect(deedTypeCreated.name).toEqual(deedType_.name);
|
||||||
expect(deedTypeCreated.description).toEqual(deedType_.description);
|
expect(deedTypeCreated.description).toEqual(deedType_.description);
|
||||||
expect(deedTypeCreated.archived_at).toBeNull();
|
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_));
|
let deedTypeArchivated: DeedType = JSON.parse(JSON.stringify(deedType_));
|
||||||
const currentDate = new Date(Date.now());
|
const currentDate = new Date(Date.now());
|
||||||
@ -173,7 +173,7 @@ describe("test update function", () => {
|
|||||||
expect(deedTypeCreated.name).toEqual(deedType_.name);
|
expect(deedTypeCreated.name).toEqual(deedType_.name);
|
||||||
expect(deedTypeCreated.description).toEqual(deedType_.description);
|
expect(deedTypeCreated.description).toEqual(deedType_.description);
|
||||||
expect(deedTypeCreated.archived_at).not.toBeNull();
|
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
|
// unarchivate a deed type by giving a null date for archivated_at attribute
|
||||||
const deedTypeUpdated = await DeedTypeServiceTest.update(deedTypeCreated.uid, deedType_);
|
const deedTypeUpdated = await DeedTypeServiceTest.update(deedTypeCreated.uid, deedType_);
|
||||||
|
@ -27,7 +27,7 @@ afterAll(async () => {
|
|||||||
describe("test create function", () => {
|
describe("test create function", () => {
|
||||||
it("should not create a new document type if office is unknown", async () => {
|
it("should not create a new document type if office is unknown", async () => {
|
||||||
let documentTypeWithoutOfficeUid: DocumentType = JSON.parse(JSON.stringify(documentType));
|
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
|
// try to create a new document type with unknown office
|
||||||
async function createDocumentTypeWithUnknownOffice() {
|
async function createDocumentTypeWithUnknownOffice() {
|
||||||
await DocumentTypesServiceTest.create(documentTypeWithoutOfficeUid);
|
await DocumentTypesServiceTest.create(documentTypeWithoutOfficeUid);
|
||||||
@ -37,7 +37,7 @@ describe("test create function", () => {
|
|||||||
|
|
||||||
it("should create a new document type", async () => {
|
it("should create a new document type", async () => {
|
||||||
let documentTypeWithOfficeUid: DocumentType = JSON.parse(JSON.stringify(documentType));
|
let documentTypeWithOfficeUid: DocumentType = JSON.parse(JSON.stringify(documentType));
|
||||||
documentTypeWithOfficeUid.office.uid = office.uid;
|
documentTypeWithOfficeUid.office!.uid = office.uid;
|
||||||
const documentTypeCreated = await DocumentTypesServiceTest.create(documentTypeWithOfficeUid);
|
const documentTypeCreated = await DocumentTypesServiceTest.create(documentTypeWithOfficeUid);
|
||||||
|
|
||||||
expect(documentTypeCreated.name).toEqual(documentType.name);
|
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 () => {
|
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_));
|
let documentTypeWithSameNameAndOffice: DocumentType = JSON.parse(JSON.stringify(documentType_));
|
||||||
documentTypeWithSameNameAndOffice.office.uid = office.uid;
|
documentTypeWithSameNameAndOffice.office!.uid = office.uid;
|
||||||
documentTypeWithSameNameAndOffice.name = documentType.name;
|
documentTypeWithSameNameAndOffice.name = documentType.name;
|
||||||
|
|
||||||
async function createDocumentTypeWithSameNameAndOffice() {
|
async function createDocumentTypeWithSameNameAndOffice() {
|
||||||
@ -60,7 +60,7 @@ describe("test create function", () => {
|
|||||||
|
|
||||||
it("should create the same document type for a different office", async () => {
|
it("should create the same document type for a different office", async () => {
|
||||||
let documentTypeDuplicatedForNewOffice: DocumentType = JSON.parse(JSON.stringify(documentType));
|
let documentTypeDuplicatedForNewOffice: DocumentType = JSON.parse(JSON.stringify(documentType));
|
||||||
documentTypeDuplicatedForNewOffice.office.uid = office_.uid;
|
documentTypeDuplicatedForNewOffice.office!.uid = office_.uid;
|
||||||
|
|
||||||
const documentTypeCreated = await DocumentTypesServiceTest.create(documentTypeDuplicatedForNewOffice);
|
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 () => {
|
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));
|
let documentTypeWithSameDescription: DocumentType = JSON.parse(JSON.stringify(documentType));
|
||||||
documentTypeWithSameDescription.office.uid = office.uid;
|
documentTypeWithSameDescription.office!.uid = office.uid;
|
||||||
documentTypeWithSameDescription.name = documentType_.name;
|
documentTypeWithSameDescription.name = documentType_.name;
|
||||||
|
|
||||||
const documentTypeCreated = await DocumentTypesServiceTest.create(documentTypeWithSameDescription);
|
const documentTypeCreated = await DocumentTypesServiceTest.create(documentTypeWithSameDescription);
|
||||||
@ -98,7 +98,7 @@ describe("test update function", () => {
|
|||||||
expect(documentTypeCreated.office_uid).toEqual(office.uid);
|
expect(documentTypeCreated.office_uid).toEqual(office.uid);
|
||||||
|
|
||||||
let documentTypeWithNewDescription: DocumentType = JSON.parse(JSON.stringify(documentType_));
|
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
|
// update the last document type created with his the right descriptions
|
||||||
const documentTypeUpdated = await DocumentTypesServiceTest.update(documentTypeCreated.uid, documentTypeWithNewDescription);
|
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 } })
|
await prisma.documentTypes.findFirstOrThrow({ where: { name: documentType_.name, office_uid: office.uid } })
|
||||||
).uid;
|
).uid;
|
||||||
let documentTypeWithSameNameAndOffice: DocumentType = JSON.parse(JSON.stringify(documentType_));
|
let documentTypeWithSameNameAndOffice: DocumentType = JSON.parse(JSON.stringify(documentType_));
|
||||||
documentTypeWithSameNameAndOffice.office.uid = office.uid;
|
documentTypeWithSameNameAndOffice.office!.uid = office.uid;
|
||||||
documentTypeWithSameNameAndOffice.name = documentType.name;
|
documentTypeWithSameNameAndOffice.name = documentType.name;
|
||||||
|
|
||||||
// update the last document type created with his the right description
|
// 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 } })
|
await prisma.documentTypes.findFirstOrThrow({ where: { name: documentType_.name, office_uid: office.uid } })
|
||||||
).uid;
|
).uid;
|
||||||
let documentTypeWithSameNameAndOffice: DocumentType = JSON.parse(JSON.stringify(documentType_));
|
let documentTypeWithSameNameAndOffice: DocumentType = JSON.parse(JSON.stringify(documentType_));
|
||||||
documentTypeWithSameNameAndOffice.office.uid = office.uid;
|
documentTypeWithSameNameAndOffice.office!.uid = office.uid;
|
||||||
documentTypeWithSameNameAndOffice.name = documentType.name;
|
documentTypeWithSameNameAndOffice.name = documentType.name;
|
||||||
|
|
||||||
// try to duplicate document type in a given office
|
// try to duplicate document type in a given office
|
||||||
@ -151,7 +151,7 @@ describe("test update function", () => {
|
|||||||
expect(documentTypeCreated.office_uid).toEqual(office.uid);
|
expect(documentTypeCreated.office_uid).toEqual(office.uid);
|
||||||
|
|
||||||
let documentTypeTransferedToNewOffice: DocumentType = JSON.parse(JSON.stringify(documentType_));
|
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
|
// update the last document type updated with a new office membership
|
||||||
const documentTypeUpdated = await DocumentTypesServiceTest.update(documentTypeCreated.uid, documentTypeTransferedToNewOffice);
|
const documentTypeUpdated = await DocumentTypesServiceTest.update(documentTypeCreated.uid, documentTypeTransferedToNewOffice);
|
||||||
@ -175,7 +175,7 @@ describe("test update function", () => {
|
|||||||
expect(documentTypeCreated.office_uid).toEqual(office_.uid);
|
expect(documentTypeCreated.office_uid).toEqual(office_.uid);
|
||||||
|
|
||||||
let documentTypeArchivated: DocumentType = JSON.parse(JSON.stringify(documentType_));
|
let documentTypeArchivated: DocumentType = JSON.parse(JSON.stringify(documentType_));
|
||||||
documentTypeArchivated.office.uid = office_.uid;
|
documentTypeArchivated.office!.uid = office_.uid;
|
||||||
const currentDate = new Date(Date.now());
|
const currentDate = new Date(Date.now());
|
||||||
documentTypeArchivated.archived_at = currentDate;
|
documentTypeArchivated.archived_at = currentDate;
|
||||||
// archivate a document type by giving a non null date for archivated_at attribute
|
// 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);
|
expect(documentTypeCreated.office_uid).toEqual(office_.uid);
|
||||||
|
|
||||||
let documentTypeUnarchivated: DocumentType = JSON.parse(JSON.stringify(documentType_));
|
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
|
// unarchivate a document type by giving a null date for archivated_at attribute
|
||||||
const documentTypeUpdated = await DocumentTypesServiceTest.update(documentTypeCreated.uid, documentTypeUnarchivated);
|
const documentTypeUpdated = await DocumentTypesServiceTest.update(documentTypeCreated.uid, documentTypeUnarchivated);
|
||||||
|
@ -38,7 +38,7 @@ afterAll(async () => {
|
|||||||
describe("test create function", () => {
|
describe("test create function", () => {
|
||||||
it("should not create a new office folder if deed type is unknown", async () => {
|
it("should not create a new office folder if deed type is unknown", async () => {
|
||||||
let officeFolderWithoutDeedTypeUid: OfficeFolder = JSON.parse(JSON.stringify(officeFolder));
|
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
|
// try to create a new deed with unknown deed type
|
||||||
async function createOfficeFolderWithUnknownDeedType() {
|
async function createOfficeFolderWithUnknownDeedType() {
|
||||||
await OfficeFolderServiceTest.create(officeFolderWithoutDeedTypeUid);
|
await OfficeFolderServiceTest.create(officeFolderWithoutDeedTypeUid);
|
||||||
@ -65,8 +65,8 @@ describe("test create function", () => {
|
|||||||
expect(officeFolderCreated.description).toEqual(officeFolder.description);
|
expect(officeFolderCreated.description).toEqual(officeFolder.description);
|
||||||
expect(officeFolderCreated.archived_description).toEqual(null);
|
expect(officeFolderCreated.archived_description).toEqual(null);
|
||||||
expect(officeFolderCreated.status).toEqual("LIVE");
|
expect(officeFolderCreated.status).toEqual("LIVE");
|
||||||
expect(officeFolderCreated.office_uid).toEqual(officeFolder.office.uid);
|
expect(officeFolderCreated.office_uid).toEqual(officeFolder.office!.uid);
|
||||||
expect(deedCreated.deed_type_uid).toEqual(officeFolder.deed.deed_type.uid);
|
expect(deedCreated.deed_type_uid).toEqual(officeFolder.deed!.deed_type!.uid);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should contains stakeholders", async () => {
|
it("should contains stakeholders", async () => {
|
||||||
|
@ -29,31 +29,31 @@ describe("test create function", () => {
|
|||||||
|
|
||||||
// verify if user contact is created in db
|
// verify if user contact is created in db
|
||||||
const contactCreated = await prisma.contacts.findUnique({ where: { uid: userCreated.contact_uid } });
|
const contactCreated = await prisma.contacts.findUnique({ where: { uid: userCreated.contact_uid } });
|
||||||
expect(contactCreated?.first_name).toEqual(user.contact.first_name);
|
expect(contactCreated?.first_name).toEqual(user.contact!.first_name);
|
||||||
expect(contactCreated?.last_name).toEqual(user.contact.last_name);
|
expect(contactCreated?.last_name).toEqual(user.contact!.last_name);
|
||||||
expect(contactCreated?.cell_phone_number).toEqual(user.contact.cell_phone_number);
|
expect(contactCreated?.cell_phone_number).toEqual(user.contact!.cell_phone_number);
|
||||||
expect(contactCreated?.phone_number).toEqual(user.contact.phone_number);
|
expect(contactCreated?.phone_number).toEqual(user.contact!.phone_number);
|
||||||
expect(contactCreated?.civility).toEqual(user.contact.civility);
|
expect(contactCreated?.civility).toEqual(user.contact!.civility);
|
||||||
expect(contactCreated?.email).toEqual(user.contact.email);
|
expect(contactCreated?.email).toEqual(user.contact!.email);
|
||||||
|
|
||||||
// verify if user address is created in db
|
// verify if user address is created in db
|
||||||
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid } });
|
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid } });
|
||||||
expect(addressForContactCreated?.address).toEqual(user.contact.address?.address);
|
expect(addressForContactCreated?.address).toEqual(user.contact!.address?.address);
|
||||||
expect(addressForContactCreated?.zip_code).toEqual(user.contact.address?.zip_code);
|
expect(addressForContactCreated?.zip_code).toEqual(user.contact!.address?.zip_code);
|
||||||
expect(addressForContactCreated?.city).toEqual(user.contact.address?.city);
|
expect(addressForContactCreated?.city).toEqual(user.contact!.address?.city);
|
||||||
|
|
||||||
// verify if user office is created in db
|
// verify if user office is created in db
|
||||||
const officeCreated = await prisma.offices.findUnique({ where: { uid: userCreated.office_uid } });
|
const officeCreated = await prisma.offices.findUnique({ where: { uid: userCreated.office_uid } });
|
||||||
expect(officeCreated?.idNot).toEqual(user.office_membership.idNot);
|
expect(officeCreated?.idNot).toEqual(user.office_membership!!.idNot);
|
||||||
expect(officeCreated?.name).toEqual(user.office_membership.name);
|
expect(officeCreated?.name).toEqual(user.office_membership!!.name);
|
||||||
expect(officeCreated?.crpcen).toEqual(user.office_membership.crpcen);
|
expect(officeCreated?.crpcen).toEqual(user.office_membership!!.crpcen);
|
||||||
expect(officeCreated?.office_status).toEqual("DESACTIVATED");
|
expect(officeCreated?.office_status).toEqual("DESACTIVATED");
|
||||||
|
|
||||||
// verify if user office's address is created in db
|
// verify if user office's address is created in db
|
||||||
const addressForOfficeCreated = await prisma.addresses.findUnique({ where: { uid: officeCreated?.address_uid } });
|
const addressForOfficeCreated = await prisma.addresses.findUnique({ where: { uid: officeCreated?.address_uid } });
|
||||||
expect(addressForOfficeCreated?.address).toEqual(user.office_membership.address.address);
|
expect(addressForOfficeCreated?.address).toEqual(user.office_membership!.address!.address);
|
||||||
expect(addressForOfficeCreated?.zip_code).toEqual(user.office_membership.address.zip_code);
|
expect(addressForOfficeCreated?.zip_code).toEqual(user.office_membership!.address!.zip_code);
|
||||||
expect(addressForOfficeCreated?.city).toEqual(user.office_membership.address.city);
|
expect(addressForOfficeCreated?.city).toEqual(user.office_membership!.address!.city);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not create an user already created", async () => {
|
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 () => {
|
it("should not create an new user with an email already created", async () => {
|
||||||
let newUser: User = JSON.parse(JSON.stringify(user_));
|
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
|
// try to create a new user with already used email
|
||||||
async function createUserWithDuplicateEmail() {
|
async function createUserWithDuplicateEmail() {
|
||||||
@ -77,7 +77,7 @@ describe("test create function", () => {
|
|||||||
|
|
||||||
it("should not create an user with an phone number already created", async () => {
|
it("should not create an user with an phone number already created", async () => {
|
||||||
let newUser: User = JSON.parse(JSON.stringify(user_));
|
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
|
// try to create a new user with already used cellphone number
|
||||||
async function duplicateUser() {
|
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 () => {
|
it("should create an new user if unique attributes differ from existing users", async () => {
|
||||||
let newUser: User = JSON.parse(JSON.stringify(user));
|
let newUser: User = JSON.parse(JSON.stringify(user));
|
||||||
newUser.idNot = user_.idNot;
|
newUser.idNot = user_.idNot;
|
||||||
newUser.contact.email = userContact_.email;
|
newUser.contact!.email = userContact_.email;
|
||||||
newUser.contact.cell_phone_number = userContact_.cell_phone_number;
|
newUser.contact!.cell_phone_number = userContact_.cell_phone_number;
|
||||||
|
|
||||||
const userCreated = await UsersServiceTest.create(newUser);
|
const userCreated = await UsersServiceTest.create(newUser);
|
||||||
|
|
||||||
@ -98,24 +98,24 @@ describe("test create function", () => {
|
|||||||
|
|
||||||
// verify if user_ contact is created in db
|
// verify if user_ contact is created in db
|
||||||
const contactCreated = await prisma.contacts.findUnique({ where: { uid: userCreated.contact_uid } });
|
const contactCreated = await prisma.contacts.findUnique({ where: { uid: userCreated.contact_uid } });
|
||||||
expect(contactCreated?.first_name).toEqual(user.contact.first_name);
|
expect(contactCreated?.first_name).toEqual(user.contact!.first_name);
|
||||||
expect(contactCreated?.last_name).toEqual(user.contact.last_name);
|
expect(contactCreated?.last_name).toEqual(user.contact!.last_name);
|
||||||
expect(contactCreated?.cell_phone_number).toEqual(user_.contact.cell_phone_number);
|
expect(contactCreated?.cell_phone_number).toEqual(user_.contact!.cell_phone_number);
|
||||||
expect(contactCreated?.phone_number).toEqual(user.contact.phone_number);
|
expect(contactCreated?.phone_number).toEqual(user.contact!.phone_number);
|
||||||
expect(contactCreated?.civility).toEqual(user.contact.civility);
|
expect(contactCreated?.civility).toEqual(user.contact!.civility);
|
||||||
expect(contactCreated?.email).toEqual(user_.contact.email);
|
expect(contactCreated?.email).toEqual(user_.contact!.email);
|
||||||
|
|
||||||
// verify if user_ address is created in db
|
// verify if user_ address is created in db
|
||||||
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid } });
|
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid } });
|
||||||
expect(addressForContactCreated?.address).toEqual(user.contact.address?.address);
|
expect(addressForContactCreated?.address).toEqual(user.contact!.address?.address);
|
||||||
expect(addressForContactCreated?.zip_code).toEqual(user.contact.address?.zip_code);
|
expect(addressForContactCreated?.zip_code).toEqual(user.contact!.address?.zip_code);
|
||||||
expect(addressForContactCreated?.city).toEqual(user.contact.address?.city);
|
expect(addressForContactCreated?.city).toEqual(user.contact!.address?.city);
|
||||||
|
|
||||||
// verify if user joined the existing office
|
// verify if user joined the existing office
|
||||||
const officeJoined = await prisma.offices.findUnique({ where: { uid: userCreated.office_uid } });
|
const officeJoined = await prisma.offices.findUnique({ where: { uid: userCreated.office_uid } });
|
||||||
expect(officeJoined?.idNot).toEqual(user.office_membership.idNot);
|
expect(officeJoined?.idNot).toEqual(user.office_membership!!.idNot);
|
||||||
expect(officeJoined?.name).toEqual(user.office_membership.name);
|
expect(officeJoined?.name).toEqual(user.office_membership!!.name);
|
||||||
expect(officeJoined?.crpcen).toEqual(user.office_membership.crpcen);
|
expect(officeJoined?.crpcen).toEqual(user.office_membership!!.crpcen);
|
||||||
expect(officeJoined?.office_status).toEqual("DESACTIVATED");
|
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 userCreated = await prisma.users.findFirstOrThrow({ where: { idNot: user_.idNot } });
|
||||||
|
|
||||||
const officeJoined = await prisma.offices.findUnique({ where: { uid: userCreated.office_uid } });
|
const officeJoined = await prisma.offices.findUnique({ where: { uid: userCreated.office_uid } });
|
||||||
expect(officeJoined?.idNot).toEqual(user.office_membership.idNot);
|
expect(officeJoined?.idNot).toEqual(user.office_membership!!.idNot);
|
||||||
expect(officeJoined?.name).toEqual(user.office_membership.name);
|
expect(officeJoined?.name).toEqual(user.office_membership!!.name);
|
||||||
expect(officeJoined?.crpcen).toEqual(user.office_membership.crpcen);
|
expect(officeJoined?.crpcen).toEqual(user.office_membership!!.crpcen);
|
||||||
expect(officeJoined?.office_status).toEqual("DESACTIVATED");
|
expect(officeJoined?.office_status).toEqual("DESACTIVATED");
|
||||||
|
|
||||||
// update the last user created with his own new office and own contact
|
// 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
|
// verify if user_ contact is created in db
|
||||||
const existingContact = await prisma.contacts.findUnique({ where: { uid: updatedUser.contact_uid } });
|
const existingContact = await prisma.contacts.findUnique({ where: { uid: updatedUser.contact_uid } });
|
||||||
expect(existingContact?.first_name).toEqual(user_.contact.first_name);
|
expect(existingContact?.first_name).toEqual(user_.contact!.first_name);
|
||||||
expect(existingContact?.last_name).toEqual(user_.contact.last_name);
|
expect(existingContact?.last_name).toEqual(user_.contact!.last_name);
|
||||||
expect(existingContact?.cell_phone_number).toEqual(user_.contact.cell_phone_number);
|
expect(existingContact?.cell_phone_number).toEqual(user_.contact!.cell_phone_number);
|
||||||
expect(existingContact?.phone_number).toEqual(user_.contact.phone_number);
|
expect(existingContact?.phone_number).toEqual(user_.contact!.phone_number);
|
||||||
expect(existingContact?.civility).toEqual(user_.contact.civility);
|
expect(existingContact?.civility).toEqual(user_.contact!.civility);
|
||||||
expect(existingContact?.email).toEqual(user_.contact.email);
|
expect(existingContact?.email).toEqual(user_.contact!.email);
|
||||||
|
|
||||||
// verify if user_ address is created in db
|
// verify if user_ address is created in db
|
||||||
const addressForExistingContact = await prisma.addresses.findUnique({ where: { uid: existingContact?.address_uid } });
|
const addressForExistingContact = await prisma.addresses.findUnique({ where: { uid: existingContact?.address_uid } });
|
||||||
expect(addressForExistingContact?.address).toEqual(user_.contact.address?.address);
|
expect(addressForExistingContact?.address).toEqual(user_.contact!.address?.address);
|
||||||
expect(addressForExistingContact?.zip_code).toEqual(user_.contact.address?.zip_code);
|
expect(addressForExistingContact?.zip_code).toEqual(user_.contact!.address?.zip_code);
|
||||||
expect(addressForExistingContact?.city).toEqual(user_.contact.address?.city);
|
expect(addressForExistingContact?.city).toEqual(user_.contact!.address?.city);
|
||||||
|
|
||||||
// verify if user_ joined the new office
|
// verify if user_ joined the new office
|
||||||
const officeCreated = await prisma.offices.findUnique({ where: { uid: updatedUser.office_uid } });
|
const officeCreated = await prisma.offices.findUnique({ where: { uid: updatedUser.office_uid } });
|
||||||
expect(officeCreated?.idNot).toEqual(user_.office_membership.idNot);
|
expect(officeCreated?.idNot).toEqual(user_.office_membership!.idNot);
|
||||||
expect(officeCreated?.name).toEqual(user_.office_membership.name);
|
expect(officeCreated?.name).toEqual(user_.office_membership!.name);
|
||||||
expect(officeCreated?.crpcen).toEqual(user_.office_membership.crpcen);
|
expect(officeCreated?.crpcen).toEqual(user_.office_membership!.crpcen);
|
||||||
expect(officeCreated?.office_status).toEqual("DESACTIVATED");
|
expect(officeCreated?.office_status).toEqual("DESACTIVATED");
|
||||||
|
|
||||||
// verify is user_ office's address is created in db
|
// verify is user_ office's address is created in db
|
||||||
const addressForOfficeCreated = await prisma.addresses.findUnique({ where: { uid: officeCreated?.address_uid } });
|
const addressForOfficeCreated = await prisma.addresses.findUnique({ where: { uid: officeCreated?.address_uid } });
|
||||||
expect(addressForOfficeCreated?.address).toEqual(user_.office_membership.address.address);
|
expect(addressForOfficeCreated?.address).toEqual(user_.office_membership!.address!.address);
|
||||||
expect(addressForOfficeCreated?.zip_code).toEqual(user_.office_membership.address.zip_code);
|
expect(addressForOfficeCreated?.zip_code).toEqual(user_.office_membership!.address!.zip_code);
|
||||||
expect(addressForOfficeCreated?.city).toEqual(user_.office_membership.address.city);
|
expect(addressForOfficeCreated?.city).toEqual(user_.office_membership!.address!.city);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not update an user with an email already used", async () => {
|
it("should not update an user with an email already used", async () => {
|
||||||
const userUid = (await prisma.users.findFirstOrThrow({ where: { idNot: user_.idNot } })).uid;
|
const userUid = (await prisma.users.findFirstOrThrow({ where: { idNot: user_.idNot } })).uid;
|
||||||
let updatedUser: User = JSON.parse(JSON.stringify(user_));
|
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
|
// try to create a new user with already used email
|
||||||
async function updateUserWithDuplicateEmail() {
|
async function updateUserWithDuplicateEmail() {
|
||||||
@ -179,7 +179,7 @@ describe("test update function", () => {
|
|||||||
it("should not update an user with an phone number already used", async () => {
|
it("should not update an user with an phone number already used", async () => {
|
||||||
const userUid = (await prisma.users.findFirstOrThrow({ where: { idNot: user_.idNot } })).uid;
|
const userUid = (await prisma.users.findFirstOrThrow({ where: { idNot: user_.idNot } })).uid;
|
||||||
let updatedUser: User = JSON.parse(JSON.stringify(user_));
|
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
|
// try to create a new user with already used email
|
||||||
async function updateUserWithDuplicateEmail() {
|
async function updateUserWithDuplicateEmail() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user