CoverMe requests logged
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pwwa",
|
"name": "pwwa",
|
||||||
"version": "1.1.2",
|
"version": "1.2.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "JW PW Web App",
|
"description": "JW PW Web App",
|
||||||
"repository": "http://git.d-popov.com/popov/next-cart-app.git",
|
"repository": "http://git.d-popov.com/popov/next-cart-app.git",
|
||||||
|
@ -8,6 +8,7 @@ const data = require('../../src/helpers/data');
|
|||||||
const emailHelper = require('../../src/helpers/email');
|
const emailHelper = require('../../src/helpers/email');
|
||||||
const { v4: uuidv4 } = require('uuid');
|
const { v4: uuidv4 } = require('uuid');
|
||||||
const CON = require("../../src/helpers/const");
|
const CON = require("../../src/helpers/const");
|
||||||
|
import { EventLogType } from "@prisma/client";
|
||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
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)}`;
|
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" });
|
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: {
|
where: {
|
||||||
email: token.email
|
email: token.email
|
||||||
}
|
}
|
||||||
@ -210,7 +220,7 @@ export default async function handler(req, res) {
|
|||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case "sendCoverMeRequestByEmail":
|
case "sendCoverMeRequestByEmail":
|
||||||
// Send CoverMe request to the user
|
// Send CoverMe request to the users
|
||||||
//get from POST data: shiftId, assignmentId, date
|
//get from POST data: shiftId, assignmentId, date
|
||||||
//let shiftId = req.body.shiftId;
|
//let shiftId = req.body.shiftId;
|
||||||
let assignmentId = req.body.assignmentId;
|
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
|
// update the assignment. generate new publicGuid, isConfirmed to false
|
||||||
@ -270,10 +280,20 @@ export default async function handler(req, res) {
|
|||||||
filter((item, index, self) =>
|
filter((item, index, self) =>
|
||||||
index === self.findIndex((t) => (
|
index === self.findIndex((t) => (
|
||||||
t.email === item.email //and exclude the user himself
|
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");
|
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
|
//send email to all subscribed publishers
|
||||||
for (let i = 0; i < pubsToSend.length; i++) {
|
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 acceptUrl = process.env.NEXTAUTH_URL + "/api/email?action=email_response&emailaction=coverMeAccept&userId=" + pubsToSend[i].id + "&shiftId=" + assignment.shiftId + "&assignmentPID=" + newPublicGuid;
|
||||||
|
|
||||||
let model = {
|
let model = {
|
||||||
user: user,
|
user: publisher,
|
||||||
shiftId: assignment.shiftId,
|
shiftId: assignment.shiftId,
|
||||||
acceptUrl: acceptUrl,
|
acceptUrl: acceptUrl,
|
||||||
prefix: user.isMale ? "Брат" : "Сестра",
|
prefix: publisher.isMale ? "Брат" : "Сестра",
|
||||||
firstName: pubsToSend[i].firstName,
|
firstName: pubsToSend[i].firstName,
|
||||||
lastName: pubsToSend[i].lastName,
|
lastName: pubsToSend[i].lastName,
|
||||||
email: pubsToSend[i].email,
|
email: pubsToSend[i].email,
|
||||||
|
@ -5,7 +5,7 @@ CREATE TABLE `EventLog` (
|
|||||||
`publisherId` VARCHAR(191) NULL,
|
`publisherId` VARCHAR(191) NULL,
|
||||||
`shiftId` INTEGER NULL,
|
`shiftId` INTEGER NULL,
|
||||||
`content` VARCHAR(191) NOT NULL,
|
`content` VARCHAR(191) NOT NULL,
|
||||||
`type` ENUM('AssignnementReplacementRequested', 'AssignnementReplacement', 'SentEmail') NOT NULL,
|
`type` ENUM('AssignmentReplacementRequested', 'AssignmentReplacementAccepted', 'SentEmail') NOT NULL,
|
||||||
|
|
||||||
|
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
|
@ -259,8 +259,8 @@ model Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum EventLogType {
|
enum EventLogType {
|
||||||
AssignnementReplacementRequested
|
AssignmentReplacementRequested
|
||||||
AssignnementReplacement
|
AssignmentReplacementAccepted
|
||||||
SentEmail
|
SentEmail
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ exports.SendEmail_NewShifts = async function (publisher, shifts) {
|
|||||||
// ],
|
// ],
|
||||||
// subject: "[CCC]: вашите смени през " + CON.monthNamesBG[date.getMonth()],
|
// subject: "[CCC]: вашите смени през " + CON.monthNamesBG[date.getMonth()],
|
||||||
// text:
|
// text:
|
||||||
// "Здравейте, " + publisher.firstName + " " + publisher.lastName + "!\n\n" +
|
// "Здравей, " + publisher.firstName + " " + publisher.lastName + "!\n\n" +
|
||||||
// "Ти регистриран да получавате известия за нови смени на количка.\n" +
|
// "Ти регистриран да получавате известия за нови смени на количка.\n" +
|
||||||
// `За месец ${CON.monthNamesBG[date.getMonth()]} имате следните смени:\n` +
|
// `За месец ${CON.monthNamesBG[date.getMonth()]} имате следните смени:\n` +
|
||||||
// ` ${shftStr} \n\n\n` +
|
// ` ${shftStr} \n\n\n` +
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<section>
|
<section>
|
||||||
<h2>Промяна твоята смяна на {{placeName}} {{dateStr}} </h2>
|
<h2>Промяна твоята смяна на {{placeName}} {{dateStr}} </h2>
|
||||||
<p>Здравейте {{firstName}}, </p>
|
<p>Здравей {{firstName}}, </p>
|
||||||
<p>{{firstName}} {{lastName}} ще замести {{oldPubName}} на смяната ви в {{dateStr}} от {{time}}</p>
|
<p>{{firstName}} {{lastName}} ще замести {{oldPubName}} на смяната ви в {{dateStr}} от {{time}}</p>
|
||||||
<p>Новаия списък с участници за тази смяна е:</p>
|
<p>Новаия списък с участници за тази смяна е:</p>
|
||||||
<ul>
|
<ul>
|
||||||
|
@ -4,7 +4,7 @@ text version. --}}
|
|||||||
|
|
||||||
<section>
|
<section>
|
||||||
<h3>Търси се зместник за смяна на {{placeName}} за {{dateStr}}!</h3>
|
<h3>Търси се зместник за смяна на {{placeName}} за {{dateStr}}!</h3>
|
||||||
<p>Здравейте,</p>
|
<p>Здравей,</p>
|
||||||
<p>{{prefix}} {{firstName}} {{lastName}} търси заместник.</p>
|
<p>{{prefix}} {{firstName}} {{lastName}} търси заместник.</p>
|
||||||
{{!-- <p><strong>Shift Details:</strong></p> --}}
|
{{!-- <p><strong>Shift Details:</strong></p> --}}
|
||||||
<p>Дата: {{dateStr}} <br>Час: {{time}}<br>Място: {{placeName}}</p>
|
<p>Дата: {{dateStr}} <br>Час: {{time}}<br>Място: {{placeName}}</p>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{{!-- Subject: ССС: Нови назначени смени--}}
|
{{!-- Subject: ССС: Нови назначени смени--}}
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<h2>Здравейте, {{publisherFirstName}} {{publisherLastName}}!</h2>
|
<h2>Здравей {{publisherFirstName}} {{publisherLastName}}!</h2>
|
||||||
<p>Ти регистриран да получавате известия за нови смени на количка.</p>
|
<p>Ти регистриран да получавате известия за нови смени на количка.</p>
|
||||||
<p>За месец {{month}} имате следните смени:</p>
|
<p>За месец {{month}} имате следните смени:</p>
|
||||||
<div>
|
<div>
|
||||||
|
Reference in New Issue
Block a user