remove if and at to query (#5838)

Co-authored-by: CarinaWolli <wollencarina@gmail.com>
pull/5841/head^2
Carina Wollendorfer 2022-12-02 14:43:07 +01:00 committed by GitHub
parent d8c1c103a1
commit e293e590bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 176 additions and 178 deletions

View File

@ -43,6 +43,9 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
where: {
method: WorkflowMethods.EMAIL,
scheduled: false,
scheduledDate: {
lte: dayjs().add(72, "hour").toISOString(),
},
},
include: {
workflowStep: true,
@ -61,10 +64,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
return;
}
const dateInSeventyTwoHours = dayjs().add(72, "hour");
for (const reminder of unscheduledReminders) {
if (dayjs(reminder.scheduledDate).isBefore(dateInSeventyTwoHours)) {
try {
let sendTo;
@ -172,7 +172,6 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
console.log(`Error scheduling Email with error ${error}`);
}
}
}
res.status(200).json({ message: "Emails scheduled" });
}

View File

@ -32,6 +32,9 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
where: {
method: WorkflowMethods.SMS,
scheduled: false,
scheduledDate: {
lte: dayjs().add(7, "day").toISOString(),
},
},
include: {
workflowStep: true,
@ -47,10 +50,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
if (!unscheduledReminders.length) res.json({ ok: true });
const dateInSevenDays = dayjs().add(7, "day");
for (const reminder of unscheduledReminders) {
if (dayjs(reminder.scheduledDate).isBefore(dateInSevenDays)) {
try {
const sendTo =
reminder.workflowStep.action === WorkflowActions.SMS_NUMBER
@ -126,7 +126,6 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
console.log(`Error scheduling SMS with error ${error}`);
}
}
}
res.status(200).json({ message: "SMS scheduled" });
}