remove N/A CR, exclude completed if has no submission

This commit is contained in:
Johannes
2023-08-04 09:51:49 +02:00
parent 7bf0fa450a
commit ee545b7ade
2 changed files with 97 additions and 3 deletions

View File

@@ -61,10 +61,14 @@ const notificationInsight = (insights: Insights) =>
<p style="font-size:0.9em">Completed</p>
<h1>${insights.totalCompletedResponses}</h1>
</td>
<td style="text-align:center;">
${
insights.totalDisplays !== 0
? `<td style="text-align:center;">
<p style="font-size:0.9em">Completion %</p>
<h1>${insights.totalDisplays === 0 ? "N/A" : `${Math.round(insights.completionRate)}%`}</h1>
</td>
<h1>${Math.round(insights.completionRate)}%</h1>
</td>`
: ""
}
</tr>
</table>
</div>

View File

@@ -133,6 +133,20 @@ const getProducts = async (): Promise<ProductData[]> => {
id: true,
surveys: {
where: {
NOT: {
AND: [
{ status: "completed" },
{
responses: {
none: {
createdAt: {
gte: sevenDaysAgo,
},
},
},
},
],
},
status: {
not: "draft",
},
@@ -190,3 +204,79 @@ const getProducts = async (): Promise<ProductData[]> => {
},
});
};
/* const getProducts = async (): Promise<ProductData[]> => {
// 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,
},
},
},
},
},
},
},
});
};
*/