2
0

feat(results): 🛂 Limit incomplete submissions

This commit is contained in:
Baptiste Arnaud
2022-02-12 12:54:16 +01:00
parent 3a7b9a0c63
commit ec470b578c
11 changed files with 93 additions and 32 deletions

View File

@ -2,6 +2,7 @@ import { User } from 'db'
import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { getSession } from 'next-auth/react'
import { isFreePlan } from 'services/user'
import { methodNotAllowed } from 'utils'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
@ -27,6 +28,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
typebotId,
typebot: { ownerId: user.id },
answers: { some: {} },
isCompleted: isFreePlan(user),
},
orderBy: {
createdAt: 'desc',

View File

@ -38,7 +38,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const stats: Stats = {
totalViews,
totalStarts,
completionRate: Math.round((totalCompleted / totalStarts) * 100),
totalCompleted,
}
return res.status(200).send({ stats })
}