diff --git a/api-node/src/controllers/event.ts b/api-node/src/controllers/event.ts index 6e26c6d7..8b6d6b7f 100644 --- a/api-node/src/controllers/event.ts +++ b/api-node/src/controllers/event.ts @@ -44,7 +44,6 @@ router.post( matomo_id: req.body.userId, }, data: { - asked_for_review: { increment: 1 }, asked_for_review_latest_at: new Date(), }, }); diff --git a/api-node/src/utils/user.ts b/api-node/src/utils/user.ts index c6a2605b..46b01117 100644 --- a/api-node/src/utils/user.ts +++ b/api-node/src/utils/user.ts @@ -1,21 +1,30 @@ import dayjs from 'dayjs'; import type { User } from '@prisma/client'; +import prisma from '~/prisma'; -export function canAskReviewForUser(user: User | null) { +export async function canAskReviewForUser(user: User | null) { if (!user) return false; // no user if (Number(user.appbuild) < 24) { console.log('store review unavailable before'); - return false; // store review unavailable before + return false; } - if (!user?.notifications_sent) { + if (user?.asked_for_review) { + console.log('already done manually'); + return false; + } + const notificationsSent = await prisma.notification.count({ + where: { + user_id: user.id, + }, + }); + if (!notificationsSent) { console.log('not enough experience with the app'); - return false; // not enough experience with the app + return false; } - if (user?.asked_for_review) { - console.log('already done'); - return false; // already done + if (!user?.asked_for_review_latest_at) { + console.log('no date, meaning never asked before so we can ask'); + return true; } - if (!user?.asked_for_review_latest_at) return true; // no date if (dayjs().diff(dayjs(user?.asked_for_review_latest_at), 'months') < 3) { console.log('too recent'); return false; // too recent