feature: add office folders services
This commit is contained in:
parent
f73fa9d017
commit
c30b9e3f9b
@ -1,4 +1,4 @@
|
|||||||
DATABASE_URL="postgresql://prisma:prisma@localhost:5433/tests"
|
DATABASE_URL="postgresql://prisma:prisma@localhost:5433/tests"
|
||||||
POSTGRES_USER=prisma
|
POSTGRES_USER=prisma
|
||||||
POSTGRES_PASSWORD=prisma
|
POSTGRES_PASSWORD=prisma
|
||||||
POSTGRES_DB: tests
|
POSTGRES_DB=tests
|
@ -29,7 +29,7 @@
|
|||||||
"docker:up": "docker-compose up -d",
|
"docker:up": "docker-compose up -d",
|
||||||
"docker:up:test": "docker-compose -f docker-compose-test.yml up -d",
|
"docker:up:test": "docker-compose -f docker-compose-test.yml up -d",
|
||||||
"docker:down": "docker-compose -f docker-compose-test.yml down",
|
"docker:down": "docker-compose -f docker-compose-test.yml down",
|
||||||
"test": "tsc && npm run docker:up:test && jest -i --verbose ./dist/test/* && npm run docker:down"
|
"test": "tsc && npm run docker:up:test && npm run migrate && jest -i --verbose ./dist/test/* && npm run docker:down"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -50,7 +50,7 @@
|
|||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"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.19",
|
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.21",
|
||||||
"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",
|
||||||
|
@ -17,7 +17,6 @@ export default class CustomersController extends ApiController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Get all customers
|
* @description Get all customers
|
||||||
* @returns ICustomer[] list of customers
|
|
||||||
*/
|
*/
|
||||||
@Get("/api/v1/super-admin/customers")
|
@Get("/api/v1/super-admin/customers")
|
||||||
protected async get(req: Request, response: Response) {
|
protected async get(req: Request, response: Response) {
|
||||||
@ -41,7 +40,6 @@ export default class CustomersController extends ApiController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Create a new customer
|
* @description Create a new customer
|
||||||
* @returns ICustomer created
|
|
||||||
*/
|
*/
|
||||||
@Post("/api/v1/super-admin/customers")
|
@Post("/api/v1/super-admin/customers")
|
||||||
protected async post(req: Request, response: Response) {
|
protected async post(req: Request, response: Response) {
|
||||||
@ -71,7 +69,6 @@ export default class CustomersController extends ApiController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Modify a specific customer by uid
|
* @description Modify a specific customer by uid
|
||||||
* @returns ICustomer modified
|
|
||||||
*/
|
*/
|
||||||
@Put("/api/v1/super-admin/customers/:uid")
|
@Put("/api/v1/super-admin/customers/:uid")
|
||||||
protected async put(req: Request, response: Response) {
|
protected async put(req: Request, response: Response) {
|
||||||
@ -104,7 +101,6 @@ export default class CustomersController extends ApiController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Get a specific customer by uid
|
* @description Get a specific customer by uid
|
||||||
* @returns ICustomer
|
|
||||||
*/
|
*/
|
||||||
@Get("/api/v1/super-admin/customers/:uid")
|
@Get("/api/v1/super-admin/customers/:uid")
|
||||||
protected async getOneByUid(req: Request, response: Response) {
|
protected async getOneByUid(req: Request, response: Response) {
|
||||||
|
@ -17,7 +17,7 @@ export default class DeedTypesController extends ApiController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Get all deedtypes
|
* @description Get all deedtypes
|
||||||
* @returns IDeedtype[] list of deedtypes
|
* @returns Deedtype[] list of deedtypes
|
||||||
*/
|
*/
|
||||||
@Get("/api/v1/super-admin/deed-types")
|
@Get("/api/v1/super-admin/deed-types")
|
||||||
protected async get(req: Request, response: Response) {
|
protected async get(req: Request, response: Response) {
|
||||||
@ -40,7 +40,7 @@ export default class DeedTypesController extends ApiController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Create a new deedtype
|
* @description Create a new deedtype
|
||||||
* @returns IDeedtype created
|
* @returns Deedtype created
|
||||||
*/
|
*/
|
||||||
@Post("/api/v1/super-admin/deed-types")
|
@Post("/api/v1/super-admin/deed-types")
|
||||||
protected async post(req: Request, response: Response) {
|
protected async post(req: Request, response: Response) {
|
||||||
@ -70,7 +70,7 @@ export default class DeedTypesController extends ApiController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Modify a specific deedtype by uid
|
* @description Modify a specific deedtype by uid
|
||||||
* @returns IDeedtype modified
|
* @returns Deedtype modified
|
||||||
*/
|
*/
|
||||||
@Put("/api/v1/super-admin/deed-types/:uid")
|
@Put("/api/v1/super-admin/deed-types/:uid")
|
||||||
protected async put(req: Request, response: Response) {
|
protected async put(req: Request, response: Response) {
|
||||||
@ -115,13 +115,13 @@ export default class DeedTypesController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const userEntity: DeedTypes = await this.deedTypesService.getByUid(uid);
|
const deedTypeEntity: DeedTypes = await this.deedTypesService.getByUid(uid);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const user = ObjectHydrate.hydrate<DeedType>(new DeedType(), userEntity, { strategy: "exposeAll" });
|
const deedType = ObjectHydrate.hydrate<DeedType>(new DeedType(), deedTypeEntity, { strategy: "exposeAll" });
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, user);
|
this.httpSuccess(response, deedType);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.httpBadRequest(response, error);
|
this.httpBadRequest(response, error);
|
||||||
return;
|
return;
|
||||||
|
@ -16,7 +16,7 @@ export default class DeedsController extends ApiController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Get all deeds
|
* @description Get all deeds
|
||||||
* @returns IDeed[] list of deeds
|
* @returns Deed[] list of deeds
|
||||||
*/
|
*/
|
||||||
@Get("/api/v1/super-admin/deeds")
|
@Get("/api/v1/super-admin/deeds")
|
||||||
protected async get(req: Request, response: Response) {
|
protected async get(req: Request, response: Response) {
|
||||||
@ -39,12 +39,24 @@ export default class DeedsController extends ApiController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Get a specific deed by uid
|
* @description Get a specific deed by uid
|
||||||
* @returns IDeed
|
* @returns Deed
|
||||||
*/
|
*/
|
||||||
@Get("/api/v1/super-admin/deeds/:uid")
|
@Get("/api/v1/super-admin/deeds/:uid")
|
||||||
protected async getOneByUid(req: Request, response: Response) {
|
protected async getOneByUid(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
// TODO
|
const uid = req.params["uid"];
|
||||||
|
if (!uid) {
|
||||||
|
throw new Error("No uuid provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
//call service to get prisma entity
|
||||||
|
const deedEntity: Deeds = await this.deedsService.getByUid(uid);
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const deed = ObjectHydrate.hydrate<Deed>(new Deed(), deedEntity, { strategy: "exposeAll" });
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, deed);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.httpBadRequest(response, error);
|
this.httpBadRequest(response, error);
|
||||||
return;
|
return;
|
||||||
|
@ -18,7 +18,6 @@ export default class DocumentTypesController extends ApiController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Get all document-types
|
* @description Get all document-types
|
||||||
* @returns DocumentType[] list of document-types
|
|
||||||
*/
|
*/
|
||||||
@Get("/api/v1/super-admin/document-types")
|
@Get("/api/v1/super-admin/document-types")
|
||||||
protected async get(req: Request, response: Response) {
|
protected async get(req: Request, response: Response) {
|
||||||
@ -44,7 +43,6 @@ export default class DocumentTypesController extends ApiController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Create a new documentType
|
* @description Create a new documentType
|
||||||
* @returns DocumentType created
|
|
||||||
*/
|
*/
|
||||||
@Post("/api/v1/super-admin/document-types")
|
@Post("/api/v1/super-admin/document-types")
|
||||||
protected async post(req: Request, response: Response) {
|
protected async post(req: Request, response: Response) {
|
||||||
@ -70,7 +68,6 @@ export default class DocumentTypesController extends ApiController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Modify a specific documentType by uid
|
* @description Modify a specific documentType by uid
|
||||||
* @returns DocumentType modified
|
|
||||||
*/
|
*/
|
||||||
@Put("/api/v1/super-admin/document-types/:uid")
|
@Put("/api/v1/super-admin/document-types/:uid")
|
||||||
protected async put(req: Request, response: Response) {
|
protected async put(req: Request, response: Response) {
|
||||||
@ -104,7 +101,6 @@ export default class DocumentTypesController extends ApiController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Get a specific documentType by uid
|
* @description Get a specific documentType by uid
|
||||||
* @returns DocumentType
|
|
||||||
*/
|
*/
|
||||||
@Get("/api/v1/super-admin/document-types/:uid")
|
@Get("/api/v1/super-admin/document-types/:uid")
|
||||||
protected async getOneByUid(req: Request, response: Response) {
|
protected async getOneByUid(req: Request, response: Response) {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { Response, Request } from "express";
|
import { Response, Request } from "express";
|
||||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
||||||
// import { processFindManyQuery } from "prisma-query";
|
import { Documents } from "@prisma/client";
|
||||||
// import { Documents } from "@prisma/client";
|
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
||||||
// import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
import { Document } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
// import Document from "le-coffre-resources/dist/SuperAdmin";
|
import { validateOrReject } from "class-validator";
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@Service()
|
@Service()
|
||||||
@ -19,25 +19,25 @@ export default class DocumentsController extends ApiController {
|
|||||||
* @description Get all documents
|
* @description Get all documents
|
||||||
* @returns IDocument[] list of documents
|
* @returns IDocument[] list of documents
|
||||||
*/
|
*/
|
||||||
// @Get("/api/super-admin/documents")
|
@Get("/api/v1/super-admin/documents")
|
||||||
// protected async get(req: Request, response: Response) {
|
protected async get(req: Request, response: Response) {
|
||||||
// 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 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 = ObjectHydrate.map<Document>(Document, prismaEntity, { strategy: "exposeAll" });
|
||||||
|
|
||||||
// //success
|
//success
|
||||||
// this.httpSuccess(response, documents);
|
this.httpSuccess(response, documents);
|
||||||
// } catch (error) {
|
} catch (error) {
|
||||||
// this.httpBadRequest(response, error);
|
this.httpBadRequest(response, error);
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Create a new document
|
* @description Create a new document
|
||||||
@ -46,41 +46,108 @@ export default class DocumentsController extends ApiController {
|
|||||||
@Post("/api/v1/super-admin/documents")
|
@Post("/api/v1/super-admin/documents")
|
||||||
protected async post(req: Request, response: Response) {
|
protected async post(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
// TODO
|
//init Document resource with request body values
|
||||||
|
const documentEntity = new Document();
|
||||||
|
ObjectHydrate.hydrate(documentEntity, req.body);
|
||||||
|
|
||||||
|
//validate document
|
||||||
|
await validateOrReject(documentEntity, { groups: ["create"] });
|
||||||
|
|
||||||
|
//call service to get prisma entity
|
||||||
|
const prismaEntityCreated = await this.documentsService.create(documentEntity);
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const documentEntityCreated = ObjectHydrate.hydrate<Document>(new Document(), prismaEntityCreated, {
|
||||||
|
strategy: "exposeAll",
|
||||||
|
});
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, documentEntityCreated);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.httpBadRequest(response, error);
|
this.httpBadRequest(response, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// this.httpSuccess(response, await this.documentsService.create());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Modify a specific document by uid
|
* @description Update a specific document
|
||||||
* @returns IDocument modified
|
|
||||||
*/
|
*/
|
||||||
@Put("/api/v1/super-admin/documents/:uid")
|
@Put("/api/v1/super-admin/documents/:uid")
|
||||||
protected async put(req: Request, response: Response) {
|
protected async update(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
// TODO
|
const uid = req.params["uid"];
|
||||||
|
if (!uid) {
|
||||||
|
throw new Error("No uuid provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
//init Document resource with request body values
|
||||||
|
const documentEntity = new Document();
|
||||||
|
ObjectHydrate.hydrate(documentEntity, req.body);
|
||||||
|
|
||||||
|
//validate document
|
||||||
|
await validateOrReject(documentEntity, { groups: ["create"] });
|
||||||
|
|
||||||
|
//call service to get prisma entity
|
||||||
|
const prismaEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity);
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const document = ObjectHydrate.hydrate<Document>(new Document(), prismaEntityUpdated, { strategy: "exposeAll" });
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, document);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpBadRequest(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Delete a specific document
|
||||||
|
*/
|
||||||
|
@Delete("/api/v1/super-admin/documents/:uid")
|
||||||
|
protected async delete(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
const uid = req.params["uid"];
|
||||||
|
if (!uid) {
|
||||||
|
throw new Error("No uuid provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
//call service to get prisma entity
|
||||||
|
const documentEntity: Documents = await this.documentsService.delete(uid);
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const document = ObjectHydrate.hydrate<Document>(new Document(), documentEntity, { strategy: "exposeAll" });
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, document);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.httpBadRequest(response, error);
|
this.httpBadRequest(response, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.httpSuccess(response, await this.documentsService.put());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Get a specific document by uid
|
* @description Get a specific document by uid
|
||||||
* @returns IDocument
|
|
||||||
*/
|
*/
|
||||||
@Get("/api/v1/super-admin/documents/:uid")
|
@Get("/api/v1/super-admin/documents/:uid")
|
||||||
protected async getOneByUid(req: Request, response: Response) {
|
protected async getOneByUid(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
// TODO
|
const uid = req.params["uid"];
|
||||||
|
if (!uid) {
|
||||||
|
throw new Error("No uuid provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
//call service to get prisma entity
|
||||||
|
const documentEntity: Documents = await this.documentsService.getByUid(uid);
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const document = ObjectHydrate.hydrate<Document>(new Document(), documentEntity, { strategy: "exposeAll" });
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, document);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.httpBadRequest(response, error);
|
this.httpBadRequest(response, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.httpSuccess(response, await this.documentsService.getByUid("uid"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,10 @@ import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
|||||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||||
import OfficeFoldersService from "@Services/super-admin/OfficeFoldersService/OfficeFoldersService";
|
import OfficeFoldersService from "@Services/super-admin/OfficeFoldersService/OfficeFoldersService";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
// import { processFindManyQuery } from "prisma-query";
|
import { OfficeFolders } from "@prisma/client";
|
||||||
// import { OfficeFolders } from "@prisma/client";
|
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
||||||
// import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
import { OfficeFolder } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
// import { OfficeFolder } from "le-coffre-resources/dist/SuperAdmin";
|
import { validateOrReject } from "class-validator";
|
||||||
// import { validateOrReject } from "class-validator";
|
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@Service()
|
@Service()
|
||||||
@ -18,21 +17,20 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Get all folders
|
* @description Get all folders
|
||||||
* @returns IFolder[] list of folders
|
|
||||||
*/
|
*/
|
||||||
@Get("/api/super-admin/folders")
|
@Get("/api/v1/super-admin/folders")
|
||||||
protected async get(req: Request, response: Response) {
|
protected async get(req: Request, response: Response) {
|
||||||
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 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 = ObjectHydrate.map<OfficeFolder>(OfficeFolder, prismaEntity, {
|
||||||
// strategy: "exposeAll",
|
strategy: "exposeAll",
|
||||||
// });
|
});
|
||||||
// //success
|
//success
|
||||||
// this.httpSuccess(response, officeFolders);
|
this.httpSuccess(response, officeFolders);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.httpBadRequest(response, error);
|
this.httpBadRequest(response, error);
|
||||||
return;
|
return;
|
||||||
@ -41,24 +39,24 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Create a new folder
|
* @description Create a new folder
|
||||||
* @returns IFolder created
|
|
||||||
*/
|
*/
|
||||||
@Post("/api/super-admin/folders")
|
@Post("/api/v1/super-admin/folders")
|
||||||
protected async post(req: Request, response: Response) {
|
protected async post(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
//init IOfficeFolder resource with request body values
|
//init OfficeFolder resource with request body values
|
||||||
// const officeFolderEntity = new OfficeFolder();
|
const officeFolderEntity = new OfficeFolder();
|
||||||
// ObjectHydrate.hydrate(officeFolderEntity, req.body);
|
ObjectHydrate.hydrate(officeFolderEntity, req.body);
|
||||||
// //validate folder
|
|
||||||
// await validateOrReject(officeFolderEntity, { groups: ["create"] });
|
//validate folder
|
||||||
// //call service to get prisma entity
|
await validateOrReject(officeFolderEntity, { groups: ["create"] });
|
||||||
// const prismaEntityCreated = await this.officeFoldersService.create(officeFolderEntity);
|
//call service to get prisma entity
|
||||||
// //Hydrate ressource with prisma entity
|
const prismaEntityCreated = await this.officeFoldersService.create(officeFolderEntity);
|
||||||
// const officeFolderEntityCreated = ObjectHydrate.hydrate<OfficeFolder>(new OfficeFolder(), prismaEntityCreated, {
|
//Hydrate ressource with prisma entity
|
||||||
// strategy: "exposeAll",
|
const officeFolderEntityCreated = ObjectHydrate.hydrate<OfficeFolder>(new OfficeFolder(), prismaEntityCreated, {
|
||||||
// });
|
strategy: "exposeAll",
|
||||||
|
});
|
||||||
//success
|
//success
|
||||||
//this.httpSuccess(response, officeFolderEntityCreated);
|
this.httpSuccess(response, officeFolderEntityCreated);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.httpBadRequest(response, error);
|
this.httpBadRequest(response, error);
|
||||||
return;
|
return;
|
||||||
@ -67,27 +65,57 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Modify a specific folder by uid
|
* @description Modify a specific folder by uid
|
||||||
* @returns IFolder modified
|
|
||||||
*/
|
*/
|
||||||
@Put("/api/super-admin/folders/:uid")
|
@Put("/api/v1/super-admin/folders/:uid")
|
||||||
protected async put(req: Request, response: Response) {
|
protected async put(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
// TODO
|
const uid = req.params["uid"];
|
||||||
|
if (!uid) {
|
||||||
|
throw new Error("No uuid provided");
|
||||||
|
}
|
||||||
|
//init IUser resource with request body values
|
||||||
|
const officeFolderEntity = new OfficeFolder();
|
||||||
|
ObjectHydrate.hydrate(officeFolderEntity, req.body);
|
||||||
|
|
||||||
|
//validate user
|
||||||
|
await validateOrReject(officeFolderEntity, { groups: ["update"] });
|
||||||
|
|
||||||
|
//call service to get prisma entity
|
||||||
|
const prismaEntityUpdated = await this.officeFoldersService.update(uid, officeFolderEntity);
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const officeFolderEntityUpdated = ObjectHydrate.hydrate<OfficeFolder>(new OfficeFolder(), prismaEntityUpdated, {
|
||||||
|
strategy: "exposeAll",
|
||||||
|
});
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, officeFolderEntityUpdated);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.httpBadRequest(response, error);
|
this.httpBadRequest(response, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//this.httpSuccess(response, await this.officeFoldersService.update());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Get a specific folder by uid
|
* @description Get a specific folder by uid
|
||||||
* @returns IFolder
|
* @returns IFolder
|
||||||
*/
|
*/
|
||||||
@Get("/api/super-admin/folders/:uid")
|
@Get("/api/v1/super-admin/folders/:uid")
|
||||||
protected async getOneByUid(req: Request, response: Response) {
|
protected async getOneByUid(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
// TODO
|
const uid = req.params["uid"];
|
||||||
|
if (!uid) {
|
||||||
|
throw new Error("No uuid provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
//call service to get prisma entity
|
||||||
|
const officeFolderEntity: OfficeFolders = await this.officeFoldersService.getByUid(uid);
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const officeFolder = ObjectHydrate.hydrate<OfficeFolder>(new OfficeFolder(), officeFolderEntity, { strategy: "exposeAll" });
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, officeFolder);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.httpBadRequest(response, error);
|
this.httpBadRequest(response, error);
|
||||||
return;
|
return;
|
||||||
|
@ -16,7 +16,6 @@ export default class OfficesController extends ApiController {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @description Get all offices
|
* @description Get all offices
|
||||||
* @returns IOffice[] list of offices
|
|
||||||
*/
|
*/
|
||||||
@Get("/api/v1/super-admin/offices")
|
@Get("/api/v1/super-admin/offices")
|
||||||
protected async get(req: Request, response: Response) {
|
protected async get(req: Request, response: Response) {
|
||||||
@ -36,7 +35,6 @@ export default class OfficesController extends ApiController {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @description Create a new office
|
* @description Create a new office
|
||||||
* @returns IOffice created
|
|
||||||
*/
|
*/
|
||||||
@Post("/api/v1/super-admin/offices")
|
@Post("/api/v1/super-admin/offices")
|
||||||
protected async post(req: Request, response: Response) {
|
protected async post(req: Request, response: Response) {
|
||||||
@ -61,7 +59,6 @@ export default class OfficesController extends ApiController {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @description Modify a specific office by uid
|
* @description Modify a specific office by uid
|
||||||
* @returns IOffice modified
|
|
||||||
*/
|
*/
|
||||||
@Put("/api/v1/super-admin/offices/:uid")
|
@Put("/api/v1/super-admin/offices/:uid")
|
||||||
protected async put(req: Request, response: Response) {
|
protected async put(req: Request, response: Response) {
|
||||||
@ -90,7 +87,6 @@ export default class OfficesController extends ApiController {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @description Get a specific office by uid
|
* @description Get a specific office by uid
|
||||||
* @returns IOffice
|
|
||||||
*/
|
*/
|
||||||
@Get("/api/v1/super-admin/offices/:uid")
|
@Get("/api/v1/super-admin/offices/:uid")
|
||||||
protected async getOneByUid(req: Request, response: Response) {
|
protected async getOneByUid(req: Request, response: Response) {
|
||||||
|
@ -17,7 +17,6 @@ export default class UsersController extends ApiController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Get all users
|
* @description Get all users
|
||||||
* @returns IUser[] list of users
|
|
||||||
*/
|
*/
|
||||||
@Get("/api/v1/super-admin/users")
|
@Get("/api/v1/super-admin/users")
|
||||||
protected async get(req: Request, response: Response) {
|
protected async get(req: Request, response: Response) {
|
||||||
@ -40,8 +39,7 @@ export default class UsersController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Get all users
|
* @description Create a new user
|
||||||
* @returns IUser[] list of users
|
|
||||||
*/
|
*/
|
||||||
@Post("/api/v1/super-admin/users")
|
@Post("/api/v1/super-admin/users")
|
||||||
protected async getAddresses(req: Request, response: Response) {
|
protected async getAddresses(req: Request, response: Response) {
|
||||||
@ -71,7 +69,6 @@ export default class UsersController extends ApiController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Modify a specific user by uid
|
* @description Modify a specific user by uid
|
||||||
* @returns IUser modified
|
|
||||||
*/
|
*/
|
||||||
@Put("/api/v1/super-admin/users/:uid")
|
@Put("/api/v1/super-admin/users/:uid")
|
||||||
protected async put(req: Request, response: Response) {
|
protected async put(req: Request, response: Response) {
|
||||||
@ -104,8 +101,7 @@ export default class UsersController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Modify a specific user by uid
|
* @description Get a specific user by uid
|
||||||
* @returns IUser modified
|
|
||||||
*/
|
*/
|
||||||
@Get("/api/v1/super-admin/users/:uid")
|
@Get("/api/v1/super-admin/users/:uid")
|
||||||
protected async getOneByUid(req: Request, response: Response) {
|
protected async getOneByUid(req: Request, response: Response) {
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- You are about to drop the column `type_uuid` on the `documents` table. All the data in the column will be lost.
|
||||||
|
- Added the required column `document_type_uuid` to the `documents` table without a default value. This is not possible if the table is not empty.
|
||||||
|
- Made the column `file_path` on table `files` required. This step will fail if there are existing NULL values in that column.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- DropForeignKey
|
||||||
|
ALTER TABLE "documents" DROP CONSTRAINT "documents_type_uuid_fkey";
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "documents" DROP COLUMN "type_uuid",
|
||||||
|
ADD COLUMN "document_type_uuid" VARCHAR(255) NOT NULL;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "files" ALTER COLUMN "file_path" SET NOT NULL;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "documents" ADD CONSTRAINT "documents_document_type_uuid_fkey" FOREIGN KEY ("document_type_uuid") REFERENCES "document_types"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
|
@ -0,0 +1,2 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "contacts" ADD COLUMN "birthdate" TIMESTAMP(3);
|
@ -38,8 +38,9 @@ model Contacts {
|
|||||||
phone_number String? @db.VarChar(50)
|
phone_number String? @db.VarChar(50)
|
||||||
cell_phone_number String? @unique @db.VarChar(50)
|
cell_phone_number String? @unique @db.VarChar(50)
|
||||||
civility ECivility @default(MALE)
|
civility ECivility @default(MALE)
|
||||||
address Addresses @relation(fields: [address_uuid], references: [uuid], onDelete: Cascade)
|
address Addresses? @relation(fields: [address_uuid], references: [uuid], onDelete: Cascade)
|
||||||
address_uuid String @unique @db.VarChar(255)
|
address_uuid String @unique @db.VarChar(255)
|
||||||
|
birthdate DateTime?
|
||||||
created_at DateTime? @default(now())
|
created_at DateTime? @default(now())
|
||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
users Users?
|
users Users?
|
||||||
@ -168,8 +169,8 @@ model OfficeFolderHasStakeholders {
|
|||||||
model Documents {
|
model Documents {
|
||||||
uuid String @id @unique @default(uuid())
|
uuid String @id @unique @default(uuid())
|
||||||
document_status EDocumentStatus @default(ASKED)
|
document_status EDocumentStatus @default(ASKED)
|
||||||
document_type DocumentTypes @relation(fields: [type_uuid], references: [uuid])
|
document_type DocumentTypes @relation(fields: [document_type_uuid], references: [uuid])
|
||||||
type_uuid String @db.VarChar(255)
|
document_type_uuid String @db.VarChar(255)
|
||||||
blockchain_anchor BlockchainAnchors? @relation(fields: [blockchain_anchor_uuid], references: [uuid])
|
blockchain_anchor BlockchainAnchors? @relation(fields: [blockchain_anchor_uuid], references: [uuid])
|
||||||
blockchain_anchor_uuid String? @db.VarChar(255)
|
blockchain_anchor_uuid String? @db.VarChar(255)
|
||||||
folder OfficeFolders @relation(fields: [folder_uuid], references: [uuid])
|
folder OfficeFolders @relation(fields: [folder_uuid], references: [uuid])
|
||||||
@ -200,7 +201,7 @@ model Files {
|
|||||||
uuid String @id @unique @default(uuid())
|
uuid String @id @unique @default(uuid())
|
||||||
document Documents @relation(fields: [document_uuid], references: [uuid], onDelete: Cascade)
|
document Documents @relation(fields: [document_uuid], references: [uuid], onDelete: Cascade)
|
||||||
document_uuid String @db.VarChar(255)
|
document_uuid String @db.VarChar(255)
|
||||||
file_path String? @unique @db.VarChar(255)
|
file_path String @unique @db.VarChar(255)
|
||||||
created_at DateTime? @default(now())
|
created_at DateTime? @default(now())
|
||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
|
|
||||||
|
@ -128,6 +128,7 @@ import {
|
|||||||
email: "john.doe@example.com",
|
email: "john.doe@example.com",
|
||||||
phone_number: randomString(),
|
phone_number: randomString(),
|
||||||
cell_phone_number: randomString(),
|
cell_phone_number: randomString(),
|
||||||
|
birthdate: null,
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
civility: ECivility.MALE,
|
civility: ECivility.MALE,
|
||||||
@ -139,9 +140,10 @@ import {
|
|||||||
last_name: "Doe",
|
last_name: "Doe",
|
||||||
email: "jane.doe@example.com",
|
email: "jane.doe@example.com",
|
||||||
phone_number: randomString(),
|
phone_number: randomString(),
|
||||||
|
cell_phone_number: randomString(),
|
||||||
|
birthdate: null,
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
cell_phone_number: randomString(),
|
|
||||||
civility: ECivility.FEMALE,
|
civility: ECivility.FEMALE,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@ -258,7 +260,7 @@ import {
|
|||||||
depositor_uuid: uuidCustomer1,
|
depositor_uuid: uuidCustomer1,
|
||||||
document_status: EDocumentStatus.ASKED,
|
document_status: EDocumentStatus.ASKED,
|
||||||
folder_uuid: uuidOfficeFolder1,
|
folder_uuid: uuidOfficeFolder1,
|
||||||
type_uuid: uuidDocumentType1,
|
document_type_uuid: uuidDocumentType1,
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
@ -268,7 +270,7 @@ import {
|
|||||||
depositor_uuid: uuidCustomer2,
|
depositor_uuid: uuidCustomer2,
|
||||||
document_status: EDocumentStatus.ASKED,
|
document_status: EDocumentStatus.ASKED,
|
||||||
folder_uuid: uuidOfficeFolder2,
|
folder_uuid: uuidOfficeFolder2,
|
||||||
type_uuid: uuidDocumentType2,
|
document_type_uuid: uuidDocumentType2,
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
|
@ -16,20 +16,27 @@ export default class AddressesRepository extends BaseRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Find many users
|
* @description : Find many addresses
|
||||||
*/
|
*/
|
||||||
public async findMany(query: any): Promise<Addresses[]> {
|
public async findMany(query: any): Promise<Addresses[]> {
|
||||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||||
return this.model.findMany(query);
|
return this.model.findMany(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async create(address: Addresses): Promise<Addresses> {
|
/**
|
||||||
return this.model.create({
|
* @description : Find one address
|
||||||
data: {
|
*/
|
||||||
address: address.address,
|
public async findOneByUid(uid: string): Promise<Addresses> {
|
||||||
city: address.city,
|
const addressEntity = await this.model.findUnique({
|
||||||
zip_code: address.zip_code,
|
where: {
|
||||||
|
uuid: uid,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!addressEntity) {
|
||||||
|
throw new Error("Address not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return addressEntity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
import Database from "@Common/databases/database";
|
|
||||||
import BaseRepository from "@Repositories/BaseRepository";
|
|
||||||
import { Service } from "typedi";
|
|
||||||
import { Addresses } from "@prisma/client";
|
|
||||||
|
|
||||||
@Service()
|
|
||||||
export default class AddressesRepository extends BaseRepository {
|
|
||||||
constructor(private database: Database) {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
protected get model() {
|
|
||||||
return this.database.getClient().addresses;
|
|
||||||
}
|
|
||||||
protected get instanceDb() {
|
|
||||||
return this.database.getClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Find many users
|
|
||||||
*/
|
|
||||||
public async findMany(query: any): Promise<Addresses[]> {
|
|
||||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
|
||||||
return this.model.findMany(query);
|
|
||||||
}
|
|
||||||
}
|
|
42
src/common/repositories/ContactsRepository.ts
Normal file
42
src/common/repositories/ContactsRepository.ts
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import Database from "@Common/databases/database";
|
||||||
|
import BaseRepository from "@Repositories/BaseRepository";
|
||||||
|
import { Service } from "typedi";
|
||||||
|
import { Contacts } from "@prisma/client";
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export default class ContactsRepository extends BaseRepository {
|
||||||
|
constructor(private database: Database) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
protected get model() {
|
||||||
|
return this.database.getClient().contacts;
|
||||||
|
}
|
||||||
|
protected get instanceDb() {
|
||||||
|
return this.database.getClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Find many contacts
|
||||||
|
*/
|
||||||
|
public async findMany(query: any): Promise<Contacts[]> {
|
||||||
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||||
|
return this.model.findMany(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Find unique contact
|
||||||
|
*/
|
||||||
|
public async findOneByUid(uid: string): Promise<Contacts> {
|
||||||
|
const contactEntity = await this.model.findUnique({
|
||||||
|
where: {
|
||||||
|
uuid: uid,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!contactEntity) {
|
||||||
|
throw new Error("contact not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return contactEntity;
|
||||||
|
}
|
||||||
|
}
|
@ -24,6 +24,9 @@ export default class CustomersRepository extends BaseRepository {
|
|||||||
return this.model.findMany(query);
|
return this.model.findMany(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Create a customer
|
||||||
|
*/
|
||||||
public async create(customer: Customer): Promise<Customers> {
|
public async create(customer: Customer): Promise<Customers> {
|
||||||
return this.model.create({
|
return this.model.create({
|
||||||
data: {
|
data: {
|
||||||
@ -34,11 +37,11 @@ export default class CustomersRepository extends BaseRepository {
|
|||||||
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,
|
||||||
},
|
},
|
||||||
@ -49,6 +52,9 @@ export default class CustomersRepository extends BaseRepository {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Update data from a customer
|
||||||
|
*/
|
||||||
public async update(uid: string, customer: Customer): Promise<Customers> {
|
public async update(uid: string, customer: Customer): Promise<Customers> {
|
||||||
return this.model.update({
|
return this.model.update({
|
||||||
where: {
|
where: {
|
||||||
@ -77,6 +83,9 @@ export default class CustomersRepository extends BaseRepository {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Find unique customer
|
||||||
|
*/
|
||||||
public async findOneByUid(uid: string): Promise<Customers> {
|
public async findOneByUid(uid: string): Promise<Customers> {
|
||||||
const customerEntity = await this.model.findUnique({
|
const customerEntity = await this.model.findUnique({
|
||||||
where: {
|
where: {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import Database from "@Common/databases/database";
|
import Database from "@Common/databases/database";
|
||||||
import { DeedTypeHasDocumentTypes, Prisma } from "@prisma/client";
|
import { DeedTypeHasDocumentTypes } from "@prisma/client";
|
||||||
import BaseRepository from "@Repositories/BaseRepository";
|
import BaseRepository from "@Repositories/BaseRepository";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ export default class DeedTypeHasDocumentTypesRepository extends BaseRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Find many users
|
* @description : Find many relations between deed type and a document type
|
||||||
*/
|
*/
|
||||||
public async findMany(query: any): Promise<DeedTypeHasDocumentTypes[]> {
|
public async findMany(query: any): Promise<DeedTypeHasDocumentTypes[]> {
|
||||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||||
@ -24,78 +24,8 @@ export default class DeedTypeHasDocumentTypesRepository extends BaseRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Create new relation between deed type and a document type
|
* @description : Find unique relation between deed type and a document type
|
||||||
*/
|
*/
|
||||||
public async create(deedTypeUuid: string, documentTypesUuid: string): Promise<DeedTypeHasDocumentTypes> {
|
|
||||||
return this.model.create({
|
|
||||||
data: {
|
|
||||||
deed_type: {
|
|
||||||
connect: {
|
|
||||||
uuid: deedTypeUuid,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
document_type: {
|
|
||||||
connect: {
|
|
||||||
uuid: documentTypesUuid,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Create new relation between deed type and a document type
|
|
||||||
*/
|
|
||||||
public async createMany(deedTypeUuid: string, documentTypesUuid: string[]): Promise<DeedTypeHasDocumentTypes[]> {
|
|
||||||
let relationsToAdd: Prisma.DeedTypeHasDocumentTypesCreateManyInput[] = [];
|
|
||||||
documentTypesUuid.forEach((item) => {
|
|
||||||
relationsToAdd.push({ deed_type_uuid: deedTypeUuid, document_type_uuid: item });
|
|
||||||
});
|
|
||||||
|
|
||||||
const numberOfRelationsAdded = (
|
|
||||||
await this.model.createMany({
|
|
||||||
data: relationsToAdd,
|
|
||||||
skipDuplicates: true,
|
|
||||||
})
|
|
||||||
).count;
|
|
||||||
|
|
||||||
return this.findMany({ where: { deed_type_uuid: deedTypeUuid }, take: numberOfRelationsAdded });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Create new relation between deed type and a document type
|
|
||||||
*/
|
|
||||||
public async delete(deedTypeUuid: string, documentTypesUuid: string): Promise<DeedTypeHasDocumentTypes> {
|
|
||||||
return this.model.delete({
|
|
||||||
where: {
|
|
||||||
deed_type_uuid_document_type_uuid: {
|
|
||||||
deed_type_uuid: deedTypeUuid,
|
|
||||||
document_type_uuid: documentTypesUuid,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Create new relation between deed type and a document type
|
|
||||||
*/
|
|
||||||
public async deleteMany(deedTypeUuid: string, documentTypesUuids: string[]): Promise<any[]> {
|
|
||||||
let relationsToRemove: any[] = [];
|
|
||||||
documentTypesUuids.forEach((relationUuid) => {
|
|
||||||
relationsToRemove.push(
|
|
||||||
this.model.delete({
|
|
||||||
where: {
|
|
||||||
deed_type_uuid_document_type_uuid: {
|
|
||||||
deed_type_uuid: deedTypeUuid,
|
|
||||||
document_type_uuid: relationUuid,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
return this.instanceDb.$transaction(relationsToRemove);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async findOneByUid(uid: string): Promise<DeedTypeHasDocumentTypes> {
|
public async findOneByUid(uid: string): Promise<DeedTypeHasDocumentTypes> {
|
||||||
const deedTypeHasDoculmentTypesEntity = await this.model.findUnique({
|
const deedTypeHasDoculmentTypesEntity = await this.model.findUnique({
|
||||||
where: {
|
where: {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import Database from "@Common/databases/database";
|
import Database from "@Common/databases/database";
|
||||||
import BaseRepository from "@Repositories/BaseRepository";
|
import BaseRepository from "@Repositories/BaseRepository";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import { DeedTypes } from "@prisma/client";
|
import { DeedTypes, Prisma } from "@prisma/client";
|
||||||
import { DeedType } from "le-coffre-resources/dist/SuperAdmin";
|
import { DeedType } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
@ -17,7 +17,7 @@ export default class DeedTypesRepository extends BaseRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Find many users
|
* @description : Find many deed types
|
||||||
*/
|
*/
|
||||||
public async findMany(query: any): Promise<DeedTypes[]> {
|
public async findMany(query: any): Promise<DeedTypes[]> {
|
||||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||||
@ -25,7 +25,7 @@ export default class DeedTypesRepository extends BaseRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Create new office folder wihtout customers nor stakeholders
|
* @description : Create new deed type
|
||||||
*/
|
*/
|
||||||
public async create(deedType: DeedType): Promise<DeedTypes> {
|
public async create(deedType: DeedType): Promise<DeedTypes> {
|
||||||
return this.model.create({
|
return this.model.create({
|
||||||
@ -42,11 +42,13 @@ export default class DeedTypesRepository extends BaseRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Create new office folder wihtout customers nor stakeholders
|
* @description : Update data of a deed type
|
||||||
*/
|
*/
|
||||||
public async update(uid: string, deedType: DeedType): Promise<DeedTypes> {
|
public async update(uid: string, deedType: DeedType): Promise<DeedTypes> {
|
||||||
return this.model.update({
|
const updateArgs: Prisma.DeedTypesUpdateArgs = {
|
||||||
where: { uuid: uid },
|
where: {
|
||||||
|
uuid: uid,
|
||||||
|
},
|
||||||
data: {
|
data: {
|
||||||
name: deedType.name,
|
name: deedType.name,
|
||||||
description: deedType.description,
|
description: deedType.description,
|
||||||
@ -57,9 +59,27 @@ export default class DeedTypesRepository extends BaseRepository {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
include: {
|
||||||
|
deed_type_has_document_types: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if (deedType.deed_type_has_document_types) {
|
||||||
|
updateArgs.data.deed_type_has_document_types = {
|
||||||
|
deleteMany: { deed_type_uuid: uid },
|
||||||
|
createMany: {
|
||||||
|
data: deedType.deed_type_has_document_types.map((relation) => ({
|
||||||
|
document_type_uuid: relation.document_type.uid,
|
||||||
|
})),
|
||||||
|
skipDuplicates: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return this.model.update(updateArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Find unique deed type
|
||||||
|
*/
|
||||||
public async findOneByUid(uid: string): Promise<DeedTypes> {
|
public async findOneByUid(uid: string): Promise<DeedTypes> {
|
||||||
const deedTypeEntity = await this.model.findUnique({
|
const deedTypeEntity = await this.model.findUnique({
|
||||||
where: {
|
where: {
|
||||||
@ -76,42 +96,4 @@ export default class DeedTypesRepository extends BaseRepository {
|
|||||||
|
|
||||||
return deedTypeEntity;
|
return deedTypeEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : update relations between document types and given deed type
|
|
||||||
*/
|
|
||||||
public async addDocumentType(uid: string, deedTypeHasDocumentTypeUuid: string): Promise<DeedTypes> {
|
|
||||||
return this.model.update({
|
|
||||||
where: { uuid: uid },
|
|
||||||
data: {
|
|
||||||
deed_type_has_document_types: {
|
|
||||||
connect: {
|
|
||||||
uuid: deedTypeHasDocumentTypeUuid,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : update relations between document types and given deed type
|
|
||||||
*/
|
|
||||||
public async addDocumentTypes(uid: string, deedTypeHasDocumentTypeUuid: string[]): Promise<any[]> {
|
|
||||||
let relationsToAdd: any[] = [];
|
|
||||||
deedTypeHasDocumentTypeUuid.forEach((relationUuid) => {
|
|
||||||
relationsToAdd.push(
|
|
||||||
this.model.update({
|
|
||||||
where: { uuid: uid },
|
|
||||||
data: {
|
|
||||||
deed_type_has_document_types: {
|
|
||||||
connect: {
|
|
||||||
uuid: relationUuid,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
return this.instanceDb.$transaction(relationsToAdd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import Database from "@Common/databases/database";
|
import Database from "@Common/databases/database";
|
||||||
import { DeedHasDocumentTypes, Prisma } from "@prisma/client";
|
import { DeedHasDocumentTypes } from "@prisma/client";
|
||||||
import BaseRepository from "@Repositories/BaseRepository";
|
import BaseRepository from "@Repositories/BaseRepository";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ export default class DeedHasDocumentTypesRepository extends BaseRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Find many users
|
* @description : Find many deeds
|
||||||
*/
|
*/
|
||||||
public async findMany(query: any): Promise<DeedHasDocumentTypes[]> {
|
public async findMany(query: any): Promise<DeedHasDocumentTypes[]> {
|
||||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||||
@ -24,89 +24,19 @@ export default class DeedHasDocumentTypesRepository extends BaseRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Create new relation between deed type and a document type
|
* @description : Find unique relation between deed and a document type
|
||||||
*/
|
*/
|
||||||
public async create(deedUuid: string, documentTypesUuid: string): Promise<DeedHasDocumentTypes> {
|
|
||||||
return this.model.create({
|
|
||||||
data: {
|
|
||||||
deed: {
|
|
||||||
connect: {
|
|
||||||
uuid: deedUuid,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
document_type: {
|
|
||||||
connect: {
|
|
||||||
uuid: documentTypesUuid,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Create new relation between deed type and a document type
|
|
||||||
*/
|
|
||||||
public async createMany(deedUuid: string, documentTypesUuid: string[]): Promise<DeedHasDocumentTypes[]> {
|
|
||||||
let relationsToAdd: Prisma.DeedHasDocumentTypesCreateManyInput[] = [];
|
|
||||||
documentTypesUuid.forEach((item) => {
|
|
||||||
relationsToAdd.push({ deed_uuid: deedUuid, document_type_uuid: item });
|
|
||||||
});
|
|
||||||
|
|
||||||
const numberOfRelationsAdded = (
|
|
||||||
await this.model.createMany({
|
|
||||||
data: relationsToAdd,
|
|
||||||
skipDuplicates: true,
|
|
||||||
})
|
|
||||||
).count;
|
|
||||||
|
|
||||||
return this.findMany({ where: { deed_uuid: deedUuid }, take: numberOfRelationsAdded });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Create new relation between deed type and a document type
|
|
||||||
*/
|
|
||||||
public async delete(deedUuid: string, documentTypesUuid: string): Promise<DeedHasDocumentTypes> {
|
|
||||||
return this.model.delete({
|
|
||||||
where: {
|
|
||||||
deed_uuid_document_type_uuid: {
|
|
||||||
deed_uuid: deedUuid,
|
|
||||||
document_type_uuid: documentTypesUuid,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Create new relation between deed type and a document type
|
|
||||||
*/
|
|
||||||
public async deleteMany(deedUuid: string, documentTypesUuids: string[]): Promise<any[]> {
|
|
||||||
let relationsToRemove: any[] = [];
|
|
||||||
documentTypesUuids.forEach((relationUuid) => {
|
|
||||||
relationsToRemove.push(
|
|
||||||
this.model.delete({
|
|
||||||
where: {
|
|
||||||
deed_uuid_document_type_uuid: {
|
|
||||||
deed_uuid: deedUuid,
|
|
||||||
document_type_uuid: relationUuid,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
return this.instanceDb.$transaction(relationsToRemove);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async findOneByUid(uid: string): Promise<DeedHasDocumentTypes> {
|
public async findOneByUid(uid: string): Promise<DeedHasDocumentTypes> {
|
||||||
const deedHasDoculmentTypesEntity = await this.model.findUnique({
|
const deedHasDocumentTypesEntity = await this.model.findUnique({
|
||||||
where: {
|
where: {
|
||||||
uuid: uid,
|
uuid: uid,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!deedHasDoculmentTypesEntity) {
|
if (!deedHasDocumentTypesEntity) {
|
||||||
throw new Error("relation between deed and document type not found");
|
throw new Error("relation between deed and document type not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
return deedHasDoculmentTypesEntity;
|
return deedHasDocumentTypesEntity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import Database from "@Common/databases/database";
|
import Database from "@Common/databases/database";
|
||||||
import BaseRepository from "@Repositories/BaseRepository";
|
import BaseRepository from "@Repositories/BaseRepository";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import { Deeds } from "@prisma/client";
|
import { Deeds, Prisma } from "@prisma/client";
|
||||||
import { DeedType } from "le-coffre-resources/dist/Customer";
|
import { Deed } from "le-coffre-resources/dist/Notary";
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class DeedsRepository extends BaseRepository {
|
export default class DeedsRepository extends BaseRepository {
|
||||||
@ -24,18 +24,51 @@ export default class DeedsRepository extends BaseRepository {
|
|||||||
return this.model.findMany(query);
|
return this.model.findMany(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async create(deedType: DeedType): Promise<Deeds> {
|
/**
|
||||||
|
* @description : Create a deed based on a deed type
|
||||||
|
*/
|
||||||
|
public async create(deed: Deed): Promise<Deeds> {
|
||||||
return this.model.create({
|
return this.model.create({
|
||||||
data: {
|
data: {
|
||||||
deed_type: {
|
deed_type: {
|
||||||
connect: {
|
connect: {
|
||||||
uuid: deedType.uid,
|
uuid: deed.deed_type.uid,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Update data of a deed type
|
||||||
|
*/
|
||||||
|
public async update(uid: string, deed: Deed): Promise<Deeds> {
|
||||||
|
const updateArgs: Prisma.DeedsUpdateArgs = {
|
||||||
|
where: {
|
||||||
|
uuid: uid,
|
||||||
|
},
|
||||||
|
data: {},
|
||||||
|
include: {
|
||||||
|
deed_has_document_types: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if (deed.deed_has_document_types) {
|
||||||
|
updateArgs.data.deed_has_document_types = {
|
||||||
|
deleteMany: { deed_uuid: uid },
|
||||||
|
createMany: {
|
||||||
|
data: deed.deed_has_document_types.map((relation) => ({
|
||||||
|
document_type_uuid: relation.document_type.uid,
|
||||||
|
})),
|
||||||
|
skipDuplicates: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return this.model.update(updateArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Find unique deed
|
||||||
|
*/
|
||||||
public async findOneByUid(uid: string): Promise<Deeds> {
|
public async findOneByUid(uid: string): Promise<Deeds> {
|
||||||
const deedTypeEntity = await this.model.findUnique({
|
const deedTypeEntity = await this.model.findUnique({
|
||||||
where: {
|
where: {
|
||||||
@ -44,47 +77,9 @@ export default class DeedsRepository extends BaseRepository {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!deedTypeEntity) {
|
if (!deedTypeEntity) {
|
||||||
throw new Error("deed type not found");
|
throw new Error("deed not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
return deedTypeEntity;
|
return deedTypeEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : update relations between document types and given deed type
|
|
||||||
*/
|
|
||||||
public async addDocumentType(uid: string, deedHasDocumentTypeUuid: string): Promise<Deeds> {
|
|
||||||
return this.model.update({
|
|
||||||
where: { uuid: uid },
|
|
||||||
data: {
|
|
||||||
deed_has_document_types: {
|
|
||||||
connect: {
|
|
||||||
uuid: deedHasDocumentTypeUuid,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : update relations between document types and given deed type
|
|
||||||
*/
|
|
||||||
public async addDocumentTypes(uid: string, deedHasDocumentTypeUuid: string[]): Promise<any[]> {
|
|
||||||
let relationsToAdd: any[] = [];
|
|
||||||
deedHasDocumentTypeUuid.forEach((relationUuid) => {
|
|
||||||
relationsToAdd.push(
|
|
||||||
this.model.update({
|
|
||||||
where: { uuid: uid },
|
|
||||||
data: {
|
|
||||||
deed_has_document_types: {
|
|
||||||
connect: {
|
|
||||||
uuid: relationUuid,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
return this.instanceDb.$transaction(relationsToAdd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,16 @@ export default class DocumentTypesRepository extends BaseRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Find many users
|
* @description : Find many document types
|
||||||
*/
|
*/
|
||||||
public async findMany(query: any): Promise<DocumentTypes[]> {
|
public async findMany(query: any): Promise<DocumentTypes[]> {
|
||||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||||
return this.model.findMany(query);
|
return this.model.findMany(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Create a document type
|
||||||
|
*/
|
||||||
public async create(documentType: DocumentType): Promise<DocumentTypes> {
|
public async create(documentType: DocumentType): Promise<DocumentTypes> {
|
||||||
return this.model.create({
|
return this.model.create({
|
||||||
data: {
|
data: {
|
||||||
@ -40,7 +43,7 @@ export default class DocumentTypesRepository extends BaseRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : update given deed
|
* @description : update given document type
|
||||||
*/
|
*/
|
||||||
public async update(uuid: string, documentType: DocumentType): Promise<DocumentTypes> {
|
public async update(uuid: string, documentType: DocumentType): Promise<DocumentTypes> {
|
||||||
return this.model.update({
|
return this.model.update({
|
||||||
@ -61,6 +64,9 @@ export default class DocumentTypesRepository extends BaseRepository {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : find unique document type
|
||||||
|
*/
|
||||||
public async findOneByUid(uid: string): Promise<DocumentTypes> {
|
public async findOneByUid(uid: string): Promise<DocumentTypes> {
|
||||||
const documentTypeEntity = await this.model.findUnique({
|
const documentTypeEntity = await this.model.findUnique({
|
||||||
where: {
|
where: {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import Database from "@Common/databases/database";
|
import Database from "@Common/databases/database";
|
||||||
import BaseRepository from "@Repositories/BaseRepository";
|
import BaseRepository from "@Repositories/BaseRepository";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import { Documents } from "@prisma/client";
|
import { Documents, EDocumentStatus, Prisma } from "@prisma/client";
|
||||||
|
import { Document } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class DocumentsRepository extends BaseRepository {
|
export default class DocumentsRepository extends BaseRepository {
|
||||||
@ -16,10 +17,114 @@ export default class DocumentsRepository extends BaseRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Find many users
|
* @description : Find many documents
|
||||||
*/
|
*/
|
||||||
public async findMany(query: any): Promise<Documents[]> {
|
public async findMany(query: any): Promise<Documents[]> {
|
||||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||||
return this.model.findMany(query);
|
return this.model.findMany(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Create a document
|
||||||
|
*/
|
||||||
|
public async create(document: Document): Promise<Documents> {
|
||||||
|
const documentCreated = await this.model.create({
|
||||||
|
data: {
|
||||||
|
folder: {
|
||||||
|
connect: {
|
||||||
|
uuid: document.folder.uid,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
depositor: {
|
||||||
|
connect: {
|
||||||
|
uuid: document.depositor.uid,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
document_type: {
|
||||||
|
connect: {
|
||||||
|
uuid: document.document_type.uid,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.instanceDb.documentHistory.create({
|
||||||
|
data: {
|
||||||
|
document: {
|
||||||
|
connect: {
|
||||||
|
uuid: documentCreated.uuid,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return documentCreated;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Create many documents linked to an office folder
|
||||||
|
*/
|
||||||
|
public async createMany(documents: Document[]): Promise<Prisma.BatchPayload> {
|
||||||
|
return this.model.createMany({
|
||||||
|
data: documents.map((document) => ({
|
||||||
|
folder_uuid: document.folder.uid,
|
||||||
|
depositor_uuid: document.depositor.uid,
|
||||||
|
document_type_uuid: document.document_type.uid,
|
||||||
|
})),
|
||||||
|
skipDuplicates: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Update data of a document
|
||||||
|
*/
|
||||||
|
public async update(uid: string, document: Document, refusedReason?: string): Promise<Documents> {
|
||||||
|
return this.model.update({
|
||||||
|
where: {
|
||||||
|
uuid: uid,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
document_status: EDocumentStatus[document.document_status as keyof typeof EDocumentStatus],
|
||||||
|
document_history: {
|
||||||
|
create: {
|
||||||
|
document_status: EDocumentStatus[document.document_status as keyof typeof EDocumentStatus],
|
||||||
|
refused_reason: refusedReason,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
depositor: {
|
||||||
|
connect: {
|
||||||
|
uuid: document.depositor.uid,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Delete a document
|
||||||
|
*/
|
||||||
|
public async delete(uid: string): Promise<Documents> {
|
||||||
|
return this.model.delete({
|
||||||
|
where: {
|
||||||
|
uuid: uid,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Find unique document
|
||||||
|
*/
|
||||||
|
public async findOneByUid(uid: string): Promise<Documents> {
|
||||||
|
const documentEntity = await this.model.findUnique({
|
||||||
|
where: {
|
||||||
|
uuid: uid,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!documentEntity) {
|
||||||
|
throw new Error("Document not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return documentEntity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
84
src/common/repositories/FilesRepository.ts
Normal file
84
src/common/repositories/FilesRepository.ts
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
import Database from "@Common/databases/database";
|
||||||
|
import BaseRepository from "@Repositories/BaseRepository";
|
||||||
|
import { Service } from "typedi";
|
||||||
|
import { Files } from "@prisma/client";
|
||||||
|
import { File } from "le-coffre-resources/dist/SuperAdmin"
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export default class FilesRepository extends BaseRepository {
|
||||||
|
constructor(private database: Database) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
protected get model() {
|
||||||
|
return this.database.getClient().files;
|
||||||
|
}
|
||||||
|
protected get instanceDb() {
|
||||||
|
return this.database.getClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Find many files
|
||||||
|
*/
|
||||||
|
public async findMany(query: any): Promise<Files[]> {
|
||||||
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||||
|
return this.model.findMany(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Create a file linked to a document
|
||||||
|
*/
|
||||||
|
public async create(file: File): Promise<Files> {
|
||||||
|
return this.model.create({
|
||||||
|
data: {
|
||||||
|
document: {
|
||||||
|
connect: {
|
||||||
|
uuid: file.document.uid
|
||||||
|
}
|
||||||
|
},
|
||||||
|
file_path: file.file_path
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Update data of a file
|
||||||
|
*/
|
||||||
|
public async update(uid: string, file: File): Promise<Files> {
|
||||||
|
return this.model.update({
|
||||||
|
where: {
|
||||||
|
uuid: uid,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
file_path: file.file_path
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Delete a file
|
||||||
|
*/
|
||||||
|
public async delete(uid: string): Promise<Files> {
|
||||||
|
return this.model.delete({
|
||||||
|
where: {
|
||||||
|
uuid: uid,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Find unique file
|
||||||
|
*/
|
||||||
|
public async findOneByUid(uid: string): Promise<Files> {
|
||||||
|
const fileEntity = await this.model.findUnique({
|
||||||
|
where: {
|
||||||
|
uuid: uid,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!fileEntity) {
|
||||||
|
throw new Error("File not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileEntity;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
import Database from "@Common/databases/database";
|
||||||
|
import { OfficeFolderHasCustomers } from "@prisma/client";
|
||||||
|
import BaseRepository from "@Repositories/BaseRepository";
|
||||||
|
import { Service } from "typedi";
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export default class OfficeFoldersHasCustomerRepository extends BaseRepository {
|
||||||
|
constructor(private database: Database) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
protected get model() {
|
||||||
|
return this.database.getClient().officeFolderHasCustomers;
|
||||||
|
}
|
||||||
|
protected get instanceDb() {
|
||||||
|
return this.database.getClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Find many relations
|
||||||
|
*/
|
||||||
|
public async findMany(query: any): Promise<OfficeFolderHasCustomers[]> {
|
||||||
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||||
|
return this.model.findMany(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Find a unique relation between an office folder and customers
|
||||||
|
*/
|
||||||
|
public async findOneByUid(uid: string): Promise<OfficeFolderHasCustomers> {
|
||||||
|
const officeFolderHasCustomersEntity = await this.model.findUnique({
|
||||||
|
where: {
|
||||||
|
uuid: uid,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!officeFolderHasCustomersEntity) {
|
||||||
|
throw new Error("relation between office folder and customer not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return officeFolderHasCustomersEntity;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
import Database from "@Common/databases/database";
|
||||||
|
import { OfficeFolderHasStakeholders } from "@prisma/client";
|
||||||
|
import BaseRepository from "@Repositories/BaseRepository";
|
||||||
|
import { Service } from "typedi";
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export default class OfficeFoldersHasStakeholderRepository extends BaseRepository {
|
||||||
|
constructor(private database: Database) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
protected get model() {
|
||||||
|
return this.database.getClient().officeFolderHasStakeholders;
|
||||||
|
}
|
||||||
|
protected get instanceDb() {
|
||||||
|
return this.database.getClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Find many relations
|
||||||
|
*/
|
||||||
|
public async findMany(query: any): Promise<OfficeFolderHasStakeholders[]> {
|
||||||
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||||
|
return this.model.findMany(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Find a unique relation between an office folder and stakeholders
|
||||||
|
*/
|
||||||
|
public async findOneByUid(uid: string): Promise<OfficeFolderHasStakeholders> {
|
||||||
|
const officeFolderHasStakeholdersEntity = await this.model.findUnique({
|
||||||
|
where: {
|
||||||
|
uuid: uid,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!officeFolderHasStakeholdersEntity) {
|
||||||
|
throw new Error("relation between office folder and stakeholder not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return officeFolderHasStakeholdersEntity;
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,7 @@
|
|||||||
import Database from "@Common/databases/database";
|
import Database from "@Common/databases/database";
|
||||||
import { ORMBadQueryError } from "@Common/system/database/exceptions/ORMBadQueryError";
|
|
||||||
import BaseRepository from "@Repositories/BaseRepository";
|
import BaseRepository from "@Repositories/BaseRepository";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import { EFolderStatus, OfficeFolders } from "@prisma/client";
|
import { EFolderStatus, OfficeFolders, Prisma } from "@prisma/client";
|
||||||
import { OfficeFolder } from "le-coffre-resources/dist/SuperAdmin";
|
import { OfficeFolder } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
@ -21,21 +20,15 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
|||||||
* @description : Find many office folders
|
* @description : Find many office folders
|
||||||
*/
|
*/
|
||||||
public async findMany(query: any): Promise<OfficeFolders[]> {
|
public async findMany(query: any): Promise<OfficeFolders[]> {
|
||||||
try {
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||||
const limit = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
return this.model.findMany(query);
|
||||||
|
|
||||||
return await this.model.findMany({ ...query, take: limit });
|
|
||||||
} catch (error) {
|
|
||||||
throw new ORMBadQueryError((error as Error).message, error as Error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Create new office folder wihtout customers nor stakeholders
|
* @description : Create new office folder without customers nor stakeholders
|
||||||
*/
|
*/
|
||||||
public async create(officeFolder: OfficeFolder): Promise<OfficeFolders> {
|
public async create(officeFolder: OfficeFolder): Promise<OfficeFolders> {
|
||||||
try {
|
const createArgs: Prisma.OfficeFoldersCreateArgs = {
|
||||||
const officeFolderEntityCreated = (await this.model.create({
|
|
||||||
data: {
|
data: {
|
||||||
folder_number: officeFolder.folder_number,
|
folder_number: officeFolder.folder_number,
|
||||||
name: officeFolder.name,
|
name: officeFolder.name,
|
||||||
@ -56,51 +49,94 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})) as OfficeFolders;
|
include: {
|
||||||
|
office_folder_has_stakeholder: true,
|
||||||
return officeFolderEntityCreated;
|
|
||||||
} catch (error) {
|
|
||||||
throw new ORMBadQueryError((error as Error).message, error as Error);
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
if (officeFolder.office_folder_has_stakeholder) {
|
||||||
|
createArgs.data.office_folder_has_stakeholder = {
|
||||||
|
createMany: {
|
||||||
|
data: officeFolder.office_folder_has_stakeholder.map((relation) => ({
|
||||||
|
user_stakeholder_uuid: relation.user_stakeholder.uid,
|
||||||
|
})),
|
||||||
|
skipDuplicates: true
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return this.model.create(createArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async update(
|
/**
|
||||||
officeFolder: OfficeFolder,
|
* @description : Update data of an office folder
|
||||||
officeFolderHasStakeholders_uuid?: string,
|
*/
|
||||||
officeFolderHasCustomers_uuid?: string,
|
public async update(officeFolderUuid: string, officeFolder: OfficeFolder): Promise<OfficeFolders> {
|
||||||
document_uuid?: string,
|
const updateArgs: Prisma.OfficeFoldersUpdateArgs = {
|
||||||
): Promise<OfficeFolders> {
|
|
||||||
try {
|
|
||||||
const officeFolderEntityUpdated = (await this.model.update({
|
|
||||||
where: {
|
where: {
|
||||||
uuid: officeFolder.uid,
|
uuid: officeFolderUuid,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
folder_number: officeFolder.folder_number,
|
folder_number: officeFolder.folder_number,
|
||||||
name: officeFolder.name,
|
name: officeFolder.name,
|
||||||
description: officeFolder.description,
|
description: officeFolder.description,
|
||||||
status: EFolderStatus.LIVE,
|
status: EFolderStatus[officeFolder.status as keyof typeof EFolderStatus],
|
||||||
office_folder_has_stakeholder: {
|
archived_description: officeFolder.archived_description,
|
||||||
connect: {
|
|
||||||
uuid: officeFolderHasStakeholders_uuid,
|
|
||||||
},
|
},
|
||||||
},
|
include: {
|
||||||
office_folder_has_customers: {
|
office_folder_has_stakeholder: true,
|
||||||
connect: {
|
office_folder_has_customers: true,
|
||||||
uuid: officeFolderHasCustomers_uuid,
|
documents: true,
|
||||||
},
|
|
||||||
},
|
|
||||||
documents: {
|
|
||||||
connect: {
|
|
||||||
uuid: document_uuid,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})) as OfficeFolders;
|
|
||||||
|
|
||||||
return officeFolderEntityUpdated;
|
|
||||||
} catch (error) {
|
|
||||||
throw new ORMBadQueryError((error as Error).message, error as Error);
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
if (officeFolder.office_folder_has_stakeholder) {
|
||||||
|
updateArgs.data.office_folder_has_stakeholder = {
|
||||||
|
deleteMany: { office_folder_uuid: officeFolderUuid },
|
||||||
|
createMany: {
|
||||||
|
data: officeFolder.office_folder_has_stakeholder.map((relation) => ({
|
||||||
|
user_stakeholder_uuid: relation.user_stakeholder.uid,
|
||||||
|
})),
|
||||||
|
skipDuplicates: true
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (officeFolder.office_folder_has_customers) {
|
||||||
|
updateArgs.data.office_folder_has_customers = {
|
||||||
|
deleteMany: { office_folder_uuid: officeFolderUuid },
|
||||||
|
createMany: {
|
||||||
|
data: officeFolder.office_folder_has_customers.map((relation) => ({
|
||||||
|
customer_uuid: relation.customer.uid,
|
||||||
|
})),
|
||||||
|
skipDuplicates: true
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (officeFolder.documents) {
|
||||||
|
updateArgs.data.documents = {
|
||||||
|
createMany: {
|
||||||
|
data: officeFolder.documents.map((relation) => ({
|
||||||
|
document_type_uuid: relation.document_type.uid,
|
||||||
|
depositor_uuid: relation.depositor.uid
|
||||||
|
})),
|
||||||
|
skipDuplicates: true
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.model.update(updateArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Find one office folder
|
||||||
|
*/
|
||||||
|
public async findOneByUid(uid: string): Promise<OfficeFolders> {
|
||||||
|
const officeFolderEntity = await this.model.findUnique({
|
||||||
|
where: {
|
||||||
|
uuid: uid,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!officeFolderEntity) {
|
||||||
|
throw new Error("office folder not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return officeFolderEntity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import Database from "@Common/databases/database";
|
import Database from "@Common/databases/database";
|
||||||
import { ORMBadQueryError } from "@Common/system/database/exceptions/ORMBadQueryError";
|
|
||||||
import BaseRepository from "@Repositories/BaseRepository";
|
import BaseRepository from "@Repositories/BaseRepository";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import { EOfficeStatus, Offices } from "@prisma/client";
|
import { EOfficeStatus, Offices } from "@prisma/client";
|
||||||
@ -21,18 +20,16 @@ export default class OfficesRepository extends BaseRepository {
|
|||||||
* @description : Find many users
|
* @description : Find many users
|
||||||
*/
|
*/
|
||||||
public async findMany(query: any): Promise<Offices[]> {
|
public async findMany(query: any): Promise<Offices[]> {
|
||||||
try {
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||||
const limit = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
|
||||||
|
|
||||||
return await this.model.findMany({ ...query, take: limit });
|
return this.model.findMany(query);
|
||||||
} catch (error) {
|
|
||||||
throw new ORMBadQueryError((error as Error).message, error as Error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Create an office
|
||||||
|
*/
|
||||||
public async create(office: OfficeRessource): Promise<Offices> {
|
public async create(office: OfficeRessource): Promise<Offices> {
|
||||||
try {
|
return this.model.create({
|
||||||
const officeEntityCreated = (await this.model.create({
|
|
||||||
data: {
|
data: {
|
||||||
idNot: office.idNot,
|
idNot: office.idNot,
|
||||||
name: office.name,
|
name: office.name,
|
||||||
@ -46,17 +43,14 @@ export default class OfficesRepository extends BaseRepository {
|
|||||||
},
|
},
|
||||||
office_status: EOfficeStatus.DESACTIVATED,
|
office_status: EOfficeStatus.DESACTIVATED,
|
||||||
},
|
},
|
||||||
})) as Offices;
|
});
|
||||||
|
|
||||||
return officeEntityCreated;
|
|
||||||
} catch (error) {
|
|
||||||
throw new ORMBadQueryError((error as Error).message, error as Error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Update data from an office
|
||||||
|
*/
|
||||||
public async update(uid: string, office: OfficeRessource): Promise<Offices> {
|
public async update(uid: string, office: OfficeRessource): Promise<Offices> {
|
||||||
try {
|
return this.model.update({
|
||||||
const officeEntityUpdated = (await this.model.update({
|
|
||||||
where: {
|
where: {
|
||||||
uuid: uid,
|
uuid: uid,
|
||||||
},
|
},
|
||||||
@ -71,15 +65,13 @@ export default class OfficesRepository extends BaseRepository {
|
|||||||
},
|
},
|
||||||
office_status: EOfficeStatus[office.office_status as keyof typeof EOfficeStatus],
|
office_status: EOfficeStatus[office.office_status as keyof typeof EOfficeStatus],
|
||||||
},
|
},
|
||||||
})) as Offices;
|
});
|
||||||
return officeEntityUpdated;
|
|
||||||
} catch (error) {
|
|
||||||
throw new ORMBadQueryError((error as Error).message, error as Error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Find one office
|
||||||
|
*/
|
||||||
public async findOneByUid(uid: string): Promise<Offices> {
|
public async findOneByUid(uid: string): Promise<Offices> {
|
||||||
try {
|
|
||||||
const officeEntity = await this.model.findUnique({
|
const officeEntity = await this.model.findUnique({
|
||||||
where: {
|
where: {
|
||||||
uuid: uid,
|
uuid: uid,
|
||||||
@ -91,10 +83,5 @@ export default class OfficesRepository extends BaseRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return officeEntity;
|
return officeEntity;
|
||||||
|
|
||||||
//return await this.model.find({ ...query, take: limit });
|
|
||||||
} catch (error) {
|
|
||||||
throw new ORMBadQueryError((error as Error).message, error as Error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,12 @@ export default class UsersRepository extends BaseRepository {
|
|||||||
*/
|
*/
|
||||||
public async findMany(query: any): Promise<Users[]> {
|
public async findMany(query: any): Promise<Users[]> {
|
||||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||||
return await this.model.findMany(query);
|
return this.model.findMany(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Create a user
|
||||||
|
*/
|
||||||
public async create(user: User): Promise<Users> {
|
public async create(user: User): Promise<Users> {
|
||||||
return this.model.create({
|
return this.model.create({
|
||||||
data: {
|
data: {
|
||||||
@ -68,6 +71,9 @@ export default class UsersRepository extends BaseRepository {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Update data from a user
|
||||||
|
*/
|
||||||
public async update(uid: string, user: User): Promise<Users> {
|
public async update(uid: string, user: User): Promise<Users> {
|
||||||
return this.model.update({
|
return this.model.update({
|
||||||
where: {
|
where: {
|
||||||
|
@ -1,64 +1,26 @@
|
|||||||
// import { Addresses } from "@prisma/client";
|
|
||||||
import { Addresses } from "@prisma/client";
|
|
||||||
import AddressesRepository from "@Repositories/AddressesRepository";
|
import AddressesRepository from "@Repositories/AddressesRepository";
|
||||||
import BaseService from "@Services/BaseService";
|
import BaseService from "@Services/BaseService";
|
||||||
import Container, { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class AddressesService extends BaseService {
|
export default class AddressesService extends BaseService {
|
||||||
constructor() {
|
constructor(private addressRepository: AddressesRepository) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Get all addresses
|
* @description : Get all addresses
|
||||||
* @returns : T
|
|
||||||
* @throws {Error} If addresses cannot be get
|
* @throws {Error} If addresses cannot be get
|
||||||
* @param : projectEntity: Partial<ProjectEntity>
|
|
||||||
*/
|
*/
|
||||||
public async get(query: any) {
|
public async get(query: any) {
|
||||||
//init repo
|
return this.addressRepository.findMany(query);
|
||||||
const repo = Container.get(AddressesRepository);
|
|
||||||
|
|
||||||
//call service to return prisma entity
|
|
||||||
return await repo.findMany(query);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Create a new address
|
|
||||||
* @returns : T
|
|
||||||
* @throws {Error} If address cannot be created
|
|
||||||
* @param : projectEntity: Partial<ProjectEntity>
|
|
||||||
*/
|
|
||||||
public async create(address: Addresses): Promise<Addresses> {
|
|
||||||
//init repo
|
|
||||||
const repo = Container.get(AddressesRepository);
|
|
||||||
|
|
||||||
// call service to return prisma entity
|
|
||||||
return await repo.create(address);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Modify a new address
|
|
||||||
* @returns : T
|
|
||||||
* @throws {Error} If address cannot be modified
|
|
||||||
* @param : projectEntity: Partial<ProjectEntity>
|
|
||||||
*/
|
|
||||||
public async put() {
|
|
||||||
// const address = await this.projectRepository.create(projectEntity);
|
|
||||||
// if (!address) Promise.reject(new Error("Cannot create project"));
|
|
||||||
return { response: "/api/addresses > PUT : Modified address > Not implemented yet" };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Get a address by uid
|
* @description : Get a address by uid
|
||||||
* @returns : T
|
* @throws {Error} If address cannot be get
|
||||||
* @throws {Error} If address cannot be created
|
|
||||||
* @param : projectEntity: Partial<ProjectEntity>
|
|
||||||
*/
|
*/
|
||||||
public async getByUid(uuid: string) {
|
public async getByUid(uuid: string) {
|
||||||
// const address = await this.usersRepository.findOne(uuid);
|
return this.addressRepository.findOneByUid(uuid);
|
||||||
// if (!address) Promise.reject(new Error("Cannot get address by uuid"));
|
|
||||||
return { response: "/api/addresses/:uuid > GET : address by uid > Not implemented yet" };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,9 @@ import { BackendVariables } from "@Common/config/variables/Variables";
|
|||||||
import Container, { Service } from "typedi";
|
import Container, { Service } from "typedi";
|
||||||
|
|
||||||
type IdNotTokens = {
|
type IdNotTokens = {
|
||||||
access_token: string,
|
access_token: string;
|
||||||
id_token: string
|
id_token: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class AuthService extends BaseService {
|
export default class AuthService extends BaseService {
|
||||||
@ -26,13 +26,16 @@ export default class AuthService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async getIdNotTokens(code: string): Promise<IdNotTokens> {
|
private async getIdNotTokens(code: string): Promise<IdNotTokens> {
|
||||||
const url = new URL(this.variables.IDNOT_CONNEXION_URL.concat("?") + new URLSearchParams({
|
const url = new URL(
|
||||||
|
this.variables.IDNOT_CONNEXION_URL.concat("?") +
|
||||||
|
new URLSearchParams({
|
||||||
client_id: this.variables.IDNOT_CLIENT_ID,
|
client_id: this.variables.IDNOT_CLIENT_ID,
|
||||||
client_secret: this.variables.IDNOT_CLIENT_SECRET,
|
client_secret: this.variables.IDNOT_CLIENT_SECRET,
|
||||||
redirect_uri: this.variables.IDNOT_REDIRECT_URL,
|
redirect_uri: this.variables.IDNOT_REDIRECT_URL,
|
||||||
code: code,
|
code: code,
|
||||||
grant_type: "authorization_code",
|
grant_type: "authorization_code",
|
||||||
}));
|
}),
|
||||||
|
);
|
||||||
try {
|
try {
|
||||||
const headers = new Headers({
|
const headers = new Headers({
|
||||||
"Content-Type": "application/x-www-form-urlencoded",
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
@ -41,10 +44,10 @@ export default class AuthService extends BaseService {
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
headers: headers,
|
headers: headers,
|
||||||
});
|
});
|
||||||
const data = await res.json()
|
const data = await res.json();
|
||||||
return data as IdNotTokens;
|
return data as IdNotTokens;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error);
|
||||||
throw new Error();
|
throw new Error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,57 +1,26 @@
|
|||||||
|
import ContactsRepository from "@Repositories/ContactsRepository";
|
||||||
import BaseService from "@Services/BaseService";
|
import BaseService from "@Services/BaseService";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class ContactsService extends BaseService {
|
export default class ContactsService extends BaseService {
|
||||||
constructor() {
|
constructor(private contactRepository: ContactsRepository) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Get all contacts
|
* @description : Get all contacts
|
||||||
* @returns : T
|
|
||||||
* @throws {Error} If contacts cannot be get
|
* @throws {Error} If contacts cannot be get
|
||||||
* @param : projectEntity: Partial<ProjectEntity>
|
|
||||||
*/
|
*/
|
||||||
public async get() {
|
public async get(query: any) {
|
||||||
// const contact = await this.usersRepository.findOne(uuid);
|
return this.contactRepository.findMany(query);
|
||||||
// if (!contact) Promise.reject(new Error("Cannot get contact by uuid"));
|
|
||||||
return { response: "/api/contacts > GET : All contacts > Not implemented yet" };
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Create a new contact
|
|
||||||
* @returns : T
|
|
||||||
* @throws {Error} If contact cannot be created
|
|
||||||
* @param : projectEntity: Partial<ProjectEntity>
|
|
||||||
*/
|
|
||||||
public async create() {
|
|
||||||
// const contact = await this.projectRepository.create(projectEntity);
|
|
||||||
// if (!contact) Promise.reject(new Error("Cannot create project"));
|
|
||||||
return { response: "/api/contacts > POST : Create contact > Not implemented yet" };
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : Modify a new contact
|
|
||||||
* @returns : T
|
|
||||||
* @throws {Error} If contact cannot be modified
|
|
||||||
* @param : projectEntity: Partial<ProjectEntity>
|
|
||||||
*/
|
|
||||||
public async put() {
|
|
||||||
// const contact = await this.projectRepository.create(projectEntity);
|
|
||||||
// if (!contact) Promise.reject(new Error("Cannot create project"));
|
|
||||||
return { response: "/api/contacts > PUT : Modified contact > Not implemented yet" };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Get a contact by uid
|
* @description : Get a contact by uid
|
||||||
* @returns : T
|
* @throws {Error} If contact cannot be get
|
||||||
* @throws {Error} If project cannot be created
|
|
||||||
* @param : projectEntity: Partial<ProjectEntity>
|
|
||||||
*/
|
*/
|
||||||
public async getByUid(uuid: string) {
|
public async getByUid(uuid: string) {
|
||||||
// const contact = await this.usersRepository.findOne(uuid);
|
return this.contactRepository.findOneByUid(uuid);
|
||||||
// if (!contact) Promise.reject(new Error("Cannot get contact by uuid"));
|
|
||||||
return { response: "/api/contacts/:uuid > GET : contact by uid > Not implemented yet" };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,57 +1,43 @@
|
|||||||
|
import FilesRepository from "@Repositories/FilesRepository";
|
||||||
import BaseService from "@Services/BaseService";
|
import BaseService from "@Services/BaseService";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
|
import { File } from "le-coffre-resources/dist/SuperAdmin"
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class FilesService extends BaseService {
|
export default class FilesService extends BaseService {
|
||||||
constructor() {
|
constructor(private filesRepository: FilesRepository) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Get all files
|
* @description : Get all files
|
||||||
* @returns : T
|
* @throws {Error} If files cannot be ge
|
||||||
* @throws {Error} If files cannot be get
|
|
||||||
* @param : projectEntity: Partial<ProjectEntity>
|
|
||||||
*/
|
*/
|
||||||
public async get() {
|
public async get(query: any) {
|
||||||
// const files = await this.usersRepository.findOne(uuid);
|
return this.filesRepository.findMany(query);
|
||||||
// if (!files) Promise.reject(new Error("Cannot get files"));
|
|
||||||
return { response: "/api/files > GET : All files > Not implemented yet" };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Create a new file
|
* @description : Create a new file
|
||||||
* @returns : T
|
|
||||||
* @throws {Error} If file cannot be created
|
* @throws {Error} If file cannot be created
|
||||||
* @param : projectEntity: Partial<ProjectEntity>
|
|
||||||
*/
|
*/
|
||||||
public async create() {
|
public async create(file: File) {
|
||||||
// const file = await this.projectRepository.create(projectEntity);
|
return this.filesRepository.create(file);
|
||||||
// if (!file) Promise.reject(new Error("Cannot create project"));
|
|
||||||
return { response: "/api/files > POST : Create file > Not implemented yet" };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Modify a new file
|
* @description : Modify a new file
|
||||||
* @returns : T
|
|
||||||
* @throws {Error} If file cannot be modified
|
* @throws {Error} If file cannot be modified
|
||||||
* @param : projectEntity: Partial<ProjectEntity>
|
|
||||||
*/
|
*/
|
||||||
public async put() {
|
public async put(uid: string, file: File) {
|
||||||
// const file = await this.projectRepository.create(projectEntity);
|
return this.filesRepository.update(uid, file);
|
||||||
// if (!file) Promise.reject(new Error("Cannot create project"));
|
|
||||||
return { response: "/api/files > PUT : Modified file > Not implemented yet" };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Get a file by uid
|
* @description : Get a file by uid
|
||||||
* @returns : T
|
|
||||||
* @throws {Error} If project cannot be created
|
* @throws {Error} If project cannot be created
|
||||||
* @param : projectEntity: Partial<ProjectEntity>
|
|
||||||
*/
|
*/
|
||||||
public async getByUid(uid: string) {
|
public async getByUid(uid: string) {
|
||||||
// const file = await this.usersRepository.findOne(uid);
|
return this.filesRepository.findOneByUid(uid);
|
||||||
// if (!file) Promise.reject(new Error("Cannot get file by uid"));
|
|
||||||
return { response: "/api/files/:uid > GET : file by uid > Not implemented yet" };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { DeedTypes } from "@prisma/client";
|
import { DeedTypes } from "@prisma/client";
|
||||||
import DeedTypeHasDocumentTypesRepository from "@Repositories/DeedTypesHasDocumentTypesRepository";
|
|
||||||
import DeedTypesRepository from "@Repositories/DeedTypesRepository";
|
import DeedTypesRepository from "@Repositories/DeedTypesRepository";
|
||||||
import BaseService from "@Services/BaseService";
|
import BaseService from "@Services/BaseService";
|
||||||
import { DeedType } from "le-coffre-resources/dist/SuperAdmin";
|
import { DeedType } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
@ -9,7 +8,6 @@ import { Service } from "typedi";
|
|||||||
export default class DeedTypesService extends BaseService {
|
export default class DeedTypesService extends BaseService {
|
||||||
constructor(
|
constructor(
|
||||||
private deedTypeRepository: DeedTypesRepository,
|
private deedTypeRepository: DeedTypesRepository,
|
||||||
private deedTypeHasDocumentTypesRepository: DeedTypeHasDocumentTypesRepository,
|
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@ -25,7 +23,6 @@ export default class DeedTypesService extends BaseService {
|
|||||||
/**
|
/**
|
||||||
* @description : Create a new deed-type
|
* @description : Create a new deed-type
|
||||||
* @throws {Error} If deed-type cannot be created
|
* @throws {Error} If deed-type cannot be created
|
||||||
* @param : deedTypesEntity: Partial<DeedTypesEntity>
|
|
||||||
*/
|
*/
|
||||||
public async create(deedTypeEntity: DeedType): Promise<DeedTypes> {
|
public async create(deedTypeEntity: DeedType): Promise<DeedTypes> {
|
||||||
return this.deedTypeRepository.create(deedTypeEntity);
|
return this.deedTypeRepository.create(deedTypeEntity);
|
||||||
@ -46,33 +43,4 @@ export default class DeedTypesService extends BaseService {
|
|||||||
public async getByUid(uid: string) {
|
public async getByUid(uid: string) {
|
||||||
return this.deedTypeRepository.findOneByUid(uid);
|
return this.deedTypeRepository.findOneByUid(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async addDocumentTypes(deedTypeUuid: string, documentTypesUuidToAdd: string[]): Promise<any[]> {
|
|
||||||
const relationsToDocumentTypes = await this.deedTypeHasDocumentTypesRepository.createMany(deedTypeUuid, documentTypesUuidToAdd);
|
|
||||||
|
|
||||||
let deedTypeHasDocumentUuids: string[] = [];
|
|
||||||
relationsToDocumentTypes.forEach((item) => {
|
|
||||||
deedTypeHasDocumentUuids.push(item.uuid);
|
|
||||||
});
|
|
||||||
|
|
||||||
return this.deedTypeRepository.addDocumentTypes(deedTypeUuid, deedTypeHasDocumentUuids);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async addDocumentType(deedTypeUuid: string, documentTypesUuidToAdd: string): Promise<DeedTypes> {
|
|
||||||
const deedTypeHasDocumentType = await this.deedTypeHasDocumentTypesRepository.create(deedTypeUuid, documentTypesUuidToAdd);
|
|
||||||
|
|
||||||
return this.deedTypeRepository.addDocumentType(deedTypeUuid, deedTypeHasDocumentType.uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async removeDocumentType(deedTypeUuid: string, documentTypesUuidToRemove: string): Promise<DeedTypes[]> {
|
|
||||||
await this.deedTypeHasDocumentTypesRepository.delete(deedTypeUuid, documentTypesUuidToRemove);
|
|
||||||
|
|
||||||
return this.get({ where: { uuid: deedTypeUuid }, include: { deed_type_has_document_types: true } });
|
|
||||||
}
|
|
||||||
|
|
||||||
public async removeDocumentTypes(deedTypeUuid: string, documentTypesUuidToRemove: string[]): Promise<DeedTypes[]> {
|
|
||||||
await this.deedTypeHasDocumentTypesRepository.deleteMany(deedTypeUuid, documentTypesUuidToRemove);
|
|
||||||
|
|
||||||
return this.get({ where: { uuid: deedTypeUuid }, include: { deed_type_has_document_types: true } });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,12 @@
|
|||||||
import { Deeds } from "@prisma/client";
|
import { Deeds } from "@prisma/client";
|
||||||
import DeedHasDocumentTypesRepository from "@Repositories/DeedsHasDocumentTypesRepository";
|
|
||||||
import DeedsRepository from "@Repositories/DeedsRepository";
|
import DeedsRepository from "@Repositories/DeedsRepository";
|
||||||
import DeedTypesHasDocumentTypesRepository from "@Repositories/DeedTypesHasDocumentTypesRepository";
|
|
||||||
import DeedTypesRepository from "@Repositories/DeedTypesRepository";
|
|
||||||
import BaseService from "@Services/BaseService";
|
import BaseService from "@Services/BaseService";
|
||||||
import { DeedType } from "le-coffre-resources/dist/Customer";
|
import { Deed } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
import Container, { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class DeedsService extends BaseService {
|
export default class DeedsService extends BaseService {
|
||||||
constructor(private deedRepository: DeedsRepository, private deedHasDocumentTypesRepository: DeedHasDocumentTypesRepository) {
|
constructor(private deedRepository: DeedsRepository) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,29 +22,16 @@ export default class DeedsService extends BaseService {
|
|||||||
* @description : Create a new deed with document types
|
* @description : Create a new deed with document types
|
||||||
* @throws {Error} If deeds cannot be created
|
* @throws {Error} If deeds cannot be created
|
||||||
*/
|
*/
|
||||||
public async create(deedType: DeedType): Promise<Deeds> {
|
public async create(deed: Deed): Promise<Deeds> {
|
||||||
let documentTypesToAdd: string[] = [];
|
return this.deedRepository.create(deed);
|
||||||
const deedTypeHasDocumentTypesRepository = Container.get(DeedTypesHasDocumentTypesRepository);
|
}
|
||||||
const deedTypesRepository = Container.get(DeedTypesRepository);
|
|
||||||
|
|
||||||
if ((await deedTypesRepository.findOneByUid(deedType.uid)).archived_at != null) throw new Error("deed type is archived");
|
/**
|
||||||
|
* @description : Update data of a deed with document types
|
||||||
const deedTypeHasDocumentTypes = await deedTypeHasDocumentTypesRepository.findMany({ where: { deed_type_uuid: deedType.uid } });
|
* @throws {Error} If deeds cannot be updated with document types or one of them
|
||||||
deedTypeHasDocumentTypes.forEach((relation) => {
|
*/
|
||||||
documentTypesToAdd.push(relation.document_type_uuid);
|
public async update(deedUuid: string, deed: Deed): Promise<Deeds> {
|
||||||
});
|
return this.deedRepository.update(deedUuid, deed);
|
||||||
|
|
||||||
const deed = await this.deedRepository.create(deedType);
|
|
||||||
const relations = await this.deedHasDocumentTypesRepository.createMany(deed.uuid, documentTypesToAdd);
|
|
||||||
|
|
||||||
let relationsToAdd: string[] = [];
|
|
||||||
relations.forEach((relation) => {
|
|
||||||
documentTypesToAdd.push(relation.uuid);
|
|
||||||
});
|
|
||||||
|
|
||||||
await this.deedRepository.addDocumentTypes(deed.uuid, relationsToAdd);
|
|
||||||
|
|
||||||
return this.getByUid(deed.uuid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,33 +41,4 @@ export default class DeedsService extends BaseService {
|
|||||||
public async getByUid(uid: string) {
|
public async getByUid(uid: string) {
|
||||||
return this.deedRepository.findOneByUid(uid);
|
return this.deedRepository.findOneByUid(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async addDocumentTypes(deedTypeUuid: string, documentTypesUuidToAdd: string[]): Promise<any[]> {
|
|
||||||
const relationsToDocumentTypes = await this.deedHasDocumentTypesRepository.createMany(deedTypeUuid, documentTypesUuidToAdd);
|
|
||||||
|
|
||||||
let deedTypeHasDocumentUuids: string[] = [];
|
|
||||||
relationsToDocumentTypes.forEach((item) => {
|
|
||||||
deedTypeHasDocumentUuids.push(item.uuid);
|
|
||||||
});
|
|
||||||
|
|
||||||
return this.deedRepository.addDocumentTypes(deedTypeUuid, deedTypeHasDocumentUuids);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async addDocumentType(deedTypeUuid: string, documentTypesUuidToAdd: string): Promise<Deeds> {
|
|
||||||
const deedTypeHasDocumentType = await this.deedHasDocumentTypesRepository.create(deedTypeUuid, documentTypesUuidToAdd);
|
|
||||||
|
|
||||||
return this.deedRepository.addDocumentType(deedTypeUuid, deedTypeHasDocumentType.uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async removeDocumentType(deedTypeUuid: string, documentTypesUuidToRemove: string): Promise<Deeds[]> {
|
|
||||||
await this.deedHasDocumentTypesRepository.delete(deedTypeUuid, documentTypesUuidToRemove);
|
|
||||||
|
|
||||||
return await this.get({ where: { uuid: deedTypeUuid }, include: { deed_has_document_types: true } });
|
|
||||||
}
|
|
||||||
|
|
||||||
public async removeDocumentTypes(deedTypeUuid: string, documentTypesUuidToRemove: string[]): Promise<Deeds[]> {
|
|
||||||
await this.deedHasDocumentTypesRepository.deleteMany(deedTypeUuid, documentTypesUuidToRemove);
|
|
||||||
|
|
||||||
return await this.get({ where: { uuid: deedTypeUuid }, include: { deed_has_document_types: true } });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,6 @@ export default class DocumentTypesService extends BaseService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Get a document-type by uid
|
* @description : Get a document-type by uid
|
||||||
* @returns : T
|
|
||||||
* @throws {Error} If document-type is not found
|
* @throws {Error} If document-type is not found
|
||||||
*/
|
*/
|
||||||
public async getByUid(uid: string) {
|
public async getByUid(uid: string) {
|
||||||
|
@ -1,62 +1,60 @@
|
|||||||
import DocumentTypesRepository from "@Repositories/DocumentTypesRepository";
|
import { Documents, Prisma } from "@prisma/client";
|
||||||
//import { DocumentTypes } from "prisma/prisma-client";
|
import { Document } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
|
import DocumentsRepository from "@Repositories/DocumentsRepository";
|
||||||
import BaseService from "@Services/BaseService";
|
import BaseService from "@Services/BaseService";
|
||||||
import Container, { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class DocumentsService extends BaseService {
|
export default class DocumentsService extends BaseService {
|
||||||
constructor() {
|
constructor(private documentsRepository: DocumentsRepository) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Get all documents
|
* @description : Get all documents
|
||||||
* @returns : Document[]
|
|
||||||
* @throws {Error} If documents cannot be get
|
* @throws {Error} If documents cannot be get
|
||||||
*/
|
*/
|
||||||
public async get(query: any) {
|
public async get(query: any) {
|
||||||
//init repo
|
return this.documentsRepository.findMany(query);
|
||||||
const repo = Container.get(DocumentTypesRepository);
|
|
||||||
|
|
||||||
//call service to return prisma entity
|
|
||||||
return await repo.findMany(query);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Create a new document
|
* @description : Create a new document
|
||||||
* @returns : T
|
|
||||||
* @throws {Error} If document cannot be created
|
* @throws {Error} If document cannot be created
|
||||||
* @param : projectEntity: Partial<ProjectEntity>
|
|
||||||
*/
|
*/
|
||||||
// public async create(documentTypeEntity: DocumentTypes): Promise<DocumentTypes> {
|
public async create(document: Document): Promise<Documents> {
|
||||||
// //init repo
|
return this.documentsRepository.create(document);
|
||||||
// const repo = Container.get(DocumentTypesRepository);
|
}
|
||||||
|
|
||||||
// // call service to return prisma entity
|
/**
|
||||||
// return await repo.create(documentTypeEntity);
|
* @description : Create new documents
|
||||||
// }
|
* @throws {Error} If documents or one of them cannot be created
|
||||||
|
*/
|
||||||
|
public async createMany(documents: Document[]): Promise<Prisma.BatchPayload> {
|
||||||
|
return this.documentsRepository.createMany(documents);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Modify a document
|
* @description : Modify a document
|
||||||
* @returns : T
|
|
||||||
* @throws {Error} If document cannot be modified
|
* @throws {Error} If document cannot be modified
|
||||||
* @param : projectEntity: Partial<ProjectEntity>
|
|
||||||
*/
|
*/
|
||||||
public async put() {
|
public async update(uid: string, document: Document): Promise<Documents> {
|
||||||
// const document = await this.projectRepository.create(projectEntity);
|
return this.documentsRepository.update(uid, document);
|
||||||
// if (!document) Promise.reject(new Error("Cannot create document"));
|
}
|
||||||
return { response: "/api/documents > PUT : Modified document > Not implemented yet" };
|
|
||||||
|
/**
|
||||||
|
* @description : Delete a document
|
||||||
|
* @throws {Error} If document cannot be deleted
|
||||||
|
*/
|
||||||
|
public async delete(uid: string): Promise<Documents> {
|
||||||
|
return this.documentsRepository.delete(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Get a document by uid
|
* @description : Get a document by uid
|
||||||
* @returns : T
|
|
||||||
* @throws {Error} If document cannot be get by uid
|
* @throws {Error} If document cannot be get by uid
|
||||||
* @param : projectEntity: Partial<ProjectEntity>
|
|
||||||
*/
|
*/
|
||||||
public async getByUid(uid: string) {
|
public async getByUid(uid: string) {
|
||||||
// const document = await this.customersRepository.findOne(uid);
|
return this.documentsRepository.findOneByUid(uid);
|
||||||
// if (!document) Promise.reject(new Error("Cannot get document by uid"));
|
|
||||||
return { response: "/api/documents/:uid > GET : document by uid > Not implemented yet" };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,64 +2,46 @@ import { OfficeFolders } from ".prisma/client";
|
|||||||
import OfficeFoldersRepository from "@Repositories/OfficeFoldersRepository";
|
import OfficeFoldersRepository from "@Repositories/OfficeFoldersRepository";
|
||||||
import BaseService from "@Services/BaseService";
|
import BaseService from "@Services/BaseService";
|
||||||
import { OfficeFolder } from "le-coffre-resources/dist/SuperAdmin";
|
import { OfficeFolder } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
import Container, { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
|
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class OfficeFoldersService extends BaseService {
|
export default class OfficeFoldersService extends BaseService {
|
||||||
constructor() {
|
constructor(
|
||||||
|
private officeFoldersRepository: OfficeFoldersRepository
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Get all folders
|
* @description : Get all folders
|
||||||
* @returns : OfficeFolders[]
|
|
||||||
* @throws {Error} If folders cannot be get
|
* @throws {Error} If folders cannot be get
|
||||||
*/
|
*/
|
||||||
public async get(query: any) {
|
public async get(query: any) {
|
||||||
//init repo
|
return this.officeFoldersRepository.findMany(query);
|
||||||
const repo = Container.get(OfficeFoldersRepository);
|
|
||||||
|
|
||||||
//call service to return prisma entity
|
|
||||||
return await repo.findMany(query);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Create a new folder
|
* @description : Create a new folder
|
||||||
* @returns : T
|
|
||||||
* @throws {Error} If folder cannot be created
|
* @throws {Error} If folder cannot be created
|
||||||
* @param : projectEntity: Partial<ProjectEntity>
|
|
||||||
*/
|
*/
|
||||||
public async create(officeFolderEntity: OfficeFolder): Promise<OfficeFolders> {
|
public async create(officeFolderEntity: OfficeFolder): Promise<OfficeFolders> {
|
||||||
//init repo
|
return this.officeFoldersRepository.create(officeFolderEntity);
|
||||||
const repo = Container.get(OfficeFoldersRepository);
|
|
||||||
|
|
||||||
// call service to return prisma entity
|
|
||||||
return await repo.create(officeFolderEntity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Modify a folder
|
* @description : Modify a folder
|
||||||
* @returns : T
|
|
||||||
* @throws {Error} If folder cannot be modified
|
* @throws {Error} If folder cannot be modified
|
||||||
* @param : projectEntity: Partial<ProjectEntity>
|
|
||||||
*/
|
*/
|
||||||
public async update(officeFolderEntity: OfficeFolder): Promise<OfficeFolders> {
|
public async update(officeFolderUuid: string, officeFolderEntity: OfficeFolder): Promise<OfficeFolders> {
|
||||||
//init repo
|
return this.officeFoldersRepository.update(officeFolderUuid, officeFolderEntity);
|
||||||
const repo = Container.get(OfficeFoldersRepository);
|
|
||||||
|
|
||||||
// call service to return prisma entity
|
|
||||||
return await repo.update(officeFolderEntity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Get a folder by uid
|
* @description : Get a folder by uid
|
||||||
* @returns : T
|
|
||||||
* @throws {Error} If folder cannot be get by uid
|
* @throws {Error} If folder cannot be get by uid
|
||||||
* @param : projectEntity: Partial<ProjectEntity>
|
|
||||||
*/
|
*/
|
||||||
public async getByUid(uid: string) {
|
public async getByUid(uid: string) {
|
||||||
// const folder = await this.foldersRepository.findOne(uid);
|
return this.officeFoldersRepository.findOneByUid(uid);
|
||||||
// if (!folder) Promise.reject(new Error("Cannot get folder by uid"));
|
|
||||||
return { response: "/api/folders/:uid > GET : folder by uid > Not implemented yet" };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
// import ProjectsRepository from "@Common/repositories/projects/ProjectsRepository";
|
|
||||||
import { Offices } from "@prisma/client";
|
import { Offices } from "@prisma/client";
|
||||||
import OfficesRepository from "@Repositories/OfficesRepository";
|
import OfficesRepository from "@Repositories/OfficesRepository";
|
||||||
import BaseService from "@Services/BaseService";
|
import BaseService from "@Services/BaseService";
|
||||||
|
@ -1,21 +1,20 @@
|
|||||||
import "module-alias/register";
|
import "module-alias/register";
|
||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { Deed, DeedType } from "le-coffre-resources/dist/SuperAdmin";
|
import { Deed } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
import DeedService from "@Services/super-admin/DeedsService/DeedsService";
|
import DeedService from "@Services/super-admin/DeedsService/DeedsService";
|
||||||
import { PrismaClient, Offices, DocumentTypes, DeedTypes, DeedTypeHasDocumentTypes } from "prisma/prisma-client";
|
import { PrismaClient, Offices, DocumentTypes, DeedTypes, DeedTypeHasDocumentTypes } from "prisma/prisma-client";
|
||||||
import { deedType, documentType, documentType_, office } from "./MockedData";
|
import { deed, deedType, documentType, office } from "./MockedData";
|
||||||
import DeedsRepository from "@Repositories/DeedsRepository";
|
import DeedsRepository from "@Repositories/DeedsRepository";
|
||||||
import Container from "typedi";
|
import Container from "typedi";
|
||||||
import DeedHasDocumentTypesRepository from "@Repositories/DeedsHasDocumentTypesRepository";
|
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
const DeedServiceTest = new DeedService(Container.get(DeedsRepository), Container.get(DeedHasDocumentTypesRepository));
|
const DeedServiceTest = new DeedService(Container.get(DeedsRepository));
|
||||||
|
|
||||||
let office1: Offices;
|
let office1: Offices;
|
||||||
|
|
||||||
let documentType1: DocumentTypes;
|
let documentType1: DocumentTypes;
|
||||||
let documentType2: DocumentTypes;
|
//let documentType2: DocumentTypes;
|
||||||
|
|
||||||
let deedType1: DeedTypes;
|
let deedType1: DeedTypes;
|
||||||
|
|
||||||
@ -47,15 +46,15 @@ beforeAll(async () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
documentType2 = await prisma.documentTypes.create({
|
// documentType2 = await prisma.documentTypes.create({
|
||||||
data: {
|
// data: {
|
||||||
name: documentType_.name,
|
// name: documentType_.name,
|
||||||
public_description: documentType_.public_description,
|
// public_description: documentType_.public_description,
|
||||||
private_description: documentType_.private_description,
|
// private_description: documentType_.private_description,
|
||||||
archived_at: null,
|
// archived_at: null,
|
||||||
office_uuid: office1.uuid,
|
// office_uuid: office1.uuid,
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
|
|
||||||
deedType1 = await prisma.deedTypes.create({
|
deedType1 = await prisma.deedTypes.create({
|
||||||
data: {
|
data: {
|
||||||
@ -96,15 +95,15 @@ 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 () => {
|
||||||
// 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(deedType);
|
await DeedServiceTest.create(deed);
|
||||||
}
|
}
|
||||||
await expect(createDeedWithUnknownDeedType).rejects.toThrow();
|
await expect(createDeedWithUnknownDeedType).rejects.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
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 deedTypeWithUid: DeedType = JSON.parse(JSON.stringify(deedType));
|
let deedWithUid: Deed = JSON.parse(JSON.stringify(deed));
|
||||||
deedTypeWithUid.uid = deedType1.uuid;
|
deedWithUid.uid = deedType1.uuid;
|
||||||
const deedCreated = await DeedServiceTest.create(deedTypeWithUid);
|
const deedCreated = await DeedServiceTest.create(deedWithUid);
|
||||||
|
|
||||||
expect(deedCreated.deed_type_uuid).toEqual(deedType1.uuid);
|
expect(deedCreated.deed_type_uuid).toEqual(deedType1.uuid);
|
||||||
});
|
});
|
||||||
@ -116,16 +115,16 @@ 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 deedTypeWithUid: DeedType = JSON.parse(JSON.stringify(deedType));
|
let deedWithUid: Deed = JSON.parse(JSON.stringify(deed));
|
||||||
deedTypeWithUid.uid = deedType1.uuid;
|
deedWithUid.uid = deedType1.uuid;
|
||||||
const deedCreated = await DeedServiceTest.create(deedTypeWithUid);
|
const deedCreated = await DeedServiceTest.create(deedWithUid);
|
||||||
|
|
||||||
expect(deedCreated.deed_type_uuid).toEqual(deedType1.uuid);
|
expect(deedCreated.deed_type_uuid).toEqual(deedType1.uuid);
|
||||||
});
|
});
|
||||||
|
|
||||||
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 deedTypeArchivated: DeedType = JSON.parse(JSON.stringify(deedType));
|
let deedArchivated: Deed = JSON.parse(JSON.stringify(deed));
|
||||||
deedTypeArchivated.uid = deedType1.uuid;
|
deedArchivated.uid = deedType1.uuid;
|
||||||
|
|
||||||
await prisma.deedTypes.update({
|
await prisma.deedTypes.update({
|
||||||
where: { uuid: deedType1.uuid },
|
where: { uuid: deedType1.uuid },
|
||||||
@ -136,118 +135,118 @@ describe("test create function", () => {
|
|||||||
|
|
||||||
// try to create a new deed with archivated deed type
|
// try to create a new deed with archivated deed type
|
||||||
async function createDeedWithArchivatedDeedType() {
|
async function createDeedWithArchivatedDeedType() {
|
||||||
await DeedServiceTest.create(deedTypeArchivated);
|
await DeedServiceTest.create(deedArchivated);
|
||||||
}
|
}
|
||||||
await expect(createDeedWithArchivatedDeedType).rejects.toThrow("deed type is archived");
|
await expect(createDeedWithArchivatedDeedType).rejects.toThrow("deed type is archived");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("test addDocumentTypes function", () => {
|
// describe("test addDocumentTypes function", () => {
|
||||||
it("should add document types to a deed", async () => {
|
// it("should add document types to a deed", async () => {
|
||||||
const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType1.uuid } })).uuid;
|
// const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType1.uuid } })).uuid;
|
||||||
const documentsToAdd = [documentType1.uuid, documentType2.uuid];
|
// const documentsToAdd = [documentType1.uuid, documentType2.uuid];
|
||||||
await DeedServiceTest.addDocumentTypes(deedUid, documentsToAdd);
|
// await DeedServiceTest.addDocumentTypes(deedUid, documentsToAdd);
|
||||||
|
|
||||||
const deed = await prisma.deeds.findFirstOrThrow({
|
// const deed = await prisma.deeds.findFirstOrThrow({
|
||||||
where: {
|
// where: {
|
||||||
uuid: deedUid,
|
// uuid: deedUid,
|
||||||
},
|
// },
|
||||||
include: {
|
// include: {
|
||||||
deed_has_document_types: true,
|
// deed_has_document_types: true,
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
expect(deed.deed_has_document_types.length).toEqual(2);
|
// expect(deed.deed_has_document_types.length).toEqual(2);
|
||||||
});
|
// });
|
||||||
|
|
||||||
it("should not add document types to a deed type that already has those document types ", async () => {
|
// it("should not add document types to a deed type that already has those document types ", async () => {
|
||||||
const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType1.uuid } })).uuid;
|
// const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType1.uuid } })).uuid;
|
||||||
let deedHasDocumentTypes = await prisma.deedHasDocumentTypes.findMany({ where: { deed_uuid: deedUid } });
|
// let deedHasDocumentTypes = await prisma.deedHasDocumentTypes.findMany({ where: { deed_uuid: deedUid } });
|
||||||
expect(deedHasDocumentTypes.length).toEqual(2);
|
// expect(deedHasDocumentTypes.length).toEqual(2);
|
||||||
|
|
||||||
const documentsToAdd = [documentType1.uuid, documentType2.uuid];
|
// const documentsToAdd = [documentType1.uuid, documentType2.uuid];
|
||||||
//we expect deedTypeHasDocumentTypes service to skip duplicates without throwing error
|
// //we expect deedTypeHasDocumentTypes service to skip duplicates without throwing error
|
||||||
await DeedServiceTest.addDocumentTypes(deedUid, documentsToAdd);
|
// await DeedServiceTest.addDocumentTypes(deedUid, documentsToAdd);
|
||||||
|
|
||||||
deedHasDocumentTypes = await prisma.deedHasDocumentTypes.findMany({ where: { deed_uuid: deedUid } });
|
// deedHasDocumentTypes = await prisma.deedHasDocumentTypes.findMany({ where: { deed_uuid: deedUid } });
|
||||||
expect(deedHasDocumentTypes.length).toEqual(2);
|
// expect(deedHasDocumentTypes.length).toEqual(2);
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
describe("test removeDocumentTypes function", () => {
|
// describe("test removeDocumentTypes function", () => {
|
||||||
it("should remove document types from a deed type", async () => {
|
// it("should remove document types from a deed type", async () => {
|
||||||
const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType1.uuid } })).uuid;
|
// const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType1.uuid } })).uuid;
|
||||||
const documentsToRemove = [documentType1.uuid];
|
// const documentsToRemove = [documentType1.uuid];
|
||||||
await DeedServiceTest.removeDocumentTypes(deedUid, documentsToRemove);
|
// await DeedServiceTest.removeDocumentTypes(deedUid, documentsToRemove);
|
||||||
|
|
||||||
const deedWithDocumentTypeRelations = await prisma.deeds.findFirstOrThrow({
|
// const deedWithDocumentTypeRelations = await prisma.deeds.findFirstOrThrow({
|
||||||
where: {
|
// where: {
|
||||||
uuid: deedUid,
|
// uuid: deedUid,
|
||||||
},
|
// },
|
||||||
include: {
|
// include: {
|
||||||
deed_has_document_types: true,
|
// deed_has_document_types: true,
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
expect(deedWithDocumentTypeRelations.deed_has_document_types.length).toEqual(1);
|
// expect(deedWithDocumentTypeRelations.deed_has_document_types.length).toEqual(1);
|
||||||
expect(deedWithDocumentTypeRelations.deed_has_document_types[0]?.document_type_uuid).toEqual(documentType2.uuid);
|
// expect(deedWithDocumentTypeRelations.deed_has_document_types[0]?.document_type_uuid).toEqual(documentType2.uuid);
|
||||||
});
|
// });
|
||||||
it("should not remove document types from a deed type is they were not linked", async () => {
|
// it("should not remove document types from a deed type is they were not linked", async () => {
|
||||||
let deedWithOneDocumentType = await prisma.deeds.findFirstOrThrow({
|
// let deedWithOneDocumentType = await prisma.deeds.findFirstOrThrow({
|
||||||
where: { deed_type_uuid: deedType1.uuid },
|
// where: { deed_type_uuid: deedType1.uuid },
|
||||||
include: {
|
// include: {
|
||||||
deed_has_document_types: true,
|
// deed_has_document_types: true,
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
expect(deedWithOneDocumentType.deed_has_document_types.length).toEqual(1);
|
// expect(deedWithOneDocumentType.deed_has_document_types.length).toEqual(1);
|
||||||
|
|
||||||
const documentsToRemove = [documentType1.uuid];
|
// const documentsToRemove = [documentType1.uuid];
|
||||||
|
|
||||||
async function removeDocumentTypeNotLinkedToDeedType() {
|
// async function removeDocumentTypeNotLinkedToDeedType() {
|
||||||
await DeedServiceTest.removeDocumentTypes(deedWithOneDocumentType.uuid, documentsToRemove);
|
// await DeedServiceTest.removeDocumentTypes(deedWithOneDocumentType.uuid, documentsToRemove);
|
||||||
}
|
// }
|
||||||
await expect(removeDocumentTypeNotLinkedToDeedType).rejects.toThrow();
|
// await expect(removeDocumentTypeNotLinkedToDeedType).rejects.toThrow();
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
describe("test removeDocumentType function", () => {
|
// describe("test removeDocumentType function", () => {
|
||||||
it("should remove only one document type from a deed type", async () => {
|
// it("should remove only one document type from a deed type", async () => {
|
||||||
let deedWithOneDocumentType = await prisma.deeds.findFirstOrThrow({
|
// let deedWithOneDocumentType = await prisma.deeds.findFirstOrThrow({
|
||||||
where: { deed_type_uuid: deedType1.uuid },
|
// where: { deed_type_uuid: deedType1.uuid },
|
||||||
include: {
|
// include: {
|
||||||
deed_has_document_types: true,
|
// deed_has_document_types: true,
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
expect(deedWithOneDocumentType.deed_has_document_types.length).toEqual(1);
|
// expect(deedWithOneDocumentType.deed_has_document_types.length).toEqual(1);
|
||||||
|
|
||||||
const documentToRemove = documentType2.uuid;
|
// const documentToRemove = documentType2.uuid;
|
||||||
await DeedServiceTest.removeDocumentType(deedWithOneDocumentType.uuid, documentToRemove);
|
// await DeedServiceTest.removeDocumentType(deedWithOneDocumentType.uuid, documentToRemove);
|
||||||
|
|
||||||
deedWithOneDocumentType = await prisma.deeds.findFirstOrThrow({
|
// deedWithOneDocumentType = await prisma.deeds.findFirstOrThrow({
|
||||||
where: {
|
// where: {
|
||||||
uuid: deedWithOneDocumentType.uuid,
|
// uuid: deedWithOneDocumentType.uuid,
|
||||||
},
|
// },
|
||||||
include: {
|
// include: {
|
||||||
deed_has_document_types: true,
|
// deed_has_document_types: true,
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
expect(deedWithOneDocumentType.deed_has_document_types.length).toEqual(0);
|
// expect(deedWithOneDocumentType.deed_has_document_types.length).toEqual(0);
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
describe("test addDocumentType function", () => {
|
// describe("test addDocumentType function", () => {
|
||||||
it("should add only one document type to a deed type", async () => {
|
// it("should add only one document type to a deed type", async () => {
|
||||||
const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType1.uuid } })).uuid;
|
// const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType1.uuid } })).uuid;
|
||||||
const documentToAdd = documentType1.uuid;
|
// const documentToAdd = documentType1.uuid;
|
||||||
await DeedServiceTest.addDocumentType(deedUid, documentToAdd);
|
// await DeedServiceTest.addDocumentType(deedUid, documentToAdd);
|
||||||
|
|
||||||
const deed = await prisma.deeds.findFirstOrThrow({
|
// const deed = await prisma.deeds.findFirstOrThrow({
|
||||||
where: {
|
// where: {
|
||||||
uuid: deedUid,
|
// uuid: deedUid,
|
||||||
},
|
// },
|
||||||
include: {
|
// include: {
|
||||||
deed_has_document_types: true,
|
// deed_has_document_types: true,
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
expect(deed.deed_has_document_types.length).toEqual(1);
|
// expect(deed.deed_has_document_types.length).toEqual(1);
|
||||||
expect(deed.deed_has_document_types[0]?.document_type_uuid).toEqual(documentType1.uuid);
|
// expect(deed.deed_has_document_types[0]?.document_type_uuid).toEqual(documentType1.uuid);
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
|
|
||||||
describe("test get function", () => {
|
describe("test get function", () => {
|
||||||
it("should return an array of Deeds", async () => {
|
it("should return an array of Deeds", async () => {
|
||||||
|
@ -2,21 +2,20 @@ import "module-alias/register";
|
|||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { DeedType } from "le-coffre-resources/dist/SuperAdmin";
|
import { DeedType } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
import DeedTypeService from "@Services/super-admin/DeedTypesService/DeedTypesService";
|
import DeedTypeService from "@Services/super-admin/DeedTypesService/DeedTypesService";
|
||||||
import { PrismaClient, Offices, DocumentTypes } from "prisma/prisma-client";
|
import { PrismaClient, Offices } from "prisma/prisma-client";
|
||||||
import { deedType, deedType_, documentType, documentType_, office, office_ } from "./MockedData";
|
import { deedType, deedType_, office, office_ } from "./MockedData";
|
||||||
import DeedTypesRepository from "@Repositories/DeedTypesRepository";
|
import DeedTypesRepository from "@Repositories/DeedTypesRepository";
|
||||||
import Container from "typedi";
|
import Container from "typedi";
|
||||||
import DeedTypeHasDocumentTypesRepository from "@Repositories/DeedTypesHasDocumentTypesRepository";
|
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
const DeedTypeServiceTest = new DeedTypeService(Container.get(DeedTypesRepository), Container.get(DeedTypeHasDocumentTypesRepository));
|
const DeedTypeServiceTest = new DeedTypeService(Container.get(DeedTypesRepository));
|
||||||
|
|
||||||
let office1: Offices;
|
let office1: Offices;
|
||||||
let office2: Offices;
|
let office2: Offices;
|
||||||
|
|
||||||
let documentType1: DocumentTypes;
|
// let documentType1: DocumentTypes;
|
||||||
let documentType2: DocumentTypes;
|
// let documentType2: DocumentTypes;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
office1 = await prisma.offices.create({
|
office1 = await prisma.offices.create({
|
||||||
@ -49,25 +48,25 @@ beforeAll(async () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
documentType1 = await prisma.documentTypes.create({
|
// documentType1 = await prisma.documentTypes.create({
|
||||||
data: {
|
// data: {
|
||||||
name: documentType.name,
|
// name: documentType.name,
|
||||||
public_description: documentType.public_description,
|
// public_description: documentType.public_description,
|
||||||
private_description: documentType.private_description,
|
// private_description: documentType.private_description,
|
||||||
archived_at: null,
|
// archived_at: null,
|
||||||
office_uuid: office1.uuid,
|
// office_uuid: office1.uuid,
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
|
|
||||||
documentType2 = await prisma.documentTypes.create({
|
// documentType2 = await prisma.documentTypes.create({
|
||||||
data: {
|
// data: {
|
||||||
name: documentType_.name,
|
// name: documentType_.name,
|
||||||
public_description: documentType_.public_description,
|
// public_description: documentType_.public_description,
|
||||||
private_description: documentType_.private_description,
|
// private_description: documentType_.private_description,
|
||||||
archived_at: null,
|
// archived_at: null,
|
||||||
office_uuid: office1.uuid,
|
// office_uuid: office1.uuid,
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
@ -244,113 +243,113 @@ describe("test update function", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("test addDocumentTypes function", () => {
|
// describe("test addDocumentTypes function", () => {
|
||||||
it("should add document types to a deed type", async () => {
|
// it("should add document types to a deed type", async () => {
|
||||||
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType.name, office_uuid: office1.uuid } })).uuid;
|
// const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType.name, office_uuid: office1.uuid } })).uuid;
|
||||||
const documentsToAdd = [documentType1.uuid, documentType2.uuid];
|
// const documentsToAdd = [documentType1.uuid, documentType2.uuid];
|
||||||
await DeedTypeServiceTest.addDocumentTypes(deedTypeUid, documentsToAdd);
|
// await DeedTypeServiceTest.addDocumentTypes(deedTypeUid, documentsToAdd);
|
||||||
|
|
||||||
const deedTypes = await prisma.deedTypes.findFirstOrThrow({
|
// const deedTypes = await prisma.deedTypes.findFirstOrThrow({
|
||||||
where: {
|
// where: {
|
||||||
uuid: deedTypeUid,
|
// uuid: deedTypeUid,
|
||||||
},
|
// },
|
||||||
include: {
|
// include: {
|
||||||
deed_type_has_document_types: true,
|
// deed_type_has_document_types: true,
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
expect(deedTypes.deed_type_has_document_types.length).toEqual(2);
|
// expect(deedTypes.deed_type_has_document_types.length).toEqual(2);
|
||||||
});
|
// });
|
||||||
|
|
||||||
it("should not add document types to a deed type that already has those document types ", async () => {
|
// it("should not add document types to a deed type that already has those document types ", async () => {
|
||||||
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType.name, office_uuid: office1.uuid } })).uuid;
|
// const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType.name, office_uuid: office1.uuid } })).uuid;
|
||||||
let deedTypeHasDocumentTypes = await prisma.deedTypeHasDocumentTypes.findMany({ where: { deed_type_uuid: deedTypeUid } });
|
// let deedTypeHasDocumentTypes = await prisma.deedTypeHasDocumentTypes.findMany({ where: { deed_type_uuid: deedTypeUid } });
|
||||||
expect(deedTypeHasDocumentTypes.length).toEqual(2);
|
// expect(deedTypeHasDocumentTypes.length).toEqual(2);
|
||||||
|
|
||||||
const documentsToAdd = [documentType1.uuid, documentType2.uuid];
|
// const documentsToAdd = [documentType1.uuid, documentType2.uuid];
|
||||||
//we expect deedTypeHasDocumentTypes service to skip duplicates without throwing error
|
// //we expect deedTypeHasDocumentTypes service to skip duplicates without throwing error
|
||||||
await DeedTypeServiceTest.addDocumentTypes(deedTypeUid, documentsToAdd);
|
// await DeedTypeServiceTest.addDocumentTypes(deedTypeUid, documentsToAdd);
|
||||||
|
|
||||||
deedTypeHasDocumentTypes = await prisma.deedTypeHasDocumentTypes.findMany({ where: { deed_type_uuid: deedTypeUid } });
|
// deedTypeHasDocumentTypes = await prisma.deedTypeHasDocumentTypes.findMany({ where: { deed_type_uuid: deedTypeUid } });
|
||||||
expect(deedTypeHasDocumentTypes.length).toEqual(2);
|
// expect(deedTypeHasDocumentTypes.length).toEqual(2);
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
describe("test removeDocumentTypes function", () => {
|
// describe("test removeDocumentTypes function", () => {
|
||||||
it("should remove document types from a deed type", async () => {
|
// it("should remove document types from a deed type", async () => {
|
||||||
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType.name, office_uuid: office1.uuid } })).uuid;
|
// const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType.name, office_uuid: office1.uuid } })).uuid;
|
||||||
const documentsToRemove = [documentType1.uuid];
|
// const documentsToRemove = [documentType1.uuid];
|
||||||
await DeedTypeServiceTest.removeDocumentTypes(deedTypeUid, documentsToRemove);
|
// await DeedTypeServiceTest.removeDocumentTypes(deedTypeUid, documentsToRemove);
|
||||||
|
|
||||||
const deedTypeWithDocumentTypeRelations = await prisma.deedTypes.findFirstOrThrow({
|
// const deedTypeWithDocumentTypeRelations = await prisma.deedTypes.findFirstOrThrow({
|
||||||
where: {
|
// where: {
|
||||||
uuid: deedTypeUid,
|
// uuid: deedTypeUid,
|
||||||
},
|
// },
|
||||||
include: {
|
// include: {
|
||||||
deed_type_has_document_types: true,
|
// deed_type_has_document_types: true,
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
expect(deedTypeWithDocumentTypeRelations.deed_type_has_document_types.length).toEqual(1);
|
// expect(deedTypeWithDocumentTypeRelations.deed_type_has_document_types.length).toEqual(1);
|
||||||
expect(deedTypeWithDocumentTypeRelations.deed_type_has_document_types[0]?.document_type_uuid).toEqual(documentType2.uuid);
|
// expect(deedTypeWithDocumentTypeRelations.deed_type_has_document_types[0]?.document_type_uuid).toEqual(documentType2.uuid);
|
||||||
});
|
// });
|
||||||
it("should not remove document types from a deed type is they were not linked", async () => {
|
// it("should not remove document types from a deed type is they were not linked", async () => {
|
||||||
let deedTypeWithOneDocumentType = await prisma.deedTypes.findFirstOrThrow({
|
// let deedTypeWithOneDocumentType = await prisma.deedTypes.findFirstOrThrow({
|
||||||
where: { name: deedType.name, office_uuid: office1.uuid },
|
// where: { name: deedType.name, office_uuid: office1.uuid },
|
||||||
include: {
|
// include: {
|
||||||
deed_type_has_document_types: true,
|
// deed_type_has_document_types: true,
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
expect(deedTypeWithOneDocumentType.deed_type_has_document_types.length).toEqual(1);
|
// expect(deedTypeWithOneDocumentType.deed_type_has_document_types.length).toEqual(1);
|
||||||
|
|
||||||
const documentsToRemove = [documentType1.uuid];
|
// const documentsToRemove = [documentType1.uuid];
|
||||||
|
|
||||||
// try to duplicate deed type in a given office
|
// // try to duplicate deed type in a given office
|
||||||
async function removeDocumentTypeNotLinkedToDeedType() {
|
// async function removeDocumentTypeNotLinkedToDeedType() {
|
||||||
await DeedTypeServiceTest.removeDocumentTypes(deedTypeWithOneDocumentType.uuid, documentsToRemove);
|
// await DeedTypeServiceTest.removeDocumentTypes(deedTypeWithOneDocumentType.uuid, documentsToRemove);
|
||||||
}
|
// }
|
||||||
await expect(removeDocumentTypeNotLinkedToDeedType).rejects.toThrow();
|
// await expect(removeDocumentTypeNotLinkedToDeedType).rejects.toThrow();
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
describe("test removeDocumentType function", () => {
|
// describe("test removeDocumentType function", () => {
|
||||||
it("should remove only one document type from a deed type", async () => {
|
// it("should remove only one document type from a deed type", async () => {
|
||||||
let deedTypeWithOneDocumentType = await prisma.deedTypes.findFirstOrThrow({
|
// let deedTypeWithOneDocumentType = await prisma.deedTypes.findFirstOrThrow({
|
||||||
where: { name: deedType.name, office_uuid: office1.uuid },
|
// where: { name: deedType.name, office_uuid: office1.uuid },
|
||||||
include: {
|
// include: {
|
||||||
deed_type_has_document_types: true,
|
// deed_type_has_document_types: true,
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
expect(deedTypeWithOneDocumentType.deed_type_has_document_types.length).toEqual(1);
|
// expect(deedTypeWithOneDocumentType.deed_type_has_document_types.length).toEqual(1);
|
||||||
|
|
||||||
const documentToRemove = documentType2.uuid;
|
// const documentToRemove = documentType2.uuid;
|
||||||
await DeedTypeServiceTest.removeDocumentType(deedTypeWithOneDocumentType.uuid, documentToRemove);
|
// await DeedTypeServiceTest.removeDocumentType(deedTypeWithOneDocumentType.uuid, documentToRemove);
|
||||||
|
|
||||||
deedTypeWithOneDocumentType = await prisma.deedTypes.findFirstOrThrow({
|
// deedTypeWithOneDocumentType = await prisma.deedTypes.findFirstOrThrow({
|
||||||
where: {
|
// where: {
|
||||||
uuid: deedTypeWithOneDocumentType.uuid,
|
// uuid: deedTypeWithOneDocumentType.uuid,
|
||||||
},
|
// },
|
||||||
include: {
|
// include: {
|
||||||
deed_type_has_document_types: true,
|
// deed_type_has_document_types: true,
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
expect(deedTypeWithOneDocumentType.deed_type_has_document_types.length).toEqual(0);
|
// expect(deedTypeWithOneDocumentType.deed_type_has_document_types.length).toEqual(0);
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
describe("test addDocumentType function", () => {
|
// describe("test addDocumentType function", () => {
|
||||||
it("should add only one document type to a deed type", async () => {
|
// it("should add only one document type to a deed type", async () => {
|
||||||
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType.name, office_uuid: office1.uuid } })).uuid;
|
// const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType.name, office_uuid: office1.uuid } })).uuid;
|
||||||
const documentToAdd = documentType1.uuid;
|
// const documentToAdd = documentType1.uuid;
|
||||||
await DeedTypeServiceTest.addDocumentType(deedTypeUid, documentToAdd);
|
// await DeedTypeServiceTest.addDocumentType(deedTypeUid, documentToAdd);
|
||||||
|
|
||||||
const deedTypes = await prisma.deedTypes.findFirstOrThrow({
|
// const deedTypes = await prisma.deedTypes.findFirstOrThrow({
|
||||||
where: {
|
// where: {
|
||||||
uuid: deedTypeUid,
|
// uuid: deedTypeUid,
|
||||||
},
|
// },
|
||||||
include: {
|
// include: {
|
||||||
deed_type_has_document_types: true,
|
// deed_type_has_document_types: true,
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
expect(deedTypes.deed_type_has_document_types.length).toEqual(1);
|
// expect(deedTypes.deed_type_has_document_types.length).toEqual(1);
|
||||||
expect(deedTypes.deed_type_has_document_types[0]?.document_type_uuid).toEqual(documentType1.uuid);
|
// expect(deedTypes.deed_type_has_document_types[0]?.document_type_uuid).toEqual(documentType1.uuid);
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
|
|
||||||
describe("test get function", () => {
|
describe("test get function", () => {
|
||||||
it("should return an array of DeedTypes", async () => {
|
it("should return an array of DeedTypes", async () => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { EOfficeStatus } from "le-coffre-resources/dist/Customer/Office";
|
import { EOfficeStatus } from "le-coffre-resources/dist/Customer/Office";
|
||||||
import User, { Address, Contact, Office, DeedType, DocumentType, Customer } from "le-coffre-resources/dist/SuperAdmin";
|
import User, { Address, Contact, Office, DeedType, DocumentType, Customer, OfficeFolder, Deed } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
|
|
||||||
export const userAddress: Address = {
|
export const userAddress: Address = {
|
||||||
uid: "",
|
uid: "",
|
||||||
@ -123,6 +123,20 @@ export const deedType_: DeedType = {
|
|||||||
updated_at: null,
|
updated_at: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const deed: Deed = {
|
||||||
|
uid: "",
|
||||||
|
deed_type: deedType,
|
||||||
|
created_at: null,
|
||||||
|
updated_at: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deed_: Deed = {
|
||||||
|
uid: "",
|
||||||
|
deed_type: deedType_,
|
||||||
|
created_at: null,
|
||||||
|
updated_at: null,
|
||||||
|
};
|
||||||
|
|
||||||
export const documentType: DocumentType = {
|
export const documentType: DocumentType = {
|
||||||
uid: "",
|
uid: "",
|
||||||
name: "Identity card",
|
name: "Identity card",
|
||||||
@ -160,3 +174,29 @@ export const customer_: Customer = {
|
|||||||
created_at: null,
|
created_at: null,
|
||||||
updated_at: null,
|
updated_at: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const officeFolder: OfficeFolder = {
|
||||||
|
uid: "",
|
||||||
|
name: "Dossier 1234567",
|
||||||
|
folder_number: "1234567",
|
||||||
|
description: "Dossier de mr Dupont",
|
||||||
|
archived_description: null,
|
||||||
|
status: "ARCHIVED",
|
||||||
|
deed: deed,
|
||||||
|
office: office,
|
||||||
|
created_at: null,
|
||||||
|
updated_at: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const officeFolder_: OfficeFolder = {
|
||||||
|
uid: "",
|
||||||
|
name: "Dossier 89101112",
|
||||||
|
folder_number: "89101112",
|
||||||
|
description: "Dossier de mme Dutunnel",
|
||||||
|
archived_description: null,
|
||||||
|
status: "LIVE",
|
||||||
|
deed: deed_,
|
||||||
|
office: office_,
|
||||||
|
created_at: null,
|
||||||
|
updated_at: null,
|
||||||
|
};
|
273
src/test/services/super-admin/OfficeFolderService.test.ts
Normal file
273
src/test/services/super-admin/OfficeFolderService.test.ts
Normal file
@ -0,0 +1,273 @@
|
|||||||
|
import "module-alias/register";
|
||||||
|
import "reflect-metadata";
|
||||||
|
import { PrismaClient, Offices, DocumentTypes, DeedTypes, DeedTypeHasDocumentTypes } from "prisma/prisma-client";
|
||||||
|
import { deedType, documentType, office } from "./MockedData";
|
||||||
|
// import Container from "typedi";
|
||||||
|
// import OfficeFoldersRepository from "@Repositories/OfficeFoldersRepository";
|
||||||
|
// import OfficeFoldersHasStakeholderRepository from "@Repositories/OfficeFoldersHasStakeholderRepository";
|
||||||
|
// import OfficeFoldersHasCustomerRepository from "@Repositories/OfficeFoldersHasCustomerRepository";
|
||||||
|
// import CustomersService from "@Services/super-admin/CustomersService/CustomersService";
|
||||||
|
// import OfficeFolderService from "@Services/super-admin/OfficeFoldersService/OfficeFoldersService";
|
||||||
|
// import DocumentsRepository from "@Repositories/DocumentsRepository";
|
||||||
|
|
||||||
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
|
// const OfficeFolderServiceTest = new OfficeFolderService(
|
||||||
|
// Container.get(OfficeFoldersRepository),
|
||||||
|
// Container.get(OfficeFoldersHasStakeholderRepository),
|
||||||
|
// Container.get(OfficeFoldersHasCustomerRepository),
|
||||||
|
// Container.get(CustomersService),
|
||||||
|
// Container.get(DocumentsRepository),
|
||||||
|
// );
|
||||||
|
|
||||||
|
let office1: Offices;
|
||||||
|
|
||||||
|
let documentType1: DocumentTypes;
|
||||||
|
//let documentType2: DocumentTypes;
|
||||||
|
|
||||||
|
let deedType1: DeedTypes;
|
||||||
|
|
||||||
|
let deedType1HasDocumentType1: DeedTypeHasDocumentTypes;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
office1 = await prisma.offices.create({
|
||||||
|
data: {
|
||||||
|
idNot: office.idNot,
|
||||||
|
name: office.name,
|
||||||
|
crpcen: office.crpcen,
|
||||||
|
address: {
|
||||||
|
create: {
|
||||||
|
address: office.address.address,
|
||||||
|
zip_code: office.address.zip_code,
|
||||||
|
city: office.address.city,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
documentType1 = await prisma.documentTypes.create({
|
||||||
|
data: {
|
||||||
|
name: documentType.name,
|
||||||
|
public_description: documentType.public_description,
|
||||||
|
private_description: documentType.private_description,
|
||||||
|
archived_at: null,
|
||||||
|
office_uuid: office1.uuid,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// documentType2 = await prisma.documentTypes.create({
|
||||||
|
// data: {
|
||||||
|
// name: documentType_.name,
|
||||||
|
// public_description: documentType_.public_description,
|
||||||
|
// private_description: documentType_.private_description,
|
||||||
|
// archived_at: null,
|
||||||
|
// office_uuid: office1.uuid,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
|
deedType1 = await prisma.deedTypes.create({
|
||||||
|
data: {
|
||||||
|
name: deedType.name,
|
||||||
|
description: deedType.description,
|
||||||
|
archived_at: null,
|
||||||
|
office_uuid: office1.uuid,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
deedType1HasDocumentType1 = await prisma.deedTypeHasDocumentTypes.create({
|
||||||
|
data: {
|
||||||
|
deed_type_uuid: deedType1.uuid,
|
||||||
|
document_type_uuid: documentType1.uuid,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await prisma.deedTypes.update({
|
||||||
|
where: { uuid: deedType1.uuid },
|
||||||
|
data: {
|
||||||
|
deed_type_has_document_types: {
|
||||||
|
connect: {
|
||||||
|
uuid: deedType1HasDocumentType1.uuid,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
const deleteDeedTypes = prisma.deedTypes.deleteMany();
|
||||||
|
const deleteOffices = prisma.offices.deleteMany();
|
||||||
|
await prisma.$transaction([deleteDeedTypes, deleteOffices]);
|
||||||
|
await prisma.$disconnect();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("test create function", () => {
|
||||||
|
it("should not create a new office folder if deed type is unknown", async () => {
|
||||||
|
// try to create a new deed with unknown deed type
|
||||||
|
// async function createDeedWithUnknownDeedType() {
|
||||||
|
// await OfficeFolderServiceTest.create(officeFolder, deedType);
|
||||||
|
// }
|
||||||
|
// await expect(createDeedWithUnknownDeedType).rejects.toThrow("deed type not found");
|
||||||
|
});
|
||||||
|
|
||||||
|
// it("should create a new office folder based on existing deed type", async () => {
|
||||||
|
// let deedTypeWithUid: DeedType = JSON.parse(JSON.stringify(deedType));
|
||||||
|
// deedTypeWithUid.uid = deedType1.uuid;
|
||||||
|
// const officeFolderCreated = await OfficeFolderServiceTest.create(officeFolder, deedTypeWithUid);
|
||||||
|
|
||||||
|
// expect(officeFolderCreated.office_uuid).toEqual(office1.uuid);
|
||||||
|
// expect(officeFolderCreated.deed_uuid.).toEqual(office1.uuid);
|
||||||
|
// });
|
||||||
|
|
||||||
|
// it("should have by default the same document types as its deed type ", async () => {
|
||||||
|
// const deedWithDocumentTypes = await prisma.deeds.findFirstOrThrow({ include: { deed_has_document_types: true } });
|
||||||
|
// expect(deedWithDocumentTypes.deed_has_document_types.length).toEqual(1);
|
||||||
|
// expect(deedWithDocumentTypes.deed_has_document_types[0]?.document_type_uuid).toEqual(documentType1.uuid);
|
||||||
|
// });
|
||||||
|
|
||||||
|
// it("should create a the same deed based on existing deed type", async () => {
|
||||||
|
// let deedTypeWithUid: DeedType = JSON.parse(JSON.stringify(deedType));
|
||||||
|
// deedTypeWithUid.uid = deedType1.uuid;
|
||||||
|
// const deedCreated = await OfficeFolderServiceTest.create(deedTypeWithUid);
|
||||||
|
|
||||||
|
// expect(deedCreated.deed_type_uuid).toEqual(deedType1.uuid);
|
||||||
|
// });
|
||||||
|
|
||||||
|
// it("should not create a new deed based on archivated deed type", async () => {
|
||||||
|
// let deedTypeArchivated: DeedType = JSON.parse(JSON.stringify(deedType));
|
||||||
|
// deedTypeArchivated.uid = deedType1.uuid;
|
||||||
|
|
||||||
|
// await prisma.deedTypes.update({
|
||||||
|
// where: { uuid: deedType1.uuid },
|
||||||
|
// data: {
|
||||||
|
// archived_at: new Date(Date.now()),
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
|
// // try to create a new deed with archivated deed type
|
||||||
|
// async function createDeedWithArchivatedDeedType() {
|
||||||
|
// await OfficeFolderServiceTest.create(deedTypeArchivated);
|
||||||
|
// }
|
||||||
|
// await expect(createDeedWithArchivatedDeedType).rejects.toThrow("deed type is archived");
|
||||||
|
// });
|
||||||
|
});
|
||||||
|
|
||||||
|
// describe("test addDocumentTypes function", () => {
|
||||||
|
// it("should add document types to a deed", async () => {
|
||||||
|
// const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType1.uuid } })).uuid;
|
||||||
|
// const documentsToAdd = [documentType1.uuid, documentType2.uuid];
|
||||||
|
// await OfficeFolderServiceTest.addDocumentTypes(deedUid, documentsToAdd);
|
||||||
|
|
||||||
|
// const deed = await prisma.deeds.findFirstOrThrow({
|
||||||
|
// where: {
|
||||||
|
// uuid: deedUid,
|
||||||
|
// },
|
||||||
|
// include: {
|
||||||
|
// deed_has_document_types: true,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
// expect(deed.deed_has_document_types.length).toEqual(2);
|
||||||
|
// });
|
||||||
|
|
||||||
|
// it("should not add document types to a deed type that already has those document types ", async () => {
|
||||||
|
// const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType1.uuid } })).uuid;
|
||||||
|
// let deedHasDocumentTypes = await prisma.deedHasDocumentTypes.findMany({ where: { deed_uuid: deedUid } });
|
||||||
|
// expect(deedHasDocumentTypes.length).toEqual(2);
|
||||||
|
|
||||||
|
// const documentsToAdd = [documentType1.uuid, documentType2.uuid];
|
||||||
|
// //we expect deedTypeHasDocumentTypes service to skip duplicates without throwing error
|
||||||
|
// await OfficeFolderServiceTest.addDocumentTypes(deedUid, documentsToAdd);
|
||||||
|
|
||||||
|
// deedHasDocumentTypes = await prisma.deedHasDocumentTypes.findMany({ where: { deed_uuid: deedUid } });
|
||||||
|
// expect(deedHasDocumentTypes.length).toEqual(2);
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
// describe("test removeDocumentTypes function", () => {
|
||||||
|
// it("should remove document types from a deed type", async () => {
|
||||||
|
// const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType1.uuid } })).uuid;
|
||||||
|
// const documentsToRemove = [documentType1.uuid];
|
||||||
|
// await OfficeFolderServiceTest.removeDocumentTypes(deedUid, documentsToRemove);
|
||||||
|
|
||||||
|
// const deedWithDocumentTypeRelations = await prisma.deeds.findFirstOrThrow({
|
||||||
|
// where: {
|
||||||
|
// uuid: deedUid,
|
||||||
|
// },
|
||||||
|
// include: {
|
||||||
|
// deed_has_document_types: true,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
// expect(deedWithDocumentTypeRelations.deed_has_document_types.length).toEqual(1);
|
||||||
|
// expect(deedWithDocumentTypeRelations.deed_has_document_types[0]?.document_type_uuid).toEqual(documentType2.uuid);
|
||||||
|
// });
|
||||||
|
// it("should not remove document types from a deed type is they were not linked", async () => {
|
||||||
|
// let deedWithOneDocumentType = await prisma.deeds.findFirstOrThrow({
|
||||||
|
// where: { deed_type_uuid: deedType1.uuid },
|
||||||
|
// include: {
|
||||||
|
// deed_has_document_types: true,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
// expect(deedWithOneDocumentType.deed_has_document_types.length).toEqual(1);
|
||||||
|
|
||||||
|
// const documentsToRemove = [documentType1.uuid];
|
||||||
|
|
||||||
|
// async function removeDocumentTypeNotLinkedToDeedType() {
|
||||||
|
// await OfficeFolderServiceTest.removeDocumentTypes(deedWithOneDocumentType.uuid, documentsToRemove);
|
||||||
|
// }
|
||||||
|
// await expect(removeDocumentTypeNotLinkedToDeedType).rejects.toThrow();
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
// describe("test removeDocumentType function", () => {
|
||||||
|
// it("should remove only one document type from a deed type", async () => {
|
||||||
|
// let deedWithOneDocumentType = await prisma.deeds.findFirstOrThrow({
|
||||||
|
// where: { deed_type_uuid: deedType1.uuid },
|
||||||
|
// include: {
|
||||||
|
// deed_has_document_types: true,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
// expect(deedWithOneDocumentType.deed_has_document_types.length).toEqual(1);
|
||||||
|
|
||||||
|
// const documentToRemove = documentType2.uuid;
|
||||||
|
// await OfficeFolderServiceTest.removeDocumentType(deedWithOneDocumentType.uuid, documentToRemove);
|
||||||
|
|
||||||
|
// deedWithOneDocumentType = await prisma.deeds.findFirstOrThrow({
|
||||||
|
// where: {
|
||||||
|
// uuid: deedWithOneDocumentType.uuid,
|
||||||
|
// },
|
||||||
|
// include: {
|
||||||
|
// deed_has_document_types: true,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
// expect(deedWithOneDocumentType.deed_has_document_types.length).toEqual(0);
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
// describe("test addDocumentType function", () => {
|
||||||
|
// it("should add only one document type to a deed type", async () => {
|
||||||
|
// const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType1.uuid } })).uuid;
|
||||||
|
// const documentToAdd = documentType1.uuid;
|
||||||
|
// await OfficeFolderServiceTest.addDocumentType(deedUid, documentToAdd);
|
||||||
|
|
||||||
|
// const deed = await prisma.deeds.findFirstOrThrow({
|
||||||
|
// where: {
|
||||||
|
// uuid: deedUid,
|
||||||
|
// },
|
||||||
|
// include: {
|
||||||
|
// deed_has_document_types: true,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
// expect(deed.deed_has_document_types.length).toEqual(1);
|
||||||
|
// expect(deed.deed_has_document_types[0]?.document_type_uuid).toEqual(documentType1.uuid);
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
|
||||||
|
// describe("test get function", () => {
|
||||||
|
// it("should return an array of Deeds", async () => {
|
||||||
|
// const deeds = await OfficeFolderServiceTest.get({});
|
||||||
|
|
||||||
|
// // verify result typing
|
||||||
|
// expect(deeds).toBeInstanceOf(Array<Deed>);
|
||||||
|
// expect(deeds.length).toEqual(2);
|
||||||
|
|
||||||
|
// // verify result content
|
||||||
|
// expect(deeds[0]?.deed_type_uuid).toEqual(deedType1.uuid);
|
||||||
|
// expect(deeds[1]?.deed_type_uuid).toEqual(deedType1.uuid);
|
||||||
|
// });
|
||||||
|
// });
|
Loading…
x
Reference in New Issue
Block a user