diff --git a/apps/web/app/api/cron/weekly_summary/email.ts b/apps/web/app/api/cron/weekly_summary/email.ts index 91a4d21f62..3e81f63177 100644 --- a/apps/web/app/api/cron/weekly_summary/email.ts +++ b/apps/web/app/api/cron/weekly_summary/email.ts @@ -61,10 +61,14 @@ const notificationInsight = (insights: Insights) =>

Completed

${insights.totalCompletedResponses}

- + ${ + insights.totalDisplays !== 0 + ? `

Completion %

-

${insights.totalDisplays === 0 ? "N/A" : `${Math.round(insights.completionRate)}%`}

- +

${Math.round(insights.completionRate)}%

+ ` + : "" + } diff --git a/apps/web/app/api/cron/weekly_summary/route.ts b/apps/web/app/api/cron/weekly_summary/route.ts index 4d9d3d0c3c..60bb02f497 100644 --- a/apps/web/app/api/cron/weekly_summary/route.ts +++ b/apps/web/app/api/cron/weekly_summary/route.ts @@ -133,6 +133,20 @@ const getProducts = async (): Promise => { id: true, surveys: { where: { + NOT: { + AND: [ + { status: "completed" }, + { + responses: { + none: { + createdAt: { + gte: sevenDaysAgo, + }, + }, + }, + }, + ], + }, status: { not: "draft", }, @@ -190,3 +204,79 @@ const getProducts = async (): Promise => { }, }); }; + +/* const getProducts = async (): Promise => { + // gets all products together with team members, surveys, responses, and displays for the last 7 days + const sevenDaysAgo = new Date(); + sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7); + + return await prisma.product.findMany({ + select: { + id: true, + name: true, + environments: { + where: { + type: "production", + }, + select: { + id: true, + surveys: { + where: { + status: { + not: "draft", + }, + }, + select: { + id: true, + name: true, + questions: true, + status: true, + responses: { + where: { + createdAt: { + gte: sevenDaysAgo, + }, + }, + select: { + id: true, + createdAt: true, + updatedAt: true, + finished: true, + data: true, + }, + orderBy: { + createdAt: "desc", + }, + }, + displays: { + where: { + createdAt: { + gte: sevenDaysAgo, + }, + }, + select: { + status: true, + }, + }, + }, + }, + }, + }, + team: { + select: { + memberships: { + select: { + user: { + select: { + email: true, + notificationSettings: true, + }, + }, + }, + }, + }, + }, + }, + }); +}; + */