Skip to content

Commit

Permalink
fix: change limit goal
Browse files Browse the repository at this point in the history
  • Loading branch information
YoanRos committed Mar 18, 2024
1 parent 2181f78 commit f63ad38
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
78 changes: 78 additions & 0 deletions api/src/controllers/consommation.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,84 @@ router.post(
const inAppModal = await checkNPSAvailability(user, allConsos);
return res.status(200).send({ ok: true, showInAppModal: inAppModal });
}
if (!drinksBadges.find((badge) => badge.stars === 6)) {
const allConsos = await prisma.consommation.findMany({
where: { userId: user.id },
orderBy: { date: "desc" },
});
const enoughConsecutiveDays = checksConsecutiveDays(60, allConsos);
if (enoughConsecutiveDays) {
await prisma.badge.create({
data: {
userId: user.id,
category: "drinks",
stars: 6,
},
});
const allBadges = await prisma.badge.findMany({ where: { userId: user.id } });

return res.status(200).send({
ok: true,
showNewBadge: showGoalNewBadge
? showGoalNewBadge
: { newBadge: grabBadgeFromCatalog("drinks", 6), allBadges, badgesCatalog: getBadgeCatalog(req.headers.appversion) },
});
}
const inAppModal = await checkNPSAvailability(user, allConsos);
return res.status(200).send({ ok: true, showInAppModal: inAppModal });
}
if (!drinksBadges.find((badge) => badge.stars === 7)) {
const allConsos = await prisma.consommation.findMany({
where: { userId: user.id },
orderBy: { date: "desc" },
});
const enoughConsecutiveDays = checksConsecutiveDays(90, allConsos);
if (enoughConsecutiveDays) {
await prisma.badge.create({
data: {
userId: user.id,
category: "drinks",
stars: 7,
},
});
const allBadges = await prisma.badge.findMany({ where: { userId: user.id } });

return res.status(200).send({
ok: true,
showNewBadge: showGoalNewBadge
? showGoalNewBadge
: { newBadge: grabBadgeFromCatalog("drinks", 7), allBadges, badgesCatalog: getBadgeCatalog(req.headers.appversion) },
});
}
const inAppModal = await checkNPSAvailability(user, allConsos);
return res.status(200).send({ ok: true, showInAppModal: inAppModal });
}
if (!drinksBadges.find((badge) => badge.stars === 8)) {
const allConsos = await prisma.consommation.findMany({
where: { userId: user.id },
orderBy: { date: "desc" },
});
const enoughConsecutiveDays = checksConsecutiveDays(180, allConsos);
if (enoughConsecutiveDays) {
await prisma.badge.create({
data: {
userId: user.id,
category: "drinks",
stars: 8,
},
});
const allBadges = await prisma.badge.findMany({ where: { userId: user.id } });

return res.status(200).send({
ok: true,
showNewBadge: showGoalNewBadge
? showGoalNewBadge
: { newBadge: grabBadgeFromCatalog("drinks", 8), allBadges, badgesCatalog: getBadgeCatalog(req.headers.appversion) },
});
}
const inAppModal = await checkNPSAvailability(user, allConsos);
return res.status(200).send({ ok: true, showInAppModal: inAppModal });
}
return res.status(200).send({ ok: true });
})
);
Expand Down
2 changes: 1 addition & 1 deletion api/src/utils/goals.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const checkIfThisWeekGoalAchieved = async (matomoId, appversion) => {
if (!!goalBadges.length) {
const lastBadge = goalBadges[0];
if (lastBadge) {
const allBadgesAreGivenAlready = lastBadge.stars === 5;
const allBadgesAreGivenAlready = lastBadge.stars === 8;
if (allBadgesAreGivenAlready) {
// the user has all the badges already, nothing to do
return null;
Expand Down

0 comments on commit f63ad38

Please sign in to comment.