step 4.5: done
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
// Combat log routes: GET /api/combat-log (recent fights for the logged-in user's character).
|
||||
const zod = require('zod');
|
||||
const { getCombatLog } = require('../services/combatLogService');
|
||||
const { requireAuth } = require('../middleware/session');
|
||||
const { getCharacterIdForUser } = require('../services/characterService');
|
||||
|
||||
function wrap(fn) {
|
||||
return (req, res, next) => Promise.resolve(fn(req, res, next)).catch(next);
|
||||
}
|
||||
|
||||
const logSchema = zod.object({
|
||||
limit: zod.coerce.number().int().min(1).max(100).optional(),
|
||||
});
|
||||
|
||||
async function handleGetCombatLog(req, res) {
|
||||
const parsed = logSchema.safeParse(req.query);
|
||||
if (!parsed.success) {
|
||||
const { AppError } = require('../utils/errors');
|
||||
throw new AppError('VALIDATION_ERROR', 'Request validation failed.', 400);
|
||||
}
|
||||
|
||||
const characterId = getCharacterIdForUser(req.session.userId);
|
||||
const limit = parsed.data.limit ?? 20;
|
||||
const logs = getCombatLog(characterId, limit);
|
||||
res.json({ ok: true, data: logs });
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
routes: {
|
||||
getCombatLog: wrap(handleGetCombatLog),
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
// Zone routes: GET /api/zones (list zones with unlocked flag).
|
||||
const zod = require('zod');
|
||||
const { listZones } = require('../services/zoneService');
|
||||
const { requireAuth } = require('../middleware/session');
|
||||
const { getCharacterProfile } = require('../services/characterService');
|
||||
|
||||
function wrap(fn) {
|
||||
return (req, res, next) => Promise.resolve(fn(req, res, next)).catch(next);
|
||||
}
|
||||
|
||||
async function handleGetZones(req, res) {
|
||||
const profile = getCharacterProfile(req.session.userId);
|
||||
const zones = listZones(profile.character.level);
|
||||
res.json({ ok: true, data: zones });
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
routes: {
|
||||
getZones: wrap(handleGetZones),
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user