Skip to content

Commit

Permalink
fix: in app rating asked from backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud AMBROSELLI committed Apr 8, 2024
1 parent 302a00c commit b5223b9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
1 change: 0 additions & 1 deletion api-node/src/controllers/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ router.post(
matomo_id: req.body.userId,
},
data: {
asked_for_review: { increment: 1 },
asked_for_review_latest_at: new Date(),
},
});
Expand Down
25 changes: 17 additions & 8 deletions api-node/src/utils/user.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit b5223b9

Please sign in to comment.