fix: minor bug in schedule sms and whatsapp reminders cron job (#10135)

pull/10159/head^2
jemiluv8 2023-07-14 17:02:06 +00:00 committed by GitHub
parent 4aaf5da36d
commit 879bc3f169
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -52,7 +52,10 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
},
});
if (!unscheduledReminders.length) res.json({ ok: true });
if (!unscheduledReminders.length) {
res.json({ ok: true });
return;
}
for (const reminder of unscheduledReminders) {
if (!reminder.workflowStep || !reminder.booking) {

View File

@ -1,13 +1,13 @@
/* Schedule any workflow reminder that falls within 7 days for WHATSAPP */
import { WorkflowActions, WorkflowMethods, WorkflowTemplates } from "@prisma/client";
import { WorkflowActions, WorkflowMethods } from "@prisma/client";
import type { NextApiRequest, NextApiResponse } from "next";
import dayjs from "@calcom/dayjs";
import { defaultHandler } from "@calcom/lib/server";
import prisma from "@calcom/prisma";
import * as twilio from "../lib/reminders/smsProviders/twilioProvider";
import { getWhatsappTemplateFunction } from "../lib/actionHelperFunctions";
import * as twilio from "../lib/reminders/smsProviders/twilioProvider";
async function handler(req: NextApiRequest, res: NextApiResponse) {
const apiKey = req.headers.authorization || req.query.apiKey;
@ -47,7 +47,10 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
},
});
if (!unscheduledReminders.length) res.json({ ok: true });
if (!unscheduledReminders.length) {
res.json({ ok: true });
return;
}
for (const reminder of unscheduledReminders) {
if (!reminder.workflowStep || !reminder.booking) {
@ -74,7 +77,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
? reminder.booking?.attendees[0].timeZone
: reminder.booking?.user?.timeZone;
const templateFunction = getWhatsappTemplateFunction(reminder.workflowStep.template)
const templateFunction = getWhatsappTemplateFunction(reminder.workflowStep.template);
const message = templateFunction(
false,
reminder.workflowStep.action,