Added vote notifications
This commit is contained in:
parent
d6d358f579
commit
d861ae84da
1622
package-lock.json
generated
1622
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,6 @@
|
|||||||
import authHandler from "@App/middlewares/AuthHandler";
|
import authHandler from "@App/middlewares/AuthHandler";
|
||||||
import roleHandler from "@App/middlewares/RolesHandler";
|
import roleHandler from "@App/middlewares/RolesHandler";
|
||||||
|
import NotificationBuilder from "@Common/notifications/NotificationBuilder";
|
||||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||||
import { Controller, Post } from "@ControllerPattern/index";
|
import { Controller, Post } from "@ControllerPattern/index";
|
||||||
import { EAppointmentStatus } from "@prisma/client";
|
import { EAppointmentStatus } from "@prisma/client";
|
||||||
@ -20,6 +21,7 @@ export default class LiveVoteController extends ApiController {
|
|||||||
private votesService: VotesService,
|
private votesService: VotesService,
|
||||||
private usersService: UsersService,
|
private usersService: UsersService,
|
||||||
private appointmentService: AppointmentService,
|
private appointmentService: AppointmentService,
|
||||||
|
private notificationBuilder : NotificationBuilder,
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@ -85,6 +87,8 @@ export default class LiveVoteController extends ApiController {
|
|||||||
strategy: "excludeAll",
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await this.notificationBuilder.sendVoteNotification(vote);
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpCreated(response, vote);
|
this.httpCreated(response, vote);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
|
|
||||||
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
||||||
import { Documents } from "@prisma/client";
|
import { Documents } from "@prisma/client";
|
||||||
import { Document } from "le-coffre-resources/dist/SuperAdmin";
|
import { Document, Vote } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import NotificationsService from "@Services/common/NotificationsService/NotificationsService";
|
import NotificationsService from "@Services/common/NotificationsService/NotificationsService";
|
||||||
|
import UsersService from "@Services/super-admin/UsersService/UsersService";
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class NotificationBuilder {
|
export default class NotificationBuilder {
|
||||||
public constructor(private notificationsService : NotificationsService, private documentsService: DocumentsService){}
|
public constructor(private notificationsService : NotificationsService, private documentsService: DocumentsService, private usersService: UsersService){}
|
||||||
|
|
||||||
public async sendDocumentDepositedNotification(documentEntity: Documents){
|
public async sendDocumentDepositedNotification(documentEntity: Documents){
|
||||||
if(documentEntity.document_status !== "DEPOSITED") return;
|
if(documentEntity.document_status !== "DEPOSITED") return;
|
||||||
@ -17,29 +18,49 @@ export default class NotificationBuilder {
|
|||||||
const document = Document.hydrate<Document>(documentPrisma);
|
const document = Document.hydrate<Document>(documentPrisma);
|
||||||
|
|
||||||
this.notificationsService.create({
|
this.notificationsService.create({
|
||||||
message: "Document déposé",
|
message: "Votre client " + document.depositor?.contact?.first_name + " " + document.depositor?.contact?.last_name + " vous a envoyé un document à valider",
|
||||||
redirection_url: "",
|
redirection_url: "",
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
user : document.folder!.stakeholders || [],
|
user : document.folder!.stakeholders || [],
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendDocumentAnchoredNotificatiom(documentEntity: Documents){
|
public async sendDocumentAnchoredNotification(documentEntity: Documents){
|
||||||
|
|
||||||
|
const documentPrisma = await this.documentsService.getByUid(documentEntity.uid, { depositor: {include: {contact: true}}, folder:{include:{ folder_anchor : true ,office: true, stakeholders: 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);
|
||||||
|
if(document.folder?.anchor?.status !== "VERIFIED_ON_CHAIN") return;
|
||||||
|
|
||||||
this.notificationsService.create({
|
this.notificationsService.create({
|
||||||
message: "Document ancré",
|
message: "Le dossier " + document.folder?.folder_number + " - " + document.folder?.name + " a été certifié. Vous pouvez désormais télécharger les fiches de preuve pour les mettre dans la GED de votre logiciel de rédaction d'acte.",
|
||||||
redirection_url: "",
|
redirection_url: "",
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
user : document.folder!.stakeholders || [],
|
user : document.folder!.stakeholders || [],
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async sendVoteNotification(vote: Vote){
|
||||||
|
if(vote.appointment.status !== "OPEN") return;
|
||||||
|
const superAdminList = await this.usersService.get({where: {role : {label : "super-admin"}}});
|
||||||
|
let message = "";
|
||||||
|
if(vote.appointment.choice === "NOMINATE"){
|
||||||
|
message = "Un collaborateur souhaite attribuer le titre de Super Administrateur à " + vote.appointment.targeted_user + ". Cliquez ici pour voter."
|
||||||
|
}
|
||||||
|
else if(vote.appointment.choice === "DISMISS"){
|
||||||
|
message = "Un collaborateur souhaite retirer le titre de Super Administrateur à " + vote.appointment.targeted_user + ". Cliquez ici pour voter."
|
||||||
|
}
|
||||||
|
|
||||||
|
this.notificationsService.create({
|
||||||
|
message: message,
|
||||||
|
redirection_url: "",
|
||||||
|
created_at: new Date(),
|
||||||
|
updated_at: new Date(),
|
||||||
|
user : superAdminList || [],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user