Add players endpoint
parent
bacb350a18
commit
8138926e1c
|
@ -9,6 +9,7 @@ module.exports = {
|
||||||
command: rootRoute + '/cmd',
|
command: rootRoute + '/cmd',
|
||||||
decorations: rootRoute + '/decorations',
|
decorations: rootRoute + '/decorations',
|
||||||
overview: rootRoute + '/overview',
|
overview: rootRoute + '/overview',
|
||||||
|
players: rootRoute + '/players',
|
||||||
ranks: rootRoute + '/ranks',
|
ranks: rootRoute + '/ranks',
|
||||||
request: rootRoute + '/request',
|
request: rootRoute + '/request',
|
||||||
signatures: '/signatures',
|
signatures: '/signatures',
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
"cors": "^2.8.3",
|
"cors": "^2.8.3",
|
||||||
"cron": "^1.2.1",
|
"cron": "^1.2.1",
|
||||||
"debug": "~2.2.0",
|
"debug": "~2.2.0",
|
||||||
"express": "~4.13.1",
|
"express": "^4.16.1",
|
||||||
"imagemin": "^5.2.2",
|
"imagemin": "^5.2.2",
|
||||||
"imagemin-pngquant": "^5.0.0",
|
"imagemin-pngquant": "^5.0.0",
|
||||||
"jimp": "^0.2.27",
|
"jimp": "^0.2.27",
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// modules
|
||||||
|
const express = require('express');
|
||||||
|
const logger = require('debug')('cc:wars');
|
||||||
|
|
||||||
|
// HTTP status codes by name
|
||||||
|
const codes = require('./http-codes');
|
||||||
|
|
||||||
|
const routerHandling = require('../middleware/router-handling');
|
||||||
|
|
||||||
|
// Mongoose Model using mongoDB
|
||||||
|
const CampaignModel = require('../models/campaign');
|
||||||
|
const PlayerModel = require('../models/player');
|
||||||
|
const WarModel = require('../models/war');
|
||||||
|
|
||||||
|
const campaignPlayer = express.Router();
|
||||||
|
|
||||||
|
// routes **********************
|
||||||
|
campaignPlayer.route('/:campaignId/:playerName')
|
||||||
|
.get((req, res, next) => {
|
||||||
|
CampaignModel.findById(req.params.campaignId, (err, campaign) => {
|
||||||
|
if (err) return next(err);
|
||||||
|
WarModel.find({campaign: req.params.campaignId}, '_id', (err, wars) => {
|
||||||
|
if (err) return next(err);
|
||||||
|
const warIds = wars.map((obj) => {
|
||||||
|
return obj._id;
|
||||||
|
});
|
||||||
|
PlayerModel.find({name: req.params.playerName, warId: {"$in": warIds}})
|
||||||
|
.populate('warId')
|
||||||
|
.exec((err, items) => {
|
||||||
|
if (err) return next(err);
|
||||||
|
if (!items || items.length === 0) {
|
||||||
|
const err = new Error('unknown player name');
|
||||||
|
err.status = codes.notfound;
|
||||||
|
return next(err)
|
||||||
|
}
|
||||||
|
res.locals.items = {
|
||||||
|
name: req.params.playerName,
|
||||||
|
campaign: campaign,
|
||||||
|
players: items
|
||||||
|
};
|
||||||
|
next();
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
.all(
|
||||||
|
routerHandling.httpMethodNotAllowed
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
campaignPlayer.use(routerHandling.emptyResponse);
|
||||||
|
|
||||||
|
module.exports = campaignPlayer;
|
|
@ -30,6 +30,7 @@ const rankRouter = require('./routes/ranks');
|
||||||
const decorationRouter = require('./routes/decorations');
|
const decorationRouter = require('./routes/decorations');
|
||||||
const awardingRouter = require('./routes/awardings');
|
const awardingRouter = require('./routes/awardings');
|
||||||
const requestRouter = require('./routes/request');
|
const requestRouter = require('./routes/request');
|
||||||
|
const playerRouter = require('./routes/players');
|
||||||
const signatureRouter = require('./routes/signatures');
|
const signatureRouter = require('./routes/signatures');
|
||||||
const commandRouter = require('./routes/command');
|
const commandRouter = require('./routes/command');
|
||||||
const campaignRouter = require('./routes/campaigns');
|
const campaignRouter = require('./routes/campaigns');
|
||||||
|
@ -80,6 +81,7 @@ app.use(urls.decorations, decorationRouter);
|
||||||
app.use(urls.request, requestRouter);
|
app.use(urls.request, requestRouter);
|
||||||
app.use(urls.awards, awardingRouter);
|
app.use(urls.awards, awardingRouter);
|
||||||
app.use(urls.wars, warRouter);
|
app.use(urls.wars, warRouter);
|
||||||
|
app.use(urls.players, playerRouter);
|
||||||
app.use(urls.campaigns,campaignRouter);
|
app.use(urls.campaigns,campaignRouter);
|
||||||
app.use(urls.command, apiAuthenticationMiddleware, checkAdmin, commandRouter);
|
app.use(urls.command, apiAuthenticationMiddleware, checkAdmin, commandRouter);
|
||||||
app.use(urls.account, apiAuthenticationMiddleware, checkAdmin, accountRouter);
|
app.use(urls.account, apiAuthenticationMiddleware, checkAdmin, accountRouter);
|
||||||
|
|
|
@ -28,6 +28,7 @@ export const RouteConfig = {
|
||||||
statsPath: 'stats',
|
statsPath: 'stats',
|
||||||
userPath: 'users',
|
userPath: 'users',
|
||||||
overviewPath: 'overview',
|
overviewPath: 'overview',
|
||||||
|
playersPath: 'players',
|
||||||
request: 'request',
|
request: 'request',
|
||||||
requestAwardPath: 'award',
|
requestAwardPath: 'award',
|
||||||
requestPromotionPath: 'promotion',
|
requestPromotionPath: 'promotion',
|
||||||
|
|
Loading…
Reference in New Issue