generated from azures04/Base-REST-API
Add badges, checkins, and transport endpoints
Introduce gamification and check-in support plus expanded transport/admin APIs. Added DDL for checkins, badges and user_badges. New repositories: badgeRepository, userBadgeRepository, checkinRepository. New routes: admin badge management, admin transport (lines/platforms/stations), public transport endpoints, user checkins and stations endpoints, and user badges on /me. Services updated: adminService (badge CRUD & user assignment), userService (checkins, badge queries), authService (hasAdminRights). Minor package.json name update. These changes implement database, repo, service and route wiring for badges, user_badins and checkin features and additional transport admin routes.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
const express = require("express")
|
||||
const adminService = require("../../../../services/adminService")
|
||||
const router = express.Router({ mergeParams: true })
|
||||
|
||||
router.post("/", async (req, res) => {
|
||||
const { name, icon, condition, description } = req.body
|
||||
const badge = await adminService.createBadge({ name, icon, condition, description })
|
||||
return res.status(201).json(badge)
|
||||
})
|
||||
|
||||
router.patch("/:badgeId", async (req, res) => {
|
||||
const { badgeId } = req.params
|
||||
const updateData = req.body.data
|
||||
const badge = await adminService.updateBadge({ badgeId, updateData })
|
||||
return res.status(200).json(badge)
|
||||
})
|
||||
|
||||
router.delete("/:badgeId", async (req, res) => {
|
||||
const { badgeId } = req.params
|
||||
await adminService.deleteBadge({ badgeId })
|
||||
return res.sendStatus(204)
|
||||
})
|
||||
|
||||
router.put("/user/:userId/:badgeId", async (req, res) => {
|
||||
const { badgeId, userId } = req.params
|
||||
const assignedBadge = await adminService.assignBadgeToUser({ badgeId, userId })
|
||||
return res.status(200).json(assignedBadge)
|
||||
})
|
||||
|
||||
router.delete("/user/:userId/:badgeId", async (req, res) => {
|
||||
const { badgeId, userId } = req.params
|
||||
await adminService.removeBadgeFromUser({ badgeId, userId })
|
||||
return res.sendStatus(204)
|
||||
})
|
||||
|
||||
router.get("/all", async (req, res) => {
|
||||
const badges = await adminService.getAllBadges()
|
||||
return res.status(200).json(badges)
|
||||
})
|
||||
|
||||
router.get("/:badgeId", async (req, res) => {
|
||||
const { badgeId } = req.params.badgeId
|
||||
const badge = await adminService.getBadgeById({ badgeId })
|
||||
return res.status(200).json(badge)
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -0,0 +1,7 @@
|
||||
const express = require("express")
|
||||
const authService = require("../../../../services/authService")
|
||||
const router = express.Router()
|
||||
|
||||
router.use("", authService.isLogged, authService.hasAdminRights)
|
||||
|
||||
module.exports = router
|
||||
@@ -0,0 +1,24 @@
|
||||
const express = require("express")
|
||||
const transportService = require("../../../../../services/transportService")
|
||||
const router = express.Router({ mergeParams: true })
|
||||
|
||||
router.post("/", async (req, res) => {
|
||||
const { code, name, backColorHex, textColorHex, transportTypeId } = req.body
|
||||
const lines = await transportService.createLine({ code, name, backColorHex, textColorHex, transportTypeId })
|
||||
return res.status(201).json(lines)
|
||||
})
|
||||
|
||||
router.delete("/:lineId", async (req, res) => {
|
||||
const { lineId } = req.params
|
||||
await transportService.deleteLine({ lineId })
|
||||
return res.sendStatus(204)
|
||||
})
|
||||
|
||||
router.patch("/:lineId", async (req, res) => {
|
||||
const { lineId } = req.params
|
||||
const updateData = req.body.data
|
||||
await transportService.updateLine({ lineId, updateData })
|
||||
return res.sendStatus(200)
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -0,0 +1,44 @@
|
||||
const express = require("express")
|
||||
const transportService = require("../../../../../services/transportService")
|
||||
const router = express.Router({ mergeParams: true })
|
||||
|
||||
router.post("/", async (req, res) => {
|
||||
const { direction, latitude, longitude, name, stationId, hasElevator, isPRM } = req.body
|
||||
const lines = await transportService.createPlatform({ direction: direction || 0, latitude, longitude, name, stationId, hasElevator, isPRM })
|
||||
return res.status(201).json(lines)
|
||||
})
|
||||
|
||||
router.delete("/:platformId", async (req, res) => {
|
||||
const { platformId } = req.params
|
||||
await transportService.deletePlatform({ platformId })
|
||||
return res.sendStatus(204)
|
||||
})
|
||||
|
||||
router.post("/:platformId/line/:lineId", async (req, res) => {
|
||||
const { platformId, lineId } = req.params
|
||||
const { orderInLine, directionId } = req.body
|
||||
const patchedPlatform = await transportService.addLineToPlatform({ platformId, lineId, orderInLine, directionId })
|
||||
return res.status(201).json(patchedPlatform)
|
||||
})
|
||||
|
||||
router.patch("/:platformId", async (req, res) => {
|
||||
const { platformId } = req.params
|
||||
const { hasElevator, isPRM } = req.body
|
||||
const patchedPlatform = await transportService.updatePlatformAccessibility({ platformId, hasElevator, isPRM })
|
||||
return res.status(200).json(patchedPlatform)
|
||||
})
|
||||
|
||||
|
||||
router.patch("/:platformLineId/:orderInLine", async (req, res) => {
|
||||
const { platformLineId, orderInLine } = req.params
|
||||
const patchedPlatform = await transportService.updatePlatformLineOrder({ platformLineId, orderInLine })
|
||||
return res.status(200).json(patchedPlatform)
|
||||
})
|
||||
|
||||
router.delete("/:platformId/:lineId", async (req, res) => {
|
||||
const { lineId, platformId, directionId } = req.body
|
||||
await transportService.removeLineFromPlatform({ lineId, platformId, directionId })
|
||||
return res.sendStatus(204)
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -0,0 +1,24 @@
|
||||
const express = require("express")
|
||||
const transportService = require("../../../../../services/transportService")
|
||||
const router = express.Router({ mergeParams: true })
|
||||
|
||||
router.post("/", async (req, res) => {
|
||||
const { name, description } = req.body
|
||||
const lines = await transportService.createStation({ name, description })
|
||||
return res.status(201).json(lines)
|
||||
})
|
||||
|
||||
router.delete("/:stationId", async (req, res) => {
|
||||
const { stationId } = req.params
|
||||
await transportService.deleteStation({ stationId })
|
||||
return res.status(204)
|
||||
})
|
||||
|
||||
router.patch("/:stationId", async (req, res) => {
|
||||
const { stationId } = req.params
|
||||
const updateData = req.body.data
|
||||
const patchedStation = await transportService.updateStation({ stationId, updateData })
|
||||
return res.status(200).json({ patched: patchedStation })
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -0,0 +1,28 @@
|
||||
const express = require("express")
|
||||
const transportService = require("../../../../services/transportService")
|
||||
const router = express.Router({ mergeParams: true })
|
||||
|
||||
router.get("/:lineId", async (req, res) => {
|
||||
const { lineId } = req.params
|
||||
const line = await transportService.getLineById({ lineId })
|
||||
return res.status(200).json(line)
|
||||
})
|
||||
|
||||
router.get("/:lineId/stations", async (req, res) => {
|
||||
const { lineId } = req.params
|
||||
const stations = await transportService.getLineStations({ lineId, directionId: 0 })
|
||||
return res.status(200).json(stations)
|
||||
})
|
||||
|
||||
router.get("/all", async (req, res) => {
|
||||
const lines = await transportService.getAllLines()
|
||||
return res.status(200).json(lines)
|
||||
})
|
||||
|
||||
router.get("/all/:transportType", async (req, res) => {
|
||||
const { transportType } = req.params
|
||||
const lines = await transportService.getLinesByTransportType(transportType)
|
||||
return res.status(200).json(lines)
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -0,0 +1,29 @@
|
||||
const express = require("express")
|
||||
const transportService = require("../../../../services/transportService")
|
||||
const router = express.Router({ mergeParams: true })
|
||||
|
||||
router.get("/:platformId", async (req, res) => {
|
||||
const { platformId } = req.params
|
||||
const line = await transportService.getPlatformById({ platformId })
|
||||
return res.status(200).json(line)
|
||||
})
|
||||
|
||||
router.get("/:platformId/lines", async (req, res) => {
|
||||
const { platformId } = req.params
|
||||
const stations = await transportService.getPlatformLines({ platformId, directionId: 0 })
|
||||
return res.status(200).json(stations)
|
||||
})
|
||||
|
||||
router.get("/bystation/:stationId", async (req, res) => {
|
||||
const { stationId } = req.params
|
||||
const platforms = await transportService.getPlatformsByStation({ stationId })
|
||||
return res.status(200).json(platforms)
|
||||
})
|
||||
|
||||
router.get("/nearest/:lineId/:latitude/:longitude/:radiusM", async (req, res) => {
|
||||
const { lineId, latitude, longitude, radiusM } = req.params
|
||||
const lines = await transportService.findNearestPlatformForLine({ lineId, latitude, longitude, radiusM })
|
||||
return res.status(200).json(lines)
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -0,0 +1,34 @@
|
||||
const express = require("express")
|
||||
const transportService = require("../../../../services/transportService")
|
||||
const router = express.Router({ mergeParams: true })
|
||||
|
||||
router.get("/:stationId", async (req, res) => {
|
||||
const { stationId } = req.params
|
||||
const station = await transportService.getStationByIdx({ stationId })
|
||||
return res.status(200).json(station)
|
||||
})
|
||||
|
||||
router.get("/:stationId/lines", async (req, res) => {
|
||||
const { stationId } = req.params
|
||||
const lines = await transportService.getStationLines(stationId)
|
||||
return res.status(200).json(lines)
|
||||
})
|
||||
|
||||
router.get("/all", async (req, res) => {
|
||||
const stations = await transportService.getAllStations()
|
||||
return res.status(200).json(stations)
|
||||
})
|
||||
|
||||
router.get("/:radiusKm/:latitude/:longitude", async (req, res) => {
|
||||
const { radiusKm, latitude, longitude } = req.params
|
||||
const station = await transportService.getStationsByDistance({ latitude, longitude, radiusKm })
|
||||
return res.status(200).json(station)
|
||||
})
|
||||
|
||||
router.get("/accessible/:radiusKm/:latitude/:longitude", async (req, res) => {
|
||||
const { radiusKm, latitude, longitude } = req.params
|
||||
const station = await transportService.getAccessibleStations({ latitude, longitude, radiusKm })
|
||||
return res.status(200).json(station)
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -0,0 +1,22 @@
|
||||
const express = require("express")
|
||||
const userService = require("../../../../services/userService")
|
||||
const router = express.Router()
|
||||
|
||||
router.post("/", async (req, res) => {
|
||||
const { stationId, platformId, latitude, longitude, distance } = req.body
|
||||
const checkin = await userService.createCheckin({ distance, latitude, longitude, platformId, stationId, userId: req.user.id })
|
||||
return res.status(200).json(checkin)
|
||||
})
|
||||
|
||||
router.get("/", async (req, res) => {
|
||||
const { limit, offset } = req.query
|
||||
const checkins = await userService.getUserCheckins({ userId: req.user.id, limit, offset })
|
||||
return res.status(200).json(checkins)
|
||||
})
|
||||
|
||||
router.get("/count", async (req, res) => {
|
||||
const checkins = await userService.getUserCheckinsCount({ userId: req.user.id })
|
||||
return res.status(200).json(checkins)
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -19,4 +19,9 @@ router.patch("/displayname", async (req, res) => {
|
||||
return res.status(200).json(updatedProfile)
|
||||
})
|
||||
|
||||
router.get("/badges", async (req, res) => {
|
||||
const badges = await userService.getUserBadges({ userId: req.user.id })
|
||||
return res.status(200).json(badges)
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -0,0 +1,16 @@
|
||||
const express = require("express")
|
||||
const userService = require("../../../../services/userService")
|
||||
const router = express.Router()
|
||||
|
||||
router.get("/", async (req, res) => {
|
||||
const stationCheckinsCount = await userService.getUserUniqueStations({ userId: req.user.id })
|
||||
return res.status(200).json(stationCheckinsCount)
|
||||
})
|
||||
|
||||
router.get("/:stationId/checkins/count", async (req, res) => {
|
||||
const { stationId } = req.params
|
||||
const stationCheckinsCount = await userService.getUserStationCheckinsCount({ stationId, userId: req.user.id })
|
||||
return res.status(200).json(stationCheckinsCount)
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
Reference in New Issue
Block a user