-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
169 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,24 +4,15 @@ const router = express.Router(); | |
const prisma = require("../prisma"); | ||
const dayjs = require("dayjs"); | ||
const { superUser30DaysInAppModal, superUser90DaysInAppModal } = require("../utils/inAppModals"); | ||
const { authenticateToken } = require("../middlewares/tokenAuth"); | ||
|
||
router.post( | ||
"/", | ||
authenticateToken, | ||
catchErrors(async (req, res) => { | ||
const { matomoId, appMilestone } = req.body || {}; | ||
const { appMilestone } = req.body || {}; | ||
|
||
if (!matomoId) return res.status(400).json({ ok: false, error: "no matomo id" }); | ||
|
||
const user = await prisma.user.upsert({ | ||
where: { matomo_id: matomoId }, | ||
create: { | ||
matomo_id: matomoId, | ||
created_from: "AppMilestonePost", | ||
email: "[email protected]", | ||
password: "password12@Abc", | ||
}, | ||
update: {}, | ||
}); | ||
const user = req.user; | ||
|
||
await prisma.appMilestone.upsert({ | ||
where: { id: `${user.id}_${appMilestone}` }, | ||
|
@@ -42,19 +33,10 @@ router.post( | |
|
||
router.post( | ||
"/init", | ||
authenticateToken, | ||
catchErrors(async (req, res) => { | ||
const { matomoId, isRegistered } = req.body || {}; | ||
if (!matomoId) return res.status(400).json({ ok: false, error: "no matomo id" }); | ||
const user = await prisma.user.upsert({ | ||
where: { matomo_id: matomoId }, | ||
create: { | ||
matomo_id: matomoId, | ||
created_from: "AppMilestoneInit", | ||
email: "[email protected]", | ||
password: "password12@Abc", | ||
}, | ||
update: {}, | ||
}); | ||
const { isRegistered } = req.body || {}; | ||
const user = req.user; | ||
|
||
const allowNotification = await prisma.appMilestone.findUnique({ | ||
where: { id: `${user.id}_@AllowNotification` }, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,24 +3,15 @@ const { catchErrors } = require("../middlewares/errors"); | |
const router = express.Router(); | ||
const prisma = require("../prisma"); | ||
const { getBadgeCatalog, grabBadgeFromCatalog } = require("../utils/badges"); | ||
const { authenticateToken } = require("../middlewares/tokenAuth"); | ||
|
||
router.post( | ||
"/", | ||
authenticateToken, | ||
catchErrors(async (req, res) => { | ||
const { matomoId, articleTitle } = req.body || {}; | ||
const { articleTitle } = req.body || {}; | ||
|
||
if (!matomoId) return res.status(400).json({ ok: false, error: "no matomo id" }); | ||
|
||
const user = await prisma.user.upsert({ | ||
where: { matomo_id: matomoId }, | ||
create: { | ||
matomo_id: matomoId, | ||
created_from: "Articles", | ||
email: "[email protected]", | ||
password: "password12@Abc", | ||
}, | ||
update: {}, | ||
}); | ||
const user = req.user; | ||
|
||
await prisma.article.upsert({ | ||
where: { id: `${user.id}_${articleTitle.replaceAll(" ", "")}` }, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ const { catchErrors } = require("../middlewares/errors"); | |
const router = express.Router(); | ||
const prisma = require("../prisma"); | ||
const { getBadgeCatalog, grabBadgeFromCatalog, missedGoal } = require("../utils/badges"); | ||
const { authenticateToken } = require("../middlewares/tokenAuth"); | ||
|
||
router.get( | ||
"/test", | ||
|
@@ -16,21 +17,17 @@ router.get( | |
|
||
router.get( | ||
"/:matomoId", | ||
authenticateToken, | ||
|
||
catchErrors(async (req, res) => { | ||
const { matomoId } = req.params; | ||
// Don't show badges that are not available in the app version | ||
|
||
if (!matomoId) return res.status(200).send({ ok: true, data: [] }); | ||
|
||
const user = req.user; | ||
|
||
// find badges of matomoId | ||
const user = await prisma.user.upsert({ | ||
where: { matomo_id: matomoId }, | ||
create: { | ||
matomo_id: matomoId, | ||
created_from: "GetBadges", | ||
}, | ||
update: {}, | ||
}); | ||
|
||
const badges = await prisma.badge.findMany({ | ||
where: { | ||
|
@@ -57,20 +54,10 @@ router.get( | |
|
||
router.post( | ||
"/shares", | ||
authenticateToken, | ||
catchErrors(async (req, res) => { | ||
const { matomoId } = req.body || {}; | ||
if (!matomoId) return res.status(400).json({ ok: false, error: "no matomo id" }); | ||
const user = await prisma.user.upsert({ | ||
where: { matomo_id: matomoId }, | ||
create: { | ||
matomo_id: matomoId, | ||
email: "[email protected]", | ||
password: "password12@Abc", | ||
created_from: "GetBadges", | ||
}, | ||
const user = req.user; | ||
|
||
update: {}, | ||
}); | ||
const share_badges = await prisma.badge.findMany({ | ||
where: { userId: user.id, category: "share" }, | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,22 +3,21 @@ const express = require("express"); | |
const { catchErrors } = require("../middlewares/errors"); | ||
const router = express.Router(); | ||
const prisma = require("../prisma"); | ||
const { authenticateToken } = require("../middlewares/tokenAuth"); | ||
|
||
router.post( | ||
"/request", | ||
authenticateToken, | ||
catchErrors(async (req, res) => { | ||
const matomoId = req.body?.matomoId; | ||
if (!matomoId) return res.status(400).json({ ok: false, error: "no matomo id" }); | ||
const user = req.user; | ||
|
||
const context = req.body.context; | ||
const category = req.body.category; | ||
// find user with matomoId | ||
let user = await prisma.user.findUnique({ where: { matomo_id: matomoId } }); | ||
|
||
if (!user) return res.status(400).json({ ok: false, error: "no user" }); | ||
await prisma.drinksContextRequest.create({ | ||
data: { | ||
userId: user.id, | ||
matomo_id: matomoId, | ||
context: context, | ||
category: category?.toLowerCase(), | ||
}, | ||
|
@@ -29,16 +28,14 @@ router.post( | |
|
||
router.post( | ||
"/", | ||
authenticateToken, | ||
catchErrors(async (req, res) => { | ||
const matomoId = req.body?.matomoId; | ||
if (!matomoId) return res.status(400).json({ ok: false, error: "no matomo id" }); | ||
const user = req.user; | ||
const id = req.body.id; | ||
const context = req.body.context; | ||
const date = req.body.date; | ||
const emotion = req.body.emotion; | ||
|
||
let user = await prisma.user.findUnique({ where: { matomo_id: matomoId } }); | ||
|
||
await prisma.drinksContext.upsert({ | ||
where: { id: id }, | ||
update: { | ||
|
@@ -61,23 +58,13 @@ router.post( | |
|
||
router.post( | ||
"/sync", | ||
authenticateToken, | ||
catchErrors(async (req, res) => { | ||
const matomoId = req.body?.matomoId; | ||
if (!matomoId) return res.status(400).json({ ok: false, error: "no matomo id" }); | ||
|
||
const { drinksContexts } = req.body; | ||
|
||
if (!drinksContexts.length) return res.status(200).json({ ok: true }); | ||
|
||
const user = await prisma.user.upsert({ | ||
where: { matomo_id: matomoId }, | ||
create: { | ||
email: "[email protected]", | ||
password: "password12@Abc", | ||
matomo_id: matomoId, | ||
}, | ||
update: {}, | ||
}); | ||
const user = req.user; | ||
|
||
const drinksContextsToSave = drinksContexts.map((drinksContext) => { | ||
return { | ||
|
@@ -89,7 +76,7 @@ router.post( | |
}; | ||
}); | ||
|
||
await prisma.DrinksContext.createMany({ | ||
await prisma.drinksContext.createMany({ | ||
data: drinksContextsToSave, | ||
skipDuplicates: true, | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,31 +5,23 @@ const prisma = require("../prisma"); | |
const { grabBadgeFromCatalog, getBadgeCatalog } = require("../utils/badges"); | ||
const { GoalStatus } = require("@prisma/client"); | ||
const router = express.Router(); | ||
const { authenticateToken } = require("../middlewares/tokenAuth"); | ||
|
||
router.post( | ||
["/", "/sync"], | ||
authenticateToken, | ||
catchErrors(async (req, res) => { | ||
const { matomoId, daysWithGoalNoDrink, dosesByDrinkingDay, dosesPerWeek, noDisplayBadge, forceDate } = req.body || {}; | ||
if (!matomoId) return res.status(400).json({ ok: false, error: "no matomo id" }); | ||
const { daysWithGoalNoDrink, dosesByDrinkingDay, dosesPerWeek, noDisplayBadge, forceDate } = req.body || {}; | ||
const user = req.user; | ||
|
||
/* 1. update user settings */ | ||
/* 2. update current goal if any */ | ||
/* 3. send badge if not yet sent */ | ||
|
||
/* 1. update user settings */ | ||
let user = await prisma.user.upsert({ | ||
where: { matomo_id: matomoId }, | ||
create: { | ||
matomo_id: matomoId, | ||
email: "[email protected]", | ||
password: "password12@Abc", | ||
created_from: "Goal", | ||
goal_isSetup: true, | ||
goal_daysWithGoalNoDrink: daysWithGoalNoDrink, | ||
goal_dosesByDrinkingDay: dosesByDrinkingDay, | ||
goal_dosesPerWeek: dosesPerWeek, | ||
}, | ||
update: { | ||
await prisma.user.update({ | ||
where: { id: user.id }, | ||
data: { | ||
goal_isSetup: true, | ||
goal_daysWithGoalNoDrink: daysWithGoalNoDrink, | ||
goal_dosesByDrinkingDay: dosesByDrinkingDay, | ||
|
@@ -107,18 +99,9 @@ router.post( | |
|
||
router.get( | ||
"/list", | ||
authenticateToken, | ||
catchErrors(async (req, res) => { | ||
const { matomoId } = req.query; | ||
const user = await prisma.user.upsert({ | ||
where: { matomo_id: matomoId }, | ||
create: { | ||
matomo_id: matomoId, | ||
email: "[email protected]", | ||
password: "password12@Abc", | ||
created_from: "GetGoal", | ||
}, | ||
update: {}, | ||
}); | ||
const user = req.query; | ||
|
||
if (user.goal_isSetup) { | ||
let currentGoal = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.