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),
|
||||
|
@ -92,8 +92,9 @@ export default function MySchedulePage({ assignments }) {
|
||||
<dd className="mt-1 text text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
{assignment.shift.assignments.map((a, index) => {
|
||||
return (
|
||||
<span key={index} className="inline-flex items-center mr-1 px-1 py-0.5 rounded-full text-sm font-medium ">
|
||||
{a.publisher.firstName} {a.publisher.lastName}{a.isWithTransport && <LocalShippingIcon style={{ paddingLeft: '4px' }} />}
|
||||
<span key={index} className="inline-flex items-center mr-1 px-2 py-0.5 border border-gray-300 rounded-full text-sm font-medium bg-gray-100">
|
||||
{a.publisher.firstName} {a.publisher.lastName}
|
||||
{a.isWithTransport && <LocalShippingIcon style={{ marginLeft: '4px' }} />}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
@ -184,11 +184,7 @@ exports.SendEmail_NewShifts = async function (publisher, shifts) {
|
||||
sentDate: new Date().toLocaleDateString() // Assuming you want to include the sent date in the email
|
||||
};
|
||||
|
||||
// Call the refactored function to send the email with Handlebars template rendering
|
||||
await exports.SendEmailHandlebars(
|
||||
publisher.email, // Assuming the publisher's email is to be used
|
||||
"newShifts", // The name of your Handlebars template for new shifts notification
|
||||
model,
|
||||
await exports.SendEmailHandlebars(publisher.email, "newShifts", model,
|
||||
[{
|
||||
filename: "calendar.ics",
|
||||
content: icsLink,
|
||||
@ -200,9 +196,6 @@ exports.SendEmail_NewShifts = async function (publisher, shifts) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//----------------------- OLD -----------------------------
|
||||
|
||||
// exports.SendEmail_NewShifts = async function (publisher, shifts) {
|
||||
|
@ -1,7 +1,9 @@
|
||||
{{!--Subject: ССС: Нужен е заместник --}}
|
||||
|
||||
<section>
|
||||
<h3>Търси се зместник за смяна на {{placeName}} за {{dateStr}}!</h3>
|
||||
<h3>Търси се зместник
|
||||
{{!-- за смяна на {{placeName}} за {{dateStr}}! --}}
|
||||
</h3>
|
||||
<p>Здравей {{firstName}},</p>
|
||||
<p>{{prefix}} {{user.firstName}} {{user.lastName}} търси заместник.</p>
|
||||
{{!-- <p><strong>Shift Details:</strong></p> --}}
|
||||
@ -20,5 +22,5 @@
|
||||
<p>Best regards,<br>{{name}}</p> --}}
|
||||
</section>
|
||||
<footer style="margin-top: 20px; text-align: center;">
|
||||
<p>Изпратено до {{firstName}} {{lastName}} на {{sentDate}}</p>
|
||||
<p>Изпратено до {{firstName}} {{lastName}} {{email}} {{sentDate}}</p>
|
||||
</footer>
|
15
src/templates/emails/coverMeAccepted.hbs
Normal file
15
src/templates/emails/coverMeAccepted.hbs
Normal file
@ -0,0 +1,15 @@
|
||||
{{!-- Subject: ССС: Нови назначени смени--}}
|
||||
|
||||
<section>
|
||||
<h2>Промяна твоята смяна на {{placeName}} {{dateStr}} </h2>
|
||||
<p>Здравейте {{firstName}}, </p>
|
||||
<p>{{firstName}} {{lastName}} ще замести {{oldPubName}} на смяната ви на {{dateStr}}</p>
|
||||
<p>Новаия списък с участници за тази смяна е:</p>
|
||||
{{{newPubNames}}}
|
||||
<div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<footer class="footer">
|
||||
Изпратено на: {{sentDate}}
|
||||
</footer>
|
Reference in New Issue
Block a user