add include query parameter to findOneByUid

This commit is contained in:
OxSaitama 2023-04-17 18:35:19 +02:00
parent 806e15f2db
commit edfc585d52
57 changed files with 1143 additions and 5155 deletions

3
init-data.sh Normal file → Executable file
View File

@ -8,9 +8,8 @@ set -e;
if [ -n "${DATABASE_USERNAME:-}" ] && [ -n "${DATABASE_PASSWORD:-}" ]; then
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE DATABASE ${DATABASE_NAME};
CREATE USER ${DATABASE_USERNAME} WITH PASSWORD '${DATABASE_PASSWORD}';
GRANT ALL PRIVILEGES ON DATABASE ${DATABASE_NAME} TO ${DATABASE_USERNAME};
ALTER USER ${DATABASE_USERNAME} CREATEDB;
EOSQL
else
echo "SETUP INFO: No Environment variables given!"

3948
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -17,20 +17,16 @@
"@Test": "./dist/test"
},
"scripts": {
"api:startonly": "node ./dist/entries/App.js",
"build-db": "npx prisma migrate dev",
"build": "tsc",
"api:start": "tsc && npm run migrate && npx prisma db seed && node ./dist/entries/App.js",
"start": "tsc && npm run api:startonly",
"start": "tsc && node ./dist/entries/App.js",
"dev": "nodemon -V",
"api:dev": "nodemon",
"build:test": "tsc && mocha ./dist/entries/Test.js",
"format": "prettier --write src",
"migrate:test": "dotenv -e .env.test -- npx prisma migrate deploy",
"migrate": "npx prisma migrate deploy",
"docker:up": "docker-compose up -d",
"docker:up:test": "docker-compose -f docker-compose-test.yml up -d",
"docker:down": "docker-compose -f docker-compose-test.yml down",
"test": "tsc && npm run docker:up:test && npm run migrate:test && dotenv -e .env.test -- jest -i --verbose ./dist/test/* && npm run docker:down"
"docker:down:test": "docker-compose down",
"test": "tsc && npm run docker:up:test && npm run migrate:test && dotenv -e .env.test -- jest -i --verbose ./dist/test/* && npm run docker:down:test"
},
"repository": {
"type": "git",

View File

@ -107,11 +107,18 @@ export default class CustomersController extends ApiController {
try {
const uid = req.params["uid"];
if (!uid) {
throw new Error("No uuid provided");
throw new Error("No uid provided");
}
//call service to get prisma entity
const customerEntity: Customers = await this.customersService.getByUid(uid);
let customerEntity: Customers;
//get query
if (req.query["q"]) {
const query = JSON.parse(req.query["q"] as string);
customerEntity = await this.customersService.getByUid(uid, query);
} else {
//call service to get prisma entity
customerEntity = await this.customersService.getByUid(uid);
}
//Hydrate ressource with prisma entity
const customer = ObjectHydrate.hydrate<Customer>(new Customer(), customerEntity, { strategy: "exposeAll" });

View File

@ -77,7 +77,7 @@ export default class DeedTypesController extends ApiController {
try {
const uid = req.params["uid"];
if (!uid) {
throw new Error("No uuid provided");
throw new Error("No uid provided");
}
//init DeedType resource with request body values
const deedTypeEntity = new DeedType();
@ -111,11 +111,18 @@ export default class DeedTypesController extends ApiController {
try {
const uid = req.params["uid"];
if (!uid) {
throw new Error("No uuid provided");
throw new Error("No uid provided");
}
//call service to get prisma entity
const deedTypeEntity: DeedTypes = await this.deedTypesService.getByUid(uid);
let deedTypeEntity: DeedTypes;
//get query
if (req.query["q"]) {
const query = JSON.parse(req.query["q"] as string);
deedTypeEntity = await this.deedTypesService.getByUid(uid, query);
} else {
//call service to get prisma entity
deedTypeEntity = await this.deedTypesService.getByUid(uid);
}
//Hydrate ressource with prisma entity
const deedType = ObjectHydrate.hydrate<DeedType>(new DeedType(), deedTypeEntity, { strategy: "exposeAll" });

View File

@ -46,7 +46,7 @@ export default class DeedsController extends ApiController {
try {
const uid = req.params["uid"];
if (!uid) {
throw new Error("No uuid provided");
throw new Error("No uid provided");
}
//call service to get prisma entity

View File

@ -74,7 +74,7 @@ export default class DocumentTypesController extends ApiController {
try {
const uid = req.params["uid"];
if (!uid) {
throw new Error("No uuid provided");
throw new Error("No uid provided");
}
//init DocumentType resource with request body values
const documentTypeEntity = new DocumentType();
@ -107,12 +107,19 @@ export default class DocumentTypesController extends ApiController {
try {
const uid = req.params["uid"];
if (!uid) {
throw new Error("No uuid provided");
throw new Error("No uid provided");
}
//call service to get prisma entity
const documentTypeEntity: DocumentTypes = await this.documentTypesService.getByUid(uid);
let documentTypeEntity: DocumentTypes;
//get query
if (req.query["q"]) {
const query = JSON.parse(req.query["q"] as string);
documentTypeEntity = await this.documentTypesService.getByUid(uid, query);
} else {
//call service to get prisma entity
documentTypeEntity = await this.documentTypesService.getByUid(uid);
}
//Hydrate ressource with prisma entity
const user = ObjectHydrate.hydrate<DocumentType>(new DocumentType(), documentTypeEntity, { strategy: "exposeAll" });

View File

@ -77,7 +77,7 @@ export default class DocumentsController extends ApiController {
try {
const uid = req.params["uid"];
if (!uid) {
throw new Error("No uuid provided");
throw new Error("No uid provided");
}
//init Document resource with request body values
@ -109,7 +109,7 @@ export default class DocumentsController extends ApiController {
try {
const uid = req.params["uid"];
if (!uid) {
throw new Error("No uuid provided");
throw new Error("No uid provided");
}
//call service to get prisma entity
@ -134,11 +134,18 @@ export default class DocumentsController extends ApiController {
try {
const uid = req.params["uid"];
if (!uid) {
throw new Error("No uuid provided");
throw new Error("No uid provided");
}
//call service to get prisma entity
const documentEntity: Documents = await this.documentsService.getByUid(uid);
let documentEntity: Documents;
//get query
if (req.query["q"]) {
const query = JSON.parse(req.query["q"] as string);
documentEntity = await this.documentsService.getByUid(uid, query);
} else {
//call service to get prisma entity
documentEntity = await this.documentsService.getByUid(uid);
}
//Hydrate ressource with prisma entity
const document = ObjectHydrate.hydrate<Document>(new Document(), documentEntity, { strategy: "exposeAll" });

View File

@ -27,7 +27,7 @@ export default class OfficeFoldersController extends ApiController {
const prismaEntity: OfficeFolders[] = await this.officeFoldersService.get(query);
//Hydrate ressource with prisma entity
const officeFolders = ObjectHydrate.map<OfficeFolder>(OfficeFolder, prismaEntity, {
strategy: "exposeAll",
strategy: "exposeAll", enableImplicitConversion: true
});
//success
this.httpSuccess(response, officeFolders);
@ -53,7 +53,7 @@ export default class OfficeFoldersController extends ApiController {
const prismaEntityCreated = await this.officeFoldersService.create(officeFolderEntity);
//Hydrate ressource with prisma entity
const officeFolderEntityCreated = ObjectHydrate.hydrate<OfficeFolder>(new OfficeFolder(), prismaEntityCreated, {
strategy: "exposeAll",
strategy: "exposeAll", enableImplicitConversion: true
});
//success
this.httpSuccess(response, officeFolderEntityCreated);
@ -71,7 +71,7 @@ export default class OfficeFoldersController extends ApiController {
try {
const uid = req.params["uid"];
if (!uid) {
throw new Error("No uuid provided");
throw new Error("No uid provided");
}
//init IUser resource with request body values
const officeFolderEntity = new OfficeFolder();
@ -105,11 +105,18 @@ export default class OfficeFoldersController extends ApiController {
try {
const uid = req.params["uid"];
if (!uid) {
throw new Error("No uuid provided");
throw new Error("No uid provided");
}
//call service to get prisma entity
const officeFolderEntity: OfficeFolders = await this.officeFoldersService.getByUid(uid);
let officeFolderEntity: OfficeFolders;
//get query
if (req.query["q"]) {
const query = JSON.parse(req.query["q"] as string);
officeFolderEntity = await this.officeFoldersService.getByUid(uid, query);
} else {
//call service to get prisma entity
officeFolderEntity = await this.officeFoldersService.getByUid(uid);
}
//Hydrate ressource with prisma entity
const officeFolder = ObjectHydrate.hydrate<OfficeFolder>(new OfficeFolder(), officeFolderEntity, { strategy: "exposeAll" });

View File

@ -65,7 +65,7 @@ export default class OfficesController extends ApiController {
try {
const uid = req.params["uid"];
if (!uid) {
throw new Error("No uuid provided");
throw new Error("No uid provided");
}
//init IUser resource with request body values
const officeEntity = new OfficeRessource();
@ -93,10 +93,17 @@ export default class OfficesController extends ApiController {
try {
const uid = req.params["uid"];
if (!uid) {
throw new Error("No uuid provided");
throw new Error("No uid provided");
}
let officeEntity: Offices;
//get query
if (req.query["q"]) {
const query = JSON.parse(req.query["q"] as string);
officeEntity = await this.officesService.getByUid(uid, query);
} else {
//call service to get prisma entity
officeEntity = await this.officesService.getByUid(uid);
}
//call service to get prisma entity
const officeEntity: Offices = await this.officesService.getByUid(uid);
//Hydrate ressource with prisma entity
const office = ObjectHydrate.hydrate<OfficeRessource>(new OfficeRessource(), officeEntity, { strategy: "exposeAll" });
//success

View File

@ -5,8 +5,9 @@ import UsersService from "@Services/super-admin/UsersService/UsersService";
import { Service } from "typedi";
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
import { validateOrReject } from "class-validator";
import User from "le-coffre-resources/dist/SuperAdmin";
import User from "le-coffre-resources/dist/Notary";
import { Users } from "@prisma/client";
import { plainToInstance } from "class-transformer";
@Controller()
@Service()
@ -28,7 +29,10 @@ export default class UsersController extends ApiController {
const usersEntity: Users[] = await this.usersService.get(query);
//Hydrate ressource with prisma entity
const users = ObjectHydrate.map<User>(User, usersEntity, { strategy: "exposeAll" });
const users = plainToInstance<User, Users[]>(User, usersEntity, {
enableImplicitConversion: true,
excludeExtraneousValues: false,
});
//success
this.httpSuccess(response, users);
@ -75,7 +79,7 @@ export default class UsersController extends ApiController {
try {
const uid = req.params["uid"];
if (!uid) {
throw new Error("No uuid provided");
throw new Error("No uid provided");
}
//init IUser resource with request body values
const userEntity = new User();
@ -108,11 +112,17 @@ export default class UsersController extends ApiController {
try {
const uid = req.params["uid"];
if (!uid) {
throw new Error("No uuid provided");
throw new Error("No uid provided");
}
let userEntity: Users;
//get query
if (req.query["q"]) {
const query = JSON.parse(req.query["q"] as string);
userEntity = await this.usersService.getByUid(uid, query);
} else {
//call service to get prisma entity
userEntity = await this.usersService.getByUid(uid);
}
//call service to get prisma entity
const userEntity: Users = await this.usersService.getByUid(uid);
//Hydrate ressource with prisma entity
const user = ObjectHydrate.hydrate<User>(new User(), userEntity, { strategy: "exposeAll" });

View File

@ -1,413 +0,0 @@
-- CreateEnum
CREATE TYPE "ECivility" AS ENUM ('MALE', 'FEMALE', 'OTHERS');
-- CreateEnum
CREATE TYPE "EFolderStatus" AS ENUM ('LIVE', 'ARCHIVED');
-- CreateEnum
CREATE TYPE "EOfficeStatus" AS ENUM ('ACTIVATED', 'DESACTIVATED');
-- CreateEnum
CREATE TYPE "ENotificationStatus" AS ENUM ('READ', 'UNREAD');
-- CreateEnum
CREATE TYPE "ECustomerStatus" AS ENUM ('VALIDATED', 'PENDING', 'ERRONED');
-- CreateEnum
CREATE TYPE "EDocumentStatus" AS ENUM ('ASKED', 'DEPOSITED', 'VALIDATED', 'ANCHORED', 'REFUSED');
-- CreateTable
CREATE TABLE "addresses" (
"uuid" TEXT NOT NULL,
"address" VARCHAR(255) NOT NULL,
"city" VARCHAR(255) NOT NULL,
"zip_code" INTEGER NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "addresses_pkey" PRIMARY KEY ("uuid")
);
-- CreateTable
CREATE TABLE "contacts" (
"uuid" TEXT NOT NULL,
"first_name" VARCHAR(255) NOT NULL,
"last_name" VARCHAR(255) NOT NULL,
"email" VARCHAR(255) NOT NULL,
"phone_number" VARCHAR(50),
"cell_phone_number" VARCHAR(50),
"civility" "ECivility" NOT NULL DEFAULT 'MALE',
"address_uuid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "contacts_pkey" PRIMARY KEY ("uuid")
);
-- CreateTable
CREATE TABLE "users" (
"uuid" TEXT NOT NULL,
"idNot" VARCHAR(255) NOT NULL,
"contact_uuid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"office_uuid" VARCHAR(255) NOT NULL,
CONSTRAINT "users_pkey" PRIMARY KEY ("uuid")
);
-- CreateTable
CREATE TABLE "offices" (
"uuid" TEXT NOT NULL,
"idNot" VARCHAR(255) NOT NULL,
"name" VARCHAR(255) NOT NULL,
"crpcen" VARCHAR(255) NOT NULL,
"address_uuid" VARCHAR(255) NOT NULL,
"office_status" "EOfficeStatus" NOT NULL DEFAULT 'DESACTIVATED',
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "offices_pkey" PRIMARY KEY ("uuid")
);
-- CreateTable
CREATE TABLE "customers" (
"uuid" TEXT NOT NULL,
"status" "ECustomerStatus" NOT NULL DEFAULT 'PENDING',
"contact_uuid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "customers_pkey" PRIMARY KEY ("uuid")
);
-- CreateTable
CREATE TABLE "user_has_notifications" (
"uuid" TEXT NOT NULL,
"user_uuid" VARCHAR(255) NOT NULL,
"notification_uuid" VARCHAR(255) NOT NULL,
"notification_status" "ENotificationStatus" NOT NULL DEFAULT 'UNREAD',
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "user_has_notifications_pkey" PRIMARY KEY ("uuid")
);
-- CreateTable
CREATE TABLE "notifications" (
"uuid" TEXT NOT NULL,
"message" VARCHAR(255) NOT NULL,
"redirection_url" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "notifications_pkey" PRIMARY KEY ("uuid")
);
-- CreateTable
CREATE TABLE "office_folders" (
"uuid" TEXT NOT NULL,
"folder_number" VARCHAR(255) NOT NULL,
"name" VARCHAR(255) NOT NULL,
"description" VARCHAR(255),
"archived_description" VARCHAR(255),
"status" "EFolderStatus" NOT NULL DEFAULT 'LIVE',
"deed_uuid" VARCHAR(255) NOT NULL,
"office_uuid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "office_folders_pkey" PRIMARY KEY ("uuid")
);
-- CreateTable
CREATE TABLE "office_folder_has_customers" (
"uuid" TEXT NOT NULL,
"customer_uuid" VARCHAR(255) NOT NULL,
"office_folder_uuid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "office_folder_has_customers_pkey" PRIMARY KEY ("uuid")
);
-- CreateTable
CREATE TABLE "office_folder_has_stakeholder" (
"uuid" TEXT NOT NULL,
"office_folder_uuid" VARCHAR(255) NOT NULL,
"user_stakeholder_uuid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "office_folder_has_stakeholder_pkey" PRIMARY KEY ("uuid")
);
-- CreateTable
CREATE TABLE "documents" (
"uuid" TEXT NOT NULL,
"document_status" "EDocumentStatus" NOT NULL DEFAULT 'ASKED',
"type_uuid" VARCHAR(255) NOT NULL,
"blockchain_anchor_uuid" VARCHAR(255),
"folder_uuid" VARCHAR(255) NOT NULL,
"depositor_uuid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "documents_pkey" PRIMARY KEY ("uuid")
);
-- CreateTable
CREATE TABLE "document_history" (
"uuid" TEXT NOT NULL,
"document_status" "EDocumentStatus" NOT NULL DEFAULT 'ASKED',
"refused_reason" VARCHAR(255),
"document_uuid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "document_history_pkey" PRIMARY KEY ("uuid")
);
-- CreateTable
CREATE TABLE "files" (
"uuid" TEXT NOT NULL,
"document_uuid" VARCHAR(255) NOT NULL,
"file_path" VARCHAR(255),
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "files_pkey" PRIMARY KEY ("uuid")
);
-- CreateTable
CREATE TABLE "blockchain_anchors" (
"uuid" TEXT NOT NULL,
"smartSigJobId" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "blockchain_anchors_pkey" PRIMARY KEY ("uuid")
);
-- CreateTable
CREATE TABLE "document_types" (
"uuid" TEXT NOT NULL,
"name" VARCHAR(255) NOT NULL,
"public_description" VARCHAR(255) NOT NULL,
"private_description" VARCHAR(255),
"archived_at" TIMESTAMP(3),
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "document_types_pkey" PRIMARY KEY ("uuid")
);
-- CreateTable
CREATE TABLE "deed_has_document_types" (
"uuid" TEXT NOT NULL,
"document_type_uuid" VARCHAR(255) NOT NULL,
"deed_uuid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "deed_has_document_types_pkey" PRIMARY KEY ("uuid")
);
-- CreateTable
CREATE TABLE "deed" (
"uuid" TEXT NOT NULL,
"deed_type_uuid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "deed_pkey" PRIMARY KEY ("uuid")
);
-- CreateTable
CREATE TABLE "deed_types" (
"uuid" TEXT NOT NULL,
"name" VARCHAR(255) NOT NULL,
"description" VARCHAR(255) NOT NULL,
"archived_at" TIMESTAMP(3),
"office_uuid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "deed_types_pkey" PRIMARY KEY ("uuid")
);
-- CreateTable
CREATE TABLE "deed_type_has_document_types" (
"uuid" TEXT NOT NULL,
"document_type_uuid" VARCHAR(255) NOT NULL,
"deed_type_uuid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "deed_type_has_document_types_pkey" PRIMARY KEY ("uuid")
);
-- CreateIndex
CREATE UNIQUE INDEX "addresses_uuid_key" ON "addresses"("uuid");
-- CreateIndex
CREATE UNIQUE INDEX "contacts_uuid_key" ON "contacts"("uuid");
-- CreateIndex
CREATE UNIQUE INDEX "contacts_address_uuid_key" ON "contacts"("address_uuid");
-- CreateIndex
CREATE UNIQUE INDEX "users_uuid_key" ON "users"("uuid");
-- CreateIndex
CREATE UNIQUE INDEX "users_idNot_key" ON "users"("idNot");
-- CreateIndex
CREATE UNIQUE INDEX "users_contact_uuid_key" ON "users"("contact_uuid");
-- CreateIndex
CREATE UNIQUE INDEX "offices_uuid_key" ON "offices"("uuid");
-- CreateIndex
CREATE UNIQUE INDEX "offices_idNot_key" ON "offices"("idNot");
-- CreateIndex
CREATE UNIQUE INDEX "offices_crpcen_key" ON "offices"("crpcen");
-- CreateIndex
CREATE UNIQUE INDEX "offices_address_uuid_key" ON "offices"("address_uuid");
-- CreateIndex
CREATE UNIQUE INDEX "customers_uuid_key" ON "customers"("uuid");
-- CreateIndex
CREATE UNIQUE INDEX "customers_contact_uuid_key" ON "customers"("contact_uuid");
-- CreateIndex
CREATE UNIQUE INDEX "user_has_notifications_uuid_key" ON "user_has_notifications"("uuid");
-- CreateIndex
CREATE UNIQUE INDEX "notifications_uuid_key" ON "notifications"("uuid");
-- CreateIndex
CREATE UNIQUE INDEX "office_folders_uuid_key" ON "office_folders"("uuid");
-- CreateIndex
CREATE UNIQUE INDEX "office_folders_deed_uuid_key" ON "office_folders"("deed_uuid");
-- CreateIndex
CREATE UNIQUE INDEX "office_folder_has_customers_uuid_key" ON "office_folder_has_customers"("uuid");
-- CreateIndex
CREATE UNIQUE INDEX "office_folder_has_stakeholder_uuid_key" ON "office_folder_has_stakeholder"("uuid");
-- CreateIndex
CREATE UNIQUE INDEX "documents_uuid_key" ON "documents"("uuid");
-- CreateIndex
CREATE UNIQUE INDEX "document_history_uuid_key" ON "document_history"("uuid");
-- CreateIndex
CREATE UNIQUE INDEX "files_uuid_key" ON "files"("uuid");
-- CreateIndex
CREATE UNIQUE INDEX "files_file_path_key" ON "files"("file_path");
-- CreateIndex
CREATE UNIQUE INDEX "blockchain_anchors_uuid_key" ON "blockchain_anchors"("uuid");
-- CreateIndex
CREATE UNIQUE INDEX "blockchain_anchors_smartSigJobId_key" ON "blockchain_anchors"("smartSigJobId");
-- CreateIndex
CREATE UNIQUE INDEX "document_types_uuid_key" ON "document_types"("uuid");
-- CreateIndex
CREATE UNIQUE INDEX "deed_has_document_types_uuid_key" ON "deed_has_document_types"("uuid");
-- CreateIndex
CREATE UNIQUE INDEX "deed_uuid_key" ON "deed"("uuid");
-- CreateIndex
CREATE UNIQUE INDEX "deed_deed_type_uuid_key" ON "deed"("deed_type_uuid");
-- CreateIndex
CREATE UNIQUE INDEX "deed_types_uuid_key" ON "deed_types"("uuid");
-- CreateIndex
CREATE UNIQUE INDEX "deed_type_has_document_types_uuid_key" ON "deed_type_has_document_types"("uuid");
-- AddForeignKey
ALTER TABLE "contacts" ADD CONSTRAINT "contacts_address_uuid_fkey" FOREIGN KEY ("address_uuid") REFERENCES "addresses"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_contact_uuid_fkey" FOREIGN KEY ("contact_uuid") REFERENCES "contacts"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_office_uuid_fkey" FOREIGN KEY ("office_uuid") REFERENCES "offices"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "offices" ADD CONSTRAINT "offices_address_uuid_fkey" FOREIGN KEY ("address_uuid") REFERENCES "addresses"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "customers" ADD CONSTRAINT "customers_contact_uuid_fkey" FOREIGN KEY ("contact_uuid") REFERENCES "contacts"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "user_has_notifications" ADD CONSTRAINT "user_has_notifications_user_uuid_fkey" FOREIGN KEY ("user_uuid") REFERENCES "users"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "user_has_notifications" ADD CONSTRAINT "user_has_notifications_notification_uuid_fkey" FOREIGN KEY ("notification_uuid") REFERENCES "notifications"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "office_folders" ADD CONSTRAINT "office_folders_deed_uuid_fkey" FOREIGN KEY ("deed_uuid") REFERENCES "deed"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "office_folders" ADD CONSTRAINT "office_folders_office_uuid_fkey" FOREIGN KEY ("office_uuid") REFERENCES "offices"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "office_folder_has_customers" ADD CONSTRAINT "office_folder_has_customers_customer_uuid_fkey" FOREIGN KEY ("customer_uuid") REFERENCES "customers"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "office_folder_has_customers" ADD CONSTRAINT "office_folder_has_customers_office_folder_uuid_fkey" FOREIGN KEY ("office_folder_uuid") REFERENCES "office_folders"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "office_folder_has_stakeholder" ADD CONSTRAINT "office_folder_has_stakeholder_office_folder_uuid_fkey" FOREIGN KEY ("office_folder_uuid") REFERENCES "office_folders"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "office_folder_has_stakeholder" ADD CONSTRAINT "office_folder_has_stakeholder_user_stakeholder_uuid_fkey" FOREIGN KEY ("user_stakeholder_uuid") REFERENCES "users"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "documents" ADD CONSTRAINT "documents_type_uuid_fkey" FOREIGN KEY ("type_uuid") REFERENCES "document_types"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "documents" ADD CONSTRAINT "documents_blockchain_anchor_uuid_fkey" FOREIGN KEY ("blockchain_anchor_uuid") REFERENCES "blockchain_anchors"("uuid") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "documents" ADD CONSTRAINT "documents_folder_uuid_fkey" FOREIGN KEY ("folder_uuid") REFERENCES "office_folders"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "documents" ADD CONSTRAINT "documents_depositor_uuid_fkey" FOREIGN KEY ("depositor_uuid") REFERENCES "customers"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "document_history" ADD CONSTRAINT "document_history_document_uuid_fkey" FOREIGN KEY ("document_uuid") REFERENCES "documents"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "files" ADD CONSTRAINT "files_document_uuid_fkey" FOREIGN KEY ("document_uuid") REFERENCES "documents"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "deed_has_document_types" ADD CONSTRAINT "deed_has_document_types_document_type_uuid_fkey" FOREIGN KEY ("document_type_uuid") REFERENCES "document_types"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "deed_has_document_types" ADD CONSTRAINT "deed_has_document_types_deed_uuid_fkey" FOREIGN KEY ("deed_uuid") REFERENCES "deed"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "deed" ADD CONSTRAINT "deed_deed_type_uuid_fkey" FOREIGN KEY ("deed_type_uuid") REFERENCES "deed_types"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "deed_types" ADD CONSTRAINT "deed_types_office_uuid_fkey" FOREIGN KEY ("office_uuid") REFERENCES "offices"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "deed_type_has_document_types" ADD CONSTRAINT "deed_type_has_document_types_document_type_uuid_fkey" FOREIGN KEY ("document_type_uuid") REFERENCES "document_types"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "deed_type_has_document_types" ADD CONSTRAINT "deed_type_has_document_types_deed_type_uuid_fkey" FOREIGN KEY ("deed_type_uuid") REFERENCES "deed_types"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@ -1,92 +0,0 @@
/*
Warnings:
- A unique constraint covering the columns `[address]` on the table `addresses` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[email]` on the table `contacts` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[cell_phone_number]` on the table `contacts` will be added. If there are existing duplicate values, this will fail.
*/
-- AlterTable
ALTER TABLE "addresses" ALTER COLUMN "created_at" DROP NOT NULL,
ALTER COLUMN "updated_at" DROP NOT NULL;
-- AlterTable
ALTER TABLE "blockchain_anchors" ALTER COLUMN "created_at" DROP NOT NULL,
ALTER COLUMN "updated_at" DROP NOT NULL;
-- AlterTable
ALTER TABLE "contacts" ALTER COLUMN "created_at" DROP NOT NULL,
ALTER COLUMN "updated_at" DROP NOT NULL;
-- AlterTable
ALTER TABLE "customers" ALTER COLUMN "created_at" DROP NOT NULL,
ALTER COLUMN "updated_at" DROP NOT NULL;
-- AlterTable
ALTER TABLE "deed" ALTER COLUMN "created_at" DROP NOT NULL,
ALTER COLUMN "updated_at" DROP NOT NULL;
-- AlterTable
ALTER TABLE "deed_has_document_types" ALTER COLUMN "created_at" DROP NOT NULL,
ALTER COLUMN "updated_at" DROP NOT NULL;
-- AlterTable
ALTER TABLE "deed_type_has_document_types" ALTER COLUMN "created_at" DROP NOT NULL,
ALTER COLUMN "updated_at" DROP NOT NULL;
-- AlterTable
ALTER TABLE "deed_types" ALTER COLUMN "created_at" DROP NOT NULL,
ALTER COLUMN "updated_at" DROP NOT NULL;
-- AlterTable
ALTER TABLE "document_history" ALTER COLUMN "created_at" DROP NOT NULL,
ALTER COLUMN "updated_at" DROP NOT NULL;
-- AlterTable
ALTER TABLE "document_types" ALTER COLUMN "created_at" DROP NOT NULL,
ALTER COLUMN "updated_at" DROP NOT NULL;
-- AlterTable
ALTER TABLE "documents" ALTER COLUMN "created_at" DROP NOT NULL,
ALTER COLUMN "updated_at" DROP NOT NULL;
-- AlterTable
ALTER TABLE "files" ALTER COLUMN "created_at" DROP NOT NULL,
ALTER COLUMN "updated_at" DROP NOT NULL;
-- AlterTable
ALTER TABLE "notifications" ALTER COLUMN "created_at" DROP NOT NULL,
ALTER COLUMN "updated_at" DROP NOT NULL;
-- AlterTable
ALTER TABLE "office_folder_has_customers" ALTER COLUMN "created_at" DROP NOT NULL,
ALTER COLUMN "updated_at" DROP NOT NULL;
-- AlterTable
ALTER TABLE "office_folder_has_stakeholder" ALTER COLUMN "created_at" DROP NOT NULL,
ALTER COLUMN "updated_at" DROP NOT NULL;
-- AlterTable
ALTER TABLE "office_folders" ALTER COLUMN "created_at" DROP NOT NULL,
ALTER COLUMN "updated_at" DROP NOT NULL;
-- AlterTable
ALTER TABLE "offices" ALTER COLUMN "created_at" DROP NOT NULL,
ALTER COLUMN "updated_at" DROP NOT NULL;
-- AlterTable
ALTER TABLE "user_has_notifications" ALTER COLUMN "created_at" DROP NOT NULL,
ALTER COLUMN "updated_at" DROP NOT NULL;
-- AlterTable
ALTER TABLE "users" ALTER COLUMN "created_at" DROP NOT NULL,
ALTER COLUMN "updated_at" DROP NOT NULL;
-- CreateIndex
CREATE UNIQUE INDEX "addresses_address_key" ON "addresses"("address");
-- CreateIndex
CREATE UNIQUE INDEX "contacts_email_key" ON "contacts"("email");
-- CreateIndex
CREATE UNIQUE INDEX "contacts_cell_phone_number_key" ON "contacts"("cell_phone_number");

View File

@ -1,2 +0,0 @@
-- DropIndex
DROP INDEX "addresses_address_key";

View File

@ -1,119 +0,0 @@
-- DropForeignKey
ALTER TABLE "contacts" DROP CONSTRAINT "contacts_address_uuid_fkey";
-- DropForeignKey
ALTER TABLE "customers" DROP CONSTRAINT "customers_contact_uuid_fkey";
-- DropForeignKey
ALTER TABLE "deed" DROP CONSTRAINT "deed_deed_type_uuid_fkey";
-- DropForeignKey
ALTER TABLE "deed_has_document_types" DROP CONSTRAINT "deed_has_document_types_deed_uuid_fkey";
-- DropForeignKey
ALTER TABLE "deed_has_document_types" DROP CONSTRAINT "deed_has_document_types_document_type_uuid_fkey";
-- DropForeignKey
ALTER TABLE "deed_type_has_document_types" DROP CONSTRAINT "deed_type_has_document_types_deed_type_uuid_fkey";
-- DropForeignKey
ALTER TABLE "deed_type_has_document_types" DROP CONSTRAINT "deed_type_has_document_types_document_type_uuid_fkey";
-- DropForeignKey
ALTER TABLE "deed_types" DROP CONSTRAINT "deed_types_office_uuid_fkey";
-- DropForeignKey
ALTER TABLE "document_history" DROP CONSTRAINT "document_history_document_uuid_fkey";
-- DropForeignKey
ALTER TABLE "documents" DROP CONSTRAINT "documents_depositor_uuid_fkey";
-- DropForeignKey
ALTER TABLE "files" DROP CONSTRAINT "files_document_uuid_fkey";
-- DropForeignKey
ALTER TABLE "office_folder_has_customers" DROP CONSTRAINT "office_folder_has_customers_customer_uuid_fkey";
-- DropForeignKey
ALTER TABLE "office_folder_has_customers" DROP CONSTRAINT "office_folder_has_customers_office_folder_uuid_fkey";
-- DropForeignKey
ALTER TABLE "office_folder_has_stakeholder" DROP CONSTRAINT "office_folder_has_stakeholder_office_folder_uuid_fkey";
-- DropForeignKey
ALTER TABLE "office_folder_has_stakeholder" DROP CONSTRAINT "office_folder_has_stakeholder_user_stakeholder_uuid_fkey";
-- DropForeignKey
ALTER TABLE "office_folders" DROP CONSTRAINT "office_folders_deed_uuid_fkey";
-- DropForeignKey
ALTER TABLE "office_folders" DROP CONSTRAINT "office_folders_office_uuid_fkey";
-- DropForeignKey
ALTER TABLE "offices" DROP CONSTRAINT "offices_address_uuid_fkey";
-- DropForeignKey
ALTER TABLE "user_has_notifications" DROP CONSTRAINT "user_has_notifications_notification_uuid_fkey";
-- DropForeignKey
ALTER TABLE "users" DROP CONSTRAINT "users_contact_uuid_fkey";
-- AddForeignKey
ALTER TABLE "contacts" ADD CONSTRAINT "contacts_address_uuid_fkey" FOREIGN KEY ("address_uuid") REFERENCES "addresses"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_contact_uuid_fkey" FOREIGN KEY ("contact_uuid") REFERENCES "contacts"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "offices" ADD CONSTRAINT "offices_address_uuid_fkey" FOREIGN KEY ("address_uuid") REFERENCES "addresses"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "customers" ADD CONSTRAINT "customers_contact_uuid_fkey" FOREIGN KEY ("contact_uuid") REFERENCES "contacts"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "user_has_notifications" ADD CONSTRAINT "user_has_notifications_notification_uuid_fkey" FOREIGN KEY ("notification_uuid") REFERENCES "notifications"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "office_folders" ADD CONSTRAINT "office_folders_deed_uuid_fkey" FOREIGN KEY ("deed_uuid") REFERENCES "deed"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "office_folders" ADD CONSTRAINT "office_folders_office_uuid_fkey" FOREIGN KEY ("office_uuid") REFERENCES "offices"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "office_folder_has_customers" ADD CONSTRAINT "office_folder_has_customers_customer_uuid_fkey" FOREIGN KEY ("customer_uuid") REFERENCES "customers"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "office_folder_has_customers" ADD CONSTRAINT "office_folder_has_customers_office_folder_uuid_fkey" FOREIGN KEY ("office_folder_uuid") REFERENCES "office_folders"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "office_folder_has_stakeholder" ADD CONSTRAINT "office_folder_has_stakeholder_office_folder_uuid_fkey" FOREIGN KEY ("office_folder_uuid") REFERENCES "office_folders"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "office_folder_has_stakeholder" ADD CONSTRAINT "office_folder_has_stakeholder_user_stakeholder_uuid_fkey" FOREIGN KEY ("user_stakeholder_uuid") REFERENCES "users"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "documents" ADD CONSTRAINT "documents_depositor_uuid_fkey" FOREIGN KEY ("depositor_uuid") REFERENCES "customers"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "document_history" ADD CONSTRAINT "document_history_document_uuid_fkey" FOREIGN KEY ("document_uuid") REFERENCES "documents"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "files" ADD CONSTRAINT "files_document_uuid_fkey" FOREIGN KEY ("document_uuid") REFERENCES "documents"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "deed_has_document_types" ADD CONSTRAINT "deed_has_document_types_document_type_uuid_fkey" FOREIGN KEY ("document_type_uuid") REFERENCES "document_types"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "deed_has_document_types" ADD CONSTRAINT "deed_has_document_types_deed_uuid_fkey" FOREIGN KEY ("deed_uuid") REFERENCES "deed"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "deed" ADD CONSTRAINT "deed_deed_type_uuid_fkey" FOREIGN KEY ("deed_type_uuid") REFERENCES "deed_types"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "deed_types" ADD CONSTRAINT "deed_types_office_uuid_fkey" FOREIGN KEY ("office_uuid") REFERENCES "offices"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "deed_type_has_document_types" ADD CONSTRAINT "deed_type_has_document_types_document_type_uuid_fkey" FOREIGN KEY ("document_type_uuid") REFERENCES "document_types"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "deed_type_has_document_types" ADD CONSTRAINT "deed_type_has_document_types_deed_type_uuid_fkey" FOREIGN KEY ("deed_type_uuid") REFERENCES "deed_types"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -1,8 +0,0 @@
-- DropForeignKey
ALTER TABLE "users" DROP CONSTRAINT "users_office_uuid_fkey";
-- DropIndex
DROP INDEX "deed_deed_type_uuid_key";
-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_office_uuid_fkey" FOREIGN KEY ("office_uuid") REFERENCES "offices"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -1,8 +0,0 @@
/*
Warnings:
- A unique constraint covering the columns `[name,office_uuid]` on the table `deed_types` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateIndex
CREATE UNIQUE INDEX "deed_types_name_office_uuid_key" ON "deed_types"("name", "office_uuid");

View File

@ -1,15 +0,0 @@
/*
Warnings:
- A unique constraint covering the columns `[name,office_uuid]` on the table `document_types` will be added. If there are existing duplicate values, this will fail.
- Added the required column `office_uuid` to the `document_types` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "document_types" ADD COLUMN "office_uuid" VARCHAR(255) NOT NULL;
-- CreateIndex
CREATE UNIQUE INDEX "document_types_name_office_uuid_key" ON "document_types"("name", "office_uuid");
-- AddForeignKey
ALTER TABLE "document_types" ADD CONSTRAINT "document_types_office_uuid_fkey" FOREIGN KEY ("office_uuid") REFERENCES "offices"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -1,24 +0,0 @@
/*
Warnings:
- A unique constraint covering the columns `[deed_uuid,document_type_uuid]` on the table `deed_has_document_types` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[deed_type_uuid,document_type_uuid]` on the table `deed_type_has_document_types` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[customer_uuid,office_folder_uuid]` on the table `office_folder_has_customers` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[office_folder_uuid,user_stakeholder_uuid]` on the table `office_folder_has_stakeholder` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[notification_uuid,user_uuid]` on the table `user_has_notifications` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateIndex
CREATE UNIQUE INDEX "deed_has_document_types_deed_uuid_document_type_uuid_key" ON "deed_has_document_types"("deed_uuid", "document_type_uuid");
-- CreateIndex
CREATE UNIQUE INDEX "deed_type_has_document_types_deed_type_uuid_document_type_u_key" ON "deed_type_has_document_types"("deed_type_uuid", "document_type_uuid");
-- CreateIndex
CREATE UNIQUE INDEX "office_folder_has_customers_customer_uuid_office_folder_uui_key" ON "office_folder_has_customers"("customer_uuid", "office_folder_uuid");
-- CreateIndex
CREATE UNIQUE INDEX "office_folder_has_stakeholder_office_folder_uuid_user_stake_key" ON "office_folder_has_stakeholder"("office_folder_uuid", "user_stakeholder_uuid");
-- CreateIndex
CREATE UNIQUE INDEX "user_has_notifications_notification_uuid_user_uuid_key" ON "user_has_notifications"("notification_uuid", "user_uuid");

View File

@ -1,20 +0,0 @@
/*
Warnings:
- You are about to drop the column `type_uuid` on the `documents` table. All the data in the column will be lost.
- Added the required column `document_type_uuid` to the `documents` table without a default value. This is not possible if the table is not empty.
- Made the column `file_path` on table `files` required. This step will fail if there are existing NULL values in that column.
*/
-- DropForeignKey
ALTER TABLE "documents" DROP CONSTRAINT "documents_type_uuid_fkey";
-- AlterTable
ALTER TABLE "documents" DROP COLUMN "type_uuid",
ADD COLUMN "document_type_uuid" VARCHAR(255) NOT NULL;
-- AlterTable
ALTER TABLE "files" ALTER COLUMN "file_path" SET NOT NULL;
-- AddForeignKey
ALTER TABLE "documents" ADD CONSTRAINT "documents_document_type_uuid_fkey" FOREIGN KEY ("document_type_uuid") REFERENCES "document_types"("uuid") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

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

View File

@ -0,0 +1,445 @@
-- CreateEnum
CREATE TYPE "ECivility" AS ENUM ('MALE', 'FEMALE', 'OTHERS');
-- CreateEnum
CREATE TYPE "EFolderStatus" AS ENUM ('LIVE', 'ARCHIVED');
-- CreateEnum
CREATE TYPE "EOfficeStatus" AS ENUM ('ACTIVATED', 'DESACTIVATED');
-- CreateEnum
CREATE TYPE "ENotificationStatus" AS ENUM ('READ', 'UNREAD');
-- CreateEnum
CREATE TYPE "ECustomerStatus" AS ENUM ('VALIDATED', 'PENDING', 'ERRONED');
-- CreateEnum
CREATE TYPE "EDocumentStatus" AS ENUM ('ASKED', 'DEPOSITED', 'VALIDATED', 'ANCHORED', 'REFUSED');
-- CreateTable
CREATE TABLE "addresses" (
"uid" TEXT NOT NULL,
"address" VARCHAR(255) NOT NULL,
"city" VARCHAR(255) NOT NULL,
"zip_code" INTEGER NOT NULL,
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3),
CONSTRAINT "addresses_pkey" PRIMARY KEY ("uid")
);
-- CreateTable
CREATE TABLE "contacts" (
"uid" TEXT NOT NULL,
"first_name" VARCHAR(255) NOT NULL,
"last_name" VARCHAR(255) NOT NULL,
"email" VARCHAR(255) NOT NULL,
"phone_number" VARCHAR(50),
"cell_phone_number" VARCHAR(50),
"civility" "ECivility" NOT NULL DEFAULT 'MALE',
"address_uid" VARCHAR(255) NOT NULL,
"birthdate" TIMESTAMP(3),
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3),
CONSTRAINT "contacts_pkey" PRIMARY KEY ("uid")
);
-- CreateTable
CREATE TABLE "users" (
"uid" TEXT NOT NULL,
"idNot" VARCHAR(255) NOT NULL,
"contact_uid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3),
"office_uid" VARCHAR(255) NOT NULL,
CONSTRAINT "users_pkey" PRIMARY KEY ("uid")
);
-- CreateTable
CREATE TABLE "offices" (
"uid" TEXT NOT NULL,
"idNot" VARCHAR(255) NOT NULL,
"name" VARCHAR(255) NOT NULL,
"crpcen" VARCHAR(255) NOT NULL,
"address_uid" VARCHAR(255) NOT NULL,
"office_status" "EOfficeStatus" NOT NULL DEFAULT 'DESACTIVATED',
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3),
CONSTRAINT "offices_pkey" PRIMARY KEY ("uid")
);
-- CreateTable
CREATE TABLE "customers" (
"uid" TEXT NOT NULL,
"status" "ECustomerStatus" NOT NULL DEFAULT 'PENDING',
"contact_uid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3),
CONSTRAINT "customers_pkey" PRIMARY KEY ("uid")
);
-- CreateTable
CREATE TABLE "user_has_notifications" (
"uid" TEXT NOT NULL,
"user_uid" VARCHAR(255) NOT NULL,
"notification_uid" VARCHAR(255) NOT NULL,
"notification_status" "ENotificationStatus" NOT NULL DEFAULT 'UNREAD',
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3),
CONSTRAINT "user_has_notifications_pkey" PRIMARY KEY ("uid")
);
-- CreateTable
CREATE TABLE "notifications" (
"uid" TEXT NOT NULL,
"message" VARCHAR(255) NOT NULL,
"redirection_url" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3),
CONSTRAINT "notifications_pkey" PRIMARY KEY ("uid")
);
-- CreateTable
CREATE TABLE "office_folders" (
"uid" TEXT NOT NULL,
"folder_number" VARCHAR(255) NOT NULL,
"name" VARCHAR(255) NOT NULL,
"description" VARCHAR(255),
"archived_description" VARCHAR(255),
"status" "EFolderStatus" NOT NULL DEFAULT 'LIVE',
"deed_uid" VARCHAR(255) NOT NULL,
"office_uid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3),
CONSTRAINT "office_folders_pkey" PRIMARY KEY ("uid")
);
-- CreateTable
CREATE TABLE "office_folder_has_customers" (
"uid" TEXT NOT NULL,
"customer_uid" VARCHAR(255) NOT NULL,
"office_folder_uid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3),
CONSTRAINT "office_folder_has_customers_pkey" PRIMARY KEY ("uid")
);
-- CreateTable
CREATE TABLE "office_folder_has_stakeholder" (
"uid" TEXT NOT NULL,
"office_folder_uid" VARCHAR(255) NOT NULL,
"user_stakeholder_uid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3),
CONSTRAINT "office_folder_has_stakeholder_pkey" PRIMARY KEY ("uid")
);
-- CreateTable
CREATE TABLE "documents" (
"uid" TEXT NOT NULL,
"document_status" "EDocumentStatus" NOT NULL DEFAULT 'ASKED',
"document_type_uid" VARCHAR(255) NOT NULL,
"blockchain_anchor_uid" VARCHAR(255),
"folder_uid" VARCHAR(255) NOT NULL,
"depositor_uid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3),
CONSTRAINT "documents_pkey" PRIMARY KEY ("uid")
);
-- CreateTable
CREATE TABLE "document_history" (
"uid" TEXT NOT NULL,
"document_status" "EDocumentStatus" NOT NULL DEFAULT 'ASKED',
"refused_reason" VARCHAR(255),
"document_uid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3),
CONSTRAINT "document_history_pkey" PRIMARY KEY ("uid")
);
-- CreateTable
CREATE TABLE "files" (
"uid" TEXT NOT NULL,
"document_uid" VARCHAR(255) NOT NULL,
"file_path" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3),
CONSTRAINT "files_pkey" PRIMARY KEY ("uid")
);
-- CreateTable
CREATE TABLE "blockchain_anchors" (
"uid" TEXT NOT NULL,
"smartSigJobId" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3),
CONSTRAINT "blockchain_anchors_pkey" PRIMARY KEY ("uid")
);
-- CreateTable
CREATE TABLE "document_types" (
"uid" TEXT NOT NULL,
"name" VARCHAR(255) NOT NULL,
"public_description" VARCHAR(255) NOT NULL,
"private_description" VARCHAR(255),
"office_uid" VARCHAR(255) NOT NULL,
"archived_at" TIMESTAMP(3),
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3),
CONSTRAINT "document_types_pkey" PRIMARY KEY ("uid")
);
-- CreateTable
CREATE TABLE "deed_has_document_types" (
"uid" TEXT NOT NULL,
"document_type_uid" VARCHAR(255) NOT NULL,
"deed_uid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3),
CONSTRAINT "deed_has_document_types_pkey" PRIMARY KEY ("uid")
);
-- CreateTable
CREATE TABLE "deed" (
"uid" TEXT NOT NULL,
"deed_type_uid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3),
CONSTRAINT "deed_pkey" PRIMARY KEY ("uid")
);
-- CreateTable
CREATE TABLE "deed_types" (
"uid" TEXT NOT NULL,
"name" VARCHAR(255) NOT NULL,
"description" VARCHAR(255) NOT NULL,
"archived_at" TIMESTAMP(3),
"office_uid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3),
CONSTRAINT "deed_types_pkey" PRIMARY KEY ("uid")
);
-- CreateTable
CREATE TABLE "deed_type_has_document_types" (
"uid" TEXT NOT NULL,
"document_type_uid" VARCHAR(255) NOT NULL,
"deed_type_uid" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3),
CONSTRAINT "deed_type_has_document_types_pkey" PRIMARY KEY ("uid")
);
-- CreateIndex
CREATE UNIQUE INDEX "addresses_uid_key" ON "addresses"("uid");
-- CreateIndex
CREATE UNIQUE INDEX "contacts_uid_key" ON "contacts"("uid");
-- CreateIndex
CREATE UNIQUE INDEX "contacts_email_key" ON "contacts"("email");
-- CreateIndex
CREATE UNIQUE INDEX "contacts_cell_phone_number_key" ON "contacts"("cell_phone_number");
-- CreateIndex
CREATE UNIQUE INDEX "contacts_address_uid_key" ON "contacts"("address_uid");
-- CreateIndex
CREATE UNIQUE INDEX "users_uid_key" ON "users"("uid");
-- CreateIndex
CREATE UNIQUE INDEX "users_idNot_key" ON "users"("idNot");
-- CreateIndex
CREATE UNIQUE INDEX "users_contact_uid_key" ON "users"("contact_uid");
-- CreateIndex
CREATE UNIQUE INDEX "offices_uid_key" ON "offices"("uid");
-- CreateIndex
CREATE UNIQUE INDEX "offices_idNot_key" ON "offices"("idNot");
-- CreateIndex
CREATE UNIQUE INDEX "offices_crpcen_key" ON "offices"("crpcen");
-- CreateIndex
CREATE UNIQUE INDEX "offices_address_uid_key" ON "offices"("address_uid");
-- CreateIndex
CREATE UNIQUE INDEX "customers_uid_key" ON "customers"("uid");
-- CreateIndex
CREATE UNIQUE INDEX "customers_contact_uid_key" ON "customers"("contact_uid");
-- CreateIndex
CREATE UNIQUE INDEX "user_has_notifications_uid_key" ON "user_has_notifications"("uid");
-- CreateIndex
CREATE UNIQUE INDEX "user_has_notifications_notification_uid_user_uid_key" ON "user_has_notifications"("notification_uid", "user_uid");
-- CreateIndex
CREATE UNIQUE INDEX "notifications_uid_key" ON "notifications"("uid");
-- CreateIndex
CREATE UNIQUE INDEX "office_folders_uid_key" ON "office_folders"("uid");
-- CreateIndex
CREATE UNIQUE INDEX "office_folders_deed_uid_key" ON "office_folders"("deed_uid");
-- CreateIndex
CREATE UNIQUE INDEX "office_folders_folder_number_office_uid_key" ON "office_folders"("folder_number", "office_uid");
-- CreateIndex
CREATE UNIQUE INDEX "office_folder_has_customers_uid_key" ON "office_folder_has_customers"("uid");
-- CreateIndex
CREATE UNIQUE INDEX "office_folder_has_customers_office_folder_uid_customer_uid_key" ON "office_folder_has_customers"("office_folder_uid", "customer_uid");
-- CreateIndex
CREATE UNIQUE INDEX "office_folder_has_stakeholder_uid_key" ON "office_folder_has_stakeholder"("uid");
-- CreateIndex
CREATE UNIQUE INDEX "office_folder_has_stakeholder_office_folder_uid_user_stakeh_key" ON "office_folder_has_stakeholder"("office_folder_uid", "user_stakeholder_uid");
-- CreateIndex
CREATE UNIQUE INDEX "documents_uid_key" ON "documents"("uid");
-- CreateIndex
CREATE UNIQUE INDEX "document_history_uid_key" ON "document_history"("uid");
-- CreateIndex
CREATE UNIQUE INDEX "files_uid_key" ON "files"("uid");
-- CreateIndex
CREATE UNIQUE INDEX "files_file_path_key" ON "files"("file_path");
-- CreateIndex
CREATE UNIQUE INDEX "blockchain_anchors_uid_key" ON "blockchain_anchors"("uid");
-- CreateIndex
CREATE UNIQUE INDEX "blockchain_anchors_smartSigJobId_key" ON "blockchain_anchors"("smartSigJobId");
-- CreateIndex
CREATE UNIQUE INDEX "document_types_uid_key" ON "document_types"("uid");
-- CreateIndex
CREATE UNIQUE INDEX "document_types_name_office_uid_key" ON "document_types"("name", "office_uid");
-- CreateIndex
CREATE UNIQUE INDEX "deed_has_document_types_uid_key" ON "deed_has_document_types"("uid");
-- CreateIndex
CREATE UNIQUE INDEX "deed_has_document_types_deed_uid_document_type_uid_key" ON "deed_has_document_types"("deed_uid", "document_type_uid");
-- CreateIndex
CREATE UNIQUE INDEX "deed_uid_key" ON "deed"("uid");
-- CreateIndex
CREATE UNIQUE INDEX "deed_types_uid_key" ON "deed_types"("uid");
-- CreateIndex
CREATE UNIQUE INDEX "deed_types_name_office_uid_key" ON "deed_types"("name", "office_uid");
-- CreateIndex
CREATE UNIQUE INDEX "deed_type_has_document_types_uid_key" ON "deed_type_has_document_types"("uid");
-- CreateIndex
CREATE UNIQUE INDEX "deed_type_has_document_types_deed_type_uid_document_type_ui_key" ON "deed_type_has_document_types"("deed_type_uid", "document_type_uid");
-- AddForeignKey
ALTER TABLE "contacts" ADD CONSTRAINT "contacts_address_uid_fkey" FOREIGN KEY ("address_uid") REFERENCES "addresses"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_contact_uid_fkey" FOREIGN KEY ("contact_uid") REFERENCES "contacts"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_office_uid_fkey" FOREIGN KEY ("office_uid") REFERENCES "offices"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "offices" ADD CONSTRAINT "offices_address_uid_fkey" FOREIGN KEY ("address_uid") REFERENCES "addresses"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "customers" ADD CONSTRAINT "customers_contact_uid_fkey" FOREIGN KEY ("contact_uid") REFERENCES "contacts"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "user_has_notifications" ADD CONSTRAINT "user_has_notifications_user_uid_fkey" FOREIGN KEY ("user_uid") REFERENCES "users"("uid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "user_has_notifications" ADD CONSTRAINT "user_has_notifications_notification_uid_fkey" FOREIGN KEY ("notification_uid") REFERENCES "notifications"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "office_folders" ADD CONSTRAINT "office_folders_deed_uid_fkey" FOREIGN KEY ("deed_uid") REFERENCES "deed"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "office_folders" ADD CONSTRAINT "office_folders_office_uid_fkey" FOREIGN KEY ("office_uid") REFERENCES "offices"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "office_folder_has_customers" ADD CONSTRAINT "office_folder_has_customers_customer_uid_fkey" FOREIGN KEY ("customer_uid") REFERENCES "customers"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "office_folder_has_customers" ADD CONSTRAINT "office_folder_has_customers_office_folder_uid_fkey" FOREIGN KEY ("office_folder_uid") REFERENCES "office_folders"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "office_folder_has_stakeholder" ADD CONSTRAINT "office_folder_has_stakeholder_office_folder_uid_fkey" FOREIGN KEY ("office_folder_uid") REFERENCES "office_folders"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "office_folder_has_stakeholder" ADD CONSTRAINT "office_folder_has_stakeholder_user_stakeholder_uid_fkey" FOREIGN KEY ("user_stakeholder_uid") REFERENCES "users"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "documents" ADD CONSTRAINT "documents_document_type_uid_fkey" FOREIGN KEY ("document_type_uid") REFERENCES "document_types"("uid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "documents" ADD CONSTRAINT "documents_blockchain_anchor_uid_fkey" FOREIGN KEY ("blockchain_anchor_uid") REFERENCES "blockchain_anchors"("uid") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "documents" ADD CONSTRAINT "documents_folder_uid_fkey" FOREIGN KEY ("folder_uid") REFERENCES "office_folders"("uid") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "documents" ADD CONSTRAINT "documents_depositor_uid_fkey" FOREIGN KEY ("depositor_uid") REFERENCES "customers"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "document_history" ADD CONSTRAINT "document_history_document_uid_fkey" FOREIGN KEY ("document_uid") REFERENCES "documents"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "files" ADD CONSTRAINT "files_document_uid_fkey" FOREIGN KEY ("document_uid") REFERENCES "documents"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "document_types" ADD CONSTRAINT "document_types_office_uid_fkey" FOREIGN KEY ("office_uid") REFERENCES "offices"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "deed_has_document_types" ADD CONSTRAINT "deed_has_document_types_document_type_uid_fkey" FOREIGN KEY ("document_type_uid") REFERENCES "document_types"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "deed_has_document_types" ADD CONSTRAINT "deed_has_document_types_deed_uid_fkey" FOREIGN KEY ("deed_uid") REFERENCES "deed"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "deed" ADD CONSTRAINT "deed_deed_type_uid_fkey" FOREIGN KEY ("deed_type_uid") REFERENCES "deed_types"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "deed_types" ADD CONSTRAINT "deed_types_office_uid_fkey" FOREIGN KEY ("office_uid") REFERENCES "offices"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "deed_type_has_document_types" ADD CONSTRAINT "deed_type_has_document_types_document_type_uid_fkey" FOREIGN KEY ("document_type_uid") REFERENCES "document_types"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "deed_type_has_document_types" ADD CONSTRAINT "deed_type_has_document_types_deed_type_uid_fkey" FOREIGN KEY ("deed_type_uid") REFERENCES "deed_types"("uid") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -18,7 +18,7 @@ datasource db {
// id String @unique @default(auto()) @map("_id") @db.ObjectId // @map de la table checker le naming avec le tiret
model Addresses {
uuid String @id @unique @default(uuid())
uid String @id @unique @default(uuid())
address String @db.VarChar(255)
city String @db.VarChar(255)
zip_code Int
@ -31,15 +31,15 @@ model Addresses {
}
model Contacts {
uuid String @id @unique @default(uuid())
uid String @id @unique @default(uuid())
first_name String @db.VarChar(255)
last_name String @db.VarChar(255)
email String @unique @db.VarChar(255)
phone_number String? @db.VarChar(50)
cell_phone_number String? @unique @db.VarChar(50)
civility ECivility @default(MALE)
address Addresses? @relation(fields: [address_uuid], references: [uuid], onDelete: Cascade)
address_uuid String @unique @db.VarChar(255)
address Addresses? @relation(fields: [address_uid], references: [uid], onDelete: Cascade)
address_uid String @unique @db.VarChar(255)
birthdate DateTime?
created_at DateTime? @default(now())
updated_at DateTime? @updatedAt
@ -50,14 +50,14 @@ model Contacts {
}
model Users {
uuid String @id @unique @default(uuid())
uid String @id @unique @default(uuid()) @map("uid")
idNot String @unique @db.VarChar(255)
contact Contacts @relation(fields: [contact_uuid], references: [uuid], onDelete: Cascade)
contact_uuid String @unique @db.VarChar(255)
contact Contacts @relation(fields: [contact_uid], references: [uid], onDelete: Cascade)
contact_uid String @unique @db.VarChar(255)
created_at DateTime? @default(now())
updated_at DateTime? @updatedAt
office_membership Offices @relation(fields: [office_uuid], references: [uuid], onDelete: Cascade)
office_uuid String @db.VarChar(255)
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[]
@ -65,12 +65,12 @@ model Users {
}
model Offices {
uuid String @id @unique @default(uuid())
uid String @id @unique @default(uuid())
idNot String @unique @db.VarChar(255)
name String @db.VarChar(255)
crpcen String @unique @db.VarChar(255)
address Addresses @relation(fields: [address_uuid], references: [uuid], onDelete: Cascade)
address_uuid String @unique @db.VarChar(255)
address Addresses @relation(fields: [address_uid], references: [uid], onDelete: Cascade)
address_uid String @unique @db.VarChar(255)
office_status EOfficeStatus @default(DESACTIVATED)
created_at DateTime? @default(now())
updated_at DateTime? @updatedAt
@ -83,10 +83,10 @@ model Offices {
}
model Customers {
uuid String @id @unique @default(uuid())
uid String @id @unique @default(uuid())
status ECustomerStatus @default(PENDING)
contact Contacts @relation(fields: [contact_uuid], references: [uuid], onDelete: Cascade)
contact_uuid String @unique @db.VarChar(255)
contact Contacts @relation(fields: [contact_uid], references: [uid], onDelete: Cascade)
contact_uid String @unique @db.VarChar(255)
created_at DateTime? @default(now())
updated_at DateTime? @updatedAt
office_folder_has_customers OfficeFolderHasCustomers[]
@ -96,21 +96,21 @@ model Customers {
}
model UserHasNotifications {
uuid String @id @unique @default(uuid())
user Users @relation(fields: [user_uuid], references: [uuid])
user_uuid String @db.VarChar(255)
notification Notifications @relation(fields: [notification_uuid], references: [uuid], onDelete: Cascade)
notification_uuid String @db.VarChar(255)
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_uuid, user_uuid])
@@unique([notification_uid, user_uid])
@@map("user_has_notifications")
}
model Notifications {
uuid String @id @unique @default(uuid())
uid String @id @unique @default(uuid())
message String @db.VarChar(255)
redirection_url String @db.VarChar(255)
created_at DateTime? @default(now())
@ -121,63 +121,63 @@ model Notifications {
}
model OfficeFolders {
uuid String @id @unique @default(uuid())
uid String @id @unique @default(uuid())
folder_number String @db.VarChar(255)
name String @db.VarChar(255)
description String? @db.VarChar(255)
archived_description String? @db.VarChar(255)
status EFolderStatus @default(LIVE)
deed Deeds @relation(fields: [deed_uuid], references: [uuid], onDelete: Cascade)
deed_uuid String @unique @db.VarChar(255)
office Offices @relation(fields: [office_uuid], references: [uuid], onDelete: Cascade)
office_uuid String @db.VarChar(255)
deed Deeds @relation(fields: [deed_uid], references: [uid], onDelete: Cascade)
deed_uid String @unique @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
office_folder_has_customers OfficeFolderHasCustomers[]
office_folder_has_stakeholder OfficeFolderHasStakeholders[]
documents Documents[]
@@unique([folder_number, office_uuid])
@@unique([folder_number, office_uid])
@@map("office_folders")
}
model OfficeFolderHasCustomers {
uuid String @id @unique @default(uuid())
customer Customers @relation(fields: [customer_uuid], references: [uuid], onDelete: Cascade)
customer_uuid String @db.VarChar(255)
office_folder OfficeFolders @relation(fields: [office_folder_uuid], references: [uuid], onDelete: Cascade)
office_folder_uuid String @db.VarChar(255)
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_uuid, customer_uuid])
@@unique([office_folder_uid, customer_uid])
@@map("office_folder_has_customers")
}
model OfficeFolderHasStakeholders {
uuid String @id @unique @default(uuid())
office_folder OfficeFolders @relation(fields: [office_folder_uuid], references: [uuid], onDelete: Cascade)
office_folder_uuid String @db.VarChar(255)
user_stakeholder Users @relation(fields: [user_stakeholder_uuid], references: [uuid], onDelete: Cascade)
user_stakeholder_uuid String @db.VarChar(255)
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_uuid, user_stakeholder_uuid])
@@unique([office_folder_uid, user_stakeholder_uid])
@@map("office_folder_has_stakeholder")
}
model Documents {
uuid String @id @unique @default(uuid())
uid String @id @unique @default(uuid())
document_status EDocumentStatus @default(ASKED)
document_type DocumentTypes @relation(fields: [document_type_uuid], references: [uuid])
document_type_uuid String @db.VarChar(255)
blockchain_anchor BlockchainAnchors? @relation(fields: [blockchain_anchor_uuid], references: [uuid])
blockchain_anchor_uuid String? @db.VarChar(255)
folder OfficeFolders @relation(fields: [folder_uuid], references: [uuid])
folder_uuid String @db.VarChar(255)
depositor Customers @relation(fields: [depositor_uuid], references: [uuid], onDelete: Cascade)
depositor_uuid String @db.VarChar(255)
document_type DocumentTypes @relation(fields: [document_type_uid], references: [uid])
document_type_uid String @db.VarChar(255)
blockchain_anchor BlockchainAnchors? @relation(fields: [blockchain_anchor_uid], references: [uid])
blockchain_anchor_uid String? @db.VarChar(255)
folder OfficeFolders @relation(fields: [folder_uid], references: [uid])
folder_uid String @db.VarChar(255)
depositor Customers @relation(fields: [depositor_uid], references: [uid], onDelete: Cascade)
depositor_uid String @db.VarChar(255)
created_at DateTime? @default(now())
updated_at DateTime? @updatedAt
files Files[]
@ -187,11 +187,11 @@ model Documents {
}
model DocumentHistory {
uuid String @id @unique @default(uuid())
uid String @id @unique @default(uuid())
document_status EDocumentStatus @default(ASKED)
refused_reason String? @db.VarChar(255)
document Documents @relation(fields: [document_uuid], references: [uuid], onDelete: Cascade)
document_uuid String @db.VarChar(255)
document Documents @relation(fields: [document_uid], references: [uid], onDelete: Cascade)
document_uid String @db.VarChar(255)
created_at DateTime? @default(now())
updated_at DateTime? @updatedAt
@ -199,9 +199,9 @@ model DocumentHistory {
}
model Files {
uuid String @id @unique @default(uuid())
document Documents @relation(fields: [document_uuid], references: [uuid], onDelete: Cascade)
document_uuid String @db.VarChar(255)
uid String @id @unique @default(uuid())
document Documents @relation(fields: [document_uid], references: [uid], onDelete: Cascade)
document_uid String @db.VarChar(255)
file_path String @unique @db.VarChar(255)
created_at DateTime? @default(now())
updated_at DateTime? @updatedAt
@ -210,7 +210,7 @@ model Files {
}
model BlockchainAnchors {
uuid String @id @unique @default(uuid())
uid String @id @unique @default(uuid())
smartSigJobId String @unique @db.VarChar(255)
created_at DateTime? @default(now())
updated_at DateTime? @updatedAt
@ -220,12 +220,12 @@ model BlockchainAnchors {
}
model DocumentTypes {
uuid String @id @unique @default(uuid())
uid String @id @unique @default(uuid())
name String @db.VarChar(255)
public_description String @db.VarChar(255)
private_description String? @db.VarChar(255)
office Offices @relation(fields: [office_uuid], references: [uuid], onDelete: Cascade)
office_uuid String @db.VarChar(255)
office Offices @relation(fields: [office_uid], references: [uid], onDelete: Cascade)
office_uid String @db.VarChar(255)
archived_at DateTime?
created_at DateTime? @default(now())
updated_at DateTime? @updatedAt
@ -233,27 +233,27 @@ model DocumentTypes {
deed_has_document_types DeedHasDocumentTypes[]
deed_type_has_document_types DeedTypeHasDocumentTypes[]
@@unique([name, office_uuid])
@@unique([name, office_uid])
@@map("document_types")
}
model DeedHasDocumentTypes {
uuid String @id @unique @default(uuid())
document_type DocumentTypes @relation(fields: [document_type_uuid], references: [uuid], onDelete: Cascade)
document_type_uuid String @db.VarChar(255)
deed Deeds @relation(fields: [deed_uuid], references: [uuid], onDelete: Cascade)
deed_uuid String @db.VarChar(255)
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_uuid, document_type_uuid])
@@unique([deed_uid, document_type_uid])
@@map("deed_has_document_types")
}
model Deeds {
uuid String @id @unique @default(uuid())
deed_type DeedTypes @relation(fields: [deed_type_uuid], references: [uuid], onDelete: Cascade)
deed_type_uuid String @db.VarChar(255)
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[]
@ -263,31 +263,31 @@ model Deeds {
}
model DeedTypes {
uuid String @id @unique @default(uuid())
uid String @id @unique @default(uuid())
name String @db.VarChar(255)
description String @db.VarChar(255)
archived_at DateTime?
office Offices @relation(fields: [office_uuid], references: [uuid], onDelete: Cascade)
office_uuid 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
deed Deeds[]
deed_type_has_document_types DeedTypeHasDocumentTypes[]
@@unique([name, office_uuid])
@@unique([name, office_uid])
@@map("deed_types")
}
model DeedTypeHasDocumentTypes {
uuid String @id @unique @default(uuid())
document_type DocumentTypes @relation(fields: [document_type_uuid], references: [uuid], onDelete: Cascade)
document_type_uuid String @db.VarChar(255)
deed_type DeedTypes @relation(fields: [deed_type_uuid], references: [uuid], onDelete: Cascade)
deed_type_uuid String @db.VarChar(255)
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_uuid, document_type_uuid])
@@unique([deed_type_uid, document_type_uid])
@@map("deed_type_has_document_types")
}

View File

@ -38,62 +38,68 @@ import {
for (let i = 10; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
return result;
};
const uuidCustomer1: string = randomString();
const uuidCustomer2: string = randomString();
const uidCustomer1: string = randomString();
const uidCustomer2: string = randomString();
const uuidContact1: string = randomString();
const uuidContact2: string = randomString();
const uidContact1: string = randomString();
const uidContact2: string = randomString();
const uuidAddress1: string = randomString();
const uuidAddress2: string = randomString();
const uidAddress1: string = randomString();
const uidAddress2: string = randomString();
const uuidOffice1: string = randomString();
const uuidOffice2: string = randomString();
const uidOffice1: string = randomString();
const uidOffice2: string = randomString();
const uuidUser1: string = randomString();
const uuidUser2: string = randomString();
const uidUser1: string = randomString();
const uidUser2: string = randomString();
const uuidOfficeFolder1: string = randomString();
const uuidOfficeFolder2: string = randomString();
const uidOfficeFolder1: string = randomString();
const uidOfficeFolder2: string = randomString();
const uidOfficeFolder3: string = randomString();
const uidOfficeFolder4: string = randomString();
const uidOfficeFolder5: string = randomString();
const uuidDeed1: string = randomString();
const uuidDeed2: string = randomString();
const uidDeed1: string = randomString();
const uidDeed2: string = randomString();
const uidDeed3: string = randomString();
const uidDeed4: string = randomString();
const uidDeed5: string = randomString();
const uuidDeedType1: string = randomString();
const uuidDeedType2: string = randomString();
const uidDeedType1: string = randomString();
const uidDeedType2: string = randomString();
const uuidDocument1: string = randomString();
const uuidDocument2: string = randomString();
const uidDocument1: string = randomString();
const uidDocument2: string = randomString();
const uuidDocumentType1: string = randomString();
const uuidDocumentType2: string = randomString();
const uidDocumentType1: string = randomString();
const uidDocumentType2: string = randomString();
const uuidOfficeFolderHasCustomer1: string = randomString();
const uuidOfficeFolderHasCustomer2: string = randomString();
const uidOfficeFolderHasCustomer1: string = randomString();
const uidOfficeFolderHasCustomer2: string = randomString();
const uuidFiles1: string = randomString();
const uuidFiles2: string = randomString();
const uidFiles1: string = randomString();
const uidFiles2: string = randomString();
const uuidDeedHasDocumentType1: string = randomString();
const uuidDeedHasDocumentType2: string = randomString();
const uidDeedHasDocumentType1: string = randomString();
const uidDeedHasDocumentType2: string = randomString();
const uuidDeedTypeHasDocumentType1: string = randomString();
const uuidDeedTypeHasDocumentType2: string = randomString();
const uidDeedTypeHasDocumentType1: string = randomString();
const uidDeedTypeHasDocumentType2: string = randomString();
const uuidDocumentHistory1: string = randomString();
const uuidDocumentHistory2: string = randomString();
const uidDocumentHistory1: string = randomString();
const uidDocumentHistory2: string = randomString();
const customers: Customers[] = [
{
uuid: uuidCustomer1,
contact_uuid: uuidContact1,
uid: uidCustomer1,
contact_uid: uidContact1,
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
},
{
uuid: uuidCustomer2,
contact_uuid: uuidContact2,
uid: uidCustomer2,
contact_uid: uidContact2,
created_at: new Date(),
updated_at: new Date(),
status: ECustomerStatus.PENDING,
@ -102,7 +108,7 @@ import {
const addresses: Addresses[] = [
{
uuid: uuidAddress1,
uid: uidAddress1,
address: "123 Main St",
city: "Los Angeles",
zip_code: 90001,
@ -110,7 +116,7 @@ import {
updated_at: new Date(),
},
{
uuid: uuidAddress2,
uid: uidAddress2,
address: "Rue Pierre Emillion",
city: "Paris",
zip_code: 75003,
@ -121,8 +127,8 @@ import {
const contacts: Contacts[] = [
{
uuid: uuidContact1,
address_uuid: uuidAddress1,
uid: uidContact1,
address_uid: uidAddress1,
first_name: "John",
last_name: "Doe",
email: "john.doe@example.com",
@ -134,8 +140,8 @@ import {
civility: ECivility.MALE,
},
{
uuid: uuidContact2,
address_uuid: uuidAddress2,
uid: uidContact2,
address_uid: uidAddress2,
first_name: "Jane",
last_name: "Doe",
email: "jane.doe@example.com",
@ -150,21 +156,21 @@ import {
const offices: Offices[] = [
{
uuid: uuidOffice1,
uid: uidOffice1,
idNot: randomString(),
name: "LA Office",
crpcen: randomString(),
address_uuid: uuidAddress1,
address_uid: uidAddress1,
created_at: new Date(),
updated_at: new Date(),
office_status: EOfficeStatus.ACTIVATED,
},
{
uuid: uuidOffice2,
uid: uidOffice2,
idNot: randomString(),
name: "NYC Office",
crpcen: randomString(),
address_uuid: uuidAddress2,
address_uid: uidAddress2,
created_at: new Date(),
updated_at: new Date(),
office_status: EOfficeStatus.DESACTIVATED,
@ -173,81 +179,135 @@ import {
const users: Users[] = [
{
uuid: uuidUser1,
uid: uidUser1,
created_at: new Date(),
updated_at: new Date(),
idNot: randomString(),
contact_uuid: uuidContact1,
office_uuid: uuidOffice1,
contact_uid: uidContact1,
office_uid: uidOffice1,
},
{
uuid: uuidUser2,
uid: uidUser2,
created_at: new Date(),
updated_at: new Date(),
idNot: randomString(),
contact_uuid: uuidContact2,
office_uuid: uuidOffice2,
contact_uid: uidContact2,
office_uid: uidOffice2,
},
];
const officeFolders: OfficeFolders[] = [
{
uuid: uuidOfficeFolder1,
folder_number: randomString(),
name: "0001",
deed_uuid: uuidDeed1,
uid: uidOfficeFolder1,
folder_number: "0001",
name: "Dossier",
deed_uid: uidDeed1,
status: EFolderStatus.LIVE,
created_at: new Date(),
updated_at: new Date(),
office_uuid: uuidOffice1,
office_uid: uidOffice1,
description: null,
archived_description: null,
},
{
uuid: uuidOfficeFolder2,
folder_number: randomString(),
name: "0001",
deed_uuid: uuidDeed2,
uid: uidOfficeFolder2,
folder_number: "0002",
name: "Dossier",
deed_uid: uidDeed2,
status: EFolderStatus.LIVE,
created_at: new Date(),
updated_at: new Date(),
office_uuid: uuidOffice2,
office_uid: uidOffice2,
description: null,
archived_description: null,
},
{
uid: uidOfficeFolder3,
folder_number: "0003",
name: "Dossier",
deed_uid: uidDeed3,
status: EFolderStatus.LIVE,
created_at: new Date(),
updated_at: new Date(),
office_uid: uidOffice2,
description: null,
archived_description: null,
},
{
uid: uidOfficeFolder4,
folder_number: "0004",
name: "Dossier",
deed_uid: uidDeed4,
status: EFolderStatus.ARCHIVED,
created_at: new Date(),
updated_at: new Date(),
office_uid: uidOffice2,
description: null,
archived_description: null,
},
{
uid: uidOfficeFolder5,
folder_number: "0005",
name: "Dossier",
deed_uid: uidDeed5,
status: EFolderStatus.ARCHIVED,
created_at: new Date(),
updated_at: new Date(),
office_uid: uidOffice2,
description: null,
archived_description: null,
}
];
const deeds: Deeds[] = [
{
uuid: uuidDeed1,
deed_type_uuid: uuidDeedType1,
uid: uidDeed1,
deed_type_uid: uidDeedType1,
created_at: new Date(),
updated_at: new Date(),
},
{
uuid: uuidDeed2,
deed_type_uuid: uuidDeedType2,
uid: uidDeed2,
deed_type_uid: uidDeedType2,
created_at: new Date(),
updated_at: new Date(),
},
{
uid: uidDeed3,
deed_type_uid: uidDeedType2,
created_at: new Date(),
updated_at: new Date(),
},
{
uid: uidDeed4,
deed_type_uid: uidDeedType2,
created_at: new Date(),
updated_at: new Date(),
},
{
uid: uidDeed5,
deed_type_uid: uidDeedType2,
created_at: new Date(),
updated_at: new Date(),
}
];
const deedTypes: DeedTypes[] = [
{
uuid: uuidDeedType1,
uid: uidDeedType1,
name: "Acte de mariage",
archived_at: null,
description: "Acte regroupant deux personnes en mariage",
office_uuid: uuidOffice1,
office_uid: uidOffice1,
created_at: new Date(),
updated_at: new Date(),
},
{
uuid: uuidDeedType2,
uid: uidDeedType2,
name: "Vente d'un bien immobilier",
archived_at: null,
description: "Permet de vendre un bien immobilier à une entité ou une personne physique",
office_uuid: uuidOffice2,
office_uid: uidOffice2,
created_at: new Date(),
updated_at: new Date(),
},
@ -255,22 +315,22 @@ import {
const documents: Documents[] = [
{
uuid: uuidDocument1,
blockchain_anchor_uuid: null,
depositor_uuid: uuidCustomer1,
uid: uidDocument1,
blockchain_anchor_uid: null,
depositor_uid: uidCustomer1,
document_status: EDocumentStatus.ASKED,
folder_uuid: uuidOfficeFolder1,
document_type_uuid: uuidDocumentType1,
folder_uid: uidOfficeFolder1,
document_type_uid: uidDocumentType1,
created_at: new Date(),
updated_at: new Date(),
},
{
uuid: uuidDocument2,
blockchain_anchor_uuid: null,
depositor_uuid: uuidCustomer2,
uid: uidDocument2,
blockchain_anchor_uid: null,
depositor_uid: uidCustomer2,
document_status: EDocumentStatus.ASKED,
folder_uuid: uuidOfficeFolder2,
document_type_uuid: uuidDocumentType2,
folder_uid: uidOfficeFolder2,
document_type_uid: uidDocumentType2,
created_at: new Date(),
updated_at: new Date(),
},
@ -278,20 +338,20 @@ import {
const documentTypes: DocumentTypes[] = [
{
uuid: uuidDocumentType1,
uid: uidDocumentType1,
archived_at: null,
name: "Acte de naissance",
office_uuid: uuidOffice1,
office_uid: uidOffice1,
private_description: "Ce document est confidentiel, et ne doit pas être divulgué",
public_description: "Acte de naissance est un document officiel qui atteste de la naissance d'une personne",
created_at: new Date(),
updated_at: new Date(),
},
{
uuid: uuidDocumentType2,
uid: uidDocumentType2,
archived_at: null,
name: "Carte d'identité",
office_uuid: uuidOffice2,
office_uid: uidOffice2,
private_description: "Ce document est confidentiel, demander un recto-verso au client",
public_description: "Carte d'identité est un document officiel qui atteste de l'identité d'une personne",
created_at: new Date(),
@ -301,16 +361,16 @@ import {
const officeFolderHasCustomers: OfficeFolderHasCustomers[] = [
{
uuid: uuidOfficeFolderHasCustomer1,
customer_uuid: uuidCustomer1,
office_folder_uuid: uuidOfficeFolder1,
uid: uidOfficeFolderHasCustomer1,
customer_uid: uidCustomer1,
office_folder_uid: uidOfficeFolder1,
created_at: new Date(),
updated_at: new Date(),
},
{
uuid: uuidOfficeFolderHasCustomer2,
customer_uuid: uuidCustomer2,
office_folder_uuid: uuidOfficeFolder2,
uid: uidOfficeFolderHasCustomer2,
customer_uid: uidCustomer2,
office_folder_uid: uidOfficeFolder2,
created_at: new Date(),
updated_at: new Date(),
},
@ -318,15 +378,15 @@ import {
const files: Files[] = [
{
uuid: uuidFiles1,
document_uuid: uuidDocument1,
uid: uidFiles1,
document_uid: uidDocument1,
file_path: "https://www.google1.com",
created_at: new Date(),
updated_at: new Date(),
},
{
uuid: uuidFiles2,
document_uuid: uuidDocument2,
uid: uidFiles2,
document_uid: uidDocument2,
file_path: "https://www.google2.com",
created_at: new Date(),
updated_at: new Date(),
@ -335,16 +395,16 @@ import {
const deedHasDocumentTypes: DeedHasDocumentTypes[] = [
{
uuid: uuidDeedHasDocumentType1,
deed_uuid: uuidDeed1,
document_type_uuid: uuidDocumentType1,
uid: uidDeedHasDocumentType1,
deed_uid: uidDeed1,
document_type_uid: uidDocumentType1,
created_at: new Date(),
updated_at: new Date(),
},
{
uuid: uuidDeedHasDocumentType2,
deed_uuid: uuidDeed2,
document_type_uuid: uuidDocumentType2,
uid: uidDeedHasDocumentType2,
deed_uid: uidDeed2,
document_type_uid: uidDocumentType2,
created_at: new Date(),
updated_at: new Date(),
},
@ -352,16 +412,16 @@ import {
const deedTypeHasDocumentTypes: DeedTypeHasDocumentTypes[] = [
{
uuid: uuidDeedTypeHasDocumentType1,
deed_type_uuid: uuidDeedType1,
document_type_uuid: uuidDocumentType1,
uid: uidDeedTypeHasDocumentType1,
deed_type_uid: uidDeedType1,
document_type_uid: uidDocumentType1,
created_at: new Date(),
updated_at: new Date(),
},
{
uuid: uuidDeedTypeHasDocumentType2,
deed_type_uuid: uuidDeedType2,
document_type_uuid: uuidDocumentType2,
uid: uidDeedTypeHasDocumentType2,
deed_type_uid: uidDeedType2,
document_type_uid: uidDocumentType2,
created_at: new Date(),
updated_at: new Date(),
},
@ -369,17 +429,17 @@ import {
const documentHistories: DocumentHistory[] = [
{
uuid: uuidDocumentHistory1,
uid: uidDocumentHistory1,
document_status: EDocumentStatus.ASKED,
document_uuid: uuidDocument1,
document_uid: uidDocument1,
refused_reason: "Le document n'est pas conforme",
created_at: new Date(),
updated_at: new Date(),
},
{
uuid: uuidDocumentHistory2,
uid: uidDocumentHistory2,
document_status: EDocumentStatus.DEPOSITED,
document_uuid: uuidDocument1,
document_uid: uidDocument1,
refused_reason: "Le document n'est pas conforme",
created_at: new Date(),
updated_at: new Date(),

View File

@ -1,4 +1,4 @@
import { type ClassTransformOptions, plainToClass, plainToClassFromExist } from "class-transformer";
import { type ClassTransformOptions, plainToClassFromExist, plainToInstance } from "class-transformer";
export default abstract class ObjectHydrate {
public static hydrate<T = {}>(object: T, from: Partial<T>, options?: ClassTransformOptions): T {
@ -7,7 +7,7 @@ export default abstract class ObjectHydrate {
public static map<T = {}>(ClassEntity: { new (): T }, fromArray: Partial<T>[], options?: ClassTransformOptions): T[] {
return fromArray.map((from) => {
return plainToClass(ClassEntity, from, options);
return plainToInstance(ClassEntity, from, options);
});
}
}

View File

@ -29,7 +29,7 @@ export default class AddressesRepository extends BaseRepository {
public async findOneByUid(uid: string): Promise<Addresses> {
const addressEntity = await this.model.findUnique({
where: {
uuid: uid,
uid: uid,
},
});

View File

@ -29,7 +29,7 @@ export default class ContactsRepository extends BaseRepository {
public async findOneByUid(uid: string): Promise<Contacts> {
const contactEntity = await this.model.findUnique({
where: {
uuid: uid,
uid: uid,
},
});

View File

@ -61,7 +61,7 @@ export default class CustomersRepository extends BaseRepository {
public async update(uid: string, customer: Customer): Promise<Customers> {
const updateArgs: Prisma.CustomersUpdateArgs = {
where: {
uuid: uid,
uid: uid,
},
data: {
status: ECustomerStatus[customer.status as keyof typeof ECustomerStatus],
@ -91,12 +91,16 @@ export default class CustomersRepository extends BaseRepository {
/**
* @description : Find unique customer
*/
public async findOneByUid(uid: string): Promise<Customers> {
const customerEntity = await this.model.findUnique({
public async findOneByUid(uid: string, query?: any): Promise<Customers> {
const findOneArgs: Prisma.CustomersFindUniqueArgs = {
where: {
uuid: uid,
},
});
uid: uid,
}
};
if(query) {
findOneArgs.include = query
}
const customerEntity = await this.model.findUnique(findOneArgs);
if (!customerEntity) {
throw new Error("Customer not found");

View File

@ -29,7 +29,7 @@ export default class DeedTypeHasDocumentTypesRepository extends BaseRepository {
public async findOneByUid(uid: string): Promise<DeedTypeHasDocumentTypes> {
const deedTypeHasDoculmentTypesEntity = await this.model.findUnique({
where: {
uuid: uid,
uid: uid,
},
});

View File

@ -34,7 +34,7 @@ export default class DeedTypesRepository extends BaseRepository {
description: deedType.description,
office: {
connect: {
uuid: deedType.office.uid,
uid: deedType.office.uid,
},
},
}
@ -43,7 +43,7 @@ export default class DeedTypesRepository extends BaseRepository {
createArgs.data.deed_type_has_document_types = {
createMany: {
data: deedType.deed_type_has_document_types.map((relation) => ({
document_type_uuid: relation.document_type.uid!,
document_type_uid: relation.document_type.uid!,
})),
skipDuplicates: true,
},
@ -58,7 +58,7 @@ export default class DeedTypesRepository extends BaseRepository {
public async update(uid: string, deedType: DeedType): Promise<DeedTypes> {
const updateArgs: Prisma.DeedTypesUpdateArgs = {
where: {
uuid: uid,
uid: uid,
},
data: {
name: deedType.name,
@ -66,7 +66,7 @@ export default class DeedTypesRepository extends BaseRepository {
archived_at: deedType.archived_at,
office: {
connect: {
uuid: deedType.office.uid,
uid: deedType.office.uid,
},
},
},
@ -76,10 +76,10 @@ export default class DeedTypesRepository extends BaseRepository {
};
if (deedType.deed_type_has_document_types) {
updateArgs.data.deed_type_has_document_types = {
deleteMany: { deed_type_uuid: uid },
deleteMany: { deed_type_uid: uid },
createMany: {
data: deedType.deed_type_has_document_types.map((relation) => ({
document_type_uuid: relation.document_type.uid!,
document_type_uid: relation.document_type.uid!,
})),
skipDuplicates: true,
},
@ -91,15 +91,16 @@ export default class DeedTypesRepository extends BaseRepository {
/**
* @description : Find unique deed type
*/
public async findOneByUid(uid: string): Promise<DeedTypes> {
const deedTypeEntity = await this.model.findUnique({
public async findOneByUid(uid: string, query?: any): Promise<DeedTypes> {
const findOneArgs: Prisma.DeedTypesFindUniqueArgs = {
where: {
uuid: uid,
},
include: {
deed_type_has_document_types: true,
},
});
uid: uid,
}
};
if(query) {
findOneArgs.include = query
}
const deedTypeEntity = await this.model.findUnique(findOneArgs);
if (!deedTypeEntity) {
throw new Error("deed type not found");

View File

@ -29,7 +29,7 @@ export default class DeedHasDocumentTypesRepository extends BaseRepository {
public async findOneByUid(uid: string): Promise<DeedHasDocumentTypes> {
const deedHasDocumentTypesEntity = await this.model.findUnique({
where: {
uuid: uid,
uid: uid,
},
});

View File

@ -32,14 +32,14 @@ export default class DeedsRepository extends BaseRepository {
data: {
deed_type: {
connect: {
uuid: deed.deed_type.uid,
uid: deed.deed_type.uid,
},
},
},
};
const deedTypeWithDocumentTypes = await this.instanceDb.deedTypes.findUniqueOrThrow({
where: {
uuid: deed.deed_type.uid,
uid: deed.deed_type.uid,
},
include: { deed_type_has_document_types: true },
});
@ -50,7 +50,7 @@ export default class DeedsRepository extends BaseRepository {
createArgs.data.deed_has_document_types = {
createMany: {
data: deedTypeWithDocumentTypes.deed_type_has_document_types.map((relation) => ({
document_type_uuid: relation.document_type_uuid,
document_type_uid: relation.document_type_uid,
})),
skipDuplicates: true,
},
@ -65,7 +65,7 @@ export default class DeedsRepository extends BaseRepository {
public async update(uid: string, deed: Deed): Promise<Deeds> {
const updateArgs: Prisma.DeedsUpdateArgs = {
where: {
uuid: uid,
uid: uid,
},
data: {},
include: {
@ -74,10 +74,10 @@ export default class DeedsRepository extends BaseRepository {
};
if (deed.deed_has_document_types) {
updateArgs.data.deed_has_document_types = {
deleteMany: { deed_uuid: uid },
deleteMany: { deed_uid: uid },
createMany: {
data: deed.deed_has_document_types.map((relation) => ({
document_type_uuid: relation.document_type.uid!,
document_type_uid: relation.document_type.uid!,
})),
skipDuplicates: true,
},
@ -92,7 +92,7 @@ export default class DeedsRepository extends BaseRepository {
public async findOneByUid(uid: string): Promise<Deeds> {
const deedTypeEntity = await this.model.findUnique({
where: {
uuid: uid,
uid: uid,
},
});

View File

@ -1,7 +1,7 @@
import Database from "@Common/databases/database";
import BaseRepository from "@Repositories/BaseRepository";
import { Service } from "typedi";
import { DocumentTypes } from "prisma/prisma-client";
import { DocumentTypes, Prisma } from "prisma/prisma-client";
import { DocumentType } from "le-coffre-resources/dist/SuperAdmin";
@Service()
@ -35,7 +35,7 @@ export default class DocumentTypesRepository extends BaseRepository {
private_description: documentType.private_description,
office: {
connect: {
uuid: documentType.office.uid,
uid: documentType.office.uid,
},
},
},
@ -45,10 +45,10 @@ export default class DocumentTypesRepository extends BaseRepository {
/**
* @description : update given document type
*/
public async update(uuid: string, documentType: DocumentType): Promise<DocumentTypes> {
public async update(uid: string, documentType: DocumentType): Promise<DocumentTypes> {
return this.model.update({
where: {
uuid: uuid,
uid: uid,
},
data: {
name: documentType.name,
@ -57,7 +57,7 @@ export default class DocumentTypesRepository extends BaseRepository {
archived_at: documentType.archived_at,
office: {
connect: {
uuid: documentType.office.uid,
uid: documentType.office.uid,
},
},
},
@ -67,12 +67,16 @@ export default class DocumentTypesRepository extends BaseRepository {
/**
* @description : find unique document type
*/
public async findOneByUid(uid: string): Promise<DocumentTypes> {
const documentTypeEntity = await this.model.findUnique({
public async findOneByUid(uid: string, query?: any): Promise<DocumentTypes> {
const findOneArgs: Prisma.DocumentTypesFindUniqueArgs = {
where: {
uuid: uid,
},
});
uid: uid,
}
};
if(query) {
findOneArgs.include = query
}
const documentTypeEntity = await this.model.findUnique(findOneArgs);
if (!documentTypeEntity) {
throw new Error("Document Type not found");

View File

@ -32,17 +32,17 @@ export default class DocumentsRepository extends BaseRepository {
data: {
folder: {
connect: {
uuid: document.folder.uid,
uid: document.folder.uid,
},
},
depositor: {
connect: {
uuid: document.depositor.uid,
uid: document.depositor.uid,
},
},
document_type: {
connect: {
uuid: document.document_type.uid,
uid: document.document_type.uid,
},
},
},
@ -52,7 +52,7 @@ export default class DocumentsRepository extends BaseRepository {
data: {
document: {
connect: {
uuid: documentCreated.uuid,
uid: documentCreated.uid,
},
},
},
@ -67,9 +67,9 @@ export default class DocumentsRepository extends BaseRepository {
public async createMany(documents: Document[]): Promise<Prisma.BatchPayload> {
return this.model.createMany({
data: documents.map((document) => ({
folder_uuid: document.folder.uid!,
depositor_uuid: document.depositor.uid!,
document_type_uuid: document.document_type.uid!,
folder_uid: document.folder.uid!,
depositor_uid: document.depositor.uid!,
document_type_uid: document.document_type.uid!,
})),
skipDuplicates: true,
});
@ -81,7 +81,7 @@ export default class DocumentsRepository extends BaseRepository {
public async update(uid: string, document: Document, refusedReason?: string): Promise<Documents> {
return this.model.update({
where: {
uuid: uid,
uid: uid,
},
data: {
document_status: EDocumentStatus[document.document_status as keyof typeof EDocumentStatus],
@ -93,7 +93,7 @@ export default class DocumentsRepository extends BaseRepository {
},
depositor: {
connect: {
uuid: document.depositor.uid,
uid: document.depositor.uid,
},
},
},
@ -106,7 +106,7 @@ export default class DocumentsRepository extends BaseRepository {
public async delete(uid: string): Promise<Documents> {
return this.model.delete({
where: {
uuid: uid,
uid: uid,
},
});
}
@ -114,13 +114,16 @@ export default class DocumentsRepository extends BaseRepository {
/**
* @description : Find unique document
*/
public async findOneByUid(uid: string): Promise<Documents> {
const documentEntity = await this.model.findUnique({
public async findOneByUid(uid: string, query?: any): Promise<Documents> {
const findOneArgs: Prisma.DocumentsFindUniqueArgs = {
where: {
uuid: uid,
},
});
uid: uid,
}
};
if(query) {
findOneArgs.include = query
}
const documentEntity = await this.model.findUnique(findOneArgs);
if (!documentEntity) {
throw new Error("Document not found");
}

View File

@ -32,7 +32,7 @@ export default class FilesRepository extends BaseRepository {
data: {
document: {
connect: {
uuid: file.document.uid
uid: file.document.uid
}
},
file_path: file.file_path
@ -46,7 +46,7 @@ export default class FilesRepository extends BaseRepository {
public async update(uid: string, file: File): Promise<Files> {
return this.model.update({
where: {
uuid: uid,
uid: uid,
},
data: {
file_path: file.file_path
@ -60,7 +60,7 @@ export default class FilesRepository extends BaseRepository {
public async delete(uid: string): Promise<Files> {
return this.model.delete({
where: {
uuid: uid,
uid: uid,
}
});
}
@ -71,7 +71,7 @@ export default class FilesRepository extends BaseRepository {
public async findOneByUid(uid: string): Promise<Files> {
const fileEntity = await this.model.findUnique({
where: {
uuid: uid,
uid: uid,
},
});

View File

@ -30,7 +30,7 @@ export default class OfficeFoldersHasCustomerRepository extends BaseRepository {
public async findOneByUid(uid: string): Promise<OfficeFolderHasCustomers> {
const officeFolderHasCustomersEntity = await this.model.findUnique({
where: {
uuid: uid,
uid: uid,
},
});

View File

@ -29,7 +29,7 @@ export default class OfficeFoldersHasStakeholderRepository extends BaseRepositor
public async findOneByUid(uid: string): Promise<OfficeFolderHasStakeholders> {
const officeFolderHasStakeholdersEntity = await this.model.findUnique({
where: {
uuid: uid,
uid: uid,
},
});

View File

@ -38,7 +38,7 @@ export default class OfficeFoldersRepository extends BaseRepository {
create: {
deed_type: {
connect: {
uuid: officeFolder.deed.deed_type.uid,
uid: officeFolder.deed.deed_type.uid,
},
},
},
@ -57,7 +57,7 @@ export default class OfficeFoldersRepository extends BaseRepository {
createArgs.data.office_folder_has_stakeholder = {
createMany: {
data: officeFolder.office_folder_has_stakeholder.map((relation) => ({
user_stakeholder_uuid: relation.user_stakeholder.uid!,
user_stakeholder_uid: relation.user_stakeholder.uid!,
})),
skipDuplicates: true
},
@ -69,10 +69,10 @@ export default class OfficeFoldersRepository extends BaseRepository {
/**
* @description : Update data of an office folder
*/
public async update(officeFolderUuid: string, officeFolder: OfficeFolder): Promise<OfficeFolders> {
public async update(officeFolderuid: string, officeFolder: OfficeFolder): Promise<OfficeFolders> {
const updateArgs: Prisma.OfficeFoldersUpdateArgs = {
where: {
uuid: officeFolderUuid,
uid: officeFolderuid,
},
data: {
folder_number: officeFolder.folder_number,
@ -89,10 +89,10 @@ export default class OfficeFoldersRepository extends BaseRepository {
};
if (officeFolder.office_folder_has_stakeholder) {
updateArgs.data.office_folder_has_stakeholder = {
deleteMany: { office_folder_uuid: officeFolderUuid },
deleteMany: { office_folder_uid: officeFolderuid },
createMany: {
data: officeFolder.office_folder_has_stakeholder.map((relation) => ({
user_stakeholder_uuid: relation.user_stakeholder.uid!,
user_stakeholder_uid: relation.user_stakeholder.uid!,
})),
skipDuplicates: true
},
@ -100,10 +100,10 @@ export default class OfficeFoldersRepository extends BaseRepository {
}
if (officeFolder.office_folder_has_customers) {
updateArgs.data.office_folder_has_customers = {
deleteMany: { office_folder_uuid: officeFolderUuid },
deleteMany: { office_folder_uid: officeFolderuid },
createMany: {
data: officeFolder.office_folder_has_customers.map((relation) => ({
customer_uuid: relation.customer.uid!,
customer_uid: relation.customer.uid!,
})),
skipDuplicates: true
},
@ -113,8 +113,8 @@ export default class OfficeFoldersRepository extends BaseRepository {
updateArgs.data.documents = {
createMany: {
data: officeFolder.documents.map((relation) => ({
document_type_uuid: relation.document_type.uid!,
depositor_uuid: relation.depositor.uid!
document_type_uid: relation.document_type.uid!,
depositor_uid: relation.depositor.uid!
})),
skipDuplicates: true
},
@ -126,12 +126,16 @@ export default class OfficeFoldersRepository extends BaseRepository {
/**
* @description : Find one office folder
*/
public async findOneByUid(uid: string): Promise<OfficeFolders> {
const officeFolderEntity = await this.model.findUnique({
public async findOneByUid(uid: string, query?: any): Promise<OfficeFolders> {
const findOneArgs: Prisma.OfficeFoldersFindUniqueArgs = {
where: {
uuid: uid,
},
});
uid: uid,
}
};
if(query) {
findOneArgs.include = query
}
const officeFolderEntity = await this.model.findUnique(findOneArgs);
if (!officeFolderEntity) {
throw new Error("office folder not found");

View File

@ -1,7 +1,7 @@
import Database from "@Common/databases/database";
import BaseRepository from "@Repositories/BaseRepository";
import { Service } from "typedi";
import { EOfficeStatus, Offices } from "@prisma/client";
import { EOfficeStatus, Offices, Prisma } from "@prisma/client";
import { Office as OfficeRessource } from "le-coffre-resources/dist/SuperAdmin";
@Service()
@ -52,7 +52,7 @@ export default class OfficesRepository extends BaseRepository {
public async update(uid: string, office: OfficeRessource): Promise<Offices> {
return this.model.update({
where: {
uuid: uid,
uid: uid,
},
data: {
name: office.name,
@ -71,15 +71,20 @@ export default class OfficesRepository extends BaseRepository {
/**
* @description : Find one office
*/
public async findOneByUid(uid: string): Promise<Offices> {
const officeEntity = await this.model.findUnique({
public async findOneByUid(uid: string, query?: any): Promise<Offices> {
const findOneArgs: Prisma.OfficesFindUniqueArgs = {
where: {
uuid: uid,
},
});
uid: uid,
}
};
if(query) {
findOneArgs.include = query
}
const officeEntity = await this.model.findUnique(findOneArgs);
if (!officeEntity) {
throw new Error("User not found");
throw new Error("office not found");
}
return officeEntity;

View File

@ -79,7 +79,7 @@ export default class UsersRepository extends BaseRepository {
public async update(uid: string, user: User): Promise<Users> {
const updateArgs: Prisma.UsersUpdateArgs = {
where: {
uuid: uid,
uid: uid,
},
data: {
idNot: user.idNot,
@ -128,12 +128,16 @@ export default class UsersRepository extends BaseRepository {
/**
* @description : Find one user
*/
public async findOneByUid(uid: string): Promise<Users> {
const userEntity = await this.model.findUnique({
public async findOneByUid(uid: string, query?: any): Promise<Users> {
const findOneArgs: Prisma.UsersFindUniqueArgs = {
where: {
uuid: uid,
},
});
uid: uid,
}
};
if(query) {
findOneArgs.include = query
}
const userEntity = await this.model.findUnique(findOneArgs);
if (!userEntity) {
throw new Error("User not found");

View File

@ -20,7 +20,7 @@ export default class AddressesService extends BaseService {
* @description : Get a address by uid
* @throws {Error} If address cannot be get
*/
public async getByUid(uuid: string) {
return this.addressRepository.findOneByUid(uuid);
public async getByUid(uid: string) {
return this.addressRepository.findOneByUid(uid);
}
}

View File

@ -20,7 +20,7 @@ export default class ContactsService extends BaseService {
* @description : Get a contact by uid
* @throws {Error} If contact cannot be get
*/
public async getByUid(uuid: string) {
return this.contactRepository.findOneByUid(uuid);
public async getByUid(uid: string) {
return this.contactRepository.findOneByUid(uid);
}
}

View File

@ -38,7 +38,7 @@ export default class CustomersService extends BaseService {
* @description : Get a customer by uid
* @throws {Error} If customer cannot be get by uid
*/
public async getByUid(uid: string): Promise<Customers> {
return this.customerRepository.findOneByUid(uid);
public async getByUid(uid: string, query?: any): Promise<Customers> {
return this.customerRepository.findOneByUid(uid, query);
}
}

View File

@ -40,7 +40,7 @@ export default class DeedTypesService extends BaseService {
* @description : Get a deedtype by uid
* @throws {Error} If deed-type cannot be get by uid
*/
public async getByUid(uid: string) {
return this.deedTypeRepository.findOneByUid(uid);
public async getByUid(uid: string, query?: any) {
return this.deedTypeRepository.findOneByUid(uid, query);
}
}

View File

@ -30,8 +30,8 @@ export default class DeedsService extends BaseService {
* @description : Update data of a deed with document types
* @throws {Error} If deeds cannot be updated with document types or one of them
*/
public async update(deedUuid: string, deed: Deed): Promise<Deeds> {
return this.deedRepository.update(deedUuid, deed);
public async update(deeduid: string, deed: Deed): Promise<Deeds> {
return this.deedRepository.update(deeduid, deed);
}
/**

View File

@ -38,7 +38,7 @@ export default class DocumentTypesService extends BaseService {
* @description : Get a document-type by uid
* @throws {Error} If document-type is not found
*/
public async getByUid(uid: string) {
return this.documentTypeRepository.findOneByUid(uid);
public async getByUid(uid: string, query?: any) {
return this.documentTypeRepository.findOneByUid(uid, query);
}
}

View File

@ -54,7 +54,7 @@ export default class DocumentsService extends BaseService {
* @description : Get a document by uid
* @throws {Error} If document cannot be get by uid
*/
public async getByUid(uid: string) {
return this.documentsRepository.findOneByUid(uid);
public async getByUid(uid: string, query?: any) {
return this.documentsRepository.findOneByUid(uid, query);
}
}

View File

@ -37,15 +37,15 @@ export default class OfficeFoldersService extends BaseService {
* @description : Modify a folder
* @throws {Error} If folder cannot be modified
*/
public async update(officeFolderUuid: string, officeFolderEntity: OfficeFolder): Promise<OfficeFolders> {
return this.officeFoldersRepository.update(officeFolderUuid, officeFolderEntity);
public async update(officeFolderuid: string, officeFolderEntity: OfficeFolder): Promise<OfficeFolders> {
return this.officeFoldersRepository.update(officeFolderuid, officeFolderEntity);
}
/**
* @description : Get a folder by uid
* @throws {Error} If folder cannot be get by uid
*/
public async getByUid(uid: string) {
return this.officeFoldersRepository.findOneByUid(uid);
public async getByUid(uid: string, query?: any) {
return this.officeFoldersRepository.findOneByUid(uid, query);
}
}

View File

@ -38,7 +38,7 @@ export default class OfficesService extends BaseService {
* @description : Get a office by uid
* @throws {Error} If office cannot be get
*/
public async getByUid(uid: string): Promise<Offices> {
return this.officeRepository.findOneByUid(uid);
public async getByUid(uid: string, query?: any): Promise<Offices> {
return this.officeRepository.findOneByUid(uid, query);
}
}

View File

@ -31,15 +31,15 @@ export default class UsersService extends BaseService {
* @description : Modify a user
* @throws {Error} If user modification failed
*/
public update(uuid: string, userEntity: User): Promise<Users> {
return this.userRepository.update(uuid, userEntity);
public update(uid: string, userEntity: User): Promise<Users> {
return this.userRepository.update(uid, userEntity);
}
/**
* @description : Get a user by uid
* @throws {Error} If user cannot be get by uid
*/
public getByUid(uid: string): Promise<Users> {
return this.userRepository.findOneByUid(uid);
public getByUid(uid: string, query?: any): Promise<Users> {
return this.userRepository.findOneByUid(uid, query);
}
}

View File

@ -27,7 +27,7 @@ export const initDocumentType = (documentType: DocumentType, office: Office): Pr
public_description: documentType.public_description,
private_description: documentType.private_description,
archived_at: null,
office_uuid: office.uid!,
office_uid: office.uid!,
},
});
};
@ -38,11 +38,11 @@ export const initDeedType = (deedType: DeedType, office: Office, documentTypes?:
name: deedType.name,
description: deedType.description,
archived_at: null,
office_uuid: office.uid!,
office_uid: office.uid!,
deed_type_has_document_types: {
createMany: {
data: documentTypes!.map((documentType) => ({
document_type_uuid: documentType,
document_type_uid: documentType,
})),
skipDuplicates: true,
},

View File

@ -28,7 +28,7 @@ describe("test create function", () => {
expect(customerCreated?.status).toEqual("PENDING");
// verify if customer contact is created in db
const contactCreated = await prisma.contacts.findUnique({ where: { uuid: customerCreated.contact_uuid } });
const contactCreated = await prisma.contacts.findUnique({ where: { uid: customerCreated.contact_uid } });
expect(contactCreated?.first_name).toEqual(customer.contact.first_name);
expect(contactCreated?.last_name).toEqual(customer.contact.last_name);
expect(contactCreated?.cell_phone_number).toEqual(customer.contact.cell_phone_number);
@ -37,7 +37,7 @@ describe("test create function", () => {
expect(contactCreated?.email).toEqual(customer.contact.email);
// verify if customer address is created in db
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uuid: contactCreated?.address_uuid } });
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid } });
expect(addressForContactCreated?.address).toEqual(customer.contact.address?.address);
expect(addressForContactCreated?.zip_code).toEqual(customer.contact.address?.zip_code);
expect(addressForContactCreated?.city).toEqual(customer.contact.address?.city);
@ -83,7 +83,7 @@ describe("test create function", () => {
expect(customerCreated?.status).toEqual("PENDING");
// verify if customer_ contact is created in db
const contactCreated = await prisma.contacts.findUnique({ where: { uuid: customerCreated.contact_uuid } });
const contactCreated = await prisma.contacts.findUnique({ where: { uid: customerCreated.contact_uid } });
expect(contactCreated?.first_name).toEqual(customer.contact.first_name);
expect(contactCreated?.last_name).toEqual(customer.contact.last_name);
expect(contactCreated?.cell_phone_number).toEqual(customer_.contact.cell_phone_number);
@ -92,7 +92,7 @@ describe("test create function", () => {
expect(contactCreated?.email).toEqual(customer_.contact.email);
// verify if customer_ address is created in db
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uuid: contactCreated?.address_uuid } });
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid } });
expect(addressForContactCreated?.address).toEqual(customer.contact.address?.address);
expect(addressForContactCreated?.zip_code).toEqual(customer.contact.address?.zip_code);
expect(addressForContactCreated?.city).toEqual(customer.contact.address?.city);
@ -104,12 +104,12 @@ describe("test update function", () => {
const customerCreated = await prisma.customers.findFirstOrThrow({ where: { contact: { email: customer_.contact.email } } });
// update the last customer created with his own new office and own contact
const updatedCustomer = await CustomersServiceTest.update(customerCreated.uuid, customer_);
const updatedCustomer = await CustomersServiceTest.update(customerCreated.uid, customer_);
expect(updatedCustomer?.status).toEqual("ERRONED");
// verify if customer_ contact is created in db
const existingContact = await prisma.contacts.findUnique({ where: { uuid: updatedCustomer.contact_uuid } });
const existingContact = await prisma.contacts.findUnique({ where: { uid: updatedCustomer.contact_uid } });
expect(existingContact?.first_name).toEqual(customer_.contact.first_name);
expect(existingContact?.last_name).toEqual(customer_.contact.last_name);
expect(existingContact?.cell_phone_number).toEqual(customer_.contact.cell_phone_number);
@ -118,14 +118,14 @@ describe("test update function", () => {
expect(existingContact?.email).toEqual(customer_.contact.email);
// verify if customer_ address is created in db
const addressForExistingContact = await prisma.addresses.findUnique({ where: { uuid: existingContact?.address_uuid } });
const addressForExistingContact = await prisma.addresses.findUnique({ where: { uid: existingContact?.address_uid } });
expect(addressForExistingContact?.address).toEqual(customer_.contact.address?.address);
expect(addressForExistingContact?.zip_code).toEqual(customer_.contact.address?.zip_code);
expect(addressForExistingContact?.city).toEqual(customer_.contact.address?.city);
});
it("should not update an customer with an email already used", async () => {
const customerUid = (await prisma.customers.findFirstOrThrow({ where: { contact: { email: customer_.contact.email } } })).uuid;
const customerUid = (await prisma.customers.findFirstOrThrow({ where: { contact: { email: customer_.contact.email } } })).uid;
let updatedCustomer: Customer = JSON.parse(JSON.stringify(customer_));
updatedCustomer.contact.email = customerContact.email;
@ -137,7 +137,7 @@ describe("test update function", () => {
});
it("should not update an customer with an phone number already used", async () => {
const customerUid = (await prisma.customers.findFirstOrThrow({ where: { contact: { email: customer_.contact.email } } })).uuid;
const customerUid = (await prisma.customers.findFirstOrThrow({ where: { contact: { email: customer_.contact.email } } })).uid;
let updatedCustomer: Customer = JSON.parse(JSON.stringify(customer_));
updatedCustomer.contact.cell_phone_number = customerContact.cell_phone_number;

View File

@ -13,10 +13,10 @@ const prisma = new PrismaClient();
const DeedServiceTest = new DeedService(Container.get(DeedsRepository));
beforeAll(async () => {
office.uid = (await initOffice(office)).uuid;
documentType.uid = (await initDocumentType(documentType, office)).uuid;
documentType_.uid = (await initDocumentType(documentType_, office)).uuid;
deedType.uid = (await initDeedType(deedType, office, [documentType.uid])).uuid;
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;
});
afterAll(async () => {
@ -29,7 +29,7 @@ afterAll(async () => {
describe("test create function", () => {
it("should not create a new deed if deed type is unknown", async () => {
let deedWithoutDeedTypeUid: Deed = JSON.parse(JSON.stringify(deed));
deedWithoutDeedTypeUid.deed_type.uid = "random uuid";
deedWithoutDeedTypeUid.deed_type.uid = "random uid";
// try to create a new deed with unknown deed type
async function createDeedWithUnknownDeedType() {
await DeedServiceTest.create(deedWithoutDeedTypeUid);
@ -42,13 +42,13 @@ describe("test create function", () => {
deedWithDeedTypeUid.deed_type.uid = deedType.uid;
const deedCreated = await DeedServiceTest.create(deedWithDeedTypeUid);
expect(deedCreated.deed_type_uuid).toEqual(deedType.uid);
expect(deedCreated.deed_type_uid).toEqual(deedType.uid);
});
it("should have by default the same document types as its deed type ", async () => {
const deedWithDocumentTypes = await prisma.deeds.findFirstOrThrow({ include: { deed_has_document_types: true } });
expect(deedWithDocumentTypes.deed_has_document_types.length).toEqual(1);
expect(deedWithDocumentTypes.deed_has_document_types[0]?.document_type_uuid).toEqual(documentType.uid);
expect(deedWithDocumentTypes.deed_has_document_types[0]?.document_type_uid).toEqual(documentType.uid);
});
it("should create a the same deed based on existing deed type", async () => {
@ -56,7 +56,7 @@ describe("test create function", () => {
deedWithDeedTypeUid.deed_type.uid = deedType.uid;
const deedCreated = await DeedServiceTest.create(deedWithDeedTypeUid);
expect(deedCreated.deed_type_uuid).toEqual(deedType.uid);
expect(deedCreated.deed_type_uid).toEqual(deedType.uid);
});
it("should not create a new deed based on archivated deed type", async () => {
@ -64,7 +64,7 @@ describe("test create function", () => {
deedArchivated.deed_type.uid = deedType.uid;
await prisma.deedTypes.update({
where: { uuid: deedType.uid },
where: { uid: deedType.uid },
data: {
archived_at: new Date(Date.now()),
},
@ -80,7 +80,7 @@ describe("test create function", () => {
describe("test update function", () => {
it("should add document types to a deed", async () => {
const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType.uid } })).uuid;
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 = [
@ -102,7 +102,7 @@ describe("test update function", () => {
const deedUpdated = await prisma.deeds.findFirstOrThrow({
where: {
uuid: deedUid,
uid: deedUid,
},
include: {
deed_has_document_types: true,
@ -112,7 +112,7 @@ describe("test update function", () => {
});
it("should not add document types to a deed type that already has those document types ", async () => {
const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType.uid } })).uuid;
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 = [
@ -134,7 +134,7 @@ describe("test update function", () => {
const deedUpdated = await prisma.deeds.findFirstOrThrow({
where: {
uuid: deedUid,
uid: deedUid,
},
include: {
deed_has_document_types: true,
@ -144,7 +144,7 @@ describe("test update function", () => {
});
it("should delete document types from a deed", async () => {
const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType.uid } })).uuid;
const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uid: deedType.uid } })).uid;
let deedToUpdate: Deed = JSON.parse(JSON.stringify(deed));
// set relation between deed and document types empty
@ -154,7 +154,7 @@ describe("test update function", () => {
const deedUpdated = await prisma.deeds.findFirstOrThrow({
where: {
uuid: deedUid,
uid: deedUid,
},
include: {
deed_has_document_types: true,
@ -173,7 +173,7 @@ describe("test get function", () => {
expect(deeds.length).toEqual(2);
// verify result content
expect(deeds[0]?.deed_type_uuid).toEqual(deedType.uid);
expect(deeds[1]?.deed_type_uuid).toEqual(deedType.uid);
expect(deeds[0]?.deed_type_uid).toEqual(deedType.uid);
expect(deeds[1]?.deed_type_uid).toEqual(deedType.uid);
});
});

View File

@ -13,10 +13,10 @@ const prisma = new PrismaClient();
const DeedTypeServiceTest = new DeedTypeService(Container.get(DeedTypesRepository));
beforeAll(async () => {
office.uid = (await initOffice(office)).uuid;
office_.uid = (await initOffice(office_)).uuid;
documentType.uid = (await initDocumentType(documentType, office)).uuid;
documentType_.uid = (await initDocumentType(documentType_, office)).uuid;
office.uid = (await initOffice(office)).uid;
office_.uid = (await initOffice(office_)).uid;
documentType.uid = (await initDocumentType(documentType, office)).uid;
documentType_.uid = (await initDocumentType(documentType_, office)).uid;
});
afterAll(async () => {
@ -29,7 +29,7 @@ afterAll(async () => {
describe("test create function", () => {
it("should not create a new deed type if office is unknown", async () => {
let deedTypeWithoutOfficeUid: DeedType = JSON.parse(JSON.stringify(deedType));
deedTypeWithoutOfficeUid.office.uid = "random uuid";
deedTypeWithoutOfficeUid.office.uid = "random uid";
// try to create a new deed type with unknown office
async function createDeedTypeWithUnknownOffice() {
await DeedTypeServiceTest.create(deedTypeWithoutOfficeUid);
@ -43,7 +43,7 @@ describe("test create function", () => {
expect(deedTypeCreated.name).toEqual(deedType.name);
expect(deedTypeCreated.description).toEqual(deedType.description);
expect(deedTypeCreated.archived_at).toBeNull();
expect(deedTypeCreated.office_uuid).toEqual(office.uid);
expect(deedTypeCreated.office_uid).toEqual(office.uid);
});
it("should not create a new deed type with a name already used for a given office", async () => {
@ -66,7 +66,7 @@ describe("test create function", () => {
expect(deedTypeCreated.name).toEqual(deedType.name);
expect(deedTypeCreated.description).toEqual(deedType.description);
expect(deedTypeCreated.archived_at).toBeNull();
expect(deedTypeCreated.office_uuid).toEqual(office_.uid);
expect(deedTypeCreated.office_uid).toEqual(office_.uid);
});
it("should create the a new deed type version with a different name for a given office", async () => {
@ -78,33 +78,33 @@ describe("test create function", () => {
expect(deedTypeCreated.name).toEqual(deedType_.name);
expect(deedTypeCreated.description).toEqual(deedType.description);
expect(deedTypeCreated.archived_at).toBeNull();
expect(deedTypeCreated.office_uuid).toEqual(office.uid);
expect(deedTypeCreated.office_uid).toEqual(office.uid);
});
});
describe("test update function", () => {
it("should update a deed type data", async () => {
const deedTypeCreated = await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uuid: office.uid } });
const deedTypeCreated = await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uid: office.uid } });
expect(deedTypeCreated.name).toEqual(deedType_.name);
expect(deedTypeCreated.description).toEqual(deedType.description);
expect(deedTypeCreated.archived_at).toBeNull();
expect(deedTypeCreated.office_uuid).toEqual(deedType.office.uid);
expect(deedTypeCreated.office_uid).toEqual(deedType.office.uid);
let deedTypeWithNewDescription: DeedType = JSON.parse(JSON.stringify(deedType_));
deedTypeWithNewDescription.office = office;
// update the last deed type created with his the right description
const deedTypeUpdated = await DeedTypeServiceTest.update(deedTypeCreated.uuid, deedTypeWithNewDescription);
const deedTypeUpdated = await DeedTypeServiceTest.update(deedTypeCreated.uid, deedTypeWithNewDescription);
expect(deedTypeUpdated.name).toEqual(deedType_.name);
expect(deedTypeUpdated.description).toEqual(deedType_.description);
expect(deedTypeUpdated.archived_at).toBeNull();
expect(deedTypeUpdated.office_uuid).toEqual(deedType.office.uid);
expect(deedTypeUpdated.office_uid).toEqual(deedType.office.uid);
});
it("should not update a deed type name with an already used name for given office", async () => {
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uuid: office.uid } })).uuid;
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uid: office.uid } })).uid;
let deedTypeWithSameNameAndOffice: DeedType = JSON.parse(JSON.stringify(deedType_));
deedTypeWithSameNameAndOffice.office.uid = office.uid;
deedTypeWithSameNameAndOffice.name = deedType.name;
@ -117,7 +117,7 @@ describe("test update function", () => {
});
it("should not update a deed type office membership if the office already have this document type", async () => {
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uuid: office.uid } })).uuid;
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uid: office.uid } })).uid;
let deedTypeWithSameNameAndOffice: DeedType = JSON.parse(JSON.stringify(deedType_));
deedTypeWithSameNameAndOffice.office.uid = office.uid;
deedTypeWithSameNameAndOffice.name = deedType.name;
@ -130,62 +130,62 @@ describe("test update function", () => {
});
it("should update a deed type office membership", async () => {
const deedTypeCreated = await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uuid: office.uid } });
const deedTypeCreated = await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uid: office.uid } });
expect(deedTypeCreated.name).toEqual(deedType_.name);
expect(deedTypeCreated.description).toEqual(deedType_.description);
expect(deedTypeCreated.archived_at).toBeNull();
expect(deedTypeCreated.office_uuid).toEqual(office.uid);
expect(deedTypeCreated.office_uid).toEqual(office.uid);
// update the last deed type updated with a new office membership
const deedTypeUpdated = await DeedTypeServiceTest.update(deedTypeCreated.uuid, deedType_);
const deedTypeUpdated = await DeedTypeServiceTest.update(deedTypeCreated.uid, deedType_);
expect(deedTypeUpdated.name).toEqual(deedType_.name);
expect(deedTypeUpdated.description).toEqual(deedType_.description);
expect(deedTypeUpdated.archived_at).toBeNull();
expect(deedTypeUpdated.office_uuid).toEqual(deedType_.office.uid);
expect(deedTypeUpdated.office_uid).toEqual(deedType_.office.uid);
});
it("should archivate a deed type", async () => {
const deedTypeCreated = await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uuid: office_.uid } });
const deedTypeCreated = await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uid: office_.uid } });
expect(deedTypeCreated.name).toEqual(deedType_.name);
expect(deedTypeCreated.description).toEqual(deedType_.description);
expect(deedTypeCreated.archived_at).toBeNull();
expect(deedTypeCreated.office_uuid).toEqual(deedType_.office.uid);
expect(deedTypeCreated.office_uid).toEqual(deedType_.office.uid);
let deedTypeArchivated: DeedType = JSON.parse(JSON.stringify(deedType_));
const currentDate = new Date(Date.now());
deedTypeArchivated.archived_at = new Date(Date.now());
// archivate a deed type by giving a non null date for archivated_at attribute
const deedTypeUpdated = await DeedTypeServiceTest.update(deedTypeCreated.uuid, deedTypeArchivated);
const deedTypeUpdated = await DeedTypeServiceTest.update(deedTypeCreated.uid, deedTypeArchivated);
expect(deedTypeUpdated.name).toEqual(deedType_.name);
expect(deedTypeUpdated.description).toEqual(deedType_.description);
expect(deedTypeUpdated.archived_at).toEqual(currentDate);
expect(deedTypeUpdated.office_uuid).toEqual(office_.uid);
expect(deedTypeUpdated.office_uid).toEqual(office_.uid);
});
it("should unarchivate a deed type", async () => {
const deedTypeCreated = await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uuid: office_.uid } });
const deedTypeCreated = await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uid: office_.uid } });
expect(deedTypeCreated.name).toEqual(deedType_.name);
expect(deedTypeCreated.description).toEqual(deedType_.description);
expect(deedTypeCreated.archived_at).not.toBeNull();
expect(deedTypeCreated.office_uuid).toEqual(deedType_.office.uid);
expect(deedTypeCreated.office_uid).toEqual(deedType_.office.uid);
// unarchivate a deed type by giving a null date for archivated_at attribute
const deedTypeUpdated = await DeedTypeServiceTest.update(deedTypeCreated.uuid, deedType_);
const deedTypeUpdated = await DeedTypeServiceTest.update(deedTypeCreated.uid, deedType_);
expect(deedTypeUpdated.name).toEqual(deedType_.name);
expect(deedTypeUpdated.description).toEqual(deedType_.description);
expect(deedTypeUpdated.archived_at).toBeNull();
expect(deedTypeUpdated.office_uuid).toEqual(office_.uid);
expect(deedTypeUpdated.office_uid).toEqual(office_.uid);
});
it("should add document types to a deed type", async () => {
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType.name, office_uuid: office.uid } })).uuid;
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 = [
@ -207,7 +207,7 @@ describe("test update function", () => {
const deedTypeUpdated = await prisma.deedTypes.findFirstOrThrow({
where: {
uuid: deedTypeUid,
uid: deedTypeUid,
},
include: {
deed_type_has_document_types: true,
@ -217,7 +217,7 @@ describe("test update function", () => {
});
it("should not add document types to a deed type that already has those document types ", async () => {
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType.name, office_uuid: office.uid } })).uuid;
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 = [
@ -239,7 +239,7 @@ describe("test update function", () => {
const deedTypeUpdated = await prisma.deedTypes.findFirstOrThrow({
where: {
uuid: deedTypeUid,
uid: deedTypeUid,
},
include: {
deed_type_has_document_types: true,
@ -249,7 +249,7 @@ describe("test update function", () => {
});
it("should delete document types from a deed", async () => {
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType.name, office_uuid: office.uid } })).uuid;
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType.name, office_uid: office.uid } })).uid;
let deedTypeToUpdate: DeedType = JSON.parse(JSON.stringify(deedType));
// set relation between deed and document types empty
@ -259,7 +259,7 @@ describe("test update function", () => {
const deedTypeUpdated = await prisma.deedTypes.findFirstOrThrow({
where: {
uuid: deedTypeUid,
uid: deedTypeUid,
},
include: {
deed_type_has_document_types: true,
@ -281,21 +281,21 @@ describe("test get function", () => {
expect(deedTypes[0]?.name).toEqual(deedType_.name);
expect(deedTypes[0]?.description).toEqual(deedType_.description);
expect(deedTypes[0]?.archived_at).toBeNull();
expect(deedTypes[0]?.office_uuid).toEqual(office_.uid);
expect(deedTypes[0]?.office_uid).toEqual(office_.uid);
expect(deedTypes[1]?.name).toEqual(deedType.name);
expect(deedTypes[1]?.description).toEqual(deedType.description);
expect(deedTypes[1]?.archived_at).toBeNull();
expect(deedTypes[1]?.office_uuid).toEqual(office.uid);
expect(deedTypes[1]?.office_uid).toEqual(office.uid);
expect(deedTypes[2]?.name).toEqual(deedType.name);
expect(deedTypes[2]?.description).toEqual(deedType.description);
expect(deedTypes[2]?.archived_at).toBeNull();
expect(deedTypes[2]?.office_uuid).toEqual(office_.uid);
expect(deedTypes[2]?.office_uid).toEqual(office_.uid);
});
it("should return an array of DeedTypes per offices", async () => {
const deedTypesForFirstOffice = await DeedTypeServiceTest.get({ where: { office: {uuid: office.uid} }, orderBy: { name: "asc" } });
const deedTypesForFirstOffice = await DeedTypeServiceTest.get({ where: { office: {uid: office.uid} }, orderBy: { name: "asc" } });
expect(deedTypesForFirstOffice.length).toEqual(1);
@ -303,9 +303,9 @@ describe("test get function", () => {
expect(deedTypesForFirstOffice[0]?.name).toEqual(deedType.name);
expect(deedTypesForFirstOffice[0]?.description).toEqual(deedType.description);
expect(deedTypesForFirstOffice[0]?.archived_at).toBeNull();
expect(deedTypesForFirstOffice[0]?.office_uuid).toEqual(office.uid);
expect(deedTypesForFirstOffice[0]?.office_uid).toEqual(office.uid);
const deedTypesForSecondOffice = await DeedTypeServiceTest.get({ where: { office: {uuid: office_.uid} }, orderBy: { name: "asc" } });
const deedTypesForSecondOffice = await DeedTypeServiceTest.get({ where: { office: {uid: office_.uid} }, orderBy: { name: "asc" } });
expect(deedTypesForSecondOffice.length).toEqual(2);
@ -313,11 +313,11 @@ describe("test get function", () => {
expect(deedTypesForSecondOffice[0]?.name).toEqual(deedType_.name);
expect(deedTypesForSecondOffice[0]?.description).toEqual(deedType_.description);
expect(deedTypesForSecondOffice[0]?.archived_at).toBeNull();
expect(deedTypesForSecondOffice[0]?.office_uuid).toEqual(office_.uid);
expect(deedTypesForSecondOffice[0]?.office_uid).toEqual(office_.uid);
expect(deedTypesForSecondOffice[1]?.name).toEqual(deedType.name);
expect(deedTypesForSecondOffice[1]?.description).toEqual(deedType.description);
expect(deedTypesForSecondOffice[1]?.archived_at).toBeNull();
expect(deedTypesForSecondOffice[1]?.office_uuid).toEqual(office_.uid);
expect(deedTypesForSecondOffice[1]?.office_uid).toEqual(office_.uid);
});
});

View File

@ -13,8 +13,8 @@ const prisma = new PrismaClient();
const DocumentTypesServiceTest = new DocumentTypesService(Container.get(DocumentTypesRepository));
beforeAll(async () => {
office.uid = (await initOffice(office)).uuid;
office_.uid = (await initOffice(office_)).uuid;
office.uid = (await initOffice(office)).uid;
office_.uid = (await initOffice(office_)).uid;
});
afterAll(async () => {
@ -27,7 +27,7 @@ afterAll(async () => {
describe("test create function", () => {
it("should not create a new document type if office is unknown", async () => {
let documentTypeWithoutOfficeUid: DocumentType = JSON.parse(JSON.stringify(documentType));
documentTypeWithoutOfficeUid.office.uid = "random uuid";
documentTypeWithoutOfficeUid.office.uid = "random uid";
// try to create a new document type with unknown office
async function createDocumentTypeWithUnknownOffice() {
await DocumentTypesServiceTest.create(documentTypeWithoutOfficeUid);
@ -44,7 +44,7 @@ describe("test create function", () => {
expect(documentTypeCreated.public_description).toEqual(documentType.public_description);
expect(documentTypeCreated.private_description).toEqual(documentType.private_description);
expect(documentTypeCreated.archived_at).toBeNull();
expect(documentTypeCreated.office_uuid).toEqual(office.uid);
expect(documentTypeCreated.office_uid).toEqual(office.uid);
});
it("should not create a new document type with a name already used for a given office", async () => {
@ -68,7 +68,7 @@ describe("test create function", () => {
expect(documentTypeCreated.public_description).toEqual(documentType.public_description);
expect(documentTypeCreated.private_description).toEqual(documentType.private_description);
expect(documentTypeCreated.archived_at).toBeNull();
expect(documentTypeCreated.office_uuid).toEqual(office_.uid);
expect(documentTypeCreated.office_uid).toEqual(office_.uid);
});
it("should create a new document type version with a different name for a given office", async () => {
@ -82,37 +82,37 @@ describe("test create function", () => {
expect(documentTypeCreated.public_description).toEqual(documentType.public_description);
expect(documentTypeCreated.private_description).toEqual(documentType.private_description);
expect(documentTypeCreated.archived_at).toBeNull();
expect(documentTypeCreated.office_uuid).toEqual(office.uid);
expect(documentTypeCreated.office_uid).toEqual(office.uid);
});
});
describe("test update function", () => {
it("should update a document type", async () => {
const documentTypeCreated = await prisma.documentTypes.findFirstOrThrow({
where: { name: documentType_.name, office_uuid: office.uid },
where: { name: documentType_.name, office_uid: office.uid },
});
expect(documentTypeCreated.name).toEqual(documentType_.name);
expect(documentTypeCreated.public_description).toEqual(documentType.public_description);
expect(documentTypeCreated.private_description).toEqual(documentType.private_description);
expect(documentTypeCreated.archived_at).toBeNull();
expect(documentTypeCreated.office_uuid).toEqual(office.uid);
expect(documentTypeCreated.office_uid).toEqual(office.uid);
let documentTypeWithNewDescription: DocumentType = JSON.parse(JSON.stringify(documentType_));
documentTypeWithNewDescription.office.uid = office.uid;
// update the last document type created with his the right descriptions
const documentTypeUpdated = await DocumentTypesServiceTest.update(documentTypeCreated.uuid, documentTypeWithNewDescription);
const documentTypeUpdated = await DocumentTypesServiceTest.update(documentTypeCreated.uid, documentTypeWithNewDescription);
expect(documentTypeUpdated.name).toEqual(documentType_.name);
expect(documentTypeUpdated.public_description).toEqual(documentType_.public_description);
expect(documentTypeUpdated.private_description).toEqual(documentType_.private_description);
expect(documentTypeUpdated.archived_at).toBeNull();
expect(documentTypeUpdated.office_uuid).toEqual(office.uid);
expect(documentTypeUpdated.office_uid).toEqual(office.uid);
});
it("should not update a document type name with an already used name for given office", async () => {
const documentTypeUid = (
await prisma.documentTypes.findFirstOrThrow({ where: { name: documentType_.name, office_uuid: office.uid } })
).uuid;
await prisma.documentTypes.findFirstOrThrow({ where: { name: documentType_.name, office_uid: office.uid } })
).uid;
let documentTypeWithSameNameAndOffice: DocumentType = JSON.parse(JSON.stringify(documentType_));
documentTypeWithSameNameAndOffice.office.uid = office.uid;
documentTypeWithSameNameAndOffice.name = documentType.name;
@ -126,8 +126,8 @@ describe("test update function", () => {
it("should not update a document type office membership if the office already has this document type", async () => {
const documentTypeUid = (
await prisma.documentTypes.findFirstOrThrow({ where: { name: documentType_.name, office_uuid: office.uid } })
).uuid;
await prisma.documentTypes.findFirstOrThrow({ where: { name: documentType_.name, office_uid: office.uid } })
).uid;
let documentTypeWithSameNameAndOffice: DocumentType = JSON.parse(JSON.stringify(documentType_));
documentTypeWithSameNameAndOffice.office.uid = office.uid;
documentTypeWithSameNameAndOffice.name = documentType.name;
@ -141,74 +141,74 @@ describe("test update function", () => {
it("should update a document type office membership", async () => {
const documentTypeCreated = await prisma.documentTypes.findFirstOrThrow({
where: { name: documentType_.name, office_uuid: office.uid },
where: { name: documentType_.name, office_uid: office.uid },
});
expect(documentTypeCreated.name).toEqual(documentType_.name);
expect(documentTypeCreated.public_description).toEqual(documentType_.public_description);
expect(documentTypeCreated.private_description).toEqual(documentType_.private_description);
expect(documentTypeCreated.archived_at).toBeNull();
expect(documentTypeCreated.office_uuid).toEqual(office.uid);
expect(documentTypeCreated.office_uid).toEqual(office.uid);
let documentTypeTransferedToNewOffice: DocumentType = JSON.parse(JSON.stringify(documentType_));
documentTypeTransferedToNewOffice.office.uid = office_.uid;
// update the last document type updated with a new office membership
const documentTypeUpdated = await DocumentTypesServiceTest.update(documentTypeCreated.uuid, documentTypeTransferedToNewOffice);
const documentTypeUpdated = await DocumentTypesServiceTest.update(documentTypeCreated.uid, documentTypeTransferedToNewOffice);
expect(documentTypeUpdated.name).toEqual(documentType_.name);
expect(documentTypeUpdated.public_description).toEqual(documentType_.public_description);
expect(documentTypeUpdated.private_description).toEqual(documentType_.private_description);
expect(documentTypeUpdated.archived_at).toBeNull();
expect(documentTypeUpdated.office_uuid).toEqual(office_.uid);
expect(documentTypeUpdated.office_uid).toEqual(office_.uid);
});
it("should archivate a document type", async () => {
const documentTypeCreated = await prisma.documentTypes.findFirstOrThrow({
where: { name: documentType_.name, office_uuid: office_.uid },
where: { name: documentType_.name, office_uid: office_.uid },
});
expect(documentTypeCreated.name).toEqual(documentType_.name);
expect(documentTypeCreated.public_description).toEqual(documentType_.public_description);
expect(documentTypeCreated.private_description).toEqual(documentType_.private_description);
expect(documentTypeCreated.archived_at).toBeNull();
expect(documentTypeCreated.office_uuid).toEqual(office_.uid);
expect(documentTypeCreated.office_uid).toEqual(office_.uid);
let documentTypeArchivated: DocumentType = JSON.parse(JSON.stringify(documentType_));
documentTypeArchivated.office.uid = office_.uid;
const currentDate = new Date(Date.now());
documentTypeArchivated.archived_at = currentDate;
// archivate a document type by giving a non null date for archivated_at attribute
const documentTypeUpdated = await DocumentTypesServiceTest.update(documentTypeCreated.uuid, documentTypeArchivated);
const documentTypeUpdated = await DocumentTypesServiceTest.update(documentTypeCreated.uid, documentTypeArchivated);
expect(documentTypeUpdated.name).toEqual(documentType_.name);
expect(documentTypeUpdated.public_description).toEqual(documentType_.public_description);
expect(documentTypeUpdated.private_description).toEqual(documentType_.private_description);
expect(documentTypeUpdated.archived_at).toEqual(currentDate);
expect(documentTypeUpdated.office_uuid).toEqual(office_.uid);
expect(documentTypeUpdated.office_uid).toEqual(office_.uid);
});
it("should unarchivate a document type", async () => {
const documentTypeCreated = await prisma.documentTypes.findFirstOrThrow({
where: { name: documentType_.name, office_uuid: office_.uid },
where: { name: documentType_.name, office_uid: office_.uid },
});
expect(documentTypeCreated.name).toEqual(documentType_.name);
expect(documentTypeCreated.public_description).toEqual(documentType_.public_description);
expect(documentTypeCreated.private_description).toEqual(documentType_.private_description);
expect(documentTypeCreated.archived_at).not.toBeNull();
expect(documentTypeCreated.office_uuid).toEqual(office_.uid);
expect(documentTypeCreated.office_uid).toEqual(office_.uid);
let documentTypeUnarchivated: DocumentType = JSON.parse(JSON.stringify(documentType_));
documentTypeUnarchivated.office.uid = office_.uid;
// unarchivate a document type by giving a null date for archivated_at attribute
const documentTypeUpdated = await DocumentTypesServiceTest.update(documentTypeCreated.uuid, documentTypeUnarchivated);
const documentTypeUpdated = await DocumentTypesServiceTest.update(documentTypeCreated.uid, documentTypeUnarchivated);
expect(documentTypeUpdated.name).toEqual(documentType_.name);
expect(documentTypeUpdated.public_description).toEqual(documentType_.public_description);
expect(documentTypeUpdated.private_description).toEqual(documentType_.private_description);
expect(documentTypeUpdated.archived_at).toBeNull();
expect(documentTypeUpdated.office_uuid).toEqual(office_.uid);
expect(documentTypeUpdated.office_uid).toEqual(office_.uid);
});
});
@ -225,23 +225,23 @@ describe("test get function", () => {
expect(documentTypes[0]?.public_description).toEqual(documentType_.public_description);
expect(documentTypes[0]?.private_description).toEqual(documentType_.private_description);
expect(documentTypes[0]?.archived_at).toBeNull();
expect(documentTypes[0]?.office_uuid).toEqual(office_.uid);
expect(documentTypes[0]?.office_uid).toEqual(office_.uid);
expect(documentTypes[1]?.name).toEqual(documentType.name);
expect(documentTypes[1]?.public_description).toEqual(documentType.public_description);
expect(documentTypes[1]?.private_description).toEqual(documentType.private_description);
expect(documentTypes[1]?.archived_at).toBeNull();
expect(documentTypes[1]?.office_uuid).toEqual(office.uid);
expect(documentTypes[1]?.office_uid).toEqual(office.uid);
expect(documentTypes[2]?.name).toEqual(documentType.name);
expect(documentTypes[2]?.public_description).toEqual(documentType.public_description);
expect(documentTypes[2]?.private_description).toEqual(documentType.private_description);
expect(documentTypes[2]?.archived_at).toBeNull();
expect(documentTypes[2]?.office_uuid).toEqual(office_.uid);
expect(documentTypes[2]?.office_uid).toEqual(office_.uid);
});
it("should return an array of DocumentTypes per offices", async () => {
const documentTypesForFirstOffice = await DocumentTypesServiceTest.get({ where: { office: {uuid : office.uid }}, orderBy: { name: "asc" } });
const documentTypesForFirstOffice = await DocumentTypesServiceTest.get({ where: { office: {uid : office.uid }}, orderBy: { name: "asc" } });
expect(documentTypesForFirstOffice.length).toEqual(1);
@ -250,9 +250,9 @@ describe("test get function", () => {
expect(documentTypesForFirstOffice[0]?.public_description).toEqual(documentType.public_description);
expect(documentTypesForFirstOffice[0]?.private_description).toEqual(documentType.private_description);
expect(documentTypesForFirstOffice[0]?.archived_at).toBeNull();
expect(documentTypesForFirstOffice[0]?.office_uuid).toEqual(office.uid);
expect(documentTypesForFirstOffice[0]?.office_uid).toEqual(office.uid);
const documentTypesForSecondOffice = await DocumentTypesServiceTest.get({ where: { office: {uuid : office_.uid }}, orderBy: { name: "asc" } });
const documentTypesForSecondOffice = await DocumentTypesServiceTest.get({ where: { office: {uid : office_.uid }}, orderBy: { name: "asc" } });
expect(documentTypesForSecondOffice.length).toEqual(2);
@ -261,12 +261,12 @@ describe("test get function", () => {
expect(documentTypesForSecondOffice[0]?.public_description).toEqual(documentType_.public_description);
expect(documentTypesForSecondOffice[0]?.private_description).toEqual(documentType_.private_description);
expect(documentTypesForSecondOffice[0]?.archived_at).toBeNull();
expect(documentTypesForSecondOffice[0]?.office_uuid).toEqual(office_.uid);
expect(documentTypesForSecondOffice[0]?.office_uid).toEqual(office_.uid);
expect(documentTypesForSecondOffice[1]?.name).toEqual(documentType.name);
expect(documentTypesForSecondOffice[1]?.public_description).toEqual(documentType.public_description);
expect(documentTypesForSecondOffice[1]?.private_description).toEqual(documentType.private_description);
expect(documentTypesForSecondOffice[1]?.archived_at).toBeNull();
expect(documentTypesForSecondOffice[1]?.office_uuid).toEqual(office_.uid);
expect(documentTypesForSecondOffice[1]?.office_uid).toEqual(office_.uid);
});
});

View File

@ -1,18 +1,7 @@
import "module-alias/register";
import "reflect-metadata";
import { OfficeFolderHasCustomers, OfficeFolderHasStakeholders, PrismaClient } from "prisma/prisma-client";
import {
customer,
customer_,
deedType,
documentType,
documentType_,
office,
officeFolder,
officeFolder_,
user,
user_,
} from "@Test/config/MockedData";
import { customer, customer_, deedType, documentType, documentType_, office, officeFolder, officeFolder_, user, user_ } from "@Test/config/MockedData";
import Container from "typedi";
import OfficeFoldersRepository from "@Repositories/OfficeFoldersRepository";
import OfficeFolderService from "@Services/super-admin/OfficeFoldersService/OfficeFoldersService";
@ -25,14 +14,14 @@ const prisma = new PrismaClient();
const OfficeFolderServiceTest = new OfficeFolderService(Container.get(OfficeFoldersRepository), Container.get(DeedTypesService));
beforeAll(async () => {
office.uid = (await initOffice(office)).uuid;
documentType.uid = (await initDocumentType(documentType, office)).uuid;
documentType_.uid = (await initDocumentType(documentType_, office)).uuid;
deedType.uid = (await initDeedType(deedType, office, [documentType.uid])).uuid;
user.uid = (await initUsers(user)).uuid;
user_.uid = (await initUsers(user_)).uuid;
customer.uid = (await initCustomers(customer)).uuid;
customer_.uid = (await initCustomers(customer_)).uuid;
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;
user.uid = (await initUsers(user)).uid;
user_.uid = (await initUsers(user_)).uid;
customer.uid = (await initCustomers(customer)).uid;
customer_.uid = (await initCustomers(customer_)).uid;
});
afterAll(async () => {
@ -49,7 +38,7 @@ afterAll(async () => {
describe("test create function", () => {
it("should not create a new office folder if deed type is unknown", async () => {
let officeFolderWithoutDeedTypeUid: OfficeFolder = JSON.parse(JSON.stringify(officeFolder));
officeFolderWithoutDeedTypeUid.deed.deed_type.uid = "random uuid";
officeFolderWithoutDeedTypeUid.deed.deed_type.uid = "random uid";
// try to create a new deed with unknown deed type
async function createOfficeFolderWithUnknownDeedType() {
await OfficeFolderServiceTest.create(officeFolderWithoutDeedTypeUid);
@ -57,18 +46,27 @@ describe("test create function", () => {
await expect(createOfficeFolderWithUnknownDeedType).rejects.toThrow();
});
it("should not create a new office folder if deed type is archived", async () => {
let officeFolderWithArchivatedDeedType: OfficeFolder = JSON.parse(JSON.stringify(officeFolder));
// try to create a new deed with unknown deed type
async function createOfficeFolderWithArchivedDeedType() {
await OfficeFolderServiceTest.create(officeFolderWithArchivatedDeedType);
}
await expect(createOfficeFolderWithArchivedDeedType).rejects.toThrow("deed type is archived");
});
it("should create a new office folder based on existing deed type", async () => {
const officeFolderCreated = await OfficeFolderServiceTest.create(officeFolder);
const deedCreated = await prisma.deeds.findUniqueOrThrow({ where: { uuid: officeFolderCreated.deed_uuid } });
const deedCreated = await prisma.deeds.findUniqueOrThrow({ where: { uid: officeFolderCreated.deed_uid } });
expect(officeFolderCreated.name).toEqual(officeFolder.name);
expect(officeFolderCreated.folder_number).toEqual(officeFolder.folder_number);
expect(officeFolderCreated.description).toEqual(officeFolder.description);
expect(officeFolderCreated.archived_description).toEqual(null);
expect(officeFolderCreated.status).toEqual("LIVE");
expect(officeFolderCreated.office_uuid).toEqual(officeFolder.office.uid);
expect(deedCreated.deed_type_uuid).toEqual(officeFolder.deed.deed_type.uid);
expect(officeFolderCreated.office_uid).toEqual(officeFolder.office.uid);
expect(deedCreated.deed_type_uid).toEqual(officeFolder.deed.deed_type.uid);
});
it("should contains stakeholders", async () => {
@ -77,32 +75,32 @@ describe("test create function", () => {
});
const stakeholderRelation = await prisma.officeFolderHasStakeholders.findUniqueOrThrow({
where: {
office_folder_uuid_user_stakeholder_uuid: {
user_stakeholder_uuid: user.uid!,
office_folder_uuid: officeFolderCreated.uuid,
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_uuid_user_stakeholder_uuid: {
user_stakeholder_uuid: user_.uid!,
office_folder_uuid: officeFolderCreated.uuid,
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 = {
uuid: stakeholderRelation.uuid,
office_folder_uuid: officeFolderCreated.uuid,
user_stakeholder_uuid: user.uid!,
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 = {
uuid: stakeholderRelation_.uuid,
office_folder_uuid: officeFolderCreated.uuid,
user_stakeholder_uuid: user_.uid!,
uid: stakeholderRelation_.uid,
office_folder_uid: officeFolderCreated.uid,
user_stakeholder_uid: user_.uid!,
created_at: officeFolderCreated.created_at,
updated_at: officeFolderCreated.updated_at,
};
@ -120,7 +118,7 @@ describe("test create function", () => {
});
it("should not create a new office folder if deed type is archived", async () => {
await prisma.deedTypes.update({ where: { uuid: deedType.uid }, data: { archived_at: new Date(Date.now()) } });
await prisma.deedTypes.update({ where: { uid: deedType.uid }, data: { archived_at: new Date(Date.now()) } });
// try to create a new deed with archivated deed type
async function createDeedWithArchivatedDeedType() {
await OfficeFolderServiceTest.create(officeFolder);
@ -137,21 +135,21 @@ describe("test update function", () => {
expect(officeFolderCreated.office_folder_has_customers).toEqual([]);
// mocked data contains the customers
await OfficeFolderServiceTest.update(officeFolderCreated.uuid, officeFolder);
await OfficeFolderServiceTest.update(officeFolderCreated.uid, officeFolder);
const customerRelation = await prisma.officeFolderHasCustomers.findUniqueOrThrow({
where: {
office_folder_uuid_customer_uuid: {
customer_uuid: customer.uid!,
office_folder_uuid: officeFolderCreated.uuid,
office_folder_uid_customer_uid: {
customer_uid: customer.uid!,
office_folder_uid: officeFolderCreated.uid,
},
},
});
const customerRelation_ = await prisma.officeFolderHasCustomers.findUniqueOrThrow({
where: {
office_folder_uuid_customer_uuid: {
customer_uuid: customer_.uid!,
office_folder_uuid: officeFolderCreated.uuid,
office_folder_uid_customer_uid: {
customer_uid: customer_.uid!,
office_folder_uid: officeFolderCreated.uid,
},
},
});
@ -162,16 +160,16 @@ describe("test update function", () => {
expect(officeFolderCreated.office_folder_has_customers.length).toEqual(2);
const officeFolderHasCustomer: OfficeFolderHasCustomers = {
uuid: customerRelation.uuid,
office_folder_uuid: officeFolderCreated.uuid,
customer_uuid: customer.uid!,
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 = {
uuid: customerRelation_.uuid,
office_folder_uuid: officeFolderCreated.uuid,
customer_uuid: customer_.uid!,
uid: customerRelation_.uid,
office_folder_uid: officeFolderCreated.uid,
customer_uid: customer_.uid!,
created_at: customerRelation_.created_at,
updated_at: customerRelation_.updated_at,
};
@ -190,13 +188,13 @@ describe("test update function", () => {
let officeFolderWithLessCustomers: OfficeFolder = JSON.parse(JSON.stringify(officeFolder));
officeFolderWithLessCustomers.office_folder_has_customers!.pop();
// mocked data contains the customers
await OfficeFolderServiceTest.update(officeFolderCreated.uuid, officeFolderWithLessCustomers);
await OfficeFolderServiceTest.update(officeFolderCreated.uid, officeFolderWithLessCustomers);
const customerRelation = await prisma.officeFolderHasCustomers.findUniqueOrThrow({
where: {
office_folder_uuid_customer_uuid: {
customer_uuid: customer.uid!,
office_folder_uuid: officeFolderCreated.uuid,
office_folder_uid_customer_uid: {
customer_uid: customer.uid!,
office_folder_uid: officeFolderCreated.uid,
},
},
});
@ -207,9 +205,9 @@ describe("test update function", () => {
expect(officeFolderCreated.office_folder_has_customers.length).toEqual(1);
const officeFolderHasCustomer: OfficeFolderHasCustomers = {
uuid: customerRelation.uuid,
office_folder_uuid: officeFolderCreated.uuid,
customer_uuid: customer.uid!,
uid: customerRelation.uid,
office_folder_uid: officeFolderCreated.uid,
customer_uid: customer.uid!,
created_at: customerRelation.created_at,
updated_at: customerRelation.updated_at,
};
@ -225,13 +223,13 @@ describe("test update function", () => {
let officeFolderWithLessStakeholders: OfficeFolder = JSON.parse(JSON.stringify(officeFolder));
officeFolderWithLessStakeholders.office_folder_has_stakeholder!.pop();
// mocked data contains the customers
await OfficeFolderServiceTest.update(officeFolderCreated.uuid, officeFolderWithLessStakeholders);
await OfficeFolderServiceTest.update(officeFolderCreated.uid, officeFolderWithLessStakeholders);
const stakeholderRelation = await prisma.officeFolderHasStakeholders.findUniqueOrThrow({
where: {
office_folder_uuid_user_stakeholder_uuid: {
user_stakeholder_uuid: user.uid!,
office_folder_uuid: officeFolderCreated.uuid,
office_folder_uid_user_stakeholder_uid: {
user_stakeholder_uid: user.uid!,
office_folder_uid: officeFolderCreated.uid,
},
},
});
@ -242,9 +240,9 @@ describe("test update function", () => {
expect(officeFolderCreated.office_folder_has_stakeholder.length).toEqual(1);
const officeFolderHasStakeholder: OfficeFolderHasStakeholders = {
uuid: stakeholderRelation.uuid,
office_folder_uuid: officeFolderCreated.uuid,
user_stakeholder_uuid: user.uid!,
uid: stakeholderRelation.uid,
office_folder_uid: officeFolderCreated.uid,
user_stakeholder_uid: user.uid!,
created_at: stakeholderRelation.created_at,
updated_at: stakeholderRelation.updated_at,
};
@ -256,7 +254,7 @@ describe("test update function", () => {
// mocked data for this office folder is "ARCHIVATED" by default
officeFolderArchived.archived_description = "folder complete";
const officeFolderUpdated = await OfficeFolderServiceTest.update(officeFolderCreated.uuid, officeFolderArchived);
const officeFolderUpdated = await OfficeFolderServiceTest.update(officeFolderCreated.uid, officeFolderArchived);
expect(officeFolderUpdated.archived_description).toEqual(officeFolderArchived.archived_description);
expect(officeFolderUpdated.status).toEqual("ARCHIVED");
@ -270,7 +268,7 @@ describe("test update function", () => {
let officeFolderUnarchived: OfficeFolder = JSON.parse(JSON.stringify(officeFolder));
officeFolderUnarchived.status = "LIVE";
const officeFolderUpdated = await OfficeFolderServiceTest.update(officeFolderCreated.uuid, officeFolderUnarchived);
const officeFolderUpdated = await OfficeFolderServiceTest.update(officeFolderCreated.uid, officeFolderUnarchived);
expect(officeFolderUpdated.archived_description).toBeNull();
expect(officeFolderUpdated.status).toEqual("LIVE");

View File

@ -28,7 +28,7 @@ describe("test create function", () => {
expect(userCreated?.idNot).toEqual(user.idNot);
// verify if user contact is created in db
const contactCreated = await prisma.contacts.findUnique({ where: { uuid: userCreated.contact_uuid } });
const contactCreated = await prisma.contacts.findUnique({ where: { uid: userCreated.contact_uid } });
expect(contactCreated?.first_name).toEqual(user.contact.first_name);
expect(contactCreated?.last_name).toEqual(user.contact.last_name);
expect(contactCreated?.cell_phone_number).toEqual(user.contact.cell_phone_number);
@ -37,20 +37,20 @@ describe("test create function", () => {
expect(contactCreated?.email).toEqual(user.contact.email);
// verify if user address is created in db
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uuid: contactCreated?.address_uuid } });
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid } });
expect(addressForContactCreated?.address).toEqual(user.contact.address?.address);
expect(addressForContactCreated?.zip_code).toEqual(user.contact.address?.zip_code);
expect(addressForContactCreated?.city).toEqual(user.contact.address?.city);
// verify if user office is created in db
const officeCreated = await prisma.offices.findUnique({ where: { uuid: userCreated.office_uuid } });
const officeCreated = await prisma.offices.findUnique({ where: { uid: userCreated.office_uid } });
expect(officeCreated?.idNot).toEqual(user.office_membership.idNot);
expect(officeCreated?.name).toEqual(user.office_membership.name);
expect(officeCreated?.crpcen).toEqual(user.office_membership.crpcen);
expect(officeCreated?.office_status).toEqual("DESACTIVATED");
// verify if user office's address is created in db
const addressForOfficeCreated = await prisma.addresses.findUnique({ where: { uuid: officeCreated?.address_uuid } });
const addressForOfficeCreated = await prisma.addresses.findUnique({ where: { uid: officeCreated?.address_uid } });
expect(addressForOfficeCreated?.address).toEqual(user.office_membership.address.address);
expect(addressForOfficeCreated?.zip_code).toEqual(user.office_membership.address.zip_code);
expect(addressForOfficeCreated?.city).toEqual(user.office_membership.address.city);
@ -97,7 +97,7 @@ describe("test create function", () => {
expect(userCreated?.idNot).toEqual(user_.idNot);
// verify if user_ contact is created in db
const contactCreated = await prisma.contacts.findUnique({ where: { uuid: userCreated.contact_uuid } });
const contactCreated = await prisma.contacts.findUnique({ where: { uid: userCreated.contact_uid } });
expect(contactCreated?.first_name).toEqual(user.contact.first_name);
expect(contactCreated?.last_name).toEqual(user.contact.last_name);
expect(contactCreated?.cell_phone_number).toEqual(user_.contact.cell_phone_number);
@ -106,13 +106,13 @@ describe("test create function", () => {
expect(contactCreated?.email).toEqual(user_.contact.email);
// verify if user_ address is created in db
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uuid: contactCreated?.address_uuid } });
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid } });
expect(addressForContactCreated?.address).toEqual(user.contact.address?.address);
expect(addressForContactCreated?.zip_code).toEqual(user.contact.address?.zip_code);
expect(addressForContactCreated?.city).toEqual(user.contact.address?.city);
// verify if user joined the existing office
const officeJoined = await prisma.offices.findUnique({ where: { uuid: userCreated.office_uuid } });
const officeJoined = await prisma.offices.findUnique({ where: { uid: userCreated.office_uid } });
expect(officeJoined?.idNot).toEqual(user.office_membership.idNot);
expect(officeJoined?.name).toEqual(user.office_membership.name);
expect(officeJoined?.crpcen).toEqual(user.office_membership.crpcen);
@ -124,19 +124,19 @@ describe("test update function", () => {
it("should update an user's data", async () => {
const userCreated = await prisma.users.findFirstOrThrow({ where: { idNot: user_.idNot } });
const officeJoined = await prisma.offices.findUnique({ where: { uuid: userCreated.office_uuid } });
const officeJoined = await prisma.offices.findUnique({ where: { uid: userCreated.office_uid } });
expect(officeJoined?.idNot).toEqual(user.office_membership.idNot);
expect(officeJoined?.name).toEqual(user.office_membership.name);
expect(officeJoined?.crpcen).toEqual(user.office_membership.crpcen);
expect(officeJoined?.office_status).toEqual("DESACTIVATED");
// update the last user created with his own new office and own contact
const updatedUser = await UsersServiceTest.update(userCreated.uuid, user_);
const updatedUser = await UsersServiceTest.update(userCreated.uid, user_);
expect(updatedUser?.idNot).toEqual(user_.idNot);
// verify if user_ contact is created in db
const existingContact = await prisma.contacts.findUnique({ where: { uuid: updatedUser.contact_uuid } });
const existingContact = await prisma.contacts.findUnique({ where: { uid: updatedUser.contact_uid } });
expect(existingContact?.first_name).toEqual(user_.contact.first_name);
expect(existingContact?.last_name).toEqual(user_.contact.last_name);
expect(existingContact?.cell_phone_number).toEqual(user_.contact.cell_phone_number);
@ -145,27 +145,27 @@ describe("test update function", () => {
expect(existingContact?.email).toEqual(user_.contact.email);
// verify if user_ address is created in db
const addressForExistingContact = await prisma.addresses.findUnique({ where: { uuid: existingContact?.address_uuid } });
const addressForExistingContact = await prisma.addresses.findUnique({ where: { uid: existingContact?.address_uid } });
expect(addressForExistingContact?.address).toEqual(user_.contact.address?.address);
expect(addressForExistingContact?.zip_code).toEqual(user_.contact.address?.zip_code);
expect(addressForExistingContact?.city).toEqual(user_.contact.address?.city);
// verify if user_ joined the new office
const officeCreated = await prisma.offices.findUnique({ where: { uuid: updatedUser.office_uuid } });
const officeCreated = await prisma.offices.findUnique({ where: { uid: updatedUser.office_uid } });
expect(officeCreated?.idNot).toEqual(user_.office_membership.idNot);
expect(officeCreated?.name).toEqual(user_.office_membership.name);
expect(officeCreated?.crpcen).toEqual(user_.office_membership.crpcen);
expect(officeCreated?.office_status).toEqual("DESACTIVATED");
// verify is user_ office's address is created in db
const addressForOfficeCreated = await prisma.addresses.findUnique({ where: { uuid: officeCreated?.address_uuid } });
const addressForOfficeCreated = await prisma.addresses.findUnique({ where: { uid: officeCreated?.address_uid } });
expect(addressForOfficeCreated?.address).toEqual(user_.office_membership.address.address);
expect(addressForOfficeCreated?.zip_code).toEqual(user_.office_membership.address.zip_code);
expect(addressForOfficeCreated?.city).toEqual(user_.office_membership.address.city);
});
it("should not update an user with an email already used", async () => {
const userUid = (await prisma.users.findFirstOrThrow({ where: { idNot: user_.idNot } })).uuid;
const userUid = (await prisma.users.findFirstOrThrow({ where: { idNot: user_.idNot } })).uid;
let updatedUser: User = JSON.parse(JSON.stringify(user_));
updatedUser.contact.email = userContact.email;
@ -177,7 +177,7 @@ describe("test update function", () => {
});
it("should not update an user with an phone number already used", async () => {
const userUid = (await prisma.users.findFirstOrThrow({ where: { idNot: user_.idNot } })).uuid;
const userUid = (await prisma.users.findFirstOrThrow({ where: { idNot: user_.idNot } })).uid;
let updatedUser: User = JSON.parse(JSON.stringify(user_));
updatedUser.contact.cell_phone_number = userContact.cell_phone_number;
@ -206,7 +206,7 @@ describe("test get function", () => {
it("should return an array of Users per offices", async () => {
const officesCreated = await prisma.offices.findMany();
const reqForFirstOffice = { where: { office_uuid: officesCreated[0]?.uuid } };
const reqForFirstOffice = { where: { office_uid: officesCreated[0]?.uid } };
const usersForFirstOffice = await UsersServiceTest.get(reqForFirstOffice);
expect(usersForFirstOffice.length).toEqual(1);
@ -214,7 +214,7 @@ describe("test get function", () => {
// verify result content
expect(usersForFirstOffice[0]?.idNot).toEqual(user.idNot);
const reqForSecondOffice = { where: { office_uuid: officesCreated[1]?.uuid } };
const reqForSecondOffice = { where: { office_uid: officesCreated[1]?.uid } };
const usersForSecondOffice = await UsersServiceTest.get(reqForSecondOffice);
expect(usersForSecondOffice.length).toEqual(1);