Fix email notification not working (#531)

This commit is contained in:
Matti Nannt
2023-07-11 22:52:17 +02:00
committed by GitHub
parent 3f2ef3e776
commit 1c58474dc2
2 changed files with 6 additions and 8 deletions
+1 -1
View File
@@ -19,5 +19,5 @@ jobs:
curl ${{ secrets.APP_URL }}/api/cron/weekly_summary \
-X POST \
-H 'content-type: application/json' \
-H 'authorization: ${{ secrets.CRON_SECRET }}' \
-H 'x-api-key: ${{ secrets.CRON_SECRET }}' \
--fail
+5 -7
View File
@@ -4,6 +4,7 @@ import { NextResponse } from "next/server";
import { AttributeClass } from "@prisma/client";
import { sendResponseFinishedEmail } from "@/lib/email";
import { Question } from "@formbricks/types/questions";
import { NotificationSettings } from "@formbricks/types/users";
export async function POST(request: Request) {
const { internalSecret, environmentId, surveyId, event, data } = await request.json();
@@ -104,14 +105,11 @@ export async function POST(request: Request) {
});
// filter all users that have email notifications enabled for this survey
const usersWithNotifications = users.filter((user) => {
if (!user.notificationSettings) {
return false;
const notificationSettings: NotificationSettings | null = user.notificationSettings;
if (notificationSettings?.alert && notificationSettings.alert[surveyId]) {
return true;
}
const notificationSettings = user.notificationSettings[surveyId];
if (!notificationSettings || !notificationSettings.responseFinished) {
return false;
}
return true;
return false;
});
if (usersWithNotifications.length > 0) {