diff --git a/api/config/api-url.js b/api/config/api-url.js index ee2bb53..4e68b70 100644 --- a/api/config/api-url.js +++ b/api/config/api-url.js @@ -1,18 +1,19 @@ const rootRoute = '/api'; module.exports = { + account: rootRoute + '/account', auth: rootRoute + '/authenticate', - signUp: rootRoute + '/authenticate/signup', awards: rootRoute + '/awardings', - command: rootRoute + '/cmd', + campaigns: rootRoute + '/campaigns', cmdCreateSig: rootRoute + '/cmd/createSignature', + command: rootRoute + '/cmd', decorations: rootRoute + '/decorations', overview: rootRoute + '/overview', ranks: rootRoute + '/ranks', + request: rootRoute + '/request', signatures: '/signatures', + signUp: rootRoute + '/authenticate/signup', squads: rootRoute + '/squads', users: rootRoute + '/users', - account: rootRoute + '/account', - request: rootRoute + '/request', wars: rootRoute + '/wars' }; diff --git a/api/models/campaign.js b/api/models/campaign.js new file mode 100644 index 0000000..405a0c1 --- /dev/null +++ b/api/models/campaign.js @@ -0,0 +1,18 @@ +"use strict"; + +const mongoose = require('mongoose'); +const Schema = mongoose.Schema; + +const CampaignSchema = new Schema({ + title: { + type: String, + required: true + } +}, { + collection: 'campaign', + timestamps: {createdAt: 'timestamp'} +}); +// optional more indices +CampaignSchema.index({timestamp: 1}); + +module.exports = mongoose.model('Campaign', CampaignSchema); diff --git a/api/models/war.js b/api/models/war.js index ad0cd43..b89bcae 100644 --- a/api/models/war.js +++ b/api/models/war.js @@ -35,6 +35,10 @@ const WarSchema = new Schema({ get: v => Math.round(v), set: v => Math.round(v), default: 0 + }, + campaign: { + type: mongoose.Schema.Types.ObjectId, + ref: 'Campaign' } }, { collection: 'war', diff --git a/api/routes/campaigns.js b/api/routes/campaigns.js new file mode 100644 index 0000000..6864cc5 --- /dev/null +++ b/api/routes/campaigns.js @@ -0,0 +1,43 @@ +"use strict"; + +// modules +const express = require('express'); +const logger = require('debug')('cc:campaigns'); + +// 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 campaigns = express.Router(); + +// routes ********************** +campaigns.route('/') + + .post((req, res, next) => { + const campaign = new CampaignModel(req.body); + // timestamp and default are set automatically by Mongoose Schema Validation + campaign.save((err) => { + if (err) { + err.status = codes.wrongrequest; + err.message += ' in fields: ' + Object.getOwnPropertyNames(err.errors); + return next(err); + } + res.status(codes.created); + res.locals.items = campaign; + next(); + }); + }) + + .all( + routerHandling.httpMethodNotAllowed + ); + +// this middleware function can be used, if you like or remove it +// it looks for object(s) in res.locals.items and if they exist, they are send to the client as json +campaigns.use(routerHandling.emptyResponse); + +module.exports = campaigns; diff --git a/api/routes/wars.js b/api/routes/wars.js index 60a9206..e98ca43 100644 --- a/api/routes/wars.js +++ b/api/routes/wars.js @@ -18,6 +18,7 @@ const checkMT = require('../middleware/permission-check').checkMT; const routerHandling = require('../middleware/router-handling'); // Mongoose Model using mongoDB +const CampaignModel = require('../models/campaign'); const WarModel = require('../models/war'); const PlayerModel = require('../models/player'); @@ -26,20 +27,37 @@ const wars = express.Router(); // routes ********************** wars.route('/') .get((req, res, next) => { - const filter = {}; - WarModel.find(filter, {}, {sort: {date: 'desc'}}, (err, items) => { + let result = []; + CampaignModel.find({}, {}, {sort: {timestamp: 'desc'}}, (err, campaigns) => { if (err) { err.status = codes.servererror; return next(err); } - if (items) { - res.locals.items = items; - } else { - res.locals.items = []; + if (campaigns) { + WarModel.find({}, {}, {sort: {date: 'desc'}}, (err, wars) => { + if (err) { + err.status = codes.servererror; + return next(err); + } + if (wars) { + campaigns.forEach(campaign => { + let entry = {title: campaign.title, wars: []}; + wars.forEach((war) => { + if (String(campaign._id) === String(war.campaign)) { + entry.wars.push(war); + } + }); + result.push(entry); + }); + res.locals.items = result; + } + res.locals.processed = true; + next(); + } + ) + ; } - res.locals.processed = true; - next(); - }); + }) }) .post(apiAuthenticationMiddleware, checkMT, upload.single('log'), (req, res, next) => { diff --git a/api/server.js b/api/server.js index c51684f..d1d2ef2 100644 --- a/api/server.js +++ b/api/server.js @@ -15,6 +15,7 @@ const urls = require('./config/api-url'); const restAPIchecks = require('./middleware/request-checks.js'); const errorResponseWare = require('./middleware/error-response'); const apiAuthenticationMiddleware = require('./middleware/auth-middleware'); +const checkMT = require('./middleware/permission-check').checkMT; const checkAdmin = require('./middleware/permission-check').checkAdmin; const signatureCronJob = require('./cron-job/cron').cronJobSignature; const backupCronJob = require('./cron-job/cron').cronJobBackup; @@ -32,6 +33,7 @@ const awardingRouter = require('./routes/awardings'); const requestRouter = require('./routes/request'); const signatureRouter = require('./routes/signatures'); const commandRouter = require('./routes/command'); +const campaignRouter = require('./routes/campaigns'); const warRouter = require('./routes/wars'); // Configuration *********************************** @@ -79,6 +81,7 @@ app.use(urls.decorations, decorationRouter); app.use(urls.request, requestRouter); app.use(urls.awards, awardingRouter); app.use(urls.wars, warRouter); +app.use(urls.campaigns, apiAuthenticationMiddleware, checkMT, campaignRouter); app.use(urls.command, apiAuthenticationMiddleware, checkAdmin, commandRouter); app.use(urls.account, apiAuthenticationMiddleware, checkAdmin, accountRouter); diff --git a/static/src/assets/award.png b/static/src/assets/award.png new file mode 100644 index 0000000..fbabac3 Binary files /dev/null and b/static/src/assets/award.png differ diff --git a/static/src/assets/loading.png b/static/src/assets/loading.png new file mode 100644 index 0000000..0e00d49 Binary files /dev/null and b/static/src/assets/loading.png differ diff --git a/static/src/assets/opt-logo-klein.png b/static/src/assets/opt-logo-klein.png new file mode 100644 index 0000000..41f597d Binary files /dev/null and b/static/src/assets/opt-logo-klein.png differ