Compare commits
No commits in common. "e8ea7dc6a9a48466b9f16c5772c4b1a38cf47893" and "f0e5b1105496f7f3b7ae8bc0e6dd90e4ea5aeaee" have entirely different histories.
e8ea7dc6a9
...
f0e5b11054
|
@ -1,53 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
// HTTP status codes by name
|
||||
const codes = require('./http-codes');
|
||||
|
||||
const genericGetById = (req, res, next, modelClass) => {
|
||||
modelClass.findById(req.params.id, (err, item) => {
|
||||
if (err) {
|
||||
err.status = codes.servererror;
|
||||
return next(err);
|
||||
} else if (!item) {
|
||||
err = new Error('item not found');
|
||||
err.status = codes.notfound;
|
||||
return next(err);
|
||||
}
|
||||
res.locals.items = item;
|
||||
return next();
|
||||
});
|
||||
};
|
||||
|
||||
const genericPatch = (req, res, next, modelClass) => {
|
||||
if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
|
||||
// little bit different as in PUT. :id does not need to be in data, but if the _id and url id must match
|
||||
const err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' +
|
||||
req.body._id);
|
||||
err.status = codes.notfound;
|
||||
next(err);
|
||||
return; // prevent node to process this function further after next() has finished.
|
||||
}
|
||||
|
||||
req.body.updatedAt = new Date();
|
||||
req.body.$inc = {__v: 1};
|
||||
if (req.body.hasOwnProperty('__v')) {
|
||||
delete req.body.__v;
|
||||
}
|
||||
|
||||
// PATCH is easier with mongoose than PUT. You simply update by all data that comes from outside. no need to
|
||||
// reset attributes that are missing.
|
||||
modelClass.findByIdAndUpdate(req.params.id, req.body, {new: true}, (err, item) => {
|
||||
if (err) {
|
||||
err.status = codes.wrongrequest;
|
||||
} else if (!item) {
|
||||
err = new Error('item not found');
|
||||
err.status = codes.notfound;
|
||||
} else {
|
||||
res.locals.items = item;
|
||||
}
|
||||
next(err);
|
||||
});
|
||||
};
|
||||
|
||||
exports.genericGetById = genericGetById;
|
||||
exports.genericPatch = genericPatch;
|
|
@ -16,10 +16,6 @@ const idValidator = require('../middleware/validators').idValidator;
|
|||
const CampaignModel = require('../models/campaign');
|
||||
const WarModel = require('../models/war');
|
||||
|
||||
// util
|
||||
const genericGetById = require('./_generic').genericGetById;
|
||||
const genericPatch = require('./_generic').genericPatch;
|
||||
|
||||
const campaigns = new express.Router();
|
||||
|
||||
// routes **********************
|
||||
|
@ -45,11 +41,49 @@ campaigns.route('/')
|
|||
|
||||
campaigns.route('/:id')
|
||||
.get(idValidator, (req, res, next) => {
|
||||
return genericGetById(req, res, next, CampaignModel);
|
||||
CampaignModel.findById(req.params.id, (err, item) => {
|
||||
if (err) {
|
||||
err.status = codes.servererror;
|
||||
return next(err);
|
||||
} else if (!item) {
|
||||
err = new Error('item not found');
|
||||
err.status = codes.notfound;
|
||||
return next(err);
|
||||
}
|
||||
res.locals.items = item;
|
||||
return next();
|
||||
});
|
||||
})
|
||||
|
||||
.patch(apiAuthenticationMiddleware, checkMT, (req, res, next) => {
|
||||
return genericPatch(req, res, next, CampaignModel);
|
||||
if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
|
||||
// little bit different as in PUT. :id does not need to be in data, but if the _id and url id must match
|
||||
const err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' +
|
||||
req.body._id);
|
||||
err.status = codes.notfound;
|
||||
next(err);
|
||||
return; // prevent node to process this function further after next() has finished.
|
||||
}
|
||||
|
||||
req.body.updatedAt = new Date();
|
||||
req.body.$inc = {__v: 1};
|
||||
if (req.body.hasOwnProperty('__v')) {
|
||||
delete req.body.__v;
|
||||
}
|
||||
|
||||
// PATCH is easier with mongoose than PUT. You simply update by all data that comes from outside. no need to
|
||||
// reset attributes that are missing.
|
||||
CampaignModel.findByIdAndUpdate(req.params.id, req.body, {new: true}, (err, item) => {
|
||||
if (err) {
|
||||
err.status = codes.wrongrequest;
|
||||
} else if (!item) {
|
||||
err = new Error('item not found');
|
||||
err.status = codes.notfound;
|
||||
} else {
|
||||
res.locals.items = item;
|
||||
}
|
||||
next(err);
|
||||
});
|
||||
})
|
||||
|
||||
.delete((req, res, next) => {
|
||||
|
|
|
@ -21,9 +21,6 @@ const resourceLocation = require('../middleware/resource-location').resourceLoca
|
|||
const DecorationModel = require('../models/decoration');
|
||||
const AwardingsModel = require('../models/awarding');
|
||||
|
||||
// util
|
||||
const genericGetById = require('./_generic').genericGetById;
|
||||
|
||||
const decoration = new express.Router();
|
||||
|
||||
// routes **********************
|
||||
|
@ -84,7 +81,18 @@ decoration.route('/')
|
|||
|
||||
decoration.route('/:id')
|
||||
.get(idValidator, (req, res, next) => {
|
||||
return genericGetById(req, res, next, DecorationModel);
|
||||
DecorationModel.findById(req.params.id, (err, item) => {
|
||||
if (err) {
|
||||
err.status = codes.servererror;
|
||||
return next(err);
|
||||
} else if (!item) {
|
||||
err = new Error('item not found');
|
||||
err.status = codes.notfound;
|
||||
return next(err);
|
||||
}
|
||||
res.locals.items = item;
|
||||
next();
|
||||
});
|
||||
})
|
||||
|
||||
.patch(apiAuthenticationMiddleware, checkHl, upload.single('image'), (req, res, next) => {
|
||||
|
|
|
@ -20,9 +20,6 @@ const resourceLocation = require('../middleware/resource-location').resourceLoca
|
|||
// Mongoose Model using mongoDB
|
||||
const RankModel = require('../models/rank');
|
||||
|
||||
// util
|
||||
const genericGetById = require('./_generic').genericGetById;
|
||||
|
||||
const ranks = new express.Router();
|
||||
|
||||
// routes **********************
|
||||
|
@ -76,7 +73,18 @@ ranks.route('/')
|
|||
|
||||
ranks.route('/:id')
|
||||
.get(idValidator, (req, res, next) => {
|
||||
return genericGetById(req, res, next, RankModel);
|
||||
RankModel.findById(req.params.id, (err, item) => {
|
||||
if (err) {
|
||||
err.status = codes.servererror;
|
||||
return next(err);
|
||||
} else if (!item) {
|
||||
err = new Error('item not found');
|
||||
err.status = codes.notfound;
|
||||
return next(err);
|
||||
}
|
||||
res.locals.items = item;
|
||||
next();
|
||||
});
|
||||
})
|
||||
|
||||
.patch(apiAuthenticationMiddleware, checkHl, upload.single('image'), (req, res, next) => {
|
||||
|
|
|
@ -20,9 +20,6 @@ const resourceLocation = require('../middleware/resource-location').resourceLoca
|
|||
// Mongoose Model using mongoDB
|
||||
const SquadModel = require('../models/squad');
|
||||
|
||||
// util
|
||||
const genericGetById = require('./_generic').genericGetById;
|
||||
|
||||
const squads = new express.Router();
|
||||
|
||||
// routes **********************
|
||||
|
@ -80,7 +77,18 @@ squads.route('/')
|
|||
|
||||
squads.route('/:id')
|
||||
.get(idValidator, (req, res, next) => {
|
||||
return genericGetById(req, res, next, SquadModel);
|
||||
SquadModel.findById(req.params.id, (err, item) => {
|
||||
if (err) {
|
||||
err.status = codes.servererror;
|
||||
return next(err);
|
||||
} else if (!item) {
|
||||
err = new Error('item not found');
|
||||
err.status = codes.notfound;
|
||||
return next(err);
|
||||
}
|
||||
res.locals.items = item;
|
||||
next();
|
||||
});
|
||||
})
|
||||
|
||||
.patch(apiAuthenticationMiddleware, checkHl, upload.single('image'), (req, res, next) => {
|
||||
|
|
|
@ -35,9 +35,6 @@ const LogFlagModel = require('../models/logs/flag');
|
|||
const LogBudgetModel = require('../models/logs/budget');
|
||||
const LogPointsModel = require('../models/logs/points');
|
||||
|
||||
// util
|
||||
const genericPatch = require('./_generic').genericPatch;
|
||||
|
||||
const wars = new express.Router();
|
||||
|
||||
// routes **********************
|
||||
|
@ -172,7 +169,34 @@ wars.route('/:id')
|
|||
})
|
||||
|
||||
.patch(apiAuthenticationMiddleware, checkMT, (req, res, next) => {
|
||||
return genericPatch(req, res, next, WarModel);
|
||||
if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
|
||||
// little bit different as in PUT. :id does not need to be in data, but if the _id and url id must match
|
||||
const err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' +
|
||||
req.body._id);
|
||||
err.status = codes.notfound;
|
||||
next(err);
|
||||
return; // prevent node to process this function further after next() has finished.
|
||||
}
|
||||
|
||||
req.body.updatedAt = new Date();
|
||||
req.body.$inc = {__v: 1};
|
||||
if (req.body.hasOwnProperty('__v')) {
|
||||
delete req.body.__v;
|
||||
}
|
||||
|
||||
// PATCH is easier with mongoose than PUT. You simply update by all data that comes from outside. no need to
|
||||
// reset attributes that are missing.
|
||||
WarModel.findByIdAndUpdate(req.params.id, req.body, {new: true}, (err, item) => {
|
||||
if (err) {
|
||||
err.status = codes.wrongrequest;
|
||||
} else if (!item) {
|
||||
err = new Error('item not found');
|
||||
err.status = codes.notfound;
|
||||
} else {
|
||||
res.locals.items = item;
|
||||
}
|
||||
next(err);
|
||||
});
|
||||
})
|
||||
|
||||
.delete(apiAuthenticationMiddleware, checkMT, (req, res, next) => {
|
||||
|
|
|
@ -137,7 +137,48 @@ let addDecorationsAndSave = (userId, loadedImage, res, next) => {
|
|||
return next(err);
|
||||
}
|
||||
if (awardings.length > 0) {
|
||||
awardings.sort((a1, a2) => sortAwardingsForSignature(a1, a2));
|
||||
// TODO: simplify this sorting hell
|
||||
awardings.sort((a1, a2) => {
|
||||
if (!a1.decorationId.isMedal && !a2.decorationId.isMedal) {
|
||||
if (a1.decorationId.fraction === a2.decorationId.fraction) {
|
||||
if (a1.date !== a2.date) {
|
||||
if (a1.date < a2.date) {
|
||||
return -1;
|
||||
}
|
||||
if (a1.date > a2.date) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
if (a1.decorationId.fraction === 'GLOBAL' && a2.decorationId.fraction !== 'GLOBAL') {
|
||||
return -1;
|
||||
}
|
||||
if (a2.decorationId.fraction === 'GLOBAL' && a1.decorationId.fraction !== 'GLOBAL') {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (a1.decorationId.isMedal !== a2.decorationId.isMedal) {
|
||||
if (a1.decorationId.isMedal && !a2.decorationId.isMedal) {
|
||||
return 1;
|
||||
}
|
||||
if (!a1.decorationId.isMedal && a2.decorationId.isMedal) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (a1.decorationId.isMedal && a2.decorationId.isMedal) {
|
||||
if (a1.date !== a2.date) {
|
||||
if (a1.date < a2.date) {
|
||||
return -1;
|
||||
}
|
||||
if (a1.date > a2.date) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
// use synchronized call to keep correct order of decorations
|
||||
async.eachSeries(awardings, (award, callback) => {
|
||||
|
@ -221,47 +262,5 @@ let saveJimpImageAndCompress = (image, userId, res, next) => {
|
|||
}, 3000);
|
||||
};
|
||||
|
||||
const sortAwardingsForSignature = (a1, a2) => {
|
||||
if (!a1.decorationId.isMedal && !a2.decorationId.isMedal) {
|
||||
if (a1.decorationId.fraction === a2.decorationId.fraction) {
|
||||
if (a1.date !== a2.date) {
|
||||
if (a1.date < a2.date) {
|
||||
return -1;
|
||||
}
|
||||
if (a1.date > a2.date) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
if (a1.decorationId.fraction === 'GLOBAL' && a2.decorationId.fraction !== 'GLOBAL') {
|
||||
return -1;
|
||||
}
|
||||
if (a2.decorationId.fraction === 'GLOBAL' && a1.decorationId.fraction !== 'GLOBAL') {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (a1.decorationId.isMedal !== a2.decorationId.isMedal) {
|
||||
if (a1.decorationId.isMedal && !a2.decorationId.isMedal) {
|
||||
return 1;
|
||||
}
|
||||
if (!a1.decorationId.isMedal && a2.decorationId.isMedal) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (a1.decorationId.isMedal && a2.decorationId.isMedal) {
|
||||
if (a1.date !== a2.date) {
|
||||
if (a1.date < a2.date) {
|
||||
return -1;
|
||||
}
|
||||
if (a1.date > a2.date) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
module.exports = createSignature;
|
||||
|
|
|
@ -39,6 +39,7 @@ const timeStringToDecimal = (timeString) => {
|
|||
return hour + (sek / 3600);
|
||||
};
|
||||
|
||||
|
||||
const decimalToTimeString = (decimal) => {
|
||||
const hours = parseInt(decimal.toString().split('.')[0]);
|
||||
const minutesFloat = ((decimal % 1) * 3600) / 60;
|
||||
|
|
|
@ -20,10 +20,10 @@ export class ScoreboardComponent implements OnChanges {
|
|||
@Output() playerTabSwitch = new EventEmitter();
|
||||
|
||||
tableHead = [
|
||||
{prop: 'name', head: 'Spieler'}, {prop: 'fraction', head: 'Fraktion'}, {prop: 'kill', head: 'Abschüsse'},
|
||||
{prop: 'friendlyFire', head: 'Friendly Fire'}, {prop: 'vehicleLight', head: 'Fahrzeug (leicht)'},
|
||||
{prop: 'name', head: 'Spieler'}, {prop: 'fraction', head: 'Fraktion'}, {prop: 'kill', head: 'Kills'},
|
||||
{prop: 'friendlyFire', head: 'FriendlyFire'}, {prop: 'vehicleLight', head: 'Fahrzeug (leicht)'},
|
||||
{prop: 'vehicleHeavy', head: 'Fahrzeug (schwer)'}, {prop: 'vehicleAir', head: 'Fahrzeug (Luft)'},
|
||||
{prop: 'revive', head: 'Revive'}, {prop: 'flagTouch', head: 'Eroberungen'}, {prop: 'death', head: 'Tode'},
|
||||
{prop: 'revive', head: 'Revive'}, {prop: 'flagTouch', head: 'Flagge'}, {prop: 'death', head: 'Tod'},
|
||||
{prop: 'respawn', head: 'Respawn'}
|
||||
];
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 659 B |
Binary file not shown.
Before Width: | Height: | Size: 3.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.7 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.6 KiB |
Binary file not shown.
Before Width: | Height: | Size: 678 B |
Binary file not shown.
Before Width: | Height: | Size: 3.6 KiB |
Loading…
Reference in New Issue