CoverMe requests logged

This commit is contained in:
Dobromir Popov
2024-04-18 13:34:17 +03:00
parent 59cbedbbb2
commit 91adc27d29
8 changed files with 34 additions and 14 deletions

View File

@ -1,6 +1,6 @@
{
"name": "pwwa",
"version": "1.1.2",
"version": "1.2.0",
"private": true,
"description": "JW PW Web App",
"repository": "http://git.d-popov.com/popov/next-cart-app.git",

View File

@ -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,

View File

@ -5,7 +5,7 @@ CREATE TABLE `EventLog` (
`publisherId` VARCHAR(191) NULL,
`shiftId` INTEGER NULL,
`content` VARCHAR(191) NOT NULL,
`type` ENUM('AssignnementReplacementRequested', 'AssignnementReplacement', 'SentEmail') NOT NULL,
`type` ENUM('AssignmentReplacementRequested', 'AssignmentReplacementAccepted', 'SentEmail') NOT NULL,
PRIMARY KEY (`id`)

View File

@ -259,8 +259,8 @@ model Message {
}
enum EventLogType {
AssignnementReplacementRequested
AssignnementReplacement
AssignmentReplacementRequested
AssignmentReplacementAccepted
SentEmail
}

View File

@ -266,7 +266,7 @@ exports.SendEmail_NewShifts = async function (publisher, shifts) {
// ],
// subject: "[CCC]: вашите смени през " + CON.monthNamesBG[date.getMonth()],
// text:
// "Здравейте, " + publisher.firstName + " " + publisher.lastName + "!\n\n" +
// "Здравей, " + publisher.firstName + " " + publisher.lastName + "!\n\n" +
// "Ти регистриран да получавате известия за нови смени на количка.\n" +
// `За месец ${CON.monthNamesBG[date.getMonth()]} имате следните смени:\n` +
// ` ${shftStr} \n\n\n` +

View File

@ -2,7 +2,7 @@
<section>
<h2>Промяна твоята смяна на {{placeName}} {{dateStr}} </h2>
<p>Здравейте {{firstName}}, </p>
<p>Здравей {{firstName}}, </p>
<p>{{firstName}} {{lastName}} ще замести {{oldPubName}} на смяната ви в {{dateStr}} от {{time}}</p>
<p>Новаия списък с участници за тази смяна е:</p>
<ul>

View File

@ -4,7 +4,7 @@ text version. --}}
<section>
<h3>Търси се зместник за смяна на {{placeName}} за {{dateStr}}!</h3>
<p>Здравейте,</p>
<p>Здравей,</p>
<p>{{prefix}} {{firstName}} {{lastName}} търси заместник.</p>
{{!-- <p><strong>Shift Details:</strong></p> --}}
<p>Дата: {{dateStr}} <br>Час: {{time}}<br>Място: {{placeName}}</p>

View File

@ -1,7 +1,7 @@
{{!-- Subject: ССС: Нови назначени смени--}}
<section>
<h2>Здравейте, {{publisherFirstName}} {{publisherLastName}}!</h2>
<h2>Здравей {{publisherFirstName}} {{publisherLastName}}!</h2>
<p>Ти регистриран да получавате известия за нови смени на количка.</p>
<p>За месец {{month}} имате следните смени:</p>
<div>