CoverMe requests logged
This commit is contained in:
@ -8,6 +8,7 @@ const data = require('../../src/helpers/data');
|
||||
const emailHelper = require('../../src/helpers/email');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
const CON = require("../../src/helpers/const");
|
||||
import { EventLogType } from "@prisma/client";
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
@ -128,6 +129,15 @@ export default async function handler(req, res) {
|
||||
}
|
||||
}
|
||||
});
|
||||
await prisma.eventLog.create({
|
||||
data: {
|
||||
date: new Date(),
|
||||
publisher: { connect: { id: publisher.id } },
|
||||
shift: { connect: { id: assignment.shiftId } },
|
||||
type: EventLogType.AssignmentReplacementAccepted,
|
||||
content: "Заявка за заместване приета от " + publisher.firstName + " " + publisher.lastName
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
const shiftStr = `${CON.weekdaysBG[assignment.shift.startTime.getDay()]} ${CON.GetDateFormat(assignment.shift.startTime)} at ${assignment.shift.cartEvent.location.name} from ${CON.GetTimeFormat(assignment.shift.startTime)} to ${CON.GetTimeFormat(assignment.shift.endTime)}`;
|
||||
@ -202,7 +212,7 @@ export default async function handler(req, res) {
|
||||
return res.status(401).json({ message: "Unauthorized to call this API endpoint" });
|
||||
}
|
||||
|
||||
const user = await prisma.publisher.findUnique({
|
||||
const publisher = await prisma.publisher.findUnique({
|
||||
where: {
|
||||
email: token.email
|
||||
}
|
||||
@ -210,7 +220,7 @@ export default async function handler(req, res) {
|
||||
|
||||
switch (action) {
|
||||
case "sendCoverMeRequestByEmail":
|
||||
// Send CoverMe request to the user
|
||||
// Send CoverMe request to the users
|
||||
//get from POST data: shiftId, assignmentId, date
|
||||
//let shiftId = req.body.shiftId;
|
||||
let assignmentId = req.body.assignmentId;
|
||||
@ -235,7 +245,7 @@ export default async function handler(req, res) {
|
||||
}
|
||||
}
|
||||
});
|
||||
console.log("User: " + user.email + " sent a 'CoverMe' request for his assignment " + assignmentId + " - " + assignment.shift.cartEvent.location.name + " " + assignment.shift.startTime.toISOString());
|
||||
console.log("User: " + publisher.email + " sent a 'CoverMe' request for his assignment " + assignmentId + " - " + assignment.shift.cartEvent.location.name + " " + assignment.shift.startTime.toISOString());
|
||||
|
||||
|
||||
// update the assignment. generate new publicGuid, isConfirmed to false
|
||||
@ -270,10 +280,20 @@ export default async function handler(req, res) {
|
||||
filter((item, index, self) =>
|
||||
index === self.findIndex((t) => (
|
||||
t.email === item.email //and exclude the user himself
|
||||
)) //&& item.email !== user.email
|
||||
)) //&& item.email !== publisher.email
|
||||
);
|
||||
console.log("Sending CoverMe request to " + pubsToSend.length + " publishers");
|
||||
|
||||
await prisma.eventLog.create({
|
||||
data: {
|
||||
date: new Date(),
|
||||
publisher: { connect: { id: publisher.id } },
|
||||
shift: { connect: { id: assignment.shiftId } },
|
||||
type: EventLogType.AssignmentReplacementRequested,
|
||||
content: "Заявка за заместване от " + publisher.firstName + " " + publisher.lastName
|
||||
+ "до: " + pubsToSend.map(p => p.firstName + " " + p.lastName + "<" + p.email + ">").join(", "),
|
||||
}
|
||||
});
|
||||
//send email to all subscribed publishers
|
||||
for (let i = 0; i < pubsToSend.length; i++) {
|
||||
|
||||
@ -281,10 +301,10 @@ export default async function handler(req, res) {
|
||||
let acceptUrl = process.env.NEXTAUTH_URL + "/api/email?action=email_response&emailaction=coverMeAccept&userId=" + pubsToSend[i].id + "&shiftId=" + assignment.shiftId + "&assignmentPID=" + newPublicGuid;
|
||||
|
||||
let model = {
|
||||
user: user,
|
||||
user: publisher,
|
||||
shiftId: assignment.shiftId,
|
||||
acceptUrl: acceptUrl,
|
||||
prefix: user.isMale ? "Брат" : "Сестра",
|
||||
prefix: publisher.isMale ? "Брат" : "Сестра",
|
||||
firstName: pubsToSend[i].firstName,
|
||||
lastName: pubsToSend[i].lastName,
|
||||
email: pubsToSend[i].email,
|
||||
|
Reference in New Issue
Block a user