fix hydratation and make nested fields optionnal
This commit is contained in:
parent
eab04fb12e
commit
a2d68d62c3
@ -47,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",
|
||||||
|
@ -7,7 +7,6 @@ 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";
|
||||||
|
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@Service()
|
@Service()
|
||||||
export default class CustomersController extends ApiController {
|
export default class CustomersController extends ApiController {
|
||||||
@ -23,7 +22,7 @@ export default class CustomersController extends ApiController {
|
|||||||
try {
|
try {
|
||||||
//get query
|
//get query
|
||||||
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 = await this.customersService.get(query);
|
const customersEntity = await this.customersService.get(query);
|
||||||
|
|
||||||
@ -49,7 +48,7 @@ export default class CustomersController extends ApiController {
|
|||||||
Customer.hydrate(customerEntity, req.body);
|
Customer.hydrate(customerEntity, req.body);
|
||||||
|
|
||||||
//validate user
|
//validate user
|
||||||
await validateOrReject(customerEntity, { groups: ["createCustomer"], forbidUnknownValues: false});
|
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);
|
||||||
@ -81,14 +80,14 @@ export default class CustomersController extends ApiController {
|
|||||||
const customerEntity = new Customer();
|
const customerEntity = new Customer();
|
||||||
Customer.hydrate(customerEntity, req.body);
|
Customer.hydrate(customerEntity, req.body);
|
||||||
//validate user
|
//validate user
|
||||||
await validateOrReject(customerEntity, { groups: ["updateCustomer"] , forbidUnknownValues: false});
|
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 = Customer.hydrate<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 = Customer.hydrate<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);
|
||||||
@ -56,8 +56,8 @@ export default class DeedTypesController extends ApiController {
|
|||||||
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: ["createDocumentType"] , forbidUnknownValues: false});
|
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: ["createDocument"] , forbidUnknownValues: false});
|
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
|
||||||
@ -91,7 +91,7 @@ export default class DocumentsController extends ApiController {
|
|||||||
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);
|
||||||
@ -84,8 +84,8 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
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: ["createOffice"], forbidUnknownValues: false });
|
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) {
|
||||||
|
@ -25,10 +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 = User.map<User>(User, usersEntity, {excludeExtraneousValues: true})
|
const users = User.map<User>(User, usersEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, users);
|
this.httpSuccess(response, users);
|
||||||
@ -49,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
|
||||||
@ -88,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
|
||||||
@ -121,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);
|
||||||
|
@ -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();
|
||||||
|
|
||||||
@ -55,7 +54,6 @@ import {
|
|||||||
|
|
||||||
const uidOfficeFolder1: string = randomString();
|
const uidOfficeFolder1: string = randomString();
|
||||||
const uidOfficeFolder2: string = randomString();
|
const uidOfficeFolder2: string = randomString();
|
||||||
<<<<<<< HEAD
|
|
||||||
const uidOfficeFolder3: string = randomString();
|
const uidOfficeFolder3: string = randomString();
|
||||||
const uidOfficeFolder4: string = randomString();
|
const uidOfficeFolder4: string = randomString();
|
||||||
const uidOfficeFolder5: string = randomString();
|
const uidOfficeFolder5: string = randomString();
|
||||||
@ -65,11 +63,6 @@ import {
|
|||||||
const uidDeed3: string = randomString();
|
const uidDeed3: string = randomString();
|
||||||
const uidDeed4: string = randomString();
|
const uidDeed4: string = randomString();
|
||||||
const uidDeed5: string = randomString();
|
const uidDeed5: string = randomString();
|
||||||
=======
|
|
||||||
|
|
||||||
const uidDeed1: string = randomString();
|
|
||||||
const uidDeed2: string = randomString();
|
|
||||||
>>>>>>> 7122ff1 (uuid --> uid)
|
|
||||||
|
|
||||||
const uidDeedType1: string = randomString();
|
const uidDeedType1: string = randomString();
|
||||||
const uidDeedType2: string = randomString();
|
const uidDeedType2: string = randomString();
|
||||||
@ -205,13 +198,8 @@ import {
|
|||||||
const officeFolders: OfficeFolders[] = [
|
const officeFolders: OfficeFolders[] = [
|
||||||
{
|
{
|
||||||
uid: uidOfficeFolder1,
|
uid: uidOfficeFolder1,
|
||||||
<<<<<<< HEAD
|
|
||||||
folder_number: "0001",
|
folder_number: "0001",
|
||||||
name: "Dossier",
|
name: "Dossier",
|
||||||
=======
|
|
||||||
folder_number: randomString(),
|
|
||||||
name: "0001",
|
|
||||||
>>>>>>> 7122ff1 (uuid --> uid)
|
|
||||||
deed_uid: uidDeed1,
|
deed_uid: uidDeed1,
|
||||||
status: EFolderStatus.LIVE,
|
status: EFolderStatus.LIVE,
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
@ -222,13 +210,8 @@ import {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
uid: uidOfficeFolder2,
|
uid: uidOfficeFolder2,
|
||||||
<<<<<<< HEAD
|
|
||||||
folder_number: "0002",
|
folder_number: "0002",
|
||||||
name: "Dossier",
|
name: "Dossier",
|
||||||
=======
|
|
||||||
folder_number: randomString(),
|
|
||||||
name: "0001",
|
|
||||||
>>>>>>> 7122ff1 (uuid --> uid)
|
|
||||||
deed_uid: uidDeed2,
|
deed_uid: uidDeed2,
|
||||||
status: EFolderStatus.LIVE,
|
status: EFolderStatus.LIVE,
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
@ -272,31 +255,24 @@ import {
|
|||||||
office_uid: uidOffice2,
|
office_uid: uidOffice2,
|
||||||
description: null,
|
description: null,
|
||||||
archived_description: null,
|
archived_description: null,
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const deeds: Deeds[] = [
|
const deeds: Deeds[] = [
|
||||||
{
|
{
|
||||||
uid: uidDeed1,
|
uid: uidDeed1,
|
||||||
deed_type_uid: uidDeedType1,
|
deed_type_uid: uidDeedType1,
|
||||||
<<<<<<< HEAD
|
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
uid: uidDeed2,
|
uid: uidDeed2,
|
||||||
deed_type_uid: uidDeedType2,
|
deed_type_uid: uidDeedType2,
|
||||||
=======
|
|
||||||
>>>>>>> 7122ff1 (uuid --> uid)
|
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
<<<<<<< HEAD
|
|
||||||
uid: uidDeed3,
|
uid: uidDeed3,
|
||||||
=======
|
|
||||||
uid: uidDeed2,
|
|
||||||
>>>>>>> 7122ff1 (uuid --> uid)
|
|
||||||
deed_type_uid: uidDeedType2,
|
deed_type_uid: uidDeedType2,
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
@ -312,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[] = [
|
||||||
@ -469,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!");
|
||||||
})();
|
})();
|
||||||
|
@ -42,23 +42,23 @@ export default class CustomersRepository extends BaseRepository {
|
|||||||
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, include: { contact: true } });
|
return this.model.create({ ...createArgs, include: { contact: true } });
|
||||||
@ -83,22 +83,22 @@ export default class CustomersRepository extends BaseRepository {
|
|||||||
status: ECustomerStatus[customer.status as keyof typeof ECustomerStatus],
|
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, include: { contact: true } });
|
return this.model.update({ ...updateArgs, include: { contact: true } });
|
||||||
@ -107,16 +107,20 @@ export default class CustomersRepository extends BaseRepository {
|
|||||||
/**
|
/**
|
||||||
* @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: {
|
||||||
uid: officeFolder.office.uid,
|
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");
|
||||||
}
|
}
|
||||||
|
@ -19,43 +19,32 @@ export default class UsersRepository extends BaseRepository {
|
|||||||
/**
|
/**
|
||||||
* @description : Find many users
|
* @description : Find many users
|
||||||
*/
|
*/
|
||||||
public async findMany(query: Prisma.UsersFindManyArgs): Promise<
|
public async findMany(query: Prisma.UsersFindManyArgs): Promise<Users[]> {
|
||||||
(Users & {
|
|
||||||
contact: Contacts;
|
|
||||||
office_membership: Offices & {
|
|
||||||
address: Addresses
|
|
||||||
};
|
|
||||||
})[]
|
|
||||||
> {
|
|
||||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||||
if (!query.include) return this.model.findMany({ ...query, include: { contact: true, office_membership: { include: { address: true } } } });
|
return this.model.findMany(query);
|
||||||
return this.model.findMany({ ...query, include: { contact: { include: { address: true } }, office_membership: { include: { address: true } } } });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Create a user
|
* @description : Create a user
|
||||||
*/
|
*/
|
||||||
public async create(user: User): Promise<Users & {
|
public async create(user: User): Promise<Users> {
|
||||||
contact: Contacts;
|
|
||||||
office_membership: Offices;
|
|
||||||
}> {
|
|
||||||
const createArgs: Prisma.UsersCreateArgs = {
|
const createArgs: Prisma.UsersCreateArgs = {
|
||||||
data: {
|
data: {
|
||||||
idNot: user.idNot,
|
idNot: user.idNot,
|
||||||
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,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -63,34 +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, include : { contact: true, office_membership: true}});
|
return this.model.create({ ...createArgs, include: { contact: true, office_membership: { include: { address: true } } } });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Update data from a user
|
* @description : Update data from a user
|
||||||
*/
|
*/
|
||||||
public async update(uid: string, user: User): Promise<Users & {
|
public async update(
|
||||||
contact: Contacts;
|
uid: string,
|
||||||
office_membership: Offices;
|
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,
|
||||||
@ -100,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,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -118,40 +114,50 @@ 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, include : { contact: true, office_membership: true}});
|
return this.model.update({ ...updateArgs, include: { contact: true, office_membership: { include: { address: true } } } });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Find one user
|
* @description : Find one user
|
||||||
*/
|
*/
|
||||||
public async findOneByUid(uid: string, query?: any): Promise<Users> {
|
public async findOneByUid(
|
||||||
|
uid: string,
|
||||||
|
query?: any,
|
||||||
|
): Promise<
|
||||||
|
Users & {
|
||||||
|
contact: Contacts;
|
||||||
|
office_membership: Offices & {
|
||||||
|
address: Addresses;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
> {
|
||||||
const findOneArgs: Prisma.UsersFindUniqueArgs = {
|
const findOneArgs: Prisma.UsersFindUniqueArgs = {
|
||||||
where: {
|
where: {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
if(query) {
|
const userEntity = await this.model.findUnique({
|
||||||
findOneArgs.include = query
|
...findOneArgs,
|
||||||
}
|
include: { contact: true, office_membership: { include: { address: true } } },
|
||||||
const userEntity = await this.model.findUnique(findOneArgs);
|
});
|
||||||
|
|
||||||
if (!userEntity) {
|
if (!userEntity) {
|
||||||
throw new Error("User not found");
|
throw new Error("User not found");
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Contacts, 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,11 +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): Promise<
|
public async get(query: Prisma.CustomersFindManyArgs): Promise<Customers[]> {
|
||||||
(Customers & {
|
|
||||||
contact: Contacts;
|
|
||||||
})[]
|
|
||||||
> {
|
|
||||||
return this.customerRepository.findMany(query);
|
return this.customerRepository.findMany(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,11 +22,7 @@ export default class CustomersService extends BaseService {
|
|||||||
* @description : Create a new customer
|
* @description : Create a new customer
|
||||||
* @throws {Error} If customer cannot be created
|
* @throws {Error} If customer cannot be created
|
||||||
*/
|
*/
|
||||||
public async create(customerEntity: Customer): Promise<
|
public async create(customerEntity: Customer): Promise<Customers> {
|
||||||
Customers & {
|
|
||||||
contact: Contacts;
|
|
||||||
}
|
|
||||||
> {
|
|
||||||
return this.customerRepository.create(customerEntity);
|
return this.customerRepository.create(customerEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,14 +30,7 @@ export default class CustomersService extends BaseService {
|
|||||||
* @description : Modify a customer
|
* @description : Modify a customer
|
||||||
* @throws {Error} If customer cannot be modified
|
* @throws {Error} If customer cannot be modified
|
||||||
*/
|
*/
|
||||||
public async update(
|
public async update(uid: string, customerEntity: Customer): Promise<Customers> {
|
||||||
uid: string,
|
|
||||||
customerEntity: Customer,
|
|
||||||
): Promise<
|
|
||||||
Customers & {
|
|
||||||
contact: Contacts;
|
|
||||||
}
|
|
||||||
> {
|
|
||||||
return this.customerRepository.update(uid, customerEntity);
|
return this.customerRepository.update(uid, customerEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 { Contacts, Offices, Prisma, 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,10 +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: Prisma.UsersFindManyArgs): Promise<(Users & {
|
public get(query: Prisma.UsersFindManyArgs): Promise<Users[]> {
|
||||||
contact: Contacts;
|
|
||||||
office_membership: Offices;
|
|
||||||
})[]> {
|
|
||||||
return this.userRepository.findMany(query);
|
return this.userRepository.findMany(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,10 +23,7 @@ export default class UsersService extends BaseService {
|
|||||||
* @description : Create a user
|
* @description : Create a user
|
||||||
* @throws {Error} If user couldn't be created
|
* @throws {Error} If user couldn't be created
|
||||||
*/
|
*/
|
||||||
public create(userEntity: User): Promise<Users & {
|
public create(userEntity: User): Promise<Users> {
|
||||||
contact: Contacts;
|
|
||||||
office_membership: Offices;
|
|
||||||
}> {
|
|
||||||
return this.userRepository.create(userEntity);
|
return this.userRepository.create(userEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,10 +31,7 @@ export default class UsersService extends BaseService {
|
|||||||
* @description : Modify a user
|
* @description : Modify a user
|
||||||
* @throws {Error} If user modification failed
|
* @throws {Error} If user modification failed
|
||||||
*/
|
*/
|
||||||
public update(uid: string, userEntity: User): Promise<Users & {
|
public update(uid: string, userEntity: User): Promise<Users> {
|
||||||
contact: Contacts;
|
|
||||||
office_membership: Offices;
|
|
||||||
}> {
|
|
||||||
return this.userRepository.update(uid, userEntity);
|
return this.userRepository.update(uid, userEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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