From 02c0c420b5f8c8600d0b5e5b186b0ef9c3f596cc Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Fri, 19 Apr 2024 17:04:25 +0300 Subject: [PATCH] tweak email template model, fix EventLog content size, etc... --- pages/api/email.ts | 7 ++++--- pages/cart/publishers/myschedule.tsx | 2 +- .../20240418092928_add_event_log_table/migration.sql | 2 +- prisma/schema.prisma | 2 +- src/templates/emails/coverMe.hbs | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pages/api/email.ts b/pages/api/email.ts index 049895a..facba07 100644 --- a/pages/api/email.ts +++ b/pages/api/email.ts @@ -279,8 +279,8 @@ export default async function handler(req, res) { let pubsToSend = subscribedPublishers.concat(availablePublishers). filter((item, index, self) => index === self.findIndex((t) => ( - t.email === item.email //and exclude the user himself - )) //&& item.email !== publisher.email + t.email === item.email && item.email !== publisher.email//and exclude the user himself + )) ); console.log("Sending CoverMe request to " + pubsToSend.length + " publishers"); @@ -294,17 +294,18 @@ export default async function handler(req, res) { + "до: " + pubsToSend.map(p => p.firstName + " " + p.lastName + "<" + p.email + ">").join(", "), } }); + //send email to all subscribed publishers for (let i = 0; i < pubsToSend.length; i++) { //send email to subscribed publisher let acceptUrl = process.env.NEXTAUTH_URL + "/api/email?action=email_response&emailaction=coverMeAccept&userId=" + pubsToSend[i].id + "&shiftId=" + assignment.shiftId + "&assignmentPID=" + newPublicGuid; + publisher.prefix = publisher.isMale ? "Брат" : "Сестра"; let model = { user: publisher, shiftId: assignment.shiftId, acceptUrl: acceptUrl, - prefix: publisher.isMale ? "Брат" : "Сестра", firstName: pubsToSend[i].firstName, lastName: pubsToSend[i].lastName, email: pubsToSend[i].email, diff --git a/pages/cart/publishers/myschedule.tsx b/pages/cart/publishers/myschedule.tsx index 017b21c..b074440 100644 --- a/pages/cart/publishers/myschedule.tsx +++ b/pages/cart/publishers/myschedule.tsx @@ -205,7 +205,7 @@ export const getServerSideProps = async (context) => { }, }); - const assignments = publisher?.assignments || []; + const assignments = publisher?.assignments.filter(assignment => assignment.shift.startTime >= lastSunday) || []; const transformedAssignments = assignments?.map(assignment => { if (assignment.shift && assignment.shift.startTime) { diff --git a/prisma/migrations/20240418092928_add_event_log_table/migration.sql b/prisma/migrations/20240418092928_add_event_log_table/migration.sql index bd811c8..2f4ef0d 100644 --- a/prisma/migrations/20240418092928_add_event_log_table/migration.sql +++ b/prisma/migrations/20240418092928_add_event_log_table/migration.sql @@ -4,7 +4,7 @@ CREATE TABLE `EventLog` ( `date` DATETIME(3) NOT NULL, `publisherId` VARCHAR(191) NULL, `shiftId` INTEGER NULL, - `content` VARCHAR(191) NOT NULL, + `content` VARCHAR(5000) NOT NULL, `type` ENUM('AssignmentReplacementRequested', 'AssignmentReplacementAccepted', 'SentEmail') NOT NULL, diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 445d589..5b91e47 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -271,7 +271,7 @@ model EventLog { publisher Publisher? @relation(fields: [publisherId], references: [id]) shiftId Int? shift Shift? @relation(fields: [shiftId], references: [id]) - content String + content String @db.VarChar(5000) type EventLogType } diff --git a/src/templates/emails/coverMe.hbs b/src/templates/emails/coverMe.hbs index 2855a11..e96a471 100644 --- a/src/templates/emails/coverMe.hbs +++ b/src/templates/emails/coverMe.hbs @@ -5,7 +5,7 @@ {{!-- за смяна на {{placeName}} за {{dateStr}}! --}}

Здравей {{firstName}},

-

{{prefix}} {{user.firstName}} {{user.lastName}} търси заместник.

+

{{user.prefix}} {{user.firstName}} {{user.lastName}} търси заместник.

{{!--

Shift Details:

--}}

Дата: {{dateStr}}
Час: {{time}}
Място: {{placeName}}

С натискането на бутона по-долу можеш да премеш да го заместваш.