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: {
|
where: {
|
||||||
method: WorkflowMethods.EMAIL,
|
method: WorkflowMethods.EMAIL,
|
||||||
scheduled: false,
|
scheduled: false,
|
||||||
|
scheduledDate: {
|
||||||
|
lte: dayjs().add(72, "hour").toISOString(),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
workflowStep: true,
|
workflowStep: true,
|
||||||
|
@ -61,10 +64,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const dateInSeventyTwoHours = dayjs().add(72, "hour");
|
|
||||||
|
|
||||||
for (const reminder of unscheduledReminders) {
|
for (const reminder of unscheduledReminders) {
|
||||||
if (dayjs(reminder.scheduledDate).isBefore(dateInSeventyTwoHours)) {
|
|
||||||
try {
|
try {
|
||||||
let sendTo;
|
let sendTo;
|
||||||
|
|
||||||
|
@ -172,7 +172,6 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
console.log(`Error scheduling Email with error ${error}`);
|
console.log(`Error scheduling Email with error ${error}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
res.status(200).json({ message: "Emails scheduled" });
|
res.status(200).json({ message: "Emails scheduled" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,9 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
where: {
|
where: {
|
||||||
method: WorkflowMethods.SMS,
|
method: WorkflowMethods.SMS,
|
||||||
scheduled: false,
|
scheduled: false,
|
||||||
|
scheduledDate: {
|
||||||
|
lte: dayjs().add(7, "day").toISOString(),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
workflowStep: true,
|
workflowStep: true,
|
||||||
|
@ -47,10 +50,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
|
|
||||||
if (!unscheduledReminders.length) res.json({ ok: true });
|
if (!unscheduledReminders.length) res.json({ ok: true });
|
||||||
|
|
||||||
const dateInSevenDays = dayjs().add(7, "day");
|
|
||||||
|
|
||||||
for (const reminder of unscheduledReminders) {
|
for (const reminder of unscheduledReminders) {
|
||||||
if (dayjs(reminder.scheduledDate).isBefore(dateInSevenDays)) {
|
|
||||||
try {
|
try {
|
||||||
const sendTo =
|
const sendTo =
|
||||||
reminder.workflowStep.action === WorkflowActions.SMS_NUMBER
|
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}`);
|
console.log(`Error scheduling SMS with error ${error}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
res.status(200).json({ message: "SMS scheduled" });
|
res.status(200).json({ message: "SMS scheduled" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue