remove if and at to query (#5838)
Co-authored-by: CarinaWolli <wollencarina@gmail.com>pull/5841/head^2
parent
d8c1c103a1
commit
e293e590bd
|
@ -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" });
|
||||
}
|
||||
|
||||
|
|
|
@ -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" });
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue