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:
+45
-1
@@ -1,4 +1,6 @@
|
||||
const userRepo = require("../repositories/usersRepo")
|
||||
const userBadgeRepo = require("../repositories/userBadgeRepository")
|
||||
const checkinRepo = require("../repositories/checkinRepository")
|
||||
const cache = require("../modules/cache")
|
||||
|
||||
async function getProfile({ userId }) {
|
||||
@@ -30,11 +32,53 @@ async function getShadowUser({ serverId, remoteId }) {
|
||||
return await userRepo.findByServerAndRemoteId(serverId, remoteId)
|
||||
}
|
||||
|
||||
async function getUserBadges({ userId }) {
|
||||
return await userBadgeRepo.findUserBadges(userId)
|
||||
}
|
||||
|
||||
async function countUserBadges({ userId }) {
|
||||
return await userBadgeRepo.countUserBadges(userId)
|
||||
}
|
||||
|
||||
async function hasBadge({ userId, badgeId }) {
|
||||
return await userBadgeRepo.hasBadge(userId, badgeId)
|
||||
}
|
||||
|
||||
async function createCheckin({ userId, stationId, platformId, latitude, longitude, distance }) {
|
||||
const checkinId = await checkinRepo.createCheckin(userId, stationId, platformId, latitude, longitude, distance)
|
||||
cache.users.delete(userId)
|
||||
return checkinId
|
||||
}
|
||||
|
||||
async function getUserCheckins({ userId, limit = 50, offset = 0 }) {
|
||||
return await checkinRepo.findCheckinsByUserId(userId, limit, offset)
|
||||
}
|
||||
|
||||
async function getUserCheckinsCount({ userId }) {
|
||||
return await checkinRepo.countCheckinsByUser(userId)
|
||||
}
|
||||
|
||||
async function getUserUniqueStations({ userId }) {
|
||||
return await checkinRepo.findUniqueStationsByUser(userId)
|
||||
}
|
||||
|
||||
async function getUserStationCheckinsCount({ userId, stationId }) {
|
||||
return await checkinRepo.countCheckinsByUserAndStation(userId, stationId)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isLocal,
|
||||
getProfile,
|
||||
createUser,
|
||||
updateProfile,
|
||||
deleteAccount,
|
||||
getShadowUser
|
||||
getShadowUser,
|
||||
getUserBadges,
|
||||
countUserBadges,
|
||||
hasBadge,
|
||||
createCheckin,
|
||||
getUserCheckins,
|
||||
getUserCheckinsCount,
|
||||
getUserUniqueStations,
|
||||
getUserStationCheckinsCount
|
||||
}
|
||||
Reference in New Issue
Block a user