feature: add office folders services

This commit is contained in:
OxSaitama 2023-04-17 18:35:19 +02:00
parent f73fa9d017
commit c30b9e3f9b
44 changed files with 1444 additions and 1017 deletions

View File

@ -1,4 +1,4 @@
DATABASE_URL="postgresql://prisma:prisma@localhost:5433/tests"
POSTGRES_USER=prisma
POSTGRES_PASSWORD=prisma
POSTGRES_DB: tests
POSTGRES_DB=tests

View File

@ -29,7 +29,7 @@
"docker:up": "docker-compose up -d",
"docker:up:test": "docker-compose -f docker-compose-test.yml up -d",
"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": {
"type": "git",
@ -50,7 +50,7 @@
"dotenv": "^16.0.3",
"express": "^4.18.2",
"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",
"next": "^13.1.5",
"node-cache": "^5.1.2",

View File

@ -17,7 +17,6 @@ export default class CustomersController extends ApiController {
/**
* @description Get all customers
* @returns ICustomer[] list of customers
*/
@Get("/api/v1/super-admin/customers")
protected async get(req: Request, response: Response) {
@ -41,7 +40,6 @@ export default class CustomersController extends ApiController {
/**
* @description Create a new customer
* @returns ICustomer created
*/
@Post("/api/v1/super-admin/customers")
protected async post(req: Request, response: Response) {
@ -71,7 +69,6 @@ export default class CustomersController extends ApiController {
/**
* @description Modify a specific customer by uid
* @returns ICustomer modified
*/
@Put("/api/v1/super-admin/customers/:uid")
protected async put(req: Request, response: Response) {
@ -104,7 +101,6 @@ export default class CustomersController extends ApiController {
/**
* @description Get a specific customer by uid
* @returns ICustomer
*/
@Get("/api/v1/super-admin/customers/:uid")
protected async getOneByUid(req: Request, response: Response) {

View File

@ -17,7 +17,7 @@ export default class DeedTypesController extends ApiController {
/**
* @description Get all deedtypes
* @returns IDeedtype[] list of deedtypes
* @returns Deedtype[] list of deedtypes
*/
@Get("/api/v1/super-admin/deed-types")
protected async get(req: Request, response: Response) {
@ -40,7 +40,7 @@ export default class DeedTypesController extends ApiController {
/**
* @description Create a new deedtype
* @returns IDeedtype created
* @returns Deedtype created
*/
@Post("/api/v1/super-admin/deed-types")
protected async post(req: Request, response: Response) {
@ -70,7 +70,7 @@ export default class DeedTypesController extends ApiController {
/**
* @description Modify a specific deedtype by uid
* @returns IDeedtype modified
* @returns Deedtype modified
*/
@Put("/api/v1/super-admin/deed-types/:uid")
protected async put(req: Request, response: Response) {
@ -115,13 +115,13 @@ export default class DeedTypesController extends ApiController {
}
//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
const user = ObjectHydrate.hydrate<DeedType>(new DeedType(), userEntity, { strategy: "exposeAll" });
const deedType = ObjectHydrate.hydrate<DeedType>(new DeedType(), deedTypeEntity, { strategy: "exposeAll" });
//success
this.httpSuccess(response, user);
this.httpSuccess(response, deedType);
} catch (error) {
this.httpBadRequest(response, error);
return;

View File

@ -16,7 +16,7 @@ export default class DeedsController extends ApiController {
/**
* @description Get all deeds
* @returns IDeed[] list of deeds
* @returns Deed[] list of deeds
*/
@Get("/api/v1/super-admin/deeds")
protected async get(req: Request, response: Response) {
@ -39,12 +39,24 @@ export default class DeedsController extends ApiController {
/**
* @description Get a specific deed by uid
* @returns IDeed
* @returns Deed
*/
@Get("/api/v1/super-admin/deeds/:uid")
protected async getOneByUid(req: Request, response: Response) {
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) {
this.httpBadRequest(response, error);
return;

View File

@ -18,7 +18,6 @@ export default class DocumentTypesController extends ApiController {
/**
* @description Get all document-types
* @returns DocumentType[] list of document-types
*/
@Get("/api/v1/super-admin/document-types")
protected async get(req: Request, response: Response) {
@ -44,7 +43,6 @@ export default class DocumentTypesController extends ApiController {
/**
* @description Create a new documentType
* @returns DocumentType created
*/
@Post("/api/v1/super-admin/document-types")
protected async post(req: Request, response: Response) {
@ -70,7 +68,6 @@ export default class DocumentTypesController extends ApiController {
/**
* @description Modify a specific documentType by uid
* @returns DocumentType modified
*/
@Put("/api/v1/super-admin/document-types/:uid")
protected async put(req: Request, response: Response) {
@ -104,7 +101,6 @@ export default class DocumentTypesController extends ApiController {
/**
* @description Get a specific documentType by uid
* @returns DocumentType
*/
@Get("/api/v1/super-admin/document-types/:uid")
protected async getOneByUid(req: Request, response: Response) {

View File

@ -1,12 +1,12 @@
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 { Service } from "typedi";
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
// import { processFindManyQuery } from "prisma-query";
// import { Documents } from "@prisma/client";
// import ObjectHydrate from "@Common/helpers/ObjectHydrate";
// import Document from "le-coffre-resources/dist/SuperAdmin";
import { Documents } from "@prisma/client";
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
import { Document } from "le-coffre-resources/dist/SuperAdmin";
import { validateOrReject } from "class-validator";
@Controller()
@Service()
@ -19,25 +19,25 @@ export default class DocumentsController extends ApiController {
* @description Get all documents
* @returns IDocument[] list of documents
*/
// @Get("/api/super-admin/documents")
// protected async get(req: Request, response: Response) {
// try {
// //get query
// const query = JSON.parse(req.query["q"] as string);
@Get("/api/v1/super-admin/documents")
protected async get(req: Request, response: Response) {
try {
//get query
const query = JSON.parse(req.query["q"] as string);
// //call service to get prisma entity
// const prismaEntity: Documents[] = await this.documentsService.get(query);
//call service to get prisma entity
const prismaEntity: Documents[] = await this.documentsService.get(query);
// //Hydrate ressource with prisma entity
// const documents = ObjectHydrate.map<Document>(Document, prismaEntity, { strategy: "exposeAll" });
//Hydrate ressource with prisma entity
const documents = ObjectHydrate.map<Document>(Document, prismaEntity, { strategy: "exposeAll" });
// //success
// this.httpSuccess(response, documents);
// } catch (error) {
// this.httpBadRequest(response, error);
// return;
// }
// }
//success
this.httpSuccess(response, documents);
} catch (error) {
this.httpBadRequest(response, error);
return;
}
}
/**
* @description Create a new document
@ -46,41 +46,108 @@ export default class DocumentsController extends ApiController {
@Post("/api/v1/super-admin/documents")
protected async post(req: Request, response: Response) {
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) {
this.httpBadRequest(response, error);
return;
}
// this.httpSuccess(response, await this.documentsService.create());
}
/**
* @description Modify a specific document by uid
* @returns IDocument modified
* @description Update a specific document
*/
@Put("/api/v1/super-admin/documents/:uid")
protected async put(req: Request, response: Response) {
protected async update(req: Request, response: Response) {
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) {
this.httpBadRequest(response, error);
return;
}
this.httpSuccess(response, await this.documentsService.put());
}
/**
* @description Get a specific document by uid
* @returns IDocument
*/
@Get("/api/v1/super-admin/documents/:uid")
protected async getOneByUid(req: Request, response: Response) {
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) {
this.httpBadRequest(response, error);
return;
}
this.httpSuccess(response, await this.documentsService.getByUid("uid"));
}
}

View File

@ -3,11 +3,10 @@ import { Controller, Get, Post, Put } from "@ControllerPattern/index";
import ApiController from "@Common/system/controller-pattern/ApiController";
import OfficeFoldersService from "@Services/super-admin/OfficeFoldersService/OfficeFoldersService";
import { Service } from "typedi";
// import { processFindManyQuery } from "prisma-query";
// import { OfficeFolders } from "@prisma/client";
// import ObjectHydrate from "@Common/helpers/ObjectHydrate";
// import { OfficeFolder } from "le-coffre-resources/dist/SuperAdmin";
// import { validateOrReject } from "class-validator";
import { OfficeFolders } from "@prisma/client";
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
import { OfficeFolder } from "le-coffre-resources/dist/SuperAdmin";
import { validateOrReject } from "class-validator";
@Controller()
@Service()
@ -18,21 +17,20 @@ export default class OfficeFoldersController extends ApiController {
/**
* @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) {
try {
//get query
// const query = JSON.parse(req.query["q"] as string);
// //call service to get prisma entity
// const prismaEntity: OfficeFolders[] = await this.officeFoldersService.get(query);
// //Hydrate ressource with prisma entity
// const officeFolders = ObjectHydrate.map<OfficeFolder>(OfficeFolder, prismaEntity, {
// strategy: "exposeAll",
// });
// //success
// this.httpSuccess(response, officeFolders);
const query = JSON.parse(req.query["q"] as string);
//call service to get prisma entity
const prismaEntity: OfficeFolders[] = await this.officeFoldersService.get(query);
//Hydrate ressource with prisma entity
const officeFolders = ObjectHydrate.map<OfficeFolder>(OfficeFolder, prismaEntity, {
strategy: "exposeAll",
});
//success
this.httpSuccess(response, officeFolders);
} catch (error) {
this.httpBadRequest(response, error);
return;
@ -41,24 +39,24 @@ export default class OfficeFoldersController extends ApiController {
/**
* @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) {
try {
//init IOfficeFolder resource with request body values
// const officeFolderEntity = new OfficeFolder();
// ObjectHydrate.hydrate(officeFolderEntity, req.body);
// //validate folder
// await validateOrReject(officeFolderEntity, { groups: ["create"] });
// //call service to get prisma entity
// const prismaEntityCreated = await this.officeFoldersService.create(officeFolderEntity);
// //Hydrate ressource with prisma entity
// const officeFolderEntityCreated = ObjectHydrate.hydrate<OfficeFolder>(new OfficeFolder(), prismaEntityCreated, {
// strategy: "exposeAll",
// });
//init OfficeFolder resource with request body values
const officeFolderEntity = new OfficeFolder();
ObjectHydrate.hydrate(officeFolderEntity, req.body);
//validate folder
await validateOrReject(officeFolderEntity, { groups: ["create"] });
//call service to get prisma entity
const prismaEntityCreated = await this.officeFoldersService.create(officeFolderEntity);
//Hydrate ressource with prisma entity
const officeFolderEntityCreated = ObjectHydrate.hydrate<OfficeFolder>(new OfficeFolder(), prismaEntityCreated, {
strategy: "exposeAll",
});
//success
//this.httpSuccess(response, officeFolderEntityCreated);
this.httpSuccess(response, officeFolderEntityCreated);
} catch (error) {
this.httpBadRequest(response, error);
return;
@ -67,27 +65,57 @@ export default class OfficeFoldersController extends ApiController {
/**
* @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) {
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) {
this.httpBadRequest(response, error);
return;
}
//this.httpSuccess(response, await this.officeFoldersService.update());
}
/**
* @description Get a specific folder by uid
* @returns IFolder
*/
@Get("/api/super-admin/folders/:uid")
@Get("/api/v1/super-admin/folders/:uid")
protected async getOneByUid(req: Request, response: Response) {
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) {
this.httpBadRequest(response, error);
return;

View File

@ -16,7 +16,6 @@ export default class OfficesController extends ApiController {
}
/**
* @description Get all offices
* @returns IOffice[] list of offices
*/
@Get("/api/v1/super-admin/offices")
protected async get(req: Request, response: Response) {
@ -36,7 +35,6 @@ export default class OfficesController extends ApiController {
}
/**
* @description Create a new office
* @returns IOffice created
*/
@Post("/api/v1/super-admin/offices")
protected async post(req: Request, response: Response) {
@ -61,7 +59,6 @@ export default class OfficesController extends ApiController {
}
/**
* @description Modify a specific office by uid
* @returns IOffice modified
*/
@Put("/api/v1/super-admin/offices/:uid")
protected async put(req: Request, response: Response) {
@ -90,7 +87,6 @@ export default class OfficesController extends ApiController {
}
/**
* @description Get a specific office by uid
* @returns IOffice
*/
@Get("/api/v1/super-admin/offices/:uid")
protected async getOneByUid(req: Request, response: Response) {

View File

@ -17,7 +17,6 @@ export default class UsersController extends ApiController {
/**
* @description Get all users
* @returns IUser[] list of users
*/
@Get("/api/v1/super-admin/users")
protected async get(req: Request, response: Response) {
@ -40,8 +39,7 @@ export default class UsersController extends ApiController {
}
/**
* @description Get all users
* @returns IUser[] list of users
* @description Create a new user
*/
@Post("/api/v1/super-admin/users")
protected async getAddresses(req: Request, response: Response) {
@ -71,7 +69,6 @@ export default class UsersController extends ApiController {
/**
* @description Modify a specific user by uid
* @returns IUser modified
*/
@Put("/api/v1/super-admin/users/:uid")
protected async put(req: Request, response: Response) {
@ -104,8 +101,7 @@ export default class UsersController extends ApiController {
}
/**
* @description Modify a specific user by uid
* @returns IUser modified
* @description Get a specific user by uid
*/
@Get("/api/v1/super-admin/users/:uid")
protected async getOneByUid(req: Request, response: Response) {

View File

@ -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;

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "contacts" ADD COLUMN "birthdate" TIMESTAMP(3);

View File

@ -38,8 +38,9 @@ model Contacts {
phone_number String? @db.VarChar(50)
cell_phone_number String? @unique @db.VarChar(50)
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)
birthdate DateTime?
created_at DateTime? @default(now())
updated_at DateTime? @updatedAt
users Users?
@ -168,8 +169,8 @@ model OfficeFolderHasStakeholders {
model Documents {
uuid String @id @unique @default(uuid())
document_status EDocumentStatus @default(ASKED)
document_type DocumentTypes @relation(fields: [type_uuid], references: [uuid])
type_uuid String @db.VarChar(255)
document_type DocumentTypes @relation(fields: [document_type_uuid], references: [uuid])
document_type_uuid String @db.VarChar(255)
blockchain_anchor BlockchainAnchors? @relation(fields: [blockchain_anchor_uuid], references: [uuid])
blockchain_anchor_uuid String? @db.VarChar(255)
folder OfficeFolders @relation(fields: [folder_uuid], references: [uuid])
@ -200,7 +201,7 @@ model Files {
uuid String @id @unique @default(uuid())
document Documents @relation(fields: [document_uuid], references: [uuid], onDelete: Cascade)
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())
updated_at DateTime? @updatedAt

View File

@ -128,6 +128,7 @@ import {
email: "john.doe@example.com",
phone_number: randomString(),
cell_phone_number: randomString(),
birthdate: null,
created_at: new Date(),
updated_at: new Date(),
civility: ECivility.MALE,
@ -139,9 +140,10 @@ import {
last_name: "Doe",
email: "jane.doe@example.com",
phone_number: randomString(),
cell_phone_number: randomString(),
birthdate: null,
created_at: new Date(),
updated_at: new Date(),
cell_phone_number: randomString(),
civility: ECivility.FEMALE,
},
];
@ -258,7 +260,7 @@ import {
depositor_uuid: uuidCustomer1,
document_status: EDocumentStatus.ASKED,
folder_uuid: uuidOfficeFolder1,
type_uuid: uuidDocumentType1,
document_type_uuid: uuidDocumentType1,
created_at: new Date(),
updated_at: new Date(),
},
@ -268,7 +270,7 @@ import {
depositor_uuid: uuidCustomer2,
document_status: EDocumentStatus.ASKED,
folder_uuid: uuidOfficeFolder2,
type_uuid: uuidDocumentType2,
document_type_uuid: uuidDocumentType2,
created_at: new Date(),
updated_at: new Date(),
},

View File

@ -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[]> {
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
return this.model.findMany(query);
}
public async create(address: Addresses): Promise<Addresses> {
return this.model.create({
data: {
address: address.address,
city: address.city,
zip_code: address.zip_code,
/**
* @description : Find one address
*/
public async findOneByUid(uid: string): Promise<Addresses> {
const addressEntity = await this.model.findUnique({
where: {
uuid: uid,
},
});
if (!addressEntity) {
throw new Error("Address not found");
}
return addressEntity;
}
}

View File

@ -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);
}
}

View 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;
}
}

View File

@ -24,6 +24,9 @@ export default class CustomersRepository extends BaseRepository {
return this.model.findMany(query);
}
/**
* @description : Create a customer
*/
public async create(customer: Customer): Promise<Customers> {
return this.model.create({
data: {
@ -34,11 +37,11 @@ export default class CustomersRepository extends BaseRepository {
last_name: customer.contact.last_name,
email: customer.contact.email,
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],
address: {
create: {
address: customer.contact.address.address,
address: customer.contact.address?.address,
zip_code: customer.contact.address.zip_code,
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> {
return this.model.update({
where: {
@ -77,6 +83,9 @@ export default class CustomersRepository extends BaseRepository {
});
}
/**
* @description : Find unique customer
*/
public async findOneByUid(uid: string): Promise<Customers> {
const customerEntity = await this.model.findUnique({
where: {

View File

@ -1,5 +1,5 @@
import Database from "@Common/databases/database";
import { DeedTypeHasDocumentTypes, Prisma } from "@prisma/client";
import { DeedTypeHasDocumentTypes } from "@prisma/client";
import BaseRepository from "@Repositories/BaseRepository";
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[]> {
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> {
const deedTypeHasDoculmentTypesEntity = await this.model.findUnique({
where: {

View File

@ -1,7 +1,7 @@
import Database from "@Common/databases/database";
import BaseRepository from "@Repositories/BaseRepository";
import { Service } from "typedi";
import { DeedTypes } from "@prisma/client";
import { DeedTypes, Prisma } from "@prisma/client";
import { DeedType } from "le-coffre-resources/dist/SuperAdmin";
@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[]> {
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> {
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> {
return this.model.update({
where: { uuid: uid },
const updateArgs: Prisma.DeedTypesUpdateArgs = {
where: {
uuid: uid,
},
data: {
name: deedType.name,
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> {
const deedTypeEntity = await this.model.findUnique({
where: {
@ -76,42 +96,4 @@ export default class DeedTypesRepository extends BaseRepository {
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);
}
}

View File

@ -1,5 +1,5 @@
import Database from "@Common/databases/database";
import { DeedHasDocumentTypes, Prisma } from "@prisma/client";
import { DeedHasDocumentTypes } from "@prisma/client";
import BaseRepository from "@Repositories/BaseRepository";
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[]> {
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> {
const deedHasDoculmentTypesEntity = await this.model.findUnique({
const deedHasDocumentTypesEntity = await this.model.findUnique({
where: {
uuid: uid,
},
});
if (!deedHasDoculmentTypesEntity) {
if (!deedHasDocumentTypesEntity) {
throw new Error("relation between deed and document type not found");
}
return deedHasDoculmentTypesEntity;
return deedHasDocumentTypesEntity;
}
}

View File

@ -1,8 +1,8 @@
import Database from "@Common/databases/database";
import BaseRepository from "@Repositories/BaseRepository";
import { Service } from "typedi";
import { Deeds } from "@prisma/client";
import { DeedType } from "le-coffre-resources/dist/Customer";
import { Deeds, Prisma } from "@prisma/client";
import { Deed } from "le-coffre-resources/dist/Notary";
@Service()
export default class DeedsRepository extends BaseRepository {
@ -24,18 +24,51 @@ export default class DeedsRepository extends BaseRepository {
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({
data: {
deed_type: {
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> {
const deedTypeEntity = await this.model.findUnique({
where: {
@ -44,47 +77,9 @@ export default class DeedsRepository extends BaseRepository {
});
if (!deedTypeEntity) {
throw new Error("deed type not found");
throw new Error("deed not found");
}
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);
}
}

View File

@ -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[]> {
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
return this.model.findMany(query);
}
/**
* @description : Create a document type
*/
public async create(documentType: DocumentType): Promise<DocumentTypes> {
return this.model.create({
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> {
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> {
const documentTypeEntity = await this.model.findUnique({
where: {

View File

@ -1,7 +1,8 @@
import Database from "@Common/databases/database";
import BaseRepository from "@Repositories/BaseRepository";
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()
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[]> {
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
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;
}
}

View 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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -1,8 +1,7 @@
import Database from "@Common/databases/database";
import { ORMBadQueryError } from "@Common/system/database/exceptions/ORMBadQueryError";
import BaseRepository from "@Repositories/BaseRepository";
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";
@Service()
@ -21,21 +20,15 @@ export default class OfficeFoldersRepository extends BaseRepository {
* @description : Find many office folders
*/
public async findMany(query: any): Promise<OfficeFolders[]> {
try {
const limit = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
return await this.model.findMany({ ...query, take: limit });
} catch (error) {
throw new ORMBadQueryError((error as Error).message, error as Error);
}
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
return this.model.findMany(query);
}
/**
* @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> {
try {
const officeFolderEntityCreated = (await this.model.create({
const createArgs: Prisma.OfficeFoldersCreateArgs = {
data: {
folder_number: officeFolder.folder_number,
name: officeFolder.name,
@ -56,51 +49,94 @@ export default class OfficeFoldersRepository extends BaseRepository {
},
},
},
})) as OfficeFolders;
return officeFolderEntityCreated;
} catch (error) {
throw new ORMBadQueryError((error as Error).message, error as Error);
include: {
office_folder_has_stakeholder: true,
}
};
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,
officeFolderHasStakeholders_uuid?: string,
officeFolderHasCustomers_uuid?: string,
document_uuid?: string,
): Promise<OfficeFolders> {
try {
const officeFolderEntityUpdated = (await this.model.update({
/**
* @description : Update data of an office folder
*/
public async update(officeFolderUuid: string, officeFolder: OfficeFolder): Promise<OfficeFolders> {
const updateArgs: Prisma.OfficeFoldersUpdateArgs = {
where: {
uuid: officeFolder.uid,
uuid: officeFolderUuid,
},
data: {
folder_number: officeFolder.folder_number,
name: officeFolder.name,
description: officeFolder.description,
status: EFolderStatus.LIVE,
office_folder_has_stakeholder: {
connect: {
uuid: officeFolderHasStakeholders_uuid,
status: EFolderStatus[officeFolder.status as keyof typeof EFolderStatus],
archived_description: officeFolder.archived_description,
},
},
office_folder_has_customers: {
connect: {
uuid: officeFolderHasCustomers_uuid,
},
},
documents: {
connect: {
uuid: document_uuid,
},
},
},
})) as OfficeFolders;
return officeFolderEntityUpdated;
} catch (error) {
throw new ORMBadQueryError((error as Error).message, error as Error);
include: {
office_folder_has_stakeholder: true,
office_folder_has_customers: true,
documents: true,
}
};
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;
}
}

View File

@ -1,5 +1,4 @@
import Database from "@Common/databases/database";
import { ORMBadQueryError } from "@Common/system/database/exceptions/ORMBadQueryError";
import BaseRepository from "@Repositories/BaseRepository";
import { Service } from "typedi";
import { EOfficeStatus, Offices } from "@prisma/client";
@ -21,18 +20,16 @@ export default class OfficesRepository extends BaseRepository {
* @description : Find many users
*/
public async findMany(query: any): Promise<Offices[]> {
try {
const limit = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
return await this.model.findMany({ ...query, take: limit });
} catch (error) {
throw new ORMBadQueryError((error as Error).message, error as Error);
}
return this.model.findMany(query);
}
/**
* @description : Create an office
*/
public async create(office: OfficeRessource): Promise<Offices> {
try {
const officeEntityCreated = (await this.model.create({
return this.model.create({
data: {
idNot: office.idNot,
name: office.name,
@ -46,17 +43,14 @@ export default class OfficesRepository extends BaseRepository {
},
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> {
try {
const officeEntityUpdated = (await this.model.update({
return this.model.update({
where: {
uuid: uid,
},
@ -71,15 +65,13 @@ export default class OfficesRepository extends BaseRepository {
},
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> {
try {
const officeEntity = await this.model.findUnique({
where: {
uuid: uid,
@ -91,10 +83,5 @@ export default class OfficesRepository extends BaseRepository {
}
return officeEntity;
//return await this.model.find({ ...query, take: limit });
} catch (error) {
throw new ORMBadQueryError((error as Error).message, error as Error);
}
}
}

View File

@ -21,9 +21,12 @@ export default class UsersRepository extends BaseRepository {
*/
public async findMany(query: any): Promise<Users[]> {
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> {
return this.model.create({
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> {
return this.model.update({
where: {

View File

@ -1,64 +1,26 @@
// import { Addresses } from "@prisma/client";
import { Addresses } from "@prisma/client";
import AddressesRepository from "@Repositories/AddressesRepository";
import BaseService from "@Services/BaseService";
import Container, { Service } from "typedi";
import { Service } from "typedi";
@Service()
export default class AddressesService extends BaseService {
constructor() {
constructor(private addressRepository: AddressesRepository) {
super();
}
/**
* @description : Get all addresses
* @returns : T
* @throws {Error} If addresses cannot be get
* @param : projectEntity: Partial<ProjectEntity>
*/
public async get(query: any) {
//init repo
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" };
return this.addressRepository.findMany(query);
}
/**
* @description : Get a address by uid
* @returns : T
* @throws {Error} If address cannot be created
* @param : projectEntity: Partial<ProjectEntity>
* @throws {Error} If address cannot be get
*/
public async getByUid(uuid: string) {
// const address = await this.usersRepository.findOne(uuid);
// if (!address) Promise.reject(new Error("Cannot get address by uuid"));
return { response: "/api/addresses/:uuid > GET : address by uid > Not implemented yet" };
return this.addressRepository.findOneByUid(uuid);
}
}

View File

@ -5,9 +5,9 @@ import { BackendVariables } from "@Common/config/variables/Variables";
import Container, { Service } from "typedi";
type IdNotTokens = {
access_token: string,
id_token: string
}
access_token: string;
id_token: string;
};
@Service()
export default class AuthService extends BaseService {
@ -26,13 +26,16 @@ export default class AuthService extends BaseService {
}
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_secret: this.variables.IDNOT_CLIENT_SECRET,
redirect_uri: this.variables.IDNOT_REDIRECT_URL,
code: code,
grant_type: "authorization_code",
}));
}),
);
try {
const headers = new Headers({
"Content-Type": "application/x-www-form-urlencoded",
@ -41,10 +44,10 @@ export default class AuthService extends BaseService {
method: "POST",
headers: headers,
});
const data = await res.json()
const data = await res.json();
return data as IdNotTokens;
} catch (error) {
console.log(error)
console.log(error);
throw new Error();
}
}

View File

@ -1,57 +1,26 @@
import ContactsRepository from "@Repositories/ContactsRepository";
import BaseService from "@Services/BaseService";
import { Service } from "typedi";
@Service()
export default class ContactsService extends BaseService {
constructor() {
constructor(private contactRepository: ContactsRepository) {
super();
}
/**
* @description : Get all contacts
* @returns : T
* @throws {Error} If contacts cannot be get
* @param : projectEntity: Partial<ProjectEntity>
*/
public async get() {
// const contact = await this.usersRepository.findOne(uuid);
// 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" };
public async get(query: any) {
return this.contactRepository.findMany(query);
}
/**
* @description : Get a contact by uid
* @returns : T
* @throws {Error} If project cannot be created
* @param : projectEntity: Partial<ProjectEntity>
* @throws {Error} If contact cannot be get
*/
public async getByUid(uuid: string) {
// const contact = await this.usersRepository.findOne(uuid);
// if (!contact) Promise.reject(new Error("Cannot get contact by uuid"));
return { response: "/api/contacts/:uuid > GET : contact by uid > Not implemented yet" };
return this.contactRepository.findOneByUid(uuid);
}
}

View File

@ -1,57 +1,43 @@
import FilesRepository from "@Repositories/FilesRepository";
import BaseService from "@Services/BaseService";
import { Service } from "typedi";
import { File } from "le-coffre-resources/dist/SuperAdmin"
@Service()
export default class FilesService extends BaseService {
constructor() {
constructor(private filesRepository: FilesRepository) {
super();
}
/**
* @description : Get all files
* @returns : T
* @throws {Error} If files cannot be get
* @param : projectEntity: Partial<ProjectEntity>
* @throws {Error} If files cannot be ge
*/
public async get() {
// const files = await this.usersRepository.findOne(uuid);
// if (!files) Promise.reject(new Error("Cannot get files"));
return { response: "/api/files > GET : All files > Not implemented yet" };
public async get(query: any) {
return this.filesRepository.findMany(query);
}
/**
* @description : Create a new file
* @returns : T
* @throws {Error} If file cannot be created
* @param : projectEntity: Partial<ProjectEntity>
*/
public async create() {
// const file = await this.projectRepository.create(projectEntity);
// if (!file) Promise.reject(new Error("Cannot create project"));
return { response: "/api/files > POST : Create file > Not implemented yet" };
public async create(file: File) {
return this.filesRepository.create(file);
}
/**
* @description : Modify a new file
* @returns : T
* @throws {Error} If file cannot be modified
* @param : projectEntity: Partial<ProjectEntity>
*/
public async put() {
// const file = await this.projectRepository.create(projectEntity);
// if (!file) Promise.reject(new Error("Cannot create project"));
return { response: "/api/files > PUT : Modified file > Not implemented yet" };
public async put(uid: string, file: File) {
return this.filesRepository.update(uid, file);
}
/**
* @description : Get a file by uid
* @returns : T
* @throws {Error} If project cannot be created
* @param : projectEntity: Partial<ProjectEntity>
*/
public async getByUid(uid: string) {
// const file = await this.usersRepository.findOne(uid);
// if (!file) Promise.reject(new Error("Cannot get file by uid"));
return { response: "/api/files/:uid > GET : file by uid > Not implemented yet" };
return this.filesRepository.findOneByUid(uid);
}
}

View File

@ -1,5 +1,4 @@
import { DeedTypes } from "@prisma/client";
import DeedTypeHasDocumentTypesRepository from "@Repositories/DeedTypesHasDocumentTypesRepository";
import DeedTypesRepository from "@Repositories/DeedTypesRepository";
import BaseService from "@Services/BaseService";
import { DeedType } from "le-coffre-resources/dist/SuperAdmin";
@ -9,7 +8,6 @@ import { Service } from "typedi";
export default class DeedTypesService extends BaseService {
constructor(
private deedTypeRepository: DeedTypesRepository,
private deedTypeHasDocumentTypesRepository: DeedTypeHasDocumentTypesRepository,
) {
super();
}
@ -25,7 +23,6 @@ export default class DeedTypesService extends BaseService {
/**
* @description : Create a new deed-type
* @throws {Error} If deed-type cannot be created
* @param : deedTypesEntity: Partial<DeedTypesEntity>
*/
public async create(deedTypeEntity: DeedType): Promise<DeedTypes> {
return this.deedTypeRepository.create(deedTypeEntity);
@ -46,33 +43,4 @@ export default class DeedTypesService extends BaseService {
public async getByUid(uid: string) {
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 } });
}
}

View File

@ -1,15 +1,12 @@
import { Deeds } from "@prisma/client";
import DeedHasDocumentTypesRepository from "@Repositories/DeedsHasDocumentTypesRepository";
import DeedsRepository from "@Repositories/DeedsRepository";
import DeedTypesHasDocumentTypesRepository from "@Repositories/DeedTypesHasDocumentTypesRepository";
import DeedTypesRepository from "@Repositories/DeedTypesRepository";
import BaseService from "@Services/BaseService";
import { DeedType } from "le-coffre-resources/dist/Customer";
import Container, { Service } from "typedi";
import { Deed } from "le-coffre-resources/dist/SuperAdmin";
import { Service } from "typedi";
@Service()
export default class DeedsService extends BaseService {
constructor(private deedRepository: DeedsRepository, private deedHasDocumentTypesRepository: DeedHasDocumentTypesRepository) {
constructor(private deedRepository: DeedsRepository) {
super();
}
@ -25,29 +22,16 @@ export default class DeedsService extends BaseService {
* @description : Create a new deed with document types
* @throws {Error} If deeds cannot be created
*/
public async create(deedType: DeedType): Promise<Deeds> {
let documentTypesToAdd: string[] = [];
const deedTypeHasDocumentTypesRepository = Container.get(DeedTypesHasDocumentTypesRepository);
const deedTypesRepository = Container.get(DeedTypesRepository);
public async create(deed: Deed): Promise<Deeds> {
return this.deedRepository.create(deed);
}
if ((await deedTypesRepository.findOneByUid(deedType.uid)).archived_at != null) throw new Error("deed type is archived");
const deedTypeHasDocumentTypes = await deedTypeHasDocumentTypesRepository.findMany({ where: { deed_type_uuid: deedType.uid } });
deedTypeHasDocumentTypes.forEach((relation) => {
documentTypesToAdd.push(relation.document_type_uuid);
});
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);
/**
* @description : Update data of a deed with document types
* @throws {Error} If deeds cannot be updated with document types or one of them
*/
public async update(deedUuid: string, deed: Deed): Promise<Deeds> {
return this.deedRepository.update(deedUuid, deed);
}
/**
@ -57,33 +41,4 @@ export default class DeedsService extends BaseService {
public async getByUid(uid: string) {
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 } });
}
}

View File

@ -36,7 +36,6 @@ export default class DocumentTypesService extends BaseService {
/**
* @description : Get a document-type by uid
* @returns : T
* @throws {Error} If document-type is not found
*/
public async getByUid(uid: string) {

View File

@ -1,62 +1,60 @@
import DocumentTypesRepository from "@Repositories/DocumentTypesRepository";
//import { DocumentTypes } from "prisma/prisma-client";
import { Documents, Prisma } from "@prisma/client";
import { Document } from "le-coffre-resources/dist/SuperAdmin";
import DocumentsRepository from "@Repositories/DocumentsRepository";
import BaseService from "@Services/BaseService";
import Container, { Service } from "typedi";
import { Service } from "typedi";
@Service()
export default class DocumentsService extends BaseService {
constructor() {
constructor(private documentsRepository: DocumentsRepository) {
super();
}
/**
* @description : Get all documents
* @returns : Document[]
* @throws {Error} If documents cannot be get
*/
public async get(query: any) {
//init repo
const repo = Container.get(DocumentTypesRepository);
//call service to return prisma entity
return await repo.findMany(query);
return this.documentsRepository.findMany(query);
}
/**
* @description : Create a new document
* @returns : T
* @throws {Error} If document cannot be created
* @param : projectEntity: Partial<ProjectEntity>
*/
// public async create(documentTypeEntity: DocumentTypes): Promise<DocumentTypes> {
// //init repo
// const repo = Container.get(DocumentTypesRepository);
public async create(document: Document): Promise<Documents> {
return this.documentsRepository.create(document);
}
// // 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
* @returns : T
* @throws {Error} If document cannot be modified
* @param : projectEntity: Partial<ProjectEntity>
*/
public async put() {
// const document = await this.projectRepository.create(projectEntity);
// if (!document) Promise.reject(new Error("Cannot create document"));
return { response: "/api/documents > PUT : Modified document > Not implemented yet" };
public async update(uid: string, document: Document): Promise<Documents> {
return this.documentsRepository.update(uid, document);
}
/**
* @description : Delete a document
* @throws {Error} If document cannot be deleted
*/
public async delete(uid: string): Promise<Documents> {
return this.documentsRepository.delete(uid);
}
/**
* @description : Get a document by uid
* @returns : T
* @throws {Error} If document cannot be get by uid
* @param : projectEntity: Partial<ProjectEntity>
*/
public async getByUid(uid: string) {
// const document = await this.customersRepository.findOne(uid);
// if (!document) Promise.reject(new Error("Cannot get document by uid"));
return { response: "/api/documents/:uid > GET : document by uid > Not implemented yet" };
return this.documentsRepository.findOneByUid(uid);
}
}

View File

@ -2,64 +2,46 @@ import { OfficeFolders } from ".prisma/client";
import OfficeFoldersRepository from "@Repositories/OfficeFoldersRepository";
import BaseService from "@Services/BaseService";
import { OfficeFolder } from "le-coffre-resources/dist/SuperAdmin";
import Container, { Service } from "typedi";
import { Service } from "typedi";
@Service()
export default class OfficeFoldersService extends BaseService {
constructor() {
constructor(
private officeFoldersRepository: OfficeFoldersRepository
) {
super();
}
/**
* @description : Get all folders
* @returns : OfficeFolders[]
* @throws {Error} If folders cannot be get
*/
public async get(query: any) {
//init repo
const repo = Container.get(OfficeFoldersRepository);
//call service to return prisma entity
return await repo.findMany(query);
return this.officeFoldersRepository.findMany(query);
}
/**
* @description : Create a new folder
* @returns : T
* @throws {Error} If folder cannot be created
* @param : projectEntity: Partial<ProjectEntity>
*/
public async create(officeFolderEntity: OfficeFolder): Promise<OfficeFolders> {
//init repo
const repo = Container.get(OfficeFoldersRepository);
// call service to return prisma entity
return await repo.create(officeFolderEntity);
return this.officeFoldersRepository.create(officeFolderEntity);
}
/**
* @description : Modify a folder
* @returns : T
* @throws {Error} If folder cannot be modified
* @param : projectEntity: Partial<ProjectEntity>
*/
public async update(officeFolderEntity: OfficeFolder): Promise<OfficeFolders> {
//init repo
const repo = Container.get(OfficeFoldersRepository);
// call service to return prisma entity
return await repo.update(officeFolderEntity);
public async update(officeFolderUuid: string, officeFolderEntity: OfficeFolder): Promise<OfficeFolders> {
return this.officeFoldersRepository.update(officeFolderUuid, officeFolderEntity);
}
/**
* @description : Get a folder by uid
* @returns : T
* @throws {Error} If folder cannot be get by uid
* @param : projectEntity: Partial<ProjectEntity>
*/
public async getByUid(uid: string) {
// const folder = await this.foldersRepository.findOne(uid);
// if (!folder) Promise.reject(new Error("Cannot get folder by uid"));
return { response: "/api/folders/:uid > GET : folder by uid > Not implemented yet" };
return this.officeFoldersRepository.findOneByUid(uid);
}
}

View File

@ -1,4 +1,3 @@
// import ProjectsRepository from "@Common/repositories/projects/ProjectsRepository";
import { Offices } from "@prisma/client";
import OfficesRepository from "@Repositories/OfficesRepository";
import BaseService from "@Services/BaseService";

View File

@ -1,21 +1,20 @@
import "module-alias/register";
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 { 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 Container from "typedi";
import DeedHasDocumentTypesRepository from "@Repositories/DeedsHasDocumentTypesRepository";
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 documentType1: DocumentTypes;
let documentType2: DocumentTypes;
//let documentType2: DocumentTypes;
let deedType1: DeedTypes;
@ -47,15 +46,15 @@ beforeAll(async () => {
},
});
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,
},
});
// 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: {
@ -96,15 +95,15 @@ describe("test create function", () => {
it("should not create a new deed if deed type is unknown", async () => {
// try to create a new deed with unknown deed type
async function createDeedWithUnknownDeedType() {
await DeedServiceTest.create(deedType);
await DeedServiceTest.create(deed);
}
await expect(createDeedWithUnknownDeedType).rejects.toThrow();
});
it("should create a new deed based on existing deed type", async () => {
let deedTypeWithUid: DeedType = JSON.parse(JSON.stringify(deedType));
deedTypeWithUid.uid = deedType1.uuid;
const deedCreated = await DeedServiceTest.create(deedTypeWithUid);
let deedWithUid: Deed = JSON.parse(JSON.stringify(deed));
deedWithUid.uid = deedType1.uuid;
const deedCreated = await DeedServiceTest.create(deedWithUid);
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 () => {
let deedTypeWithUid: DeedType = JSON.parse(JSON.stringify(deedType));
deedTypeWithUid.uid = deedType1.uuid;
const deedCreated = await DeedServiceTest.create(deedTypeWithUid);
let deedWithUid: Deed = JSON.parse(JSON.stringify(deed));
deedWithUid.uid = deedType1.uuid;
const deedCreated = await DeedServiceTest.create(deedWithUid);
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;
let deedArchivated: Deed = JSON.parse(JSON.stringify(deed));
deedArchivated.uid = deedType1.uuid;
await prisma.deedTypes.update({
where: { uuid: deedType1.uuid },
@ -136,118 +135,118 @@ describe("test create function", () => {
// try to create a new deed with archivated deed type
async function createDeedWithArchivatedDeedType() {
await DeedServiceTest.create(deedTypeArchivated);
await DeedServiceTest.create(deedArchivated);
}
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 DeedServiceTest.addDocumentTypes(deedUid, documentsToAdd);
// 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 DeedServiceTest.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);
});
// 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);
// 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 DeedServiceTest.addDocumentTypes(deedUid, documentsToAdd);
// const documentsToAdd = [documentType1.uuid, documentType2.uuid];
// //we expect deedTypeHasDocumentTypes service to skip duplicates without throwing error
// await DeedServiceTest.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 DeedServiceTest.removeDocumentTypes(deedUid, documentsToRemove);
// 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 DeedServiceTest.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 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];
// const documentsToRemove = [documentType1.uuid];
async function removeDocumentTypeNotLinkedToDeedType() {
await DeedServiceTest.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);
// async function removeDocumentTypeNotLinkedToDeedType() {
// await DeedServiceTest.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 DeedServiceTest.removeDocumentType(deedWithOneDocumentType.uuid, documentToRemove);
// const documentToRemove = documentType2.uuid;
// await DeedServiceTest.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 DeedServiceTest.addDocumentType(deedUid, documentToAdd);
// 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 DeedServiceTest.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);
});
});
// 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 () => {

View File

@ -2,21 +2,20 @@ import "module-alias/register";
import "reflect-metadata";
import { DeedType } from "le-coffre-resources/dist/SuperAdmin";
import DeedTypeService from "@Services/super-admin/DeedTypesService/DeedTypesService";
import { PrismaClient, Offices, DocumentTypes } from "prisma/prisma-client";
import { deedType, deedType_, documentType, documentType_, office, office_ } from "./MockedData";
import { PrismaClient, Offices } from "prisma/prisma-client";
import { deedType, deedType_, office, office_ } from "./MockedData";
import DeedTypesRepository from "@Repositories/DeedTypesRepository";
import Container from "typedi";
import DeedTypeHasDocumentTypesRepository from "@Repositories/DeedTypesHasDocumentTypesRepository";
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 office2: Offices;
let documentType1: DocumentTypes;
let documentType2: DocumentTypes;
// let documentType1: DocumentTypes;
// let documentType2: DocumentTypes;
beforeAll(async () => {
office1 = await prisma.offices.create({
@ -49,25 +48,25 @@ beforeAll(async () => {
},
});
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,
},
});
// 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,
},
});
// 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,
// },
// });
});
afterAll(async () => {
@ -244,113 +243,113 @@ describe("test update function", () => {
});
});
describe("test addDocumentTypes function", () => {
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 documentsToAdd = [documentType1.uuid, documentType2.uuid];
await DeedTypeServiceTest.addDocumentTypes(deedTypeUid, documentsToAdd);
// describe("test addDocumentTypes function", () => {
// 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 documentsToAdd = [documentType1.uuid, documentType2.uuid];
// await DeedTypeServiceTest.addDocumentTypes(deedTypeUid, documentsToAdd);
const deedTypes = await prisma.deedTypes.findFirstOrThrow({
where: {
uuid: deedTypeUid,
},
include: {
deed_type_has_document_types: true,
},
});
expect(deedTypes.deed_type_has_document_types.length).toEqual(2);
});
// const deedTypes = await prisma.deedTypes.findFirstOrThrow({
// where: {
// uuid: deedTypeUid,
// },
// include: {
// deed_type_has_document_types: true,
// },
// });
// 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 () => {
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 } });
expect(deedTypeHasDocumentTypes.length).toEqual(2);
// 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;
// let deedTypeHasDocumentTypes = await prisma.deedTypeHasDocumentTypes.findMany({ where: { deed_type_uuid: deedTypeUid } });
// expect(deedTypeHasDocumentTypes.length).toEqual(2);
const documentsToAdd = [documentType1.uuid, documentType2.uuid];
//we expect deedTypeHasDocumentTypes service to skip duplicates without throwing error
await DeedTypeServiceTest.addDocumentTypes(deedTypeUid, documentsToAdd);
// const documentsToAdd = [documentType1.uuid, documentType2.uuid];
// //we expect deedTypeHasDocumentTypes service to skip duplicates without throwing error
// await DeedTypeServiceTest.addDocumentTypes(deedTypeUid, documentsToAdd);
deedTypeHasDocumentTypes = await prisma.deedTypeHasDocumentTypes.findMany({ where: { deed_type_uuid: deedTypeUid } });
expect(deedTypeHasDocumentTypes.length).toEqual(2);
});
});
describe("test removeDocumentTypes function", () => {
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 documentsToRemove = [documentType1.uuid];
await DeedTypeServiceTest.removeDocumentTypes(deedTypeUid, documentsToRemove);
// deedTypeHasDocumentTypes = await prisma.deedTypeHasDocumentTypes.findMany({ where: { deed_type_uuid: deedTypeUid } });
// expect(deedTypeHasDocumentTypes.length).toEqual(2);
// });
// });
// describe("test removeDocumentTypes function", () => {
// 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 documentsToRemove = [documentType1.uuid];
// await DeedTypeServiceTest.removeDocumentTypes(deedTypeUid, documentsToRemove);
const deedTypeWithDocumentTypeRelations = await prisma.deedTypes.findFirstOrThrow({
where: {
uuid: deedTypeUid,
},
include: {
deed_type_has_document_types: true,
},
});
expect(deedTypeWithDocumentTypeRelations.deed_type_has_document_types.length).toEqual(1);
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 () => {
let deedTypeWithOneDocumentType = await prisma.deedTypes.findFirstOrThrow({
where: { name: deedType.name, office_uuid: office1.uuid },
include: {
deed_type_has_document_types: true,
},
});
expect(deedTypeWithOneDocumentType.deed_type_has_document_types.length).toEqual(1);
// const deedTypeWithDocumentTypeRelations = await prisma.deedTypes.findFirstOrThrow({
// where: {
// uuid: deedTypeUid,
// },
// include: {
// deed_type_has_document_types: true,
// },
// });
// expect(deedTypeWithDocumentTypeRelations.deed_type_has_document_types.length).toEqual(1);
// 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 () => {
// let deedTypeWithOneDocumentType = await prisma.deedTypes.findFirstOrThrow({
// where: { name: deedType.name, office_uuid: office1.uuid },
// include: {
// deed_type_has_document_types: true,
// },
// });
// 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
async function removeDocumentTypeNotLinkedToDeedType() {
await DeedTypeServiceTest.removeDocumentTypes(deedTypeWithOneDocumentType.uuid, documentsToRemove);
}
await expect(removeDocumentTypeNotLinkedToDeedType).rejects.toThrow();
});
});
describe("test removeDocumentType function", () => {
it("should remove only one document type from a deed type", async () => {
let deedTypeWithOneDocumentType = await prisma.deedTypes.findFirstOrThrow({
where: { name: deedType.name, office_uuid: office1.uuid },
include: {
deed_type_has_document_types: true,
},
});
expect(deedTypeWithOneDocumentType.deed_type_has_document_types.length).toEqual(1);
// // try to duplicate deed type in a given office
// async function removeDocumentTypeNotLinkedToDeedType() {
// await DeedTypeServiceTest.removeDocumentTypes(deedTypeWithOneDocumentType.uuid, documentsToRemove);
// }
// await expect(removeDocumentTypeNotLinkedToDeedType).rejects.toThrow();
// });
// });
// describe("test removeDocumentType function", () => {
// it("should remove only one document type from a deed type", async () => {
// let deedTypeWithOneDocumentType = await prisma.deedTypes.findFirstOrThrow({
// where: { name: deedType.name, office_uuid: office1.uuid },
// include: {
// deed_type_has_document_types: true,
// },
// });
// expect(deedTypeWithOneDocumentType.deed_type_has_document_types.length).toEqual(1);
const documentToRemove = documentType2.uuid;
await DeedTypeServiceTest.removeDocumentType(deedTypeWithOneDocumentType.uuid, documentToRemove);
// const documentToRemove = documentType2.uuid;
// await DeedTypeServiceTest.removeDocumentType(deedTypeWithOneDocumentType.uuid, documentToRemove);
deedTypeWithOneDocumentType = await prisma.deedTypes.findFirstOrThrow({
where: {
uuid: deedTypeWithOneDocumentType.uuid,
},
include: {
deed_type_has_document_types: true,
},
});
expect(deedTypeWithOneDocumentType.deed_type_has_document_types.length).toEqual(0);
});
});
describe("test addDocumentType function", () => {
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 documentToAdd = documentType1.uuid;
await DeedTypeServiceTest.addDocumentType(deedTypeUid, documentToAdd);
// deedTypeWithOneDocumentType = await prisma.deedTypes.findFirstOrThrow({
// where: {
// uuid: deedTypeWithOneDocumentType.uuid,
// },
// include: {
// deed_type_has_document_types: true,
// },
// });
// expect(deedTypeWithOneDocumentType.deed_type_has_document_types.length).toEqual(0);
// });
// });
// describe("test addDocumentType function", () => {
// 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 documentToAdd = documentType1.uuid;
// await DeedTypeServiceTest.addDocumentType(deedTypeUid, documentToAdd);
const deedTypes = await prisma.deedTypes.findFirstOrThrow({
where: {
uuid: deedTypeUid,
},
include: {
deed_type_has_document_types: true,
},
});
expect(deedTypes.deed_type_has_document_types.length).toEqual(1);
expect(deedTypes.deed_type_has_document_types[0]?.document_type_uuid).toEqual(documentType1.uuid);
});
});
// const deedTypes = await prisma.deedTypes.findFirstOrThrow({
// where: {
// uuid: deedTypeUid,
// },
// include: {
// deed_type_has_document_types: true,
// },
// });
// expect(deedTypes.deed_type_has_document_types.length).toEqual(1);
// expect(deedTypes.deed_type_has_document_types[0]?.document_type_uuid).toEqual(documentType1.uuid);
// });
// });
describe("test get function", () => {
it("should return an array of DeedTypes", async () => {

View File

@ -1,5 +1,5 @@
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 = {
uid: "",
@ -123,6 +123,20 @@ export const deedType_: DeedType = {
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 = {
uid: "",
name: "Identity card",
@ -160,3 +174,29 @@ export const customer_: Customer = {
created_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,
};

View 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);
// });
// });