Refacto: prisma types and relations (#47)
This commit is contained in:
commit
c01fdfdaad
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,6 +6,7 @@ dist
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
package-lock.json
|
||||
|
||||
# envs
|
||||
.env
|
||||
|
547
package-lock.json
generated
547
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -49,7 +49,7 @@
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.18.2",
|
||||
"jsonwebtoken": "^9.0.0",
|
||||
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.52",
|
||||
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.54",
|
||||
"module-alias": "^2.2.2",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"next": "^13.1.5",
|
||||
|
@ -17,20 +17,24 @@ export default class UserController extends ApiController {
|
||||
* @todo Used for test, should be removed
|
||||
* @returns User
|
||||
*/
|
||||
// @Post("/api/v1/idnot/user/:code")
|
||||
// protected async getUserInfosFromIdnot(req: Request, response: Response) {
|
||||
// console.warn("/api/v1/idnot/user/:code used for test, should be removed");
|
||||
@Post("/api/v1/idnot/user/:code")
|
||||
protected async getUserInfosFromIdnot(req: Request, response: Response) {
|
||||
console.warn("/api/v1/idnot/user/:code used for test, should be removed");
|
||||
|
||||
// try {
|
||||
// const code = req.params["code"];
|
||||
try {
|
||||
const code = req.params["code"];
|
||||
if (!code) throw new Error("code is required");
|
||||
const token = await fetch('https://qual-connexion.idnot.fr/IdPOAuth2/token/idnot_idp_v1', {method: 'POST'});
|
||||
console.log(token);
|
||||
//const user = await this.authService.getUserFromIdNotTokens(code!);
|
||||
// //success
|
||||
// this.httpSuccess(response, user);
|
||||
// } catch (error) {
|
||||
// this.httpInternalError(response);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
//success
|
||||
this.httpSuccess(response);
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Post("/api/v1/idnot/user/login/:idnot")
|
||||
protected async login(req: Request, response: Response) {
|
||||
@ -38,14 +42,13 @@ export default class UserController extends ApiController {
|
||||
const id = req.params["idnot"];
|
||||
if (!id) throw new Error("idnot is required");
|
||||
|
||||
const payload = await this.authService.getUserPayload(id!);
|
||||
const payload = await this.authService.getUserJwtPayload(id!);
|
||||
const accessToken = this.authService.generateAccessToken(payload);
|
||||
const refreshToken = this.authService.generateRefreshToken(payload);
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, { accessToken, refreshToken });
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
|
147
src/app/api/super-admin/OfficeRolesController.ts
Normal file
147
src/app/api/super-admin/OfficeRolesController.ts
Normal file
@ -0,0 +1,147 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import OfficeRolesService from "@Services/super-admin/OfficeRolesService/OfficeRolesService";
|
||||
import { Service } from "typedi";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import { OfficeRole } from "le-coffre-resources/dist/Notary";
|
||||
import { OfficeRoles } from "@prisma/client";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class OfficeRolesController extends ApiController {
|
||||
constructor(private officeRolesService: OfficeRolesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all officeRoles
|
||||
*/
|
||||
@Get("/api/v1/super-admin/officeRoles", [authHandler,ruleHandler])
|
||||
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 officeRolesEntities = await this.officeRolesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeRoles = OfficeRole.hydrateArray<OfficeRole>(officeRolesEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeRoles);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new officeRole
|
||||
*/
|
||||
@Post("/api/v1/super-admin/office-roles", [authHandler,ruleHandler])
|
||||
protected async getAddresses(req: Request, response: Response) {
|
||||
try {
|
||||
//init IOfficeRole resource with request body values
|
||||
const officeRoleEntity = OfficeRole.hydrate<OfficeRole>(req.body);
|
||||
|
||||
//validate officeRole
|
||||
await validateOrReject(officeRoleEntity, { groups: ["createOfficeRole"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeRoleEntityCreated = await this.officeRolesService.create(officeRoleEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeRole = OfficeRole.hydrate<OfficeRole>(officeRoleEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, officeRole);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific officeRole by uid
|
||||
*/
|
||||
@Put("/api/v1/super-admin/office-roles/:uid", [authHandler,ruleHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const officeRoleFound = await this.officeRolesService.getByUid(uid);
|
||||
|
||||
if (!officeRoleFound) {
|
||||
this.httpNotFoundRequest(response, "officeRole not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init IOfficeRole resource with request body values
|
||||
const officeRoleEntity = OfficeRole.hydrate<OfficeRole>(req.body);
|
||||
|
||||
//validate officeRole
|
||||
await validateOrReject(officeRoleEntity, { groups: ["updateOfficeRole"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeRoleEntityUpdated = await this.officeRolesService.update(officeRoleEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeRole = OfficeRole.hydrate<OfficeRole>(officeRoleEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeRole);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific officeRole by uid
|
||||
*/
|
||||
@Get("/api/v1/super-admin/office-roles/:uid", [authHandler,ruleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
let officeRoleEntity: OfficeRoles | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
officeRoleEntity = await this.officeRolesService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
officeRoleEntity = await this.officeRolesService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!officeRoleEntity) {
|
||||
this.httpNotFoundRequest(response, "officeRole not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeRole = OfficeRole.hydrate<OfficeRole>(officeRoleEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeRole);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ import DocumentTypesController from "./api/super-admin/DocumentTypesController";
|
||||
import IdNotUserController from "./api/idnot/UserController";
|
||||
import DocumentsControllerCustomer from "./api/customer/DocumentsController";
|
||||
import FilesController from "./api/super-admin/FilesController";
|
||||
import RulesController from "./api/super-admin/RolesController";
|
||||
import RulesController from "./api/super-admin/RulesController";
|
||||
import RolesController from "./api/super-admin/RolesController";
|
||||
|
||||
|
||||
|
@ -18,7 +18,6 @@ export default function authHandler(req: Request, response: Response, next: Next
|
||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
||||
return;
|
||||
}
|
||||
console.log(userPayload);
|
||||
req.body.user = userPayload
|
||||
next();
|
||||
});
|
||||
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the `office_role_has_rules` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `role_has_rules` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "office_role_has_rules" DROP CONSTRAINT "office_role_has_rules_office_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "office_role_has_rules" DROP CONSTRAINT "office_role_has_rules_role_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "office_role_has_rules" DROP CONSTRAINT "office_role_has_rules_rule_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "role_has_rules" DROP CONSTRAINT "role_has_rules_role_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "role_has_rules" DROP CONSTRAINT "role_has_rules_rule_uid_fkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "office_role_uid" VARCHAR(255);
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "office_role_has_rules";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "role_has_rules";
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "office_roles" (
|
||||
"uid" TEXT NOT NULL,
|
||||
"name" VARCHAR(255) NOT NULL,
|
||||
"office_uid" VARCHAR(255) NOT NULL,
|
||||
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3),
|
||||
|
||||
CONSTRAINT "office_roles_pkey" PRIMARY KEY ("uid")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "_RolesHasRules" (
|
||||
"A" TEXT NOT NULL,
|
||||
"B" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "_OfficeRolesHasRules" (
|
||||
"A" TEXT NOT NULL,
|
||||
"B" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "office_roles_uid_key" ON "office_roles"("uid");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "_RolesHasRules_AB_unique" ON "_RolesHasRules"("A", "B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "_RolesHasRules_B_index" ON "_RolesHasRules"("B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "_OfficeRolesHasRules_AB_unique" ON "_OfficeRolesHasRules"("A", "B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "_OfficeRolesHasRules_B_index" ON "_OfficeRolesHasRules"("B");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_office_role_uid_fkey" FOREIGN KEY ("office_role_uid") REFERENCES "office_roles"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "office_roles" ADD CONSTRAINT "office_roles_office_uid_fkey" FOREIGN KEY ("office_uid") REFERENCES "offices"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_RolesHasRules" ADD CONSTRAINT "_RolesHasRules_A_fkey" FOREIGN KEY ("A") REFERENCES "roles"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_RolesHasRules" ADD CONSTRAINT "_RolesHasRules_B_fkey" FOREIGN KEY ("B") REFERENCES "rules"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_OfficeRolesHasRules" ADD CONSTRAINT "_OfficeRolesHasRules_A_fkey" FOREIGN KEY ("A") REFERENCES "office_roles"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_OfficeRolesHasRules" ADD CONSTRAINT "_OfficeRolesHasRules_B_fkey" FOREIGN KEY ("B") REFERENCES "rules"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
144
src/common/databases/migrations/20230628100711_v7/migration.sql
Normal file
144
src/common/databases/migrations/20230628100711_v7/migration.sql
Normal file
@ -0,0 +1,144 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the `deed_has_document_types` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `deed_type_has_document_types` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `office_folder_has_customers` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `office_folder_has_stakeholder` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `user_has_notifications` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "deed_has_document_types" DROP CONSTRAINT "deed_has_document_types_deed_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "deed_has_document_types" DROP CONSTRAINT "deed_has_document_types_document_type_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "deed_type_has_document_types" DROP CONSTRAINT "deed_type_has_document_types_deed_type_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "deed_type_has_document_types" DROP CONSTRAINT "deed_type_has_document_types_document_type_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "office_folder_has_customers" DROP CONSTRAINT "office_folder_has_customers_customer_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "office_folder_has_customers" DROP CONSTRAINT "office_folder_has_customers_office_folder_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "office_folder_has_stakeholder" DROP CONSTRAINT "office_folder_has_stakeholder_office_folder_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "office_folder_has_stakeholder" DROP CONSTRAINT "office_folder_has_stakeholder_user_stakeholder_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "user_has_notifications" DROP CONSTRAINT "user_has_notifications_notification_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "user_has_notifications" DROP CONSTRAINT "user_has_notifications_user_uid_fkey";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "deed_has_document_types";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "deed_type_has_document_types";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "office_folder_has_customers";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "office_folder_has_stakeholder";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "user_has_notifications";
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "_OfficeFolderHasCustomers" (
|
||||
"A" TEXT NOT NULL,
|
||||
"B" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "_UserHasNotifications" (
|
||||
"A" TEXT NOT NULL,
|
||||
"B" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "_OfficeFolderHasStakeholders" (
|
||||
"A" TEXT NOT NULL,
|
||||
"B" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "_DeedHasDocumentTypes" (
|
||||
"A" TEXT NOT NULL,
|
||||
"B" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "_DeedTypeHasDocumentTypes" (
|
||||
"A" TEXT NOT NULL,
|
||||
"B" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "_OfficeFolderHasCustomers_AB_unique" ON "_OfficeFolderHasCustomers"("A", "B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "_OfficeFolderHasCustomers_B_index" ON "_OfficeFolderHasCustomers"("B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "_UserHasNotifications_AB_unique" ON "_UserHasNotifications"("A", "B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "_UserHasNotifications_B_index" ON "_UserHasNotifications"("B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "_OfficeFolderHasStakeholders_AB_unique" ON "_OfficeFolderHasStakeholders"("A", "B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "_OfficeFolderHasStakeholders_B_index" ON "_OfficeFolderHasStakeholders"("B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "_DeedHasDocumentTypes_AB_unique" ON "_DeedHasDocumentTypes"("A", "B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "_DeedHasDocumentTypes_B_index" ON "_DeedHasDocumentTypes"("B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "_DeedTypeHasDocumentTypes_AB_unique" ON "_DeedTypeHasDocumentTypes"("A", "B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "_DeedTypeHasDocumentTypes_B_index" ON "_DeedTypeHasDocumentTypes"("B");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_OfficeFolderHasCustomers" ADD CONSTRAINT "_OfficeFolderHasCustomers_A_fkey" FOREIGN KEY ("A") REFERENCES "customers"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_OfficeFolderHasCustomers" ADD CONSTRAINT "_OfficeFolderHasCustomers_B_fkey" FOREIGN KEY ("B") REFERENCES "office_folders"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_UserHasNotifications" ADD CONSTRAINT "_UserHasNotifications_A_fkey" FOREIGN KEY ("A") REFERENCES "notifications"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_UserHasNotifications" ADD CONSTRAINT "_UserHasNotifications_B_fkey" FOREIGN KEY ("B") REFERENCES "users"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_OfficeFolderHasStakeholders" ADD CONSTRAINT "_OfficeFolderHasStakeholders_A_fkey" FOREIGN KEY ("A") REFERENCES "office_folders"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_OfficeFolderHasStakeholders" ADD CONSTRAINT "_OfficeFolderHasStakeholders_B_fkey" FOREIGN KEY ("B") REFERENCES "users"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_DeedHasDocumentTypes" ADD CONSTRAINT "_DeedHasDocumentTypes_A_fkey" FOREIGN KEY ("A") REFERENCES "deed"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_DeedHasDocumentTypes" ADD CONSTRAINT "_DeedHasDocumentTypes_B_fkey" FOREIGN KEY ("B") REFERENCES "document_types"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_DeedTypeHasDocumentTypes" ADD CONSTRAINT "_DeedTypeHasDocumentTypes_A_fkey" FOREIGN KEY ("A") REFERENCES "deed_types"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_DeedTypeHasDocumentTypes" ADD CONSTRAINT "_DeedTypeHasDocumentTypes_B_fkey" FOREIGN KEY ("B") REFERENCES "document_types"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
@ -56,12 +56,14 @@ model Users {
|
||||
contact_uid String @unique @db.VarChar(255)
|
||||
role Roles @relation(fields: [roles_uid], references: [uid], onDelete: Cascade)
|
||||
roles_uid String @db.VarChar(255)
|
||||
office_role OfficeRoles? @relation(fields: [office_role_uid], references: [uid], onDelete: Cascade)
|
||||
office_role_uid String? @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
office_membership Offices @relation(fields: [office_uid], references: [uid], onDelete: Cascade)
|
||||
office_uid String @db.VarChar(255)
|
||||
user_has_notifications UserHasNotifications[]
|
||||
office_folder_has_stakeholder OfficeFolderHasStakeholders[]
|
||||
notifications Notifications[] @relation("UserHasNotifications")
|
||||
office_folders OfficeFolders[] @relation("OfficeFolderHasStakeholders")
|
||||
|
||||
@@map("users")
|
||||
}
|
||||
@ -80,7 +82,7 @@ model Offices {
|
||||
users Users[]
|
||||
office_folders OfficeFolders[]
|
||||
document_types DocumentTypes[]
|
||||
office_role_has_rules OfficesRolesHasRules[]
|
||||
office_roles OfficeRoles[]
|
||||
|
||||
@@map("offices")
|
||||
}
|
||||
@ -92,33 +94,19 @@ model Customers {
|
||||
contact_uid String @unique @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
office_folder_has_customers OfficeFolderHasCustomers[]
|
||||
office_folders OfficeFolders[] @relation("OfficeFolderHasCustomers")
|
||||
documents Documents[]
|
||||
|
||||
@@map("customers")
|
||||
}
|
||||
|
||||
model UserHasNotifications {
|
||||
uid String @id @unique @default(uuid())
|
||||
user Users @relation(fields: [user_uid], references: [uid])
|
||||
user_uid String @db.VarChar(255)
|
||||
notification Notifications @relation(fields: [notification_uid], references: [uid], onDelete: Cascade)
|
||||
notification_uid String @db.VarChar(255)
|
||||
notification_status ENotificationStatus @default(UNREAD)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
|
||||
@@unique([notification_uid, user_uid])
|
||||
@@map("user_has_notifications")
|
||||
}
|
||||
|
||||
model Notifications {
|
||||
uid String @id @unique @default(uuid())
|
||||
message String @db.VarChar(255)
|
||||
redirection_url String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
user_has_notifications UserHasNotifications[]
|
||||
users Users[] @relation("UserHasNotifications")
|
||||
|
||||
@@map("notifications")
|
||||
}
|
||||
@ -136,40 +124,14 @@ model OfficeFolders {
|
||||
office_uid String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
office_folder_has_customers OfficeFolderHasCustomers[]
|
||||
office_folder_has_stakeholder OfficeFolderHasStakeholders[]
|
||||
stakeholders Users[] @relation("OfficeFolderHasStakeholders")
|
||||
customers Customers[] @relation("OfficeFolderHasCustomers")
|
||||
documents Documents[]
|
||||
|
||||
@@unique([folder_number, office_uid])
|
||||
@@map("office_folders")
|
||||
}
|
||||
|
||||
model OfficeFolderHasCustomers {
|
||||
uid String @id @unique @default(uuid())
|
||||
customer Customers @relation(fields: [customer_uid], references: [uid], onDelete: Cascade)
|
||||
customer_uid String @db.VarChar(255)
|
||||
office_folder OfficeFolders @relation(fields: [office_folder_uid], references: [uid], onDelete: Cascade)
|
||||
office_folder_uid String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
|
||||
@@unique([office_folder_uid, customer_uid])
|
||||
@@map("office_folder_has_customers")
|
||||
}
|
||||
|
||||
model OfficeFolderHasStakeholders {
|
||||
uid String @id @unique @default(uuid())
|
||||
office_folder OfficeFolders @relation(fields: [office_folder_uid], references: [uid], onDelete: Cascade)
|
||||
office_folder_uid String @db.VarChar(255)
|
||||
user_stakeholder Users @relation(fields: [user_stakeholder_uid], references: [uid], onDelete: Cascade)
|
||||
user_stakeholder_uid String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
|
||||
@@unique([office_folder_uid, user_stakeholder_uid])
|
||||
@@map("office_folder_has_stakeholder")
|
||||
}
|
||||
|
||||
model Documents {
|
||||
uid String @id @unique @default(uuid())
|
||||
document_status EDocumentStatus @default(ASKED)
|
||||
@ -238,33 +200,20 @@ model DocumentTypes {
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
documents Documents[]
|
||||
deed_has_document_types DeedHasDocumentTypes[]
|
||||
deed_type_has_document_types DeedTypeHasDocumentTypes[]
|
||||
deeds Deeds[] @relation("DeedHasDocumentTypes")
|
||||
deed_type DeedTypes[] @relation("DeedTypeHasDocumentTypes")
|
||||
|
||||
@@unique([name, office_uid])
|
||||
@@map("document_types")
|
||||
}
|
||||
|
||||
model DeedHasDocumentTypes {
|
||||
uid String @id @unique @default(uuid())
|
||||
document_type DocumentTypes @relation(fields: [document_type_uid], references: [uid], onDelete: Cascade)
|
||||
document_type_uid String @db.VarChar(255)
|
||||
deed Deeds @relation(fields: [deed_uid], references: [uid], onDelete: Cascade)
|
||||
deed_uid String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
|
||||
@@unique([deed_uid, document_type_uid])
|
||||
@@map("deed_has_document_types")
|
||||
}
|
||||
|
||||
model Deeds {
|
||||
uid String @id @unique @default(uuid())
|
||||
deed_type DeedTypes @relation(fields: [deed_type_uid], references: [uid], onDelete: Cascade)
|
||||
deed_type_uid String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
deed_has_document_types DeedHasDocumentTypes[]
|
||||
document_types DocumentTypes[] @relation("DeedHasDocumentTypes")
|
||||
office_folder OfficeFolders?
|
||||
|
||||
@@map("deed")
|
||||
@ -280,74 +229,47 @@ model DeedTypes {
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
deed Deeds[]
|
||||
deed_type_has_document_types DeedTypeHasDocumentTypes[]
|
||||
document_types DocumentTypes[] @relation("DeedTypeHasDocumentTypes")
|
||||
|
||||
@@unique([name, office_uid])
|
||||
@@map("deed_types")
|
||||
}
|
||||
|
||||
model DeedTypeHasDocumentTypes {
|
||||
uid String @id @unique @default(uuid())
|
||||
document_type DocumentTypes @relation(fields: [document_type_uid], references: [uid], onDelete: Cascade)
|
||||
document_type_uid String @db.VarChar(255)
|
||||
deed_type DeedTypes @relation(fields: [deed_type_uid], references: [uid], onDelete: Cascade)
|
||||
deed_type_uid String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
|
||||
@@unique([deed_type_uid, document_type_uid])
|
||||
@@map("deed_type_has_document_types")
|
||||
}
|
||||
|
||||
model Roles {
|
||||
uid String @id @unique @default(uuid())
|
||||
name String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
role_has_rules RolesHasRules[]
|
||||
office_role_has_rules OfficesRolesHasRules[]
|
||||
rules Rules[] @relation("RolesHasRules")
|
||||
users Users[]
|
||||
|
||||
@@map("roles")
|
||||
}
|
||||
|
||||
model OfficeRoles {
|
||||
uid String @id @unique @default(uuid())
|
||||
name String @db.VarChar(255)
|
||||
office Offices @relation(fields: [office_uid], references: [uid], onDelete: Cascade)
|
||||
office_uid String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
rules Rules[] @relation("OfficeRolesHasRules")
|
||||
users Users[]
|
||||
|
||||
@@map("office_roles")
|
||||
}
|
||||
|
||||
model Rules {
|
||||
uid String @id @unique @default(uuid())
|
||||
name String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
role_has_rules RolesHasRules[]
|
||||
office_roles_has_rules OfficesRolesHasRules[]
|
||||
role Roles[] @relation("RolesHasRules")
|
||||
office_roles OfficeRoles[] @relation("OfficeRolesHasRules")
|
||||
|
||||
@@map("rules")
|
||||
}
|
||||
|
||||
model RolesHasRules {
|
||||
uid String @id @unique @default(uuid())
|
||||
role Roles @relation(fields: [role_uid], references: [uid], onDelete: Cascade)
|
||||
role_uid String @db.VarChar(255)
|
||||
rule Rules @relation(fields: [rule_uid], references: [uid], onDelete: Cascade)
|
||||
rule_uid String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
|
||||
@@map("role_has_rules")
|
||||
}
|
||||
|
||||
model OfficesRolesHasRules {
|
||||
uid String @id @unique @default(uuid())
|
||||
office Offices @relation(fields: [office_uid], references: [uid], onDelete: Cascade)
|
||||
role Roles @relation(fields: [role_uid], references: [uid], onDelete: Cascade)
|
||||
rule Rules @relation(fields: [rule_uid], references: [uid], onDelete: Cascade)
|
||||
office_uid String @db.VarChar(255)
|
||||
role_uid String @db.VarChar(255)
|
||||
rule_uid String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
|
||||
@@map("office_role_has_rules")
|
||||
}
|
||||
|
||||
enum ECivility {
|
||||
MALE
|
||||
FEMALE
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,38 +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 addresses
|
||||
*/
|
||||
public async findMany(query: any): Promise<Addresses[]> {
|
||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||
return this.model.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find one address
|
||||
*/
|
||||
public async findOneByUid(uid: string): Promise<Addresses | null> {
|
||||
const addressEntity = await this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
});
|
||||
|
||||
return addressEntity;
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
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 | null> {
|
||||
const contactEntity = await this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
});
|
||||
|
||||
return contactEntity;
|
||||
}
|
||||
}
|
@ -19,11 +19,7 @@ export default class CustomersRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find many customers
|
||||
*/
|
||||
public async findMany(query: Prisma.CustomersFindManyArgs): Promise<
|
||||
(Customers & {
|
||||
contact: Contacts;
|
||||
})[]
|
||||
> {
|
||||
public async findMany(query: Prisma.CustomersFindManyArgs) {
|
||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||
if (!query.include) return this.model.findMany({ ...query, include: { contact: true } });
|
||||
return this.model.findMany({ ...query, include: { contact: { include: { address: true } } } });
|
||||
@ -32,7 +28,7 @@ export default class CustomersRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Create a customer
|
||||
*/
|
||||
public async create(customer: Customer): Promise<Customers> {
|
||||
public async create(customer: Customer): Promise<Customers & { contact: Contacts }> {
|
||||
const createArgs: Prisma.CustomersCreateArgs = {
|
||||
data: {
|
||||
status: ECustomerStatus.PENDING,
|
||||
@ -50,12 +46,12 @@ export default class CustomersRepository extends BaseRepository {
|
||||
},
|
||||
};
|
||||
|
||||
if (customer.contact!.address) {
|
||||
if (customer.contact?.address) {
|
||||
createArgs.data.contact!.create!.address = {
|
||||
create: {
|
||||
address: customer.contact!.address!.address,
|
||||
zip_code: customer.contact!.address!.zip_code,
|
||||
city: customer.contact!.address!.city,
|
||||
address: customer.contact?.address?.address,
|
||||
zip_code: customer.contact?.address?.zip_code,
|
||||
city: customer.contact?.address?.city,
|
||||
},
|
||||
};
|
||||
}
|
||||
@ -65,7 +61,7 @@ export default class CustomersRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Update data from a customer
|
||||
*/
|
||||
public async update(uid: string, customer: Customer): Promise<Customers> {
|
||||
public async update(uid: string, customer: Customer): Promise<Customers & { contact: Contacts }> {
|
||||
const updateArgs: Prisma.CustomersUpdateArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
@ -98,17 +94,12 @@ export default class CustomersRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find unique customer
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<Customers | null> {
|
||||
const findOneArgs: Prisma.CustomersFindUniqueArgs = {
|
||||
public async findOneByUid(uid: string, query?: Prisma.CustomersInclude) {
|
||||
return this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
};
|
||||
if (query) {
|
||||
findOneArgs.include = query;
|
||||
}
|
||||
const customerEntity = await this.model.findUnique(findOneArgs);
|
||||
|
||||
return customerEntity;
|
||||
include: query,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +0,0 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import { DeedTypeHasDocumentTypes } from "@prisma/client";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Service()
|
||||
export default class DeedTypeHasDocumentTypesRepository extends BaseRepository {
|
||||
constructor(private database: Database) {
|
||||
super();
|
||||
}
|
||||
protected get model() {
|
||||
return this.database.getClient().deedTypeHasDocumentTypes;
|
||||
}
|
||||
protected get instanceDb() {
|
||||
return this.database.getClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
return this.model.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find unique relation between deed type and a document type
|
||||
*/
|
||||
public async findOneByUid(uid: string): Promise<DeedTypeHasDocumentTypes | null> {
|
||||
const deedTypeHasDoculmentTypesEntity = await this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
});
|
||||
|
||||
return deedTypeHasDoculmentTypesEntity;
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { DeedTypes, Prisma } from "@prisma/client";
|
||||
import { DeedTypes, DocumentTypes, Prisma } from "@prisma/client";
|
||||
import { DeedType } from "le-coffre-resources/dist/SuperAdmin";
|
||||
|
||||
@Service()
|
||||
@ -19,7 +19,7 @@ export default class DeedTypesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find many deed types
|
||||
*/
|
||||
public async findMany(query: any): Promise<DeedTypes[]> {
|
||||
public async findMany(query: Prisma.DeedTypesFindManyArgs): Promise<DeedTypes[]> {
|
||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||
return this.model.findMany(query);
|
||||
}
|
||||
@ -39,23 +39,20 @@ export default class DeedTypesRepository extends BaseRepository {
|
||||
},
|
||||
},
|
||||
};
|
||||
if (deedType.deed_type_has_document_types) {
|
||||
createArgs.data.deed_type_has_document_types = {
|
||||
createMany: {
|
||||
data: deedType.deed_type_has_document_types.map((relation) => ({
|
||||
document_type_uid: relation.document_type.uid!,
|
||||
if (deedType.document_types) {
|
||||
createArgs.data.document_types = {
|
||||
connect: deedType.document_types.map((documentType) => ({
|
||||
uid: documentType.uid,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
return this.model.create(createArgs);
|
||||
return this.model.create({...createArgs, include: { document_types: true }});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Update data of a deed type
|
||||
*/
|
||||
public async update(uid: string, deedType: DeedType): Promise<DeedTypes> {
|
||||
public async update(uid: string, deedType: DeedType): Promise<DeedTypes & {document_types: DocumentTypes[]}> {
|
||||
const updateArgs: Prisma.DeedTypesUpdateArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
@ -69,39 +66,26 @@ export default class DeedTypesRepository extends BaseRepository {
|
||||
uid: deedType.office!.uid,
|
||||
},
|
||||
},
|
||||
},
|
||||
include: {
|
||||
deed_type_has_document_types: true,
|
||||
},
|
||||
};
|
||||
if (deedType.deed_type_has_document_types) {
|
||||
updateArgs.data.deed_type_has_document_types = {
|
||||
deleteMany: { deed_type_uid: uid },
|
||||
createMany: {
|
||||
data: deedType.deed_type_has_document_types.map((relation) => ({
|
||||
document_type_uid: relation.document_type.uid!,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
},
|
||||
};
|
||||
document_types: {
|
||||
set: deedType.document_types?.map((documentType) => ({
|
||||
uid: documentType.uid!,
|
||||
}))
|
||||
}
|
||||
return this.model.update(updateArgs);
|
||||
},
|
||||
};
|
||||
|
||||
return this.model.update({...updateArgs, include: { document_types: true }});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find unique deed type
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<DeedTypes | null> {
|
||||
const findOneArgs: Prisma.DeedTypesFindUniqueArgs = {
|
||||
public async findOneByUid(uid: string, query?: Prisma.DeedTypesInclude) {
|
||||
return this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
};
|
||||
if (query) {
|
||||
findOneArgs.include = query;
|
||||
}
|
||||
const deedTypeEntity = await this.model.findUnique(findOneArgs);
|
||||
|
||||
return deedTypeEntity;
|
||||
include: query,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +0,0 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import { DeedHasDocumentTypes } from "@prisma/client";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Service()
|
||||
export default class DeedHasDocumentTypesRepository extends BaseRepository {
|
||||
constructor(private database: Database) {
|
||||
super();
|
||||
}
|
||||
protected get model() {
|
||||
return this.database.getClient().deedHasDocumentTypes;
|
||||
}
|
||||
protected get instanceDb() {
|
||||
return this.database.getClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find many deeds
|
||||
*/
|
||||
public async findMany(query: any): Promise<DeedHasDocumentTypes[]> {
|
||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||
return this.model.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find unique relation between deed and a document type
|
||||
*/
|
||||
public async findOneByUid(uid: string): Promise<DeedHasDocumentTypes | null> {
|
||||
const deedHasDocumentTypesEntity = await this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
});
|
||||
|
||||
return deedHasDocumentTypesEntity;
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { Deeds, Prisma } from "@prisma/client";
|
||||
import { Deeds, DocumentTypes, Prisma } from "@prisma/client";
|
||||
import { Deed } from "le-coffre-resources/dist/Notary";
|
||||
|
||||
@Service()
|
||||
@ -19,7 +19,7 @@ export default class DeedsRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find many users
|
||||
*/
|
||||
public async findMany(query: any): Promise<Deeds[]> {
|
||||
public async findMany(query: Prisma.DeedsFindManyArgs) {
|
||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||
return this.model.findMany(query);
|
||||
}
|
||||
@ -27,7 +27,7 @@ export default class DeedsRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Create a deed based on a deed type
|
||||
*/
|
||||
public async create(deed: Deed): Promise<Deeds> {
|
||||
public async create(deed: Deed): Promise<Deeds & { document_types: DocumentTypes[] }> {
|
||||
const createArgs: Prisma.DeedsCreateArgs = {
|
||||
data: {
|
||||
deed_type: {
|
||||
@ -41,66 +41,53 @@ export default class DeedsRepository extends BaseRepository {
|
||||
where: {
|
||||
uid: deed.deed_type!.uid,
|
||||
},
|
||||
include: { deed_type_has_document_types: true },
|
||||
include: { document_types: true },
|
||||
});
|
||||
|
||||
if (deedTypeWithDocumentTypes.archived_at) throw new Error("deed type is archived");
|
||||
|
||||
if (deedTypeWithDocumentTypes.deed_type_has_document_types) {
|
||||
createArgs.data.deed_has_document_types = {
|
||||
createMany: {
|
||||
data: deedTypeWithDocumentTypes.deed_type_has_document_types.map((relation) => ({
|
||||
document_type_uid: relation.document_type_uid,
|
||||
if (deedTypeWithDocumentTypes.document_types) {
|
||||
createArgs.data.document_types = {
|
||||
connect: deedTypeWithDocumentTypes.document_types.map((documentType) => ({
|
||||
uid: documentType.uid,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
return this.model.create(createArgs);
|
||||
return this.model.create({ ...createArgs, include: { document_types: true } });
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Update data of a deed type
|
||||
*/
|
||||
public async update(uid: string, deed: Deed): Promise<Deeds> {
|
||||
public async update(uid: string, deed: Deed): Promise<Deeds & { document_types: DocumentTypes[] }> {
|
||||
const updateArgs: Prisma.DeedsUpdateArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
data: {},
|
||||
data: {
|
||||
document_types: {
|
||||
set: deed.document_types?.map((documentType) => ({
|
||||
uid: documentType.uid!,
|
||||
})),
|
||||
},
|
||||
},
|
||||
include: {
|
||||
deed_has_document_types: true,
|
||||
document_types: true,
|
||||
},
|
||||
};
|
||||
|
||||
if (deed.deed_has_document_types) {
|
||||
updateArgs.data.deed_has_document_types = {
|
||||
deleteMany: { deed_uid: uid },
|
||||
createMany: {
|
||||
data: deed.deed_has_document_types.map((relation) => ({
|
||||
document_type_uid: relation.document_type.uid!,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
return this.model.update(updateArgs);
|
||||
return this.model.update({ ...updateArgs, include: { document_types: true } });
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find unique deed
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<Deeds | null> {
|
||||
const findOneArgs: Prisma.DeedsFindUniqueArgs = {
|
||||
public async findOneByUid(uid: string, query?: Prisma.DeedsInclude) {
|
||||
return this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
};
|
||||
if (query) {
|
||||
findOneArgs.include = query;
|
||||
}
|
||||
const deedTypeEntity = await this.model.findUnique(findOneArgs);
|
||||
|
||||
return deedTypeEntity;
|
||||
include: query,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ export default class DocumentTypesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find many document types
|
||||
*/
|
||||
public async findMany(query: any): Promise<DocumentTypes[]> {
|
||||
public async findMany(query: Prisma.DocumentTypesFindManyArgs) {
|
||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||
return this.model.findMany(query);
|
||||
}
|
||||
@ -28,7 +28,7 @@ export default class DocumentTypesRepository extends BaseRepository {
|
||||
* @description : Create a document type
|
||||
*/
|
||||
public async create(documentType: DocumentType): Promise<DocumentTypes> {
|
||||
return this.model.create({
|
||||
const createArgs: Prisma.DocumentTypesCreateArgs = {
|
||||
data: {
|
||||
name: documentType.name,
|
||||
public_description: documentType.public_description,
|
||||
@ -39,14 +39,15 @@ export default class DocumentTypesRepository extends BaseRepository {
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
return this.model.create(createArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : update given document type
|
||||
*/
|
||||
public async update(uid: string, documentType: DocumentType): Promise<DocumentTypes> {
|
||||
return this.model.update({
|
||||
const updateArgs: Prisma.DocumentTypesUpdateArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
@ -60,24 +61,21 @@ export default class DocumentTypesRepository extends BaseRepository {
|
||||
uid: documentType.office!.uid,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return this.model.update(updateArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : find unique document type
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<DocumentTypes | null> {
|
||||
const findOneArgs: Prisma.DocumentTypesFindUniqueArgs = {
|
||||
public async findOneByUid(uid: string, query?: Prisma.DocumentTypesInclude) {
|
||||
return this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
};
|
||||
if (query) {
|
||||
findOneArgs.include = query;
|
||||
}
|
||||
const documentTypeEntity = await this.model.findUnique(findOneArgs);
|
||||
|
||||
return documentTypeEntity;
|
||||
include: query,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { Documents, EDocumentStatus, Prisma } from "@prisma/client";
|
||||
import { DocumentTypes, Documents, EDocumentStatus, Prisma } from "@prisma/client";
|
||||
import { Document } from "le-coffre-resources/dist/SuperAdmin";
|
||||
|
||||
@Service()
|
||||
@ -19,7 +19,7 @@ export default class DocumentsRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find many documents
|
||||
*/
|
||||
public async findMany(query: any): Promise<Documents[]> {
|
||||
public async findMany(query: Prisma.DocumentsFindManyArgs) {
|
||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||
return this.model.findMany(query);
|
||||
}
|
||||
@ -27,8 +27,8 @@ export default class DocumentsRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Create a document
|
||||
*/
|
||||
public async create(document: Document): Promise<Documents> {
|
||||
const documentCreated = await this.model.create({
|
||||
public async create(document: Document): Promise<Documents & {document_type: DocumentTypes}> {
|
||||
const createArgs: Prisma.DocumentsCreateArgs = {
|
||||
data: {
|
||||
folder: {
|
||||
connect: {
|
||||
@ -46,7 +46,9 @@ export default class DocumentsRepository extends BaseRepository {
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const documentCreated = await this.model.create({...createArgs, include: {document_type: true}});
|
||||
|
||||
await this.instanceDb.documentHistory.create({
|
||||
data: {
|
||||
@ -64,15 +66,29 @@ export default class DocumentsRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Create many documents linked to an office folder
|
||||
*/
|
||||
public async createMany(documents: Document[]): Promise<Prisma.BatchPayload> {
|
||||
return this.model.createMany({
|
||||
public async createMany(documents: Document[]): Promise<Documents[]> {
|
||||
const createArgs: Prisma.DocumentsCreateManyArgs = {
|
||||
data: documents.map((document) => ({
|
||||
folder_uid: document.folder!.uid!,
|
||||
depositor_uid: document.depositor!.uid!,
|
||||
document_type_uid: document.document_type!.uid!,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
});
|
||||
};
|
||||
|
||||
const batchPayload = await this.model.createMany(createArgs);
|
||||
|
||||
const documentsCreated = await this.model.findMany({orderBy: {created_at: 'desc'}, take: batchPayload.count});
|
||||
|
||||
const createHistoryArgs: Prisma.DocumentHistoryCreateManyArgs = {
|
||||
data: documentsCreated.map((document) => ({
|
||||
document_uid: document.uid!,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
};
|
||||
await this.instanceDb.documentHistory.createMany(createHistoryArgs);
|
||||
|
||||
return documentsCreated;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,17 +125,12 @@ export default class DocumentsRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find unique document
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<Documents | null> {
|
||||
const findOneArgs: Prisma.DocumentsFindUniqueArgs = {
|
||||
public async findOneByUid(uid: string, query?: Prisma.DocumentsInclude) {
|
||||
return this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
};
|
||||
if (query) {
|
||||
findOneArgs.include = query;
|
||||
}
|
||||
const documentEntity = await this.model.findUnique(findOneArgs);
|
||||
|
||||
return documentEntity;
|
||||
include: query,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { Files } from "@prisma/client";
|
||||
import { Documents, Files, Prisma } from "@prisma/client";
|
||||
import { File } from "le-coffre-resources/dist/SuperAdmin";
|
||||
|
||||
@Service()
|
||||
@ -19,7 +19,7 @@ export default class FilesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find many files
|
||||
*/
|
||||
public async findMany(query: any): Promise<Files[]> {
|
||||
public async findMany(query: Prisma.FilesFindManyArgs) {
|
||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||
return this.model.findMany(query);
|
||||
}
|
||||
@ -27,8 +27,8 @@ export default class FilesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Create a file linked to a document
|
||||
*/
|
||||
public async create(file: File, key: string): Promise<Files> {
|
||||
return this.model.create({
|
||||
public async create(file: File, key: string): Promise<Files & {document: Documents}> {
|
||||
const createArgs: Prisma.FilesCreateArgs = {
|
||||
data: {
|
||||
document: {
|
||||
connect: {
|
||||
@ -40,30 +40,35 @@ export default class FilesRepository extends BaseRepository {
|
||||
mimetype: file.mimetype,
|
||||
size: file.size,
|
||||
key: key
|
||||
},
|
||||
include: { document: true }
|
||||
});
|
||||
}
|
||||
};
|
||||
return this.model.create({...createArgs, include: { document: true }});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Update data of a file
|
||||
*/
|
||||
public async update(uid: string, file: File): Promise<Files> {
|
||||
return this.model.update({
|
||||
public async update(uid: string, file: File, key: string): Promise<Files& {document: Documents}> {
|
||||
const updateArgs: Prisma.FilesUpdateArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
data: {
|
||||
file_name: file.file_name,
|
||||
file_path: file.file_path,
|
||||
},
|
||||
});
|
||||
mimetype: file.mimetype,
|
||||
size: file.size,
|
||||
key: key
|
||||
}
|
||||
};
|
||||
return this.model.update({...updateArgs, include: { document: true }});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Delete a file key and archive
|
||||
*/
|
||||
public async deleteKeyAndArchive(uid: string): Promise<Files> {
|
||||
return this.model.update({
|
||||
public async deleteKeyAndArchive(uid: string): Promise<Files& {document: Documents}> {
|
||||
const updateArgs: Prisma.FilesUpdateArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
@ -71,19 +76,19 @@ export default class FilesRepository extends BaseRepository {
|
||||
key: null,
|
||||
archived_at: new Date(Date.now())
|
||||
}
|
||||
});
|
||||
};
|
||||
return this.model.update({...updateArgs, include: { document: true }});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find unique file
|
||||
*/
|
||||
public async findOneByUid(uid: string): Promise<Files | null> {
|
||||
const fileEntity = await this.model.findUnique({
|
||||
public async findOneByUid(uid: string, query?: Prisma.FilesInclude) {
|
||||
return this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
include: query,
|
||||
});
|
||||
|
||||
return fileEntity;
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +0,0 @@
|
||||
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 | null> {
|
||||
const officeFolderHasCustomersEntity = await this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
});
|
||||
|
||||
return officeFolderHasCustomersEntity;
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
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 | null> {
|
||||
const officeFolderHasStakeholdersEntity = await this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
});
|
||||
|
||||
return officeFolderHasStakeholdersEntity;
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { EFolderStatus, OfficeFolders, Prisma } from "@prisma/client";
|
||||
import { Customers, Documents, EFolderStatus, OfficeFolders, Prisma, Users } from "@prisma/client";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/SuperAdmin";
|
||||
|
||||
@Service()
|
||||
@ -19,7 +19,7 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find many office folders
|
||||
*/
|
||||
public async findMany(query: any): Promise<OfficeFolders[]> {
|
||||
public async findMany(query: Prisma.OfficeFoldersFindManyArgs) {
|
||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||
return this.model.findMany(query);
|
||||
}
|
||||
@ -27,7 +27,7 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Create new office folder with stakeholders
|
||||
*/
|
||||
public async create(officeFolder: OfficeFolder): Promise<OfficeFolders> {
|
||||
public async create(officeFolder: OfficeFolder): Promise<OfficeFolders & { stakeholders: Users[]}> {
|
||||
const createArgs: Prisma.OfficeFoldersCreateArgs = {
|
||||
data: {
|
||||
folder_number: officeFolder.folder_number,
|
||||
@ -36,7 +36,7 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
||||
status: EFolderStatus.LIVE,
|
||||
deed: {
|
||||
connect: {
|
||||
uid: officeFolder.deed?.uid
|
||||
uid: officeFolder.deed?.uid,
|
||||
},
|
||||
},
|
||||
office: {
|
||||
@ -44,28 +44,24 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
||||
uid: officeFolder.office!.uid,
|
||||
},
|
||||
},
|
||||
},
|
||||
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_uid: relation.user_stakeholder.uid!,
|
||||
stakeholders: {
|
||||
connect: officeFolder.stakeholders?.map((stakeholder) => ({
|
||||
uid: stakeholder.uid!,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
return this.model.create(createArgs);
|
||||
}
|
||||
};
|
||||
|
||||
return this.model.create({...createArgs, include: {stakeholders: true}});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Update data of an office folder
|
||||
*/
|
||||
public async update(officeFolderuid: string, officeFolder: OfficeFolder): Promise<OfficeFolders> {
|
||||
public async update(
|
||||
officeFolderuid: string,
|
||||
officeFolder: OfficeFolder,
|
||||
): Promise<OfficeFolders & { stakeholders: Users[]; customers: Customers[]; documents: Documents[] }> {
|
||||
const updateArgs: Prisma.OfficeFoldersUpdateArgs = {
|
||||
where: {
|
||||
uid: officeFolderuid,
|
||||
@ -76,64 +72,44 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
||||
description: officeFolder.description,
|
||||
status: EFolderStatus[officeFolder.status as keyof typeof EFolderStatus],
|
||||
archived_description: officeFolder.archived_description,
|
||||
stakeholders: {
|
||||
set: officeFolder.stakeholders?.map((stakeholder) => ({
|
||||
uid: stakeholder.uid!,
|
||||
})),
|
||||
},
|
||||
customers: {
|
||||
set: officeFolder.customers?.map((customer) => ({
|
||||
uid: customer.uid!,
|
||||
})),
|
||||
},
|
||||
documents: {
|
||||
set: officeFolder.documents?.map((document) => ({
|
||||
uid: document.uid!,
|
||||
})),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
return this.model.update({
|
||||
...updateArgs,
|
||||
include: {
|
||||
office_folder_has_stakeholder: true,
|
||||
office_folder_has_customers: true,
|
||||
stakeholders: true,
|
||||
customers: true,
|
||||
documents: true,
|
||||
},
|
||||
};
|
||||
if (officeFolder.office_folder_has_stakeholder) {
|
||||
updateArgs.data.office_folder_has_stakeholder = {
|
||||
deleteMany: { office_folder_uid: officeFolderuid },
|
||||
createMany: {
|
||||
data: officeFolder.office_folder_has_stakeholder.map((relation) => ({
|
||||
user_stakeholder_uid: relation.user_stakeholder.uid!,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (officeFolder.office_folder_has_customers) {
|
||||
updateArgs.data.office_folder_has_customers = {
|
||||
deleteMany: { office_folder_uid: officeFolderuid },
|
||||
createMany: {
|
||||
data: officeFolder.office_folder_has_customers.map((relation) => ({
|
||||
customer_uid: relation.customer.uid!,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (officeFolder.documents) {
|
||||
updateArgs.data.documents = {
|
||||
createMany: {
|
||||
data: officeFolder.documents.map((relation) => ({
|
||||
document_type_uid: relation.document_type!.uid!,
|
||||
depositor_uid: relation.depositor!.uid!,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
return this.model.update(updateArgs);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find one office folder
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<OfficeFolders | null> {
|
||||
const findOneArgs: Prisma.OfficeFoldersFindUniqueArgs = {
|
||||
public async findOneByUid(uid: string, query?: Prisma.OfficeFoldersInclude) {
|
||||
return this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
};
|
||||
if (query) {
|
||||
findOneArgs.include = query;
|
||||
}
|
||||
const officeFolderEntity = await this.model.findUnique(findOneArgs);
|
||||
|
||||
return officeFolderEntity;
|
||||
include: query,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,42 +0,0 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { OfficesRolesHasRules, Prisma } from "@prisma/client";
|
||||
|
||||
@Service()
|
||||
export default class OfficeRoleHasRulesRepository extends BaseRepository {
|
||||
constructor(private database: Database) {
|
||||
super();
|
||||
}
|
||||
protected get model() {
|
||||
return this.database.getClient().officesRolesHasRules;
|
||||
}
|
||||
protected get instanceDb() {
|
||||
return this.database.getClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find many relations between office roles and rules
|
||||
*/
|
||||
public async findMany(query: any): Promise<OfficesRolesHasRules[]> {
|
||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||
return this.model.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find one relation between an office role and rules
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<OfficesRolesHasRules | null> {
|
||||
const findOneArgs: Prisma.OfficesRolesHasRulesFindUniqueArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
};
|
||||
if (query) {
|
||||
findOneArgs.include = query;
|
||||
}
|
||||
const roleEntity = await this.model.findUnique(findOneArgs);
|
||||
|
||||
return roleEntity;
|
||||
}
|
||||
}
|
93
src/common/repositories/OfficeRolesRepository.ts
Normal file
93
src/common/repositories/OfficeRolesRepository.ts
Normal file
@ -0,0 +1,93 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { OfficeRoles, Prisma, Rules } from "@prisma/client";
|
||||
import { OfficeRole } from "le-coffre-resources/dist/SuperAdmin";
|
||||
|
||||
@Service()
|
||||
export default class OfficeRolesRepository extends BaseRepository {
|
||||
constructor(private database: Database) {
|
||||
super();
|
||||
}
|
||||
protected get model() {
|
||||
return this.database.getClient().officeRoles;
|
||||
}
|
||||
protected get instanceDb() {
|
||||
return this.database.getClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find many officeRoles
|
||||
*/
|
||||
public async findMany(query: Prisma.OfficeRolesFindManyArgs) {
|
||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||
return this.model.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create new officeRole with rules
|
||||
*/
|
||||
public async create(officeRole: OfficeRole): Promise<OfficeRoles & {rules: Rules[]}> {
|
||||
const createArgs: Prisma.OfficeRolesCreateArgs = {
|
||||
data: {
|
||||
name: officeRole.name,
|
||||
office: {
|
||||
connect: {
|
||||
uid: officeRole.office.uid,
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
connect: officeRole.rules?.map((rule) => ({
|
||||
uid: rule.uid!,
|
||||
})),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
return this.model.create({...createArgs, include: {rules: true}});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Update data of a officeRole with rules
|
||||
*/
|
||||
public async update(officeRole: OfficeRole): Promise<OfficeRoles & {rules: Rules[]}> {
|
||||
const updateArgs: Prisma.OfficeRolesUpdateArgs = {
|
||||
where: {
|
||||
uid: officeRole.uid,
|
||||
},
|
||||
data: {
|
||||
name: officeRole.name,
|
||||
rules: {
|
||||
set: officeRole.rules?.map((rule) => ({
|
||||
uid: rule.uid!,
|
||||
})),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
return this.model.update({...updateArgs, include: {rules: true}});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find one officeRole
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: Prisma.OfficeRolesInclude) {
|
||||
return this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
include: query,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Delete a officeRole
|
||||
*/
|
||||
public async delete(uid: string): Promise<OfficeRoles> {
|
||||
return this.model.delete({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ export default class OfficesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find many users
|
||||
*/
|
||||
public async findMany(query: any): Promise<Offices[]> {
|
||||
public async findMany(query: Prisma.OfficesFindManyArgs) {
|
||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||
|
||||
return this.model.findMany(query);
|
||||
@ -29,7 +29,7 @@ export default class OfficesRepository extends BaseRepository {
|
||||
* @description : Create an office
|
||||
*/
|
||||
public async create(office: OfficeRessource): Promise<Offices> {
|
||||
return this.model.create({
|
||||
const createArgs: Prisma.OfficesCreateArgs = {
|
||||
data: {
|
||||
idNot: office.idNot,
|
||||
name: office.name,
|
||||
@ -43,14 +43,15 @@ export default class OfficesRepository extends BaseRepository {
|
||||
},
|
||||
office_status: EOfficeStatus.DESACTIVATED,
|
||||
},
|
||||
});
|
||||
};
|
||||
return this.model.create(createArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Update data from an office
|
||||
*/
|
||||
public async update(uid: string, office: OfficeRessource): Promise<Offices> {
|
||||
return this.model.update({
|
||||
const updateArgs: Prisma.OfficesUpdateArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
@ -65,23 +66,29 @@ export default class OfficesRepository extends BaseRepository {
|
||||
},
|
||||
office_status: EOfficeStatus[office.office_status as keyof typeof EOfficeStatus],
|
||||
},
|
||||
};
|
||||
return this.model.update(updateArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find one office
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: Prisma.OfficesInclude) {
|
||||
return this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
include: query,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find one office
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<Offices | null> {
|
||||
const findOneArgs: Prisma.OfficesFindUniqueArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
};
|
||||
if (query) {
|
||||
findOneArgs.include = query;
|
||||
}
|
||||
const officeEntity = await this.model.findUnique(findOneArgs);
|
||||
|
||||
return officeEntity;
|
||||
public async findOneByProvider(providerName: string, id: string, query?: Prisma.OfficesInclude) {
|
||||
return this.model.findUnique({
|
||||
where: { [providerName]: id },
|
||||
include: query,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,42 +0,0 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { RolesHasRules, Prisma } from "@prisma/client";
|
||||
|
||||
@Service()
|
||||
export default class RolesHasRulesRepository extends BaseRepository {
|
||||
constructor(private database: Database) {
|
||||
super();
|
||||
}
|
||||
protected get model() {
|
||||
return this.database.getClient().rolesHasRules;
|
||||
}
|
||||
protected get instanceDb() {
|
||||
return this.database.getClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find many relations between basic roles and rules
|
||||
*/
|
||||
public async findMany(query: any): Promise<RolesHasRules[]> {
|
||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||
return this.model.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find one relation between an basic role and rules
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<RolesHasRules | null> {
|
||||
const findOneArgs: Prisma.RolesHasRulesFindUniqueArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
};
|
||||
if (query) {
|
||||
findOneArgs.include = query;
|
||||
}
|
||||
const roleEntity = await this.model.findUnique(findOneArgs);
|
||||
|
||||
return roleEntity;
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ export default class RolesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find many roles
|
||||
*/
|
||||
public async findMany(query: any): Promise<Roles[]> {
|
||||
public async findMany(query: Prisma.RolesFindManyArgs) {
|
||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||
return this.model.findMany(query);
|
||||
}
|
||||
@ -31,27 +31,13 @@ export default class RolesRepository extends BaseRepository {
|
||||
const createArgs: Prisma.RolesCreateArgs = {
|
||||
data: {
|
||||
name: role.name,
|
||||
role_has_rules: {
|
||||
createMany: {
|
||||
data: role.role_has_rules!.rules.map((relation) => ({
|
||||
rule_uid: relation.uid!,
|
||||
rules: {
|
||||
connect: role.rules?.map((rule) => ({
|
||||
uid: rule.uid!,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
if (role.office_role_has_rules) {
|
||||
createArgs.data.office_role_has_rules = {
|
||||
createMany: {
|
||||
data: role.office_role_has_rules.rules.map((relation) => ({
|
||||
office_uid: role.office_role_has_rules!.office.uid!,
|
||||
rule_uid: relation.uid!,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return this.model.create(createArgs);
|
||||
}
|
||||
@ -66,29 +52,13 @@ export default class RolesRepository extends BaseRepository {
|
||||
},
|
||||
data: {
|
||||
name: role.name,
|
||||
role_has_rules: {
|
||||
deleteMany: { role_uid: role.uid },
|
||||
createMany: {
|
||||
data: role.role_has_rules!.rules.map((relation) => ({
|
||||
rule_uid: relation.uid!,
|
||||
rules: {
|
||||
set: role.rules?.map((rule) => ({
|
||||
uid: rule.uid!,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
if (role.office_role_has_rules) {
|
||||
updateArgs.data.office_role_has_rules = {
|
||||
deleteMany: { role_uid: role.uid },
|
||||
createMany: {
|
||||
data: role.office_role_has_rules.rules.map((relation) => ({
|
||||
office_uid: role.office_role_has_rules!.office.uid!,
|
||||
rule_uid: relation.uid!,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return this.model.update(updateArgs);
|
||||
}
|
||||
@ -96,18 +66,13 @@ export default class RolesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find one role
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<Roles | null> {
|
||||
const findOneArgs: Prisma.RolesFindUniqueArgs = {
|
||||
public async findOneByUid(uid: string, query?: Prisma.RolesInclude) {
|
||||
return this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
};
|
||||
if (query) {
|
||||
findOneArgs.include = query;
|
||||
}
|
||||
const roleEntity = await this.model.findUnique(findOneArgs);
|
||||
|
||||
return roleEntity;
|
||||
include: query,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,7 +19,7 @@ export default class RulesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find many rules
|
||||
*/
|
||||
public async findMany(query: any): Promise<Rules[]> {
|
||||
public async findMany(query: Prisma.RulesFindManyArgs) {
|
||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||
return this.model.findMany(query);
|
||||
}
|
||||
@ -56,18 +56,13 @@ export default class RulesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find one rule
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<Rules | null> {
|
||||
const findOneArgs: Prisma.RulesFindUniqueArgs = {
|
||||
public async findOneByUid(uid: string, query?: Prisma.RulesInclude) {
|
||||
return this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
};
|
||||
if (query) {
|
||||
findOneArgs.include = query;
|
||||
}
|
||||
const ruleEntity = await this.model.findUnique(findOneArgs);
|
||||
|
||||
return ruleEntity;
|
||||
include: query,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,7 +19,7 @@ export default class UsersRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find many users
|
||||
*/
|
||||
public async findMany(query: Prisma.UsersFindManyArgs): Promise<Users[]> {
|
||||
public async findMany(query: Prisma.UsersFindManyArgs) {
|
||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||
return this.model.findMany(query);
|
||||
}
|
||||
@ -65,7 +65,7 @@ export default class UsersRepository extends BaseRepository {
|
||||
connect: {
|
||||
uid: user.role!.uid,
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
if (user.contact!.address) {
|
||||
@ -75,6 +75,13 @@ export default class UsersRepository extends BaseRepository {
|
||||
city: user.contact!.address.city,
|
||||
};
|
||||
}
|
||||
if (user.office_role) {
|
||||
createArgs.data.office_role = {
|
||||
connect: {
|
||||
uid: user.office_role.uid,
|
||||
},
|
||||
};
|
||||
}
|
||||
return this.model.create({ ...createArgs, include: { contact: true, office_membership: { include: { address: true } } } });
|
||||
}
|
||||
|
||||
@ -137,23 +144,39 @@ export default class UsersRepository extends BaseRepository {
|
||||
city: user.contact!.address!.city,
|
||||
};
|
||||
}
|
||||
if (user.office_role) {
|
||||
updateArgs.data.office_role = {
|
||||
connect: {
|
||||
uid: user.office_role.uid,
|
||||
},
|
||||
};
|
||||
}
|
||||
return this.model.update({ ...updateArgs, include: { contact: true, office_membership: { include: { address: true } } } });
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find one user
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<Users | null> {
|
||||
const findOneArgs: Prisma.UsersFindUniqueArgs = {
|
||||
public async findOneByUid(uid: string, query?: Prisma.UsersInclude){
|
||||
return this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
};
|
||||
if (query) {
|
||||
findOneArgs.include = query;
|
||||
include: query,
|
||||
});
|
||||
}
|
||||
const userEntity = await this.model.findUnique(findOneArgs);
|
||||
|
||||
return userEntity;
|
||||
/**
|
||||
* @description : Find one user
|
||||
*/
|
||||
public async findOneByProvider(providerName: string, id: string) {
|
||||
return this.model.findUnique({
|
||||
where: { [providerName]: id },
|
||||
include: {
|
||||
role: { include: { rules: true } } ,
|
||||
office_role: { include: { rules: true } } ,
|
||||
office_membership: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,21 @@ export type Tokens = {
|
||||
token_type: string;
|
||||
};
|
||||
|
||||
export type OpenIdConfig = {
|
||||
authorization_endpoint: string;
|
||||
token_endpoint: string;
|
||||
userinfo_endpoint: string;
|
||||
claims_supported: string[];
|
||||
end_session_endpoint: string;
|
||||
grant_types_supported: string[];
|
||||
response_types_supported: string[];
|
||||
scopes_supported: string[];
|
||||
issuer: string;
|
||||
jwks_uri: string;
|
||||
}
|
||||
|
||||
export default interface OpenIdInterface {
|
||||
getOpenIdConfig(): Promise<OpenIdConfig>
|
||||
verifyIdToken(signingKey: string): Promise<Payload>;
|
||||
getSigningKeys(jwksUri: string): Promise<string[]>;
|
||||
}
|
||||
|
@ -5,10 +5,8 @@ import ExpressServer from "@Common/system/ExpressServer";
|
||||
import routes from "@App/index";
|
||||
import cors from "cors";
|
||||
import bodyParser from "body-parser";
|
||||
// import TezosLink from "@Common/databases/TezosLink";
|
||||
import errorHandler from "@App/middlewares/ErrorHandler";
|
||||
import { BackendVariables } from "@Common/config/variables/Variables";
|
||||
//import fileHandler from "@App/middlewares/FileHandler";
|
||||
import multer from "multer";
|
||||
|
||||
|
||||
@ -22,7 +20,6 @@ const storage = multer.memoryStorage();
|
||||
const rootUrl = variables.APP_ROOT_URL;
|
||||
const label = variables.APP_LABEL ?? "Unknown Service";
|
||||
|
||||
// Container.get(TezosLink).connect();
|
||||
Container.get(ExpressServer).init({
|
||||
label,
|
||||
port: parseInt(port),
|
||||
|
@ -1,27 +0,0 @@
|
||||
import AddressesRepository from "@Repositories/AddressesRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Addresses } from "@prisma/client";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Service()
|
||||
export default class AddressesService extends BaseService {
|
||||
constructor(private addressRepository: AddressesRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all addresses
|
||||
* @throws {Error} If addresses cannot be get
|
||||
*/
|
||||
public async get(query: any): Promise<Addresses[]> {
|
||||
return this.addressRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a address by uid
|
||||
* @throws {Error} If address cannot be get
|
||||
*/
|
||||
public async getByUid(uid: string): Promise<Addresses | null> {
|
||||
return this.addressRepository.findOneByUid(uid);
|
||||
}
|
||||
}
|
@ -1,17 +1,23 @@
|
||||
import jwt, { VerifyCallback } from "jsonwebtoken";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import "reflect-metadata";
|
||||
import { BackendVariables } from "@Common/config/variables/Variables";
|
||||
import { Service } from "typedi";
|
||||
import UsersService from "@Services/super-admin/UsersService/UsersService";
|
||||
|
||||
export type UserPayload = {
|
||||
uid: string;
|
||||
idNot: string;
|
||||
office_idNot: string;
|
||||
enum PROVIDER_OPENID {
|
||||
idNot = "idNot",
|
||||
}
|
||||
|
||||
interface IJwtPayload {
|
||||
userId: string;
|
||||
openId: {
|
||||
providerName: PROVIDER_OPENID;
|
||||
userId: string | number;
|
||||
};
|
||||
office_IdNot_Id: string;
|
||||
role: string;
|
||||
rules: string[];
|
||||
};
|
||||
}
|
||||
|
||||
@Service()
|
||||
export default class AuthService extends BaseService {
|
||||
@ -19,32 +25,35 @@ export default class AuthService extends BaseService {
|
||||
super();
|
||||
}
|
||||
|
||||
public async getUserPayload(id: string): Promise<UserPayload> {
|
||||
const user: any = (
|
||||
await this.userService.get({
|
||||
where: { idNot: id },
|
||||
include: {
|
||||
role: { include: { role_has_rules: { include: { rule: true } }, office_role_has_rules: { include: { rule: true } } } },
|
||||
office_membership: true,
|
||||
},
|
||||
})
|
||||
)[0];
|
||||
public async getUserJwtPayload(id: string, providerName: PROVIDER_OPENID = PROVIDER_OPENID.idNot): Promise<IJwtPayload | null> {
|
||||
const user = await this.userService.getByProvider(providerName, id);
|
||||
|
||||
if (!user) throw new Error("User not found");
|
||||
if (!user) return null;
|
||||
|
||||
let rules: string[] = [];
|
||||
if (user.role.office_role_has_rules.length) {
|
||||
user.role.office_role_has_rules.forEach((relation: any) => {
|
||||
if (relation.office_uid === user.office_membership.uid) rules.push(relation.rule.name);
|
||||
const rules: string[] = [];
|
||||
if (user.office_role) {
|
||||
user.office_role.rules.forEach((rule) => {
|
||||
rules.push(rule.name);
|
||||
});
|
||||
return { uid: user.uid, idNot: user.idNot, office_idNot: user.office_membership.idNot, role: user.role.name, rules: rules };
|
||||
return {
|
||||
userId: user.uid,
|
||||
openId: { providerName: providerName, userId: user.idNot },
|
||||
office_IdNot_Id: user.office_membership.idNot,
|
||||
role: user.role.name,
|
||||
rules: rules,
|
||||
};
|
||||
}
|
||||
if (!rules.length) {
|
||||
user.role.role_has_rules.forEach((relation: any) => {
|
||||
rules.push(relation.rule.name);
|
||||
|
||||
user.role.rules.forEach((rule) => {
|
||||
rules.push(rule.name);
|
||||
});
|
||||
}
|
||||
return { uid: user.uid, idNot: user.idNot, office_idNot: user.office_membership.idNot, role: user.role.name, rules: rules };
|
||||
return {
|
||||
userId: user.uid,
|
||||
openId: { providerName: providerName, userId: user.idNot },
|
||||
office_IdNot_Id: user.office_membership.idNot,
|
||||
role: user.role.name,
|
||||
rules: rules,
|
||||
};
|
||||
}
|
||||
|
||||
public generateAccessToken(user: any): string {
|
||||
|
@ -1,27 +0,0 @@
|
||||
import ContactsRepository from "@Repositories/ContactsRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Contacts } from "@prisma/client";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Service()
|
||||
export default class ContactsService extends BaseService {
|
||||
constructor(private contactRepository: ContactsRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all contacts
|
||||
* @throws {Error} If contacts cannot be get
|
||||
*/
|
||||
public async get(query: any): Promise<Contacts[]> {
|
||||
return this.contactRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a contact by uid
|
||||
* @throws {Error} If contact cannot be get
|
||||
*/
|
||||
public async getByUid(uid: string): Promise<Contacts | null> {
|
||||
return this.contactRepository.findOneByUid(uid);
|
||||
}
|
||||
}
|
@ -72,7 +72,8 @@ export default class FilesService extends BaseService {
|
||||
* @throws {Error} If file cannot be modified
|
||||
*/
|
||||
public async update(uid: string, file: File): Promise<Files> {
|
||||
return this.filesRepository.update(uid, file);
|
||||
const key = v4();
|
||||
return this.filesRepository.update(uid, file, key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
55
src/services/common/OpenIdService/OpenIdService.ts
Normal file
55
src/services/common/OpenIdService/OpenIdService.ts
Normal file
@ -0,0 +1,55 @@
|
||||
import jwt from "jsonwebtoken";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Service } from "typedi";
|
||||
|
||||
export type Tokens = {
|
||||
access_token: string;
|
||||
expires_in: number;
|
||||
id_token: string;
|
||||
token_type: string;
|
||||
};
|
||||
|
||||
export type OpenIdConfig = {
|
||||
authorization_endpoint: string;
|
||||
token_endpoint: string;
|
||||
userinfo_endpoint: string;
|
||||
claims_supported: string[];
|
||||
end_session_endpoint: string;
|
||||
grant_types_supported: string[];
|
||||
response_types_supported: string[];
|
||||
scopes_supported: string[];
|
||||
issuer: string;
|
||||
jwks_uri: string;
|
||||
}
|
||||
|
||||
@Service()
|
||||
export default class OpenIdService extends BaseService {
|
||||
protected authorizationServerUrl: string;
|
||||
constructor(authorizationServerUrl: string) {
|
||||
super();
|
||||
this.authorizationServerUrl = authorizationServerUrl;
|
||||
}
|
||||
|
||||
public async getOpenIdConfig(): Promise<OpenIdConfig> {
|
||||
const response = await fetch(this.authorizationServerUrl + "/.well-known/openid-configuration");
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
public async getSigningKey(kid: string): Promise<string | null> {
|
||||
const jwksUri = (await this.getOpenIdConfig()).jwks_uri;
|
||||
const response = await fetch(jwksUri);
|
||||
const jwks = await response.json();
|
||||
const signingKey = jwks.keys.find((key: any) => key.kid === kid);
|
||||
if (!signingKey) return null;
|
||||
return signingKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
public async verifyIdToken(idToken: string, kid: string) {
|
||||
const signingKey = await this.getSigningKey(kid);
|
||||
if (!signingKey) throw new Error("Signing key not found");
|
||||
return jwt.verify(idToken, signingKey);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import { Documents, Prisma } from "@prisma/client";
|
||||
import { Documents } from "@prisma/client";
|
||||
import { Document } from "le-coffre-resources/dist/Customer";
|
||||
import DocumentsRepository from "@Repositories/DocumentsRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
@ -30,7 +30,7 @@ export default class DocumentsService extends BaseService {
|
||||
* @description : Create new documents
|
||||
* @throws {Error} If documents or one of them cannot be created
|
||||
*/
|
||||
public async createMany(documents: Document[]): Promise<Prisma.BatchPayload> {
|
||||
public async createMany(documents: Document[]): Promise<Documents[]> {
|
||||
return this.documentsRepository.createMany(documents);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Documents, Prisma } from "@prisma/client";
|
||||
import { Documents } from "@prisma/client";
|
||||
import { Document } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import DocumentsRepository from "@Repositories/DocumentsRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
@ -30,7 +30,7 @@ export default class DocumentsService extends BaseService {
|
||||
* @description : Create new documents
|
||||
* @throws {Error} If documents or one of them cannot be created
|
||||
*/
|
||||
public async createMany(documents: Document[]): Promise<Prisma.BatchPayload> {
|
||||
public async createMany(documents: Document[]): Promise<Documents[]> {
|
||||
return this.documentsRepository.createMany(documents);
|
||||
}
|
||||
|
||||
|
@ -59,11 +59,11 @@ export default class OfficeFoldersService extends BaseService {
|
||||
* @throws {Error} If document cannot be deleted
|
||||
*/
|
||||
public async delete(uid: string): Promise<OfficeFolders> {
|
||||
const officeFolderEntity = await this.officeFoldersRepository.findOneByUid(uid, { office_folder_has_customers: true });
|
||||
const officeFolderEntity = await this.officeFoldersRepository.findOneByUid(uid, { customers: true });
|
||||
if(!officeFolderEntity) throw new Error('office folder not found');
|
||||
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntity, { strategy: "excludeAll" });
|
||||
|
||||
if (officeFolder.office_folder_has_customers && officeFolder.office_folder_has_customers.length !== 0) {
|
||||
if (officeFolder.customers?.length) {
|
||||
throw new Error("This folder is used by customers");
|
||||
}
|
||||
return this.officeFoldersRepository.delete(uid);
|
||||
|
@ -0,0 +1,44 @@
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Service } from "typedi";
|
||||
import OfficeRolesRepository from "@Repositories/OfficeRolesRepository";
|
||||
import { OfficeRole } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import {Prisma, OfficeRoles } from "@prisma/client";
|
||||
|
||||
@Service()
|
||||
export default class OfficeRolesService extends BaseService {
|
||||
constructor(private officeRoleRepository: OfficeRolesRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all officeRoles
|
||||
* @throws {Error} If officeRoles cannot be get
|
||||
*/
|
||||
public get(query: Prisma.OfficeRolesFindManyArgs): Promise<OfficeRoles[]> {
|
||||
return this.officeRoleRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a officeRole
|
||||
* @throws {Error} If officeRole couldn't be created
|
||||
*/
|
||||
public create(officeRoleEntity: OfficeRole): Promise<OfficeRoles> {
|
||||
return this.officeRoleRepository.create(officeRoleEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Modify a officeRole
|
||||
* @throws {Error} If officeRole modification failed
|
||||
*/
|
||||
public update(officeRoleEntity: OfficeRole): Promise<OfficeRoles> {
|
||||
return this.officeRoleRepository.update(officeRoleEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a officeRole by uid
|
||||
* @throws {Error} If officeRole cannot be get by uid
|
||||
*/
|
||||
public getByUid(uid: string, query?: any): Promise<OfficeRoles | null> {
|
||||
return this.officeRoleRepository.findOneByUid(uid, query);
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ export default class UsersService extends BaseService {
|
||||
* @description : Get all users
|
||||
* @throws {Error} If users cannot be get
|
||||
*/
|
||||
public get(query: Prisma.UsersFindManyArgs): Promise<Users[]> {
|
||||
public get(query: Prisma.UsersFindManyArgs) {
|
||||
return this.userRepository.findMany(query);
|
||||
}
|
||||
|
||||
@ -42,4 +42,12 @@ export default class UsersService extends BaseService {
|
||||
public getByUid(uid: string, query?: any): Promise<Users | null> {
|
||||
return this.userRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a user by uid
|
||||
* @throws {Error} If user cannot be get by uid
|
||||
*/
|
||||
public getByProvider(providerName: string, id: string) {
|
||||
return this.userRepository.findOneByProvider(providerName, id);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import {
|
||||
ECivility,
|
||||
ECustomerStatus,
|
||||
Offices,
|
||||
Prisma,
|
||||
PrismaClient,
|
||||
Roles,
|
||||
Rules,
|
||||
@ -43,23 +44,26 @@ export const initDocumentType = (documentType: DocumentType, office: Office): Pr
|
||||
});
|
||||
};
|
||||
|
||||
export const initDeedType = (deedType: DeedType, office: Office, documentTypes?: string[]): Promise<DeedTypes> => {
|
||||
return prisma.deedTypes.create({
|
||||
export const initDeedType = (deedType: DeedType): Promise<DeedTypes> => {
|
||||
const createArgs: Prisma.DeedTypesCreateArgs = {
|
||||
data: {
|
||||
name: deedType.name,
|
||||
description: deedType.description,
|
||||
archived_at: null,
|
||||
office_uid: office.uid!,
|
||||
deed_type_has_document_types: {
|
||||
createMany: {
|
||||
data: documentTypes!.map((documentType) => ({
|
||||
document_type_uid: documentType,
|
||||
office: {
|
||||
connect: {
|
||||
uid: deedType.office!.uid,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
if (deedType.document_types) {
|
||||
createArgs.data.document_types = {
|
||||
connect: deedType.document_types.map((documentType) => ({
|
||||
uid: documentType.uid,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
return prisma.deedTypes.create(createArgs);
|
||||
};
|
||||
|
||||
export const initCustomers = (customer: Customer): Promise<Customers> => {
|
||||
|
@ -144,14 +144,7 @@ export const deedType: DeedType = {
|
||||
office: office,
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
deed_type_has_document_types: [
|
||||
{
|
||||
document_type: documentType,
|
||||
deed_type: new DeedType(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
],
|
||||
document_types: [documentType],
|
||||
};
|
||||
|
||||
export const deedType_: DeedType = {
|
||||
@ -197,34 +190,8 @@ export const officeFolder: OfficeFolder = {
|
||||
status: "ARCHIVED",
|
||||
deed: deed,
|
||||
office: office,
|
||||
office_folder_has_customers: [
|
||||
{
|
||||
customer: customer,
|
||||
office_folder: new OfficeFolder(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
{
|
||||
customer: customer_,
|
||||
office_folder: new OfficeFolder(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
],
|
||||
office_folder_has_stakeholder: [
|
||||
{
|
||||
user_stakeholder: user,
|
||||
office_folder: new OfficeFolder(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
{
|
||||
user_stakeholder: user_,
|
||||
office_folder: new OfficeFolder(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
],
|
||||
customers: [customer, customer_],
|
||||
stakeholders: [user, user_],
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
};
|
||||
|
@ -16,7 +16,7 @@ beforeAll(async () => {
|
||||
office.uid = (await initOffice(office)).uid;
|
||||
documentType.uid = (await initDocumentType(documentType, office)).uid;
|
||||
documentType_.uid = (await initDocumentType(documentType_, office)).uid;
|
||||
deedType.uid = (await initDeedType(deedType, office, [documentType.uid])).uid;
|
||||
deedType.uid = (await initDeedType(deedType)).uid;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
@ -46,9 +46,9 @@ describe("test create function", () => {
|
||||
});
|
||||
|
||||
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_uid).toEqual(documentType.uid);
|
||||
const deedWithDocumentTypes = await prisma.deeds.findFirstOrThrow({ include: { document_types: true } });
|
||||
expect(deedWithDocumentTypes.document_types.length).toEqual(1);
|
||||
expect(deedWithDocumentTypes.document_types[0]?.uid).toEqual(documentType.uid);
|
||||
});
|
||||
|
||||
it("should create a the same deed based on existing deed type", async () => {
|
||||
@ -83,20 +83,7 @@ describe("test update function", () => {
|
||||
const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uid: deedType.uid } })).uid;
|
||||
let deedToUpdate: Deed = JSON.parse(JSON.stringify(deed));
|
||||
|
||||
deedToUpdate.deed_has_document_types = [
|
||||
{
|
||||
document_type: documentType,
|
||||
deed: new Deed(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
{
|
||||
document_type: documentType_,
|
||||
deed: new Deed(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
];
|
||||
deedToUpdate.document_types = [documentType, documentType_];
|
||||
|
||||
await DeedServiceTest.update(deedUid, deedToUpdate);
|
||||
|
||||
@ -105,30 +92,17 @@ describe("test update function", () => {
|
||||
uid: deedUid,
|
||||
},
|
||||
include: {
|
||||
deed_has_document_types: true,
|
||||
document_types: true,
|
||||
},
|
||||
});
|
||||
expect(deedUpdated.deed_has_document_types.length).toEqual(2);
|
||||
expect(deedUpdated.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_uid: deedType.uid } })).uid;
|
||||
let deedToUpdate: Deed = JSON.parse(JSON.stringify(deed));
|
||||
|
||||
deedToUpdate.deed_has_document_types = [
|
||||
{
|
||||
document_type: documentType,
|
||||
deed: new Deed(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
{
|
||||
document_type: documentType_,
|
||||
deed: new Deed(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
];
|
||||
deedToUpdate.document_types = [documentType, documentType_];
|
||||
|
||||
await DeedServiceTest.update(deedUid, deedToUpdate);
|
||||
|
||||
@ -137,10 +111,10 @@ describe("test update function", () => {
|
||||
uid: deedUid,
|
||||
},
|
||||
include: {
|
||||
deed_has_document_types: true,
|
||||
document_types: true,
|
||||
},
|
||||
});
|
||||
expect(deedUpdated.deed_has_document_types.length).toEqual(2);
|
||||
expect(deedUpdated.document_types.length).toEqual(2);
|
||||
});
|
||||
|
||||
it("should delete document types from a deed", async () => {
|
||||
@ -148,7 +122,7 @@ describe("test update function", () => {
|
||||
let deedToUpdate: Deed = JSON.parse(JSON.stringify(deed));
|
||||
|
||||
// set relation between deed and document types empty
|
||||
deedToUpdate.deed_has_document_types = [];
|
||||
deedToUpdate.document_types = [];
|
||||
|
||||
await DeedServiceTest.update(deedUid, deedToUpdate);
|
||||
|
||||
@ -157,10 +131,10 @@ describe("test update function", () => {
|
||||
uid: deedUid,
|
||||
},
|
||||
include: {
|
||||
deed_has_document_types: true,
|
||||
document_types: true,
|
||||
},
|
||||
});
|
||||
expect(deedUpdated.deed_has_document_types.length).toEqual(0);
|
||||
expect(deedUpdated.document_types.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -188,20 +188,7 @@ describe("test update function", () => {
|
||||
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType.name, office_uid: office.uid } })).uid;
|
||||
let deedTypeToUpdate: DeedType = JSON.parse(JSON.stringify(deedType));
|
||||
|
||||
deedTypeToUpdate.deed_type_has_document_types = [
|
||||
{
|
||||
document_type: documentType,
|
||||
deed_type: new DeedType(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
{
|
||||
document_type: documentType_,
|
||||
deed_type: new DeedType(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
];
|
||||
deedTypeToUpdate.document_types = [documentType, documentType_];
|
||||
|
||||
await DeedTypeServiceTest.update(deedTypeUid, deedTypeToUpdate);
|
||||
|
||||
@ -210,30 +197,17 @@ describe("test update function", () => {
|
||||
uid: deedTypeUid,
|
||||
},
|
||||
include: {
|
||||
deed_type_has_document_types: true,
|
||||
document_types: true,
|
||||
},
|
||||
});
|
||||
expect(deedTypeUpdated.deed_type_has_document_types.length).toEqual(2);
|
||||
expect(deedTypeUpdated.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_uid: office.uid } })).uid;
|
||||
let deedTypeToUpdate: DeedType = JSON.parse(JSON.stringify(deedType));
|
||||
|
||||
deedTypeToUpdate.deed_type_has_document_types = [
|
||||
{
|
||||
document_type: documentType,
|
||||
deed_type: new DeedType(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
{
|
||||
document_type: documentType_,
|
||||
deed_type: new DeedType(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
];
|
||||
deedTypeToUpdate.document_types = [documentType, documentType_];
|
||||
|
||||
await DeedTypeServiceTest.update(deedTypeUid, deedTypeToUpdate);
|
||||
|
||||
@ -242,10 +216,10 @@ describe("test update function", () => {
|
||||
uid: deedTypeUid,
|
||||
},
|
||||
include: {
|
||||
deed_type_has_document_types: true,
|
||||
document_types: true,
|
||||
},
|
||||
});
|
||||
expect(deedTypeUpdated.deed_type_has_document_types.length).toEqual(2);
|
||||
expect(deedTypeUpdated.document_types.length).toEqual(2);
|
||||
});
|
||||
|
||||
it("should delete document types from a deed", async () => {
|
||||
@ -253,7 +227,7 @@ describe("test update function", () => {
|
||||
let deedTypeToUpdate: DeedType = JSON.parse(JSON.stringify(deedType));
|
||||
|
||||
// set relation between deed and document types empty
|
||||
deedTypeToUpdate.deed_type_has_document_types = [];
|
||||
deedTypeToUpdate.document_types = [];
|
||||
|
||||
await DeedTypeServiceTest.update(deedTypeUid, deedTypeToUpdate);
|
||||
|
||||
@ -262,10 +236,10 @@ describe("test update function", () => {
|
||||
uid: deedTypeUid,
|
||||
},
|
||||
include: {
|
||||
deed_type_has_document_types: true,
|
||||
document_types: true,
|
||||
},
|
||||
});
|
||||
expect(deedTypeUpdated.deed_type_has_document_types.length).toEqual(0);
|
||||
expect(deedTypeUpdated.document_types.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import "module-alias/register";
|
||||
import "reflect-metadata";
|
||||
import { OfficeFolderHasCustomers, OfficeFolderHasStakeholders, PrismaClient } from "prisma/prisma-client";
|
||||
import { PrismaClient } from "prisma/prisma-client";
|
||||
import { customer, customer_, deedType, documentType, documentType_, office, officeFolder, officeFolder_, user, user_ } from "@Test/config/MockedData";
|
||||
import Container from "typedi";
|
||||
import OfficeFoldersRepository from "@Repositories/OfficeFoldersRepository";
|
||||
@ -18,7 +18,7 @@ beforeAll(async () => {
|
||||
office.uid = (await initOffice(office)).uid;
|
||||
documentType.uid = (await initDocumentType(documentType, office)).uid;
|
||||
documentType_.uid = (await initDocumentType(documentType_, office)).uid;
|
||||
deedType.uid = (await initDeedType(deedType, office, [documentType.uid])).uid;
|
||||
deedType.uid = (await initDeedType(deedType)).uid;
|
||||
user.uid = (await initUsers(user)).uid;
|
||||
user_.uid = (await initUsers(user_)).uid;
|
||||
customer.uid = (await initCustomers(customer)).uid;
|
||||
@ -72,40 +72,9 @@ describe("test create function", () => {
|
||||
|
||||
it("should contains stakeholders", async () => {
|
||||
const officeFolderCreated = await prisma.officeFolders.findFirstOrThrow({
|
||||
include: { office_folder_has_stakeholder: true },
|
||||
include: { stakeholders: true },
|
||||
});
|
||||
const stakeholderRelation = await prisma.officeFolderHasStakeholders.findUniqueOrThrow({
|
||||
where: {
|
||||
office_folder_uid_user_stakeholder_uid: {
|
||||
user_stakeholder_uid: user.uid!,
|
||||
office_folder_uid: officeFolderCreated.uid,
|
||||
},
|
||||
},
|
||||
});
|
||||
const stakeholderRelation_ = await prisma.officeFolderHasStakeholders.findUniqueOrThrow({
|
||||
where: {
|
||||
office_folder_uid_user_stakeholder_uid: {
|
||||
user_stakeholder_uid: user_.uid!,
|
||||
office_folder_uid: officeFolderCreated.uid,
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(officeFolderCreated.office_folder_has_stakeholder.length).toEqual(2);
|
||||
const stakeholder: OfficeFolderHasStakeholders = {
|
||||
uid: stakeholderRelation.uid,
|
||||
office_folder_uid: officeFolderCreated.uid,
|
||||
user_stakeholder_uid: user.uid!,
|
||||
created_at: officeFolderCreated.created_at,
|
||||
updated_at: officeFolderCreated.updated_at,
|
||||
};
|
||||
const stakeholder_: OfficeFolderHasStakeholders = {
|
||||
uid: stakeholderRelation_.uid,
|
||||
office_folder_uid: officeFolderCreated.uid,
|
||||
user_stakeholder_uid: user_.uid!,
|
||||
created_at: officeFolderCreated.created_at,
|
||||
updated_at: officeFolderCreated.updated_at,
|
||||
};
|
||||
expect(officeFolderCreated.office_folder_has_stakeholder).toEqual(expect.arrayContaining([stakeholder, stakeholder_]));
|
||||
expect(officeFolderCreated.stakeholders).toEqual([user, user_]);
|
||||
});
|
||||
|
||||
it("should not create a new office folder with folder number already created", async () => {
|
||||
@ -131,123 +100,51 @@ describe("test create function", () => {
|
||||
describe("test update function", () => {
|
||||
it("should add customers", async () => {
|
||||
let officeFolderCreated = await prisma.officeFolders.findFirstOrThrow({
|
||||
include: { office_folder_has_customers: true },
|
||||
include: { customers: true },
|
||||
});
|
||||
|
||||
expect(officeFolderCreated.office_folder_has_customers).toEqual([]);
|
||||
expect(officeFolderCreated.customers).toEqual([]);
|
||||
// mocked data contains the customers
|
||||
await OfficeFolderServiceTest.update(officeFolderCreated.uid, officeFolder);
|
||||
|
||||
const customerRelation = await prisma.officeFolderHasCustomers.findUniqueOrThrow({
|
||||
where: {
|
||||
office_folder_uid_customer_uid: {
|
||||
customer_uid: customer.uid!,
|
||||
office_folder_uid: officeFolderCreated.uid,
|
||||
},
|
||||
},
|
||||
});
|
||||
const customerRelation_ = await prisma.officeFolderHasCustomers.findUniqueOrThrow({
|
||||
where: {
|
||||
office_folder_uid_customer_uid: {
|
||||
customer_uid: customer_.uid!,
|
||||
office_folder_uid: officeFolderCreated.uid,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
officeFolderCreated = await prisma.officeFolders.findFirstOrThrow({
|
||||
include: { office_folder_has_customers: true },
|
||||
include: { customers: true },
|
||||
});
|
||||
|
||||
expect(officeFolderCreated.office_folder_has_customers.length).toEqual(2);
|
||||
const officeFolderHasCustomer: OfficeFolderHasCustomers = {
|
||||
uid: customerRelation.uid,
|
||||
office_folder_uid: officeFolderCreated.uid,
|
||||
customer_uid: customer.uid!,
|
||||
created_at: customerRelation.created_at,
|
||||
updated_at: customerRelation.updated_at,
|
||||
};
|
||||
const officeFolderHasCustomer_: OfficeFolderHasCustomers = {
|
||||
uid: customerRelation_.uid,
|
||||
office_folder_uid: officeFolderCreated.uid,
|
||||
customer_uid: customer_.uid!,
|
||||
created_at: customerRelation_.created_at,
|
||||
updated_at: customerRelation_.updated_at,
|
||||
};
|
||||
expect(officeFolderCreated.office_folder_has_customers).toEqual(
|
||||
expect.arrayContaining([officeFolderHasCustomer, officeFolderHasCustomer_]),
|
||||
);
|
||||
expect(officeFolderCreated.customers.length).toEqual([customer, customer_].length);
|
||||
});
|
||||
|
||||
it("should remove customers", async () => {
|
||||
let officeFolderCreated = await prisma.officeFolders.findFirstOrThrow({
|
||||
include: { office_folder_has_customers: true },
|
||||
include: { customers: true },
|
||||
});
|
||||
|
||||
expect(officeFolderCreated.office_folder_has_customers.length).toEqual(2);
|
||||
expect(officeFolderCreated.customers.length).toEqual(2);
|
||||
|
||||
let officeFolderWithLessCustomers: OfficeFolder = JSON.parse(JSON.stringify(officeFolder));
|
||||
officeFolderWithLessCustomers.office_folder_has_customers!.pop();
|
||||
officeFolderWithLessCustomers.customers!.pop();
|
||||
// mocked data contains the customers
|
||||
await OfficeFolderServiceTest.update(officeFolderCreated.uid, officeFolderWithLessCustomers);
|
||||
|
||||
const customerRelation = await prisma.officeFolderHasCustomers.findUniqueOrThrow({
|
||||
where: {
|
||||
office_folder_uid_customer_uid: {
|
||||
customer_uid: customer.uid!,
|
||||
office_folder_uid: officeFolderCreated.uid,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
officeFolderCreated = await prisma.officeFolders.findFirstOrThrow({
|
||||
include: { office_folder_has_customers: true },
|
||||
});
|
||||
|
||||
expect(officeFolderCreated.office_folder_has_customers.length).toEqual(1);
|
||||
const officeFolderHasCustomer: OfficeFolderHasCustomers = {
|
||||
uid: customerRelation.uid,
|
||||
office_folder_uid: officeFolderCreated.uid,
|
||||
customer_uid: customer.uid!,
|
||||
created_at: customerRelation.created_at,
|
||||
updated_at: customerRelation.updated_at,
|
||||
};
|
||||
expect(officeFolderCreated.office_folder_has_customers).toEqual([officeFolderHasCustomer]);
|
||||
expect(officeFolderCreated.customers.length).toEqual([customer]);
|
||||
});
|
||||
it("should remove stakeholders", async () => {
|
||||
let officeFolderCreated = await prisma.officeFolders.findFirstOrThrow({
|
||||
include: { office_folder_has_stakeholder: true },
|
||||
include: { stakeholders: true },
|
||||
});
|
||||
|
||||
expect(officeFolderCreated.office_folder_has_stakeholder.length).toEqual(2);
|
||||
expect(officeFolderCreated.stakeholders.length).toEqual(2);
|
||||
|
||||
let officeFolderWithLessStakeholders: OfficeFolder = JSON.parse(JSON.stringify(officeFolder));
|
||||
officeFolderWithLessStakeholders.office_folder_has_stakeholder!.pop();
|
||||
officeFolderWithLessStakeholders.stakeholders!.pop();
|
||||
// mocked data contains the customers
|
||||
await OfficeFolderServiceTest.update(officeFolderCreated.uid, officeFolderWithLessStakeholders);
|
||||
|
||||
const stakeholderRelation = await prisma.officeFolderHasStakeholders.findUniqueOrThrow({
|
||||
where: {
|
||||
office_folder_uid_user_stakeholder_uid: {
|
||||
user_stakeholder_uid: user.uid!,
|
||||
office_folder_uid: officeFolderCreated.uid,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
officeFolderCreated = await prisma.officeFolders.findFirstOrThrow({
|
||||
include: { office_folder_has_stakeholder: true },
|
||||
include: { stakeholders: true },
|
||||
});
|
||||
|
||||
expect(officeFolderCreated.office_folder_has_stakeholder.length).toEqual(1);
|
||||
const officeFolderHasStakeholder: OfficeFolderHasStakeholders = {
|
||||
uid: stakeholderRelation.uid,
|
||||
office_folder_uid: officeFolderCreated.uid,
|
||||
user_stakeholder_uid: user.uid!,
|
||||
created_at: stakeholderRelation.created_at,
|
||||
updated_at: stakeholderRelation.updated_at,
|
||||
};
|
||||
expect(officeFolderCreated.office_folder_has_stakeholder).toEqual([officeFolderHasStakeholder]);
|
||||
expect(officeFolderCreated.stakeholders).toEqual([user]);
|
||||
});
|
||||
it("should archivate an office folder", async () => {
|
||||
const officeFolderCreated = await prisma.officeFolders.findFirstOrThrow({});
|
||||
|
@ -95,8 +95,7 @@
|
||||
"include": [
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
"src/app/api/admin/UsersController.ts"
|
||||
, "src/common/databases/seeders/seeder.ts" ],
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user