notif schema updated
This commit is contained in:
parent
c2431bace6
commit
643ba11732
2
package-lock.json
generated
2
package-lock.json
generated
@ -19,7 +19,7 @@
|
|||||||
"cron": "^2.3.1",
|
"cron": "^2.3.1",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"jsonwebtoken": "^9.0.0",
|
"jsonwebtoken": "^9.0.0",
|
||||||
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.71",
|
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.72",
|
||||||
"module-alias": "^2.2.2",
|
"module-alias": "^2.2.2",
|
||||||
"multer": "^1.4.5-lts.1",
|
"multer": "^1.4.5-lts.1",
|
||||||
"next": "^13.1.5",
|
"next": "^13.1.5",
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
"cron": "^2.3.1",
|
"cron": "^2.3.1",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"jsonwebtoken": "^9.0.0",
|
"jsonwebtoken": "^9.0.0",
|
||||||
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.71",
|
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.72",
|
||||||
"module-alias": "^2.2.2",
|
"module-alias": "^2.2.2",
|
||||||
"multer": "^1.4.5-lts.1",
|
"multer": "^1.4.5-lts.1",
|
||||||
"next": "^13.1.5",
|
"next": "^13.1.5",
|
||||||
|
@ -13,11 +13,12 @@ import fileHandler from "@App/middlewares/CustomerHandler/FileHandler";
|
|||||||
import DocumentTypesService from "@Services/super-admin/DocumentTypesService/DocumentTypesService";
|
import DocumentTypesService from "@Services/super-admin/DocumentTypesService/DocumentTypesService";
|
||||||
import { DocumentType } from "le-coffre-resources/dist/SuperAdmin";
|
import { DocumentType } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
||||||
|
import NotificationBuilder from "@Common/notifications/NotificationBuilder";
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@Service()
|
@Service()
|
||||||
export default class FilesController extends ApiController {
|
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();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +91,6 @@ export default class FilesController extends ApiController {
|
|||||||
|
|
||||||
//init File resource with request body values
|
//init File resource with request body values
|
||||||
const fileEntity = File.hydrate<File>(JSON.parse(req.body["q"]));
|
const fileEntity = File.hydrate<File>(JSON.parse(req.body["q"]));
|
||||||
console.log(fileEntity);
|
|
||||||
|
|
||||||
//validate File
|
//validate File
|
||||||
// await validateOrReject(fileEntity, { groups: ["createFile"] });
|
// await validateOrReject(fileEntity, { groups: ["createFile"] });
|
||||||
@ -103,7 +103,8 @@ export default class FilesController extends ApiController {
|
|||||||
const documentToUpdate = Document.hydrate<Document>(document!);
|
const documentToUpdate = Document.hydrate<Document>(document!);
|
||||||
|
|
||||||
documentToUpdate!.document_status = "DEPOSITED";
|
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
|
//Hydrate ressource with prisma entity
|
||||||
const fileEntityHydrated = File.hydrate<File>(fileEntityCreated, {
|
const fileEntityHydrated = File.hydrate<File>(fileEntityCreated, {
|
||||||
|
@ -3,7 +3,7 @@ import { Controller, Get } from "@ControllerPattern/index";
|
|||||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||||
import UsersService from "@Services/notary/UsersService/UsersService";
|
import UsersService from "@Services/notary/UsersService/UsersService";
|
||||||
import { Service } from "typedi";
|
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 { Prisma } from "@prisma/client";
|
||||||
import authHandler from "@App/middlewares/AuthHandler";
|
import authHandler from "@App/middlewares/AuthHandler";
|
||||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||||
|
@ -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;
|
@ -63,10 +63,10 @@ model Users {
|
|||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
office_membership Offices @relation(fields: [office_uid], references: [uid], onDelete: Cascade)
|
office_membership Offices @relation(fields: [office_uid], references: [uid], onDelete: Cascade)
|
||||||
office_uid String @db.VarChar(255)
|
office_uid String @db.VarChar(255)
|
||||||
notifications Notifications[] @relation("UserHasNotifications")
|
|
||||||
office_folders OfficeFolders[] @relation("OfficeFolderHasStakeholders")
|
office_folders OfficeFolders[] @relation("OfficeFolderHasStakeholders")
|
||||||
appointment Appointments[]
|
appointment Appointments[]
|
||||||
votes Votes[]
|
votes Votes[]
|
||||||
|
user_notifications UserNotifications[]
|
||||||
|
|
||||||
@@map("users")
|
@@map("users")
|
||||||
}
|
}
|
||||||
@ -108,13 +108,23 @@ model Notifications {
|
|||||||
message String @db.VarChar(255)
|
message String @db.VarChar(255)
|
||||||
redirection_url String @db.VarChar(255)
|
redirection_url String @db.VarChar(255)
|
||||||
created_at DateTime? @default(now())
|
created_at DateTime? @default(now())
|
||||||
status ENotificationStatus @default(UNREAD)
|
updated_at DateTime? @updatedAt
|
||||||
updated_at DateTime? @updatedAt
|
userNotifications UserNotifications[]
|
||||||
users Users[] @relation("UserHasNotifications")
|
|
||||||
|
|
||||||
@@map("notifications")
|
@@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 {
|
model OfficeFolders {
|
||||||
uid String @id @unique @default(uuid())
|
uid String @id @unique @default(uuid())
|
||||||
folder_number String @db.VarChar(255)
|
folder_number String @db.VarChar(255)
|
||||||
|
@ -10,9 +10,12 @@ export default class NotificationBuilder {
|
|||||||
public constructor(private notificationsService : NotificationsService, private documentsService: DocumentsService){}
|
public constructor(private notificationsService : NotificationsService, private documentsService: DocumentsService){}
|
||||||
|
|
||||||
public async sendDocumentDepositedNotification(documentEntity: Documents){
|
public async sendDocumentDepositedNotification(documentEntity: Documents){
|
||||||
|
console.log(documentEntity);
|
||||||
if(documentEntity.document_status !== "DEPOSITED") return;
|
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");
|
if(!documentPrisma) throw new Error("Document not found");
|
||||||
const document = Document.hydrate<Document>(documentPrisma);
|
const document = Document.hydrate<Document>(documentPrisma);
|
||||||
console.log(document);
|
console.log(document);
|
||||||
@ -22,6 +25,7 @@ export default class NotificationBuilder {
|
|||||||
redirection_url: "",
|
redirection_url: "",
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
|
user : document.folder!.stakeholders || [],
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,31 +32,28 @@ export default class NotificationRepository extends BaseRepository {
|
|||||||
data: {
|
data: {
|
||||||
message: notification.message,
|
message: notification.message,
|
||||||
redirection_url: notification.redirection_url,
|
redirection_url: notification.redirection_url,
|
||||||
users: {
|
// users: {
|
||||||
connect: notification.user
|
// 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);
|
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
|
* @description : find unique email
|
||||||
*/
|
*/
|
||||||
|
@ -28,15 +28,6 @@ export default class NotificationsService extends BaseService {
|
|||||||
return this.notificationRepository.create(notification);
|
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
|
* @description : Get a notification by uid
|
||||||
* @returns : T
|
* @returns : T
|
||||||
|
Loading…
x
Reference in New Issue
Block a user