coverMeRourine completed :)
This commit is contained in:
@ -6,6 +6,7 @@ import { createRouter, expressWrapper } from "next-connect";
|
||||
const common = require('../../src/helpers/common');
|
||||
const emailHelper = require('../../src/helpers/email');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
const CON = require("../../src/helpers/const");
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
@ -36,13 +37,13 @@ export default async function handler(req, res) {
|
||||
//validate shiftId and assignmentId
|
||||
let shiftId = req.query.shiftId;
|
||||
let userId = req.query.userId;
|
||||
let user = await prisma.publisher.findUnique({
|
||||
let publisher = await prisma.publisher.findUnique({
|
||||
where: {
|
||||
id: userId
|
||||
}
|
||||
});
|
||||
// Update the user status to accepted
|
||||
console.log("User: " + user.firstName + " " + user.lastName + " accepted the CoverMe request");
|
||||
console.log("User: " + publisher.firstName + " " + publisher.lastName + " accepted the CoverMe request");
|
||||
|
||||
let assignmentPID = req.query.assignmentPID;
|
||||
if (!shiftId) {
|
||||
@ -65,9 +66,22 @@ export default async function handler(req, res) {
|
||||
include: {
|
||||
location: true
|
||||
}
|
||||
},
|
||||
assignments: {
|
||||
include: {
|
||||
publisher: true
|
||||
// {
|
||||
// include: {
|
||||
// email: true,
|
||||
// firstName: true,
|
||||
// lastName: true
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
publisher: true
|
||||
}
|
||||
});
|
||||
|
||||
@ -77,7 +91,64 @@ export default async function handler(req, res) {
|
||||
return;
|
||||
}
|
||||
|
||||
emailHelper.SendEmail_NewShifts(user, [assignment.shift]);
|
||||
let to = assignment.shift.assignments.map(a => a.publisher.email);
|
||||
to.push(publisher.email);
|
||||
|
||||
// update the assignment. clear the guid, isConfirmed to true
|
||||
await prisma.assignment.update({
|
||||
where: {
|
||||
id: assignment.id
|
||||
},
|
||||
data: {
|
||||
publisherId: userId,
|
||||
publicGuid: null, // if this exists, we consider the request open
|
||||
isConfirmed: true
|
||||
}
|
||||
});
|
||||
const newAssignment = await prisma.assignment.findFirst({
|
||||
where: {
|
||||
shiftId: parseInt(shiftId),
|
||||
isConfirmed: true
|
||||
},
|
||||
include: {
|
||||
shift: {
|
||||
include: {
|
||||
cartEvent: {
|
||||
include: {
|
||||
location: true
|
||||
}
|
||||
},
|
||||
assignments: {
|
||||
include: {
|
||||
publisher: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
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 allNewPubNames = newAssignment.shift.assignments.map(a => a.publisher.firstName + " " + a.publisher.lastName + "\t\t" + a.publisher.phone + ).join("</br>");
|
||||
|
||||
let model = {
|
||||
user: publisher,
|
||||
shiftStr: shiftStr,
|
||||
shiftId: assignment.shiftId,
|
||||
prefix: publisher.isMale ? "Брат" : "Сестра",
|
||||
oldPubName: assignment.publisher.firstName + " " + assignment.publisher.lastName,
|
||||
firstName: publisher.firstName,
|
||||
lastName: publisher.lastName,
|
||||
newPubNames: allNewPubNames,
|
||||
placeName: assignment.shift.cartEvent.location.name,
|
||||
dateStr: common.getDateFormated(assignment.shift.startTime),
|
||||
time: common.formatTimeHHmm(assignment.shift.startTime),
|
||||
sentDate: common.getDateFormated(new Date())
|
||||
};
|
||||
|
||||
emailHelper.SendEmailHandlebars(to, "coverMeAccepted", model);
|
||||
|
||||
// await prisma.user.update({
|
||||
// where: {
|
||||
@ -200,6 +271,7 @@ export default async function handler(req, res) {
|
||||
prefix: user.isMale ? "Брат" : "Сестра",
|
||||
firstName: subscribedPublishers[i].firstName,
|
||||
lastName: subscribedPublishers[i].lastName,
|
||||
email: subscribedPublishers[i].email,
|
||||
placeName: assignment.shift.cartEvent.location.name,
|
||||
dateStr: common.getDateFormated(assignment.shift.startTime),
|
||||
time: common.formatTimeHHmm(assignment.shift.startTime),
|
||||
|
Reference in New Issue
Block a user