Skip to content

Commit

Permalink
better sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud AMBROSELLI committed May 7, 2024
1 parent 53c1732 commit a79e899
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
17 changes: 15 additions & 2 deletions api/src/controllers/consommation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { catchErrors } = require("../middlewares/errors");
const router = express.Router();
const prisma = require("../prisma");
const { getBadgeCatalog } = require("../utils/badges");
const { syncGoalsWithConsos } = require("../utils/goals");
const { syncGoalsWithConsos, syncAllGoalsWithConsos } = require("../utils/goals");
const { checksConsecutiveDays, syncDrinkBadgesWithConsos } = require("../utils/drinks");

router.post(
Expand All @@ -23,7 +23,15 @@ router.post(

const { drinks, drinksCatalog } = req.body;

if (!drinks.length) return res.status(200).json({ ok: true });
if (!drinks.length) {
await syncDrinkBadgesWithConsos(matomoId);

await syncAllGoalsWithConsos(matomoId, true);

// TODO: uncomment this line when the notifications for goals sync is sent
// await syncBadgesWithGoals(matomoId, true);
return res.status(200).json({ ok: true });
}

const user = await prisma.user.upsert({
where: { matomo_id: matomoId },
Expand Down Expand Up @@ -70,6 +78,11 @@ router.post(

await syncDrinkBadgesWithConsos(matomoId);

await syncAllGoalsWithConsos(matomoId, true);

// TODO: uncomment this line when the notifications for goals sync is sent
// await syncBadgesWithGoals(matomoId, true);

return res.status(200).send({ ok: true });
})
);
Expand Down
6 changes: 0 additions & 6 deletions api/src/controllers/goal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const dayjs = require("dayjs");
const prisma = require("../prisma");
const { grabBadgeFromCatalog, getBadgeCatalog } = require("../utils/badges");
const { GoalStatus } = require("@prisma/client");
const { syncAllGoalsWithConsos, syncBadgesWithGoals } = require("../utils/goals");
const router = express.Router();

router.post(
Expand Down Expand Up @@ -140,11 +139,6 @@ router.get(
}
}

await syncAllGoalsWithConsos(matomoId, true);

// TODO: uncomment this line when the notifications for goals sync is sent
// await syncBadgesWithGoals(matomoId, true);

const goals = await prisma.goal.findMany({
where: { userId: user.id },
orderBy: { date: "desc" },
Expand Down

0 comments on commit a79e899

Please sign in to comment.