notif schema updated

This commit is contained in:
Vins 2023-09-14 10:20:12 +02:00
parent c2431bace6
commit 643ba11732
9 changed files with 79 additions and 39 deletions

2
package-lock.json generated
View File

@ -19,7 +19,7 @@
"cron": "^2.3.1",
"express": "^4.18.2",
"jsonwebtoken": "^9.0.0",
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.71",
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.72",
"module-alias": "^2.2.2",
"multer": "^1.4.5-lts.1",
"next": "^13.1.5",

View File

@ -52,7 +52,7 @@
"cron": "^2.3.1",
"express": "^4.18.2",
"jsonwebtoken": "^9.0.0",
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.71",
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.72",
"module-alias": "^2.2.2",
"multer": "^1.4.5-lts.1",
"next": "^13.1.5",

View File

@ -13,11 +13,12 @@ import fileHandler from "@App/middlewares/CustomerHandler/FileHandler";
import DocumentTypesService from "@Services/super-admin/DocumentTypesService/DocumentTypesService";
import { DocumentType } from "le-coffre-resources/dist/SuperAdmin";
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
import NotificationBuilder from "@Common/notifications/NotificationBuilder";
@Controller()
@Service()
export default class FilesController extends ApiController {
constructor(private filesService: FilesService, private documentService: DocumentsService, private documentTypesService : DocumentTypesService) {
constructor(private filesService: FilesService, private documentService: DocumentsService, private documentTypesService : DocumentTypesService, private notificationBuilder : NotificationBuilder) {
super();
}
@ -90,7 +91,6 @@ export default class FilesController extends ApiController {
//init File resource with request body values
const fileEntity = File.hydrate<File>(JSON.parse(req.body["q"]));
console.log(fileEntity);
//validate File
// await validateOrReject(fileEntity, { groups: ["createFile"] });
@ -103,7 +103,8 @@ export default class FilesController extends ApiController {
const documentToUpdate = Document.hydrate<Document>(document!);
documentToUpdate!.document_status = "DEPOSITED";
await this.documentService.update(document!.uid!, documentToUpdate);
const documentUpdated = await this.documentService.update(document!.uid!, documentToUpdate);
await this.notificationBuilder.sendDocumentDepositedNotification(documentUpdated!);
//Hydrate ressource with prisma entity
const fileEntityHydrated = File.hydrate<File>(fileEntityCreated, {

View File

@ -3,7 +3,7 @@ import { Controller, Get } from "@ControllerPattern/index";
import ApiController from "@Common/system/controller-pattern/ApiController";
import UsersService from "@Services/notary/UsersService/UsersService";
import { Service } from "typedi";
import User from "le-coffre-resources/dist/Notary";
import User from "le-coffre-resources/dist/SuperAdmin";
import { Prisma } from "@prisma/client";
import authHandler from "@App/middlewares/AuthHandler";
import ruleHandler from "@App/middlewares/RulesHandler";

View File

@ -0,0 +1,37 @@
/*
Warnings:
- You are about to drop the column `status` on the `notifications` table. All the data in the column will be lost.
- You are about to drop the `_UserHasNotifications` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropForeignKey
ALTER TABLE "_UserHasNotifications" DROP CONSTRAINT "_UserHasNotifications_A_fkey";
-- DropForeignKey
ALTER TABLE "_UserHasNotifications" DROP CONSTRAINT "_UserHasNotifications_B_fkey";
-- AlterTable
ALTER TABLE "notifications" DROP COLUMN "status";
-- DropTable
DROP TABLE "_UserHasNotifications";
-- CreateTable
CREATE TABLE "user_notifications" (
"uid" TEXT NOT NULL,
"user_uid" VARCHAR(255) NOT NULL,
"read" BOOLEAN NOT NULL DEFAULT false,
"notification_uid" VARCHAR(255) NOT NULL,
CONSTRAINT "user_notifications_pkey" PRIMARY KEY ("uid")
);
-- CreateIndex
CREATE UNIQUE INDEX "user_notifications_uid_key" ON "user_notifications"("uid");
-- AddForeignKey
ALTER TABLE "user_notifications" ADD CONSTRAINT "user_notifications_user_uid_fkey" FOREIGN KEY ("user_uid") REFERENCES "users"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "user_notifications" ADD CONSTRAINT "user_notifications_notification_uid_fkey" FOREIGN KEY ("notification_uid") REFERENCES "notifications"("uid") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -63,10 +63,10 @@ model Users {
updated_at DateTime? @updatedAt
office_membership Offices @relation(fields: [office_uid], references: [uid], onDelete: Cascade)
office_uid String @db.VarChar(255)
notifications Notifications[] @relation("UserHasNotifications")
office_folders OfficeFolders[] @relation("OfficeFolderHasStakeholders")
appointment Appointments[]
votes Votes[]
user_notifications UserNotifications[]
@@map("users")
}
@ -108,13 +108,23 @@ model Notifications {
message String @db.VarChar(255)
redirection_url String @db.VarChar(255)
created_at DateTime? @default(now())
status ENotificationStatus @default(UNREAD)
updated_at DateTime? @updatedAt
users Users[] @relation("UserHasNotifications")
updated_at DateTime? @updatedAt
userNotifications UserNotifications[]
@@map("notifications")
}
model UserNotifications {
uid String @id @unique @default(uuid())
user Users @relation(fields: [user_uid], references: [uid], onDelete: Cascade)
user_uid String @db.VarChar(255)
read Boolean @default(false)
notification Notifications @relation(fields: [notification_uid], references: [uid], onDelete: Cascade)
notification_uid String @db.VarChar(255)
@@map("user_notifications")
}
model OfficeFolders {
uid String @id @unique @default(uuid())
folder_number String @db.VarChar(255)

View File

@ -10,9 +10,12 @@ export default class NotificationBuilder {
public constructor(private notificationsService : NotificationsService, private documentsService: DocumentsService){}
public async sendDocumentDepositedNotification(documentEntity: Documents){
console.log(documentEntity);
if(documentEntity.document_status !== "DEPOSITED") return;
const documentPrisma = await this.documentsService.getByUid(documentEntity.uid, { depositor: {include: {contact: true}}, folder:{include:{ office: true}} });
const documentPrisma = await this.documentsService.getByUid(documentEntity.uid, { depositor: {include: {contact: true}}, folder:{include:{ office: true, stakeholders: true}} });
if(!documentPrisma) throw new Error("Document not found");
const document = Document.hydrate<Document>(documentPrisma);
console.log(document);
@ -22,6 +25,7 @@ export default class NotificationBuilder {
redirection_url: "",
created_at: new Date(),
updated_at: new Date(),
user : document.folder!.stakeholders || [],
});
}

View File

@ -32,31 +32,28 @@ export default class NotificationRepository extends BaseRepository {
data: {
message: notification.message,
redirection_url: notification.redirection_url,
users: {
connect: notification.user
}
// users: {
// connect: notification.user!.map((user) => {
// return { uid: user.uid };
// }),
// }
userNotifications:{
create: notification.user!.map((user) => {
return {
user: {
connect: {
uid: user.uid
}
}
}
})
}
},
};
return this.model.create(createArgs);
}
/**
* @description : update given email
*/
public async update(uid: string, notification: Notifications): Promise<Notifications> {
const updateArgs: Prisma.NotificationsUpdateArgs = {
where: {
uid: uid,
},
data: {
status: notification.status,
},
};
return this.model.update(updateArgs);
}
/**
* @description : find unique email
*/

View File

@ -28,15 +28,6 @@ export default class NotificationsService extends BaseService {
return this.notificationRepository.create(notification);
}
/**
* @description : Modify a new notification
* @returns : T
* @throws {Error} If notification cannot be modified
*/
public async update(uid: string, notificationEntity: Notifications): Promise<Notifications> {
return this.notificationRepository.update(uid, notificationEntity);
}
/**
* @description : Get a notification by uid
* @returns : T