Apply code convention for passing linting
parent
e7df8a0c94
commit
140ba2f254
|
@ -26,9 +26,10 @@ const logger = require('debug')('middleware:filterware');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* private helper function to filter Objects by given keys
|
* private helper function to filter Objects by given keys
|
||||||
* @param keys {Array} the keys from GET parameter filter
|
*
|
||||||
* @param schema [Object} containing the keys as attributes that are allowed
|
* @param {Array} keys - the keys from GET parameter filter
|
||||||
* @returns {Object or Error} either the filtered items or an Error object
|
* @param {Object} schema - containing the keys as attributes that are allowed
|
||||||
|
* @return {Object} either the filtered items or an Error object
|
||||||
*/
|
*/
|
||||||
const limitFilterToSchema = (keys, schema) => {
|
const limitFilterToSchema = (keys, schema) => {
|
||||||
if (!keys || !schema) { // empty arrays evaluate to false
|
if (!keys || !schema) { // empty arrays evaluate to false
|
||||||
|
@ -57,7 +58,7 @@ const limitFilterToSchema = (keys, schema) => {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const createFilterRouter = (schema, supressID) => {
|
const createFilterRouter = (schema, supressID) => {
|
||||||
const router = express.Router();
|
const router = new express.Router();
|
||||||
// the exported router with handler
|
// the exported router with handler
|
||||||
router.use((req, res, next) => {
|
router.use((req, res, next) => {
|
||||||
const filterString = req.query.filter;
|
const filterString = req.query.filter;
|
||||||
|
|
|
@ -19,7 +19,8 @@
|
||||||
// 3.) exports (which is module.exports)
|
// 3.) exports (which is module.exports)
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const router = require('express').Router();
|
const express = require('express');
|
||||||
|
const router = new express.Router();
|
||||||
const logger = require('debug')('middleware:offsetlimit');
|
const logger = require('debug')('middleware:offsetlimit');
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
// 3.) exports (which is module.exports)
|
// 3.) exports (which is module.exports)
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const router = require('express').Router();
|
const express = require('express');
|
||||||
|
const router = new express.Router();
|
||||||
|
|
||||||
// API-Version control. We use HTTP Header field Accept-Version instead of URL-part /v1/
|
// API-Version control. We use HTTP Header field Accept-Version instead of URL-part /v1/
|
||||||
router.use((req, res, next) => {
|
router.use((req, res, next) => {
|
||||||
|
|
|
@ -5,6 +5,11 @@ const codes = require('../routes/http-codes');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if id has valid UUID format
|
* check if id has valid UUID format
|
||||||
|
*
|
||||||
|
* @param {object} req
|
||||||
|
* @param {function} res
|
||||||
|
* @param {function} next
|
||||||
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
const idValidator = (req, res, next) => {
|
const idValidator = (req, res, next) => {
|
||||||
const reqId = req.params.id;
|
const reqId = req.params.id;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
// modules
|
// modules
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const logger = require('debug')('cc:awardings');
|
|
||||||
|
|
||||||
// HTTP status codes by name
|
// HTTP status codes by name
|
||||||
const codes = require('./http-codes');
|
const codes = require('./http-codes');
|
||||||
|
@ -12,7 +11,7 @@ const routerHandling = require('../middleware/router-handling');
|
||||||
// Mongoose Model using mongoDB
|
// Mongoose Model using mongoDB
|
||||||
const AppUserModel = require('../models/app-user');
|
const AppUserModel = require('../models/app-user');
|
||||||
|
|
||||||
const account = express.Router();
|
const account = new express.Router();
|
||||||
|
|
||||||
account.route('/')
|
account.route('/')
|
||||||
.get((req, res, next) => {
|
.get((req, res, next) => {
|
||||||
|
@ -35,7 +34,8 @@ account.route('/:id')
|
||||||
.patch((req, res, next) => {
|
.patch((req, res, next) => {
|
||||||
if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
|
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
|
// 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);
|
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;
|
err.status = codes.notfound;
|
||||||
next(err);
|
next(err);
|
||||||
return; // prevent node to process this function further after next() has finished.
|
return; // prevent node to process this function further after next() has finished.
|
||||||
|
|
|
@ -6,7 +6,6 @@ const jwt = require('jsonwebtoken');
|
||||||
const bcrypt = require('bcryptjs');
|
const bcrypt = require('bcryptjs');
|
||||||
const Q = require('q');
|
const Q = require('q');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const logger = require('debug')('cc:authenticate');
|
|
||||||
|
|
||||||
// HTTP status codes by name
|
// HTTP status codes by name
|
||||||
const codes = require('./http-codes');
|
const codes = require('./http-codes');
|
||||||
|
@ -17,7 +16,7 @@ const routerHandling = require('../middleware/router-handling');
|
||||||
|
|
||||||
const AppUserModel = require('../models/app-user');
|
const AppUserModel = require('../models/app-user');
|
||||||
|
|
||||||
const authenticate = express.Router();
|
const authenticate = new express.Router();
|
||||||
|
|
||||||
// routes **********************
|
// routes **********************
|
||||||
authenticate.route('/')
|
authenticate.route('/')
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
// modules
|
// modules
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const logger = require('debug')('cc:awardings');
|
|
||||||
|
|
||||||
// HTTP status codes by name
|
// HTTP status codes by name
|
||||||
const codes = require('./http-codes');
|
const codes = require('./http-codes');
|
||||||
|
@ -20,7 +19,7 @@ const resultSet = {
|
||||||
'__v': 0, 'updatedAt': 0, 'timestamp': 0, 'password': 0, 'permission': 0, 'secret': 0, 'activated': 0,
|
'__v': 0, 'updatedAt': 0, 'timestamp': 0, 'password': 0, 'permission': 0, 'secret': 0, 'activated': 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
const awarding = express.Router();
|
const awarding = new express.Router();
|
||||||
|
|
||||||
|
|
||||||
// routes **********************
|
// routes **********************
|
||||||
|
@ -100,7 +99,8 @@ awarding.route('/:id')
|
||||||
.patch(apiAuthenticationMiddleware, checkHl, (req, res, next) => {
|
.patch(apiAuthenticationMiddleware, checkHl, (req, res, next) => {
|
||||||
if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
|
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
|
// 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);
|
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;
|
err.status = codes.notfound;
|
||||||
next(err);
|
next(err);
|
||||||
return; // prevent node to process this function further after next() has finished.
|
return; // prevent node to process this function further after next() has finished.
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
// modules
|
// modules
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const logger = require('debug')('cc:campaigns');
|
|
||||||
|
|
||||||
// HTTP status codes by name
|
// HTTP status codes by name
|
||||||
const codes = require('./http-codes');
|
const codes = require('./http-codes');
|
||||||
|
@ -18,7 +17,7 @@ const CampaignModel = require('../models/campaign');
|
||||||
const WarModel = require('../models/war');
|
const WarModel = require('../models/war');
|
||||||
|
|
||||||
|
|
||||||
const campaigns = express.Router();
|
const campaigns = new express.Router();
|
||||||
|
|
||||||
// routes **********************
|
// routes **********************
|
||||||
campaigns.route('/')
|
campaigns.route('/')
|
||||||
|
|
|
@ -2,16 +2,12 @@
|
||||||
|
|
||||||
// modules
|
// modules
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const logger = require('debug')('cc:command');
|
|
||||||
|
|
||||||
// HTTP status codes by name
|
|
||||||
const codes = require('./http-codes');
|
|
||||||
|
|
||||||
const routerHandling = require('../middleware/router-handling');
|
const routerHandling = require('../middleware/router-handling');
|
||||||
const createAllSignatures = require('../cron-job/cron').createAllSignatures;
|
const createAllSignatures = require('../cron-job/cron').createAllSignatures;
|
||||||
const createSignature = require('../tools/signature-tool');
|
const createSignature = require('../tools/signature-tool');
|
||||||
|
|
||||||
const command = express.Router();
|
const command = new express.Router();
|
||||||
|
|
||||||
command.route('/createSignature')
|
command.route('/createSignature')
|
||||||
.post((req, res, next) => {
|
.post((req, res, next) => {
|
||||||
|
|
|
@ -6,7 +6,6 @@ const express = require('express');
|
||||||
const multer = require('multer');
|
const multer = require('multer');
|
||||||
const storage = multer.memoryStorage();
|
const storage = multer.memoryStorage();
|
||||||
const upload = multer({storage: storage});
|
const upload = multer({storage: storage});
|
||||||
const logger = require('debug')('cc:decorations');
|
|
||||||
|
|
||||||
// HTTP status codes by name
|
// HTTP status codes by name
|
||||||
const codes = require('./http-codes');
|
const codes = require('./http-codes');
|
||||||
|
@ -21,8 +20,7 @@ const idValidator = require('../middleware/validators').idValidator;
|
||||||
const DecorationModel = require('../models/decoration');
|
const DecorationModel = require('../models/decoration');
|
||||||
const AwardingsModel = require('../models/awarding');
|
const AwardingsModel = require('../models/awarding');
|
||||||
|
|
||||||
const decoration = express.Router();
|
const decoration = new express.Router();
|
||||||
|
|
||||||
|
|
||||||
// routes **********************
|
// routes **********************
|
||||||
decoration.route('/')
|
decoration.route('/')
|
||||||
|
@ -99,7 +97,8 @@ decoration.route('/:id')
|
||||||
.patch(apiAuthenticationMiddleware, checkHl, upload.single('image'), (req, res, next) => {
|
.patch(apiAuthenticationMiddleware, checkHl, upload.single('image'), (req, res, next) => {
|
||||||
if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
|
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
|
// 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);
|
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;
|
err.status = codes.notfound;
|
||||||
next(err);
|
next(err);
|
||||||
return; // prevent node to process this function further after next() has finished.
|
return; // prevent node to process this function further after next() has finished.
|
||||||
|
|
|
@ -3,10 +3,8 @@
|
||||||
// modules
|
// modules
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const logger = require('debug')('cc:logs');
|
|
||||||
|
|
||||||
const routerHandling = require('../middleware/router-handling');
|
const routerHandling = require('../middleware/router-handling');
|
||||||
const decimalToTimeString = require('../tools/util').decimalToTimeString;
|
|
||||||
|
|
||||||
// Mongoose Model using mongoDB
|
// Mongoose Model using mongoDB
|
||||||
const LogBudgetModel = require('../models/logs/budget');
|
const LogBudgetModel = require('../models/logs/budget');
|
||||||
|
@ -18,9 +16,9 @@ const LogTransportModel = require('../models/logs/transport');
|
||||||
const LogFlagModel = require('../models/logs/flag');
|
const LogFlagModel = require('../models/logs/flag');
|
||||||
const LogPointsModel = require('../models/logs/points');
|
const LogPointsModel = require('../models/logs/points');
|
||||||
|
|
||||||
const logsRouter = express.Router();
|
const logsRouter = new express.Router();
|
||||||
|
|
||||||
function processLogRequest(model, filter, res, next) {
|
const processLogRequest = (model, filter, res, next) => {
|
||||||
model.find(filter, {}, {sort: {time: 1}}, (err, log) => {
|
model.find(filter, {}, {sort: {time: 1}}, (err, log) => {
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
if (!log || log.length === 0) {
|
if (!log || log.length === 0) {
|
||||||
|
@ -31,7 +29,7 @@ function processLogRequest(model, filter, res, next) {
|
||||||
res.locals.items = log;
|
res.locals.items = log;
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
// routes **********************
|
// routes **********************
|
||||||
logsRouter.route('/:warId')
|
logsRouter.route('/:warId')
|
||||||
|
@ -58,7 +56,7 @@ logsRouter.route('/:warId')
|
||||||
flag: flagObjects.exec.bind(flagObjects),
|
flag: flagObjects.exec.bind(flagObjects),
|
||||||
};
|
};
|
||||||
|
|
||||||
async.parallel(resources, function(error, results) {
|
async.parallel(resources, (error, results) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
res.status(500).send(error);
|
res.status(500).send(error);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -3,10 +3,8 @@
|
||||||
// modules
|
// modules
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const logger = require('debug')('cc:overview');
|
|
||||||
|
|
||||||
// HTTP status codes by name
|
// HTTP status codes by name
|
||||||
const codes = require('./http-codes');
|
|
||||||
const routerHandling = require('../middleware/router-handling');
|
const routerHandling = require('../middleware/router-handling');
|
||||||
|
|
||||||
// Mongoose Model using mongoDB
|
// Mongoose Model using mongoDB
|
||||||
|
@ -14,7 +12,7 @@ const UserModel = require('../models/user');
|
||||||
const SquadModel = require('../models/squad');
|
const SquadModel = require('../models/squad');
|
||||||
const RankModel = require('../models/rank');
|
const RankModel = require('../models/rank');
|
||||||
|
|
||||||
const overview = express.Router();
|
const overview = new express.Router();
|
||||||
|
|
||||||
// routes **********************
|
// routes **********************
|
||||||
overview.route('/')
|
overview.route('/')
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
// modules
|
// modules
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const logger = require('debug')('cc:players');
|
|
||||||
|
|
||||||
// HTTP status codes by name
|
// HTTP status codes by name
|
||||||
const codes = require('./http-codes');
|
const codes = require('./http-codes');
|
||||||
|
@ -17,7 +16,7 @@ const WarModel = require('../models/war');
|
||||||
// Util
|
// Util
|
||||||
const isSteamUUID = require('../tools/util').isSteamUUID;
|
const isSteamUUID = require('../tools/util').isSteamUUID;
|
||||||
|
|
||||||
const campaignPlayer = express.Router();
|
const campaignPlayer = new express.Router();
|
||||||
|
|
||||||
// routes **********************
|
// routes **********************
|
||||||
campaignPlayer.route('/ranking/:campaignId')
|
campaignPlayer.route('/ranking/:campaignId')
|
||||||
|
@ -67,7 +66,7 @@ campaignPlayer.route('/ranking/:campaignId')
|
||||||
rankingItems.push(resItem);
|
rankingItems.push(resItem);
|
||||||
});
|
});
|
||||||
|
|
||||||
function getSortedField(fieldName) {
|
const getSortedField = (fieldName) => {
|
||||||
let num = 1;
|
let num = 1;
|
||||||
rankingItems.sort((a, b) => b[fieldName] - a[fieldName]);
|
rankingItems.sort((a, b) => b[fieldName] - a[fieldName]);
|
||||||
const res = JSON.parse(JSON.stringify(rankingItems));
|
const res = JSON.parse(JSON.stringify(rankingItems));
|
||||||
|
@ -75,7 +74,7 @@ campaignPlayer.route('/ranking/:campaignId')
|
||||||
entity.num = num++;
|
entity.num = num++;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
};
|
||||||
|
|
||||||
res.locals.items = {
|
res.locals.items = {
|
||||||
kill: getSortedField('kill'),
|
kill: getSortedField('kill'),
|
||||||
|
|
|
@ -6,7 +6,6 @@ const express = require('express');
|
||||||
const multer = require('multer');
|
const multer = require('multer');
|
||||||
const storage = multer.memoryStorage();
|
const storage = multer.memoryStorage();
|
||||||
const upload = multer({storage: storage});
|
const upload = multer({storage: storage});
|
||||||
const logger = require('debug')('cc:ranks');
|
|
||||||
|
|
||||||
// HTTP status codes by name
|
// HTTP status codes by name
|
||||||
const codes = require('./http-codes');
|
const codes = require('./http-codes');
|
||||||
|
@ -20,7 +19,7 @@ const idValidator = require('../middleware/validators').idValidator;
|
||||||
// Mongoose Model using mongoDB
|
// Mongoose Model using mongoDB
|
||||||
const RankModel = require('../models/rank');
|
const RankModel = require('../models/rank');
|
||||||
|
|
||||||
const ranks = express.Router();
|
const ranks = new express.Router();
|
||||||
|
|
||||||
// routes **********************
|
// routes **********************
|
||||||
ranks.route('/')
|
ranks.route('/')
|
||||||
|
@ -91,7 +90,8 @@ ranks.route('/:id')
|
||||||
.patch(apiAuthenticationMiddleware, checkHl, upload.single('image'), (req, res, next) => {
|
.patch(apiAuthenticationMiddleware, checkHl, upload.single('image'), (req, res, next) => {
|
||||||
if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
|
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
|
// 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);
|
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;
|
err.status = codes.notfound;
|
||||||
next(err);
|
next(err);
|
||||||
return; // prevent node to process this function further after next() has finished.
|
return; // prevent node to process this function further after next() has finished.
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
// modules
|
// modules
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const logger = require('debug')('cc:awardings');
|
|
||||||
|
|
||||||
// HTTP status codes by name
|
// HTTP status codes by name
|
||||||
const codes = require('./http-codes');
|
const codes = require('./http-codes');
|
||||||
|
@ -29,7 +28,7 @@ const resultSet = {
|
||||||
'activated': 0,
|
'activated': 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
const request = express.Router();
|
const request = new express.Router();
|
||||||
|
|
||||||
|
|
||||||
// routes **********************
|
// routes **********************
|
||||||
|
@ -131,7 +130,8 @@ request.route('/promotion/:id')
|
||||||
.patch(apiAuthenticationMiddleware, checkHl, (req, res, next) => {
|
.patch(apiAuthenticationMiddleware, checkHl, (req, res, next) => {
|
||||||
if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
|
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
|
// 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);
|
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;
|
err.status = codes.notfound;
|
||||||
next(err);
|
next(err);
|
||||||
return; // prevent node to process this function further after next() has finished.
|
return; // prevent node to process this function further after next() has finished.
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
// modules
|
// modules
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const logger = require('debug')('cc:signatures');
|
|
||||||
|
|
||||||
// HTTP status codes by name
|
// HTTP status codes by name
|
||||||
const codes = require('./http-codes');
|
const codes = require('./http-codes');
|
||||||
|
@ -12,7 +11,7 @@ const routerHandling = require('../middleware/router-handling');
|
||||||
|
|
||||||
const UserModel = require('../models/user');
|
const UserModel = require('../models/user');
|
||||||
|
|
||||||
const signatures = express.Router();
|
const signatures = new express.Router();
|
||||||
|
|
||||||
// routes **********************
|
// routes **********************
|
||||||
signatures.route('/:id')
|
signatures.route('/:id')
|
||||||
|
|
|
@ -6,7 +6,6 @@ const express = require('express');
|
||||||
const multer = require('multer');
|
const multer = require('multer');
|
||||||
const storage = multer.memoryStorage();
|
const storage = multer.memoryStorage();
|
||||||
const upload = multer({storage: storage});
|
const upload = multer({storage: storage});
|
||||||
const logger = require('debug')('cc:squads');
|
|
||||||
|
|
||||||
// HTTP status codes by name
|
// HTTP status codes by name
|
||||||
const codes = require('./http-codes');
|
const codes = require('./http-codes');
|
||||||
|
@ -20,7 +19,7 @@ const idValidator = require('../middleware/validators').idValidator;
|
||||||
// Mongoose Model using mongoDB
|
// Mongoose Model using mongoDB
|
||||||
const SquadModel = require('../models/squad');
|
const SquadModel = require('../models/squad');
|
||||||
|
|
||||||
const squads = express.Router();
|
const squads = new express.Router();
|
||||||
|
|
||||||
// routes **********************
|
// routes **********************
|
||||||
squads.route('/')
|
squads.route('/')
|
||||||
|
@ -94,7 +93,8 @@ squads.route('/:id')
|
||||||
.patch(apiAuthenticationMiddleware, checkHl, upload.single('image'), (req, res, next) => {
|
.patch(apiAuthenticationMiddleware, checkHl, upload.single('image'), (req, res, next) => {
|
||||||
if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
|
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
|
// 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);
|
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;
|
err.status = codes.notfound;
|
||||||
next(err);
|
next(err);
|
||||||
return; // prevent node to process this function further after next() has finished.
|
return; // prevent node to process this function further after next() has finished.
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
// modules
|
// modules
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const logger = require('debug')('me2u5:users');
|
|
||||||
|
|
||||||
// HTTP status codes by name
|
// HTTP status codes by name
|
||||||
const codes = require('./http-codes');
|
const codes = require('./http-codes');
|
||||||
|
@ -21,7 +20,7 @@ const UserModel = require('../models/user');
|
||||||
const SquadModel = require('../models/squad');
|
const SquadModel = require('../models/squad');
|
||||||
const AwardingModel = require('../models/awarding');
|
const AwardingModel = require('../models/awarding');
|
||||||
|
|
||||||
const users = express.Router();
|
const users = new express.Router();
|
||||||
|
|
||||||
users.get('/', filterHandlerCreator(UserModel.schema.paths));
|
users.get('/', filterHandlerCreator(UserModel.schema.paths));
|
||||||
users.get('/', offsetlimitMiddleware);
|
users.get('/', offsetlimitMiddleware);
|
||||||
|
@ -107,7 +106,8 @@ users.route('/:id')
|
||||||
.patch(apiAuthenticationMiddleware, checkHl, (req, res, next) => {
|
.patch(apiAuthenticationMiddleware, checkHl, (req, res, next) => {
|
||||||
if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
|
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
|
// 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);
|
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;
|
err.status = codes.notfound;
|
||||||
next(err);
|
next(err);
|
||||||
return; // prevent node to process this function further after next() has finished.
|
return; // prevent node to process this function further after next() has finished.
|
||||||
|
@ -147,14 +147,15 @@ users.route('/:id')
|
||||||
// first check that the given element id is the same as the URL id
|
// first check that the given element id is the same as the URL id
|
||||||
if (!req.body || req.body._id !== req.params.id) {
|
if (!req.body || req.body._id !== req.params.id) {
|
||||||
// the URL does not fit the given element
|
// the URL does not fit the given element
|
||||||
let err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' + req.body._id);
|
let err =
|
||||||
|
new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' + req.body._id);
|
||||||
err.status = codes.notfound;
|
err.status = codes.notfound;
|
||||||
next(err);
|
next(err);
|
||||||
return; // prevent node to process this function further after next() has finished.
|
return; // prevent node to process this function further after next() has finished.
|
||||||
}
|
}
|
||||||
// main difference of PUT and PATCH is that PUT expects all data in request: checked by using the schema
|
// main difference of PUT and PATCH is that PUT expects all data in request: checked by using the schema
|
||||||
const user = new UserModel(req.body);
|
const user = new UserModel(req.body);
|
||||||
UserModel.findById(req.params.id, req.body, {new: true}, function(err, item) {
|
UserModel.findById(req.params.id, req.body, {new: true}, (err, item) => {
|
||||||
// with parameter {new: true} the TweetNModel will return the new and changed object from the DB and not the
|
// with parameter {new: true} the TweetNModel will return the new and changed object from the DB and not the
|
||||||
// old one.
|
// old one.
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -164,9 +165,8 @@ users.route('/:id')
|
||||||
err = new Error('item not found');
|
err = new Error('item not found');
|
||||||
err.status = codes.notfound;
|
err.status = codes.notfound;
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
} else if (user.__v !== item.__v) {
|
||||||
// check that version is still accurate
|
// checked that version is still accurate
|
||||||
else if (user.__v !== item.__v) {
|
|
||||||
err = new Error('version outdated. Meanwhile update on item happened. Please GET resource again');
|
err = new Error('version outdated. Meanwhile update on item happened. Please GET resource again');
|
||||||
err.status = codes.conflict;
|
err.status = codes.conflict;
|
||||||
return next(err);
|
return next(err);
|
||||||
|
@ -182,7 +182,7 @@ users.route('/:id')
|
||||||
// update updatedAt and increase version
|
// update updatedAt and increase version
|
||||||
item.updatedAt = new Date();
|
item.updatedAt = new Date();
|
||||||
item.increment(); // this sets __v++
|
item.increment(); // this sets __v++
|
||||||
item.save(function(err) {
|
item.save((err) => {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
res.locals.items = item;
|
res.locals.items = item;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -7,7 +7,6 @@ const express = require('express');
|
||||||
const multer = require('multer');
|
const multer = require('multer');
|
||||||
const storage = multer.memoryStorage();
|
const storage = multer.memoryStorage();
|
||||||
const upload = multer({storage: storage});
|
const upload = multer({storage: storage});
|
||||||
const logger = require('debug')('cc:wars');
|
|
||||||
|
|
||||||
// HTTP status codes by name
|
// HTTP status codes by name
|
||||||
const codes = require('./http-codes');
|
const codes = require('./http-codes');
|
||||||
|
@ -35,7 +34,7 @@ const LogFlagModel = require('../models/logs/flag');
|
||||||
const LogBudgetModel = require('../models/logs/budget');
|
const LogBudgetModel = require('../models/logs/budget');
|
||||||
const LogPointsModel = require('../models/logs/points');
|
const LogPointsModel = require('../models/logs/points');
|
||||||
|
|
||||||
const wars = express.Router();
|
const wars = new express.Router();
|
||||||
|
|
||||||
// routes **********************
|
// routes **********************
|
||||||
wars.route('/')
|
wars.route('/')
|
||||||
|
@ -88,20 +87,20 @@ wars.route('/')
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
PlayerModel.create(statsResult.players, function(err) {
|
PlayerModel.create(statsResult.players, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
LogKillModel.create(statsResult.kills, function() {
|
LogKillModel.create(statsResult.kills, () => {
|
||||||
LogVehicleKillModel.create(statsResult.vehicles, function() {
|
LogVehicleKillModel.create(statsResult.vehicles, () => {
|
||||||
LogRespawnModel.create(statsResult.respawn, function() {
|
LogRespawnModel.create(statsResult.respawn, () => {
|
||||||
LogReviveModel.create(statsResult.revive, function() {
|
LogReviveModel.create(statsResult.revive, () => {
|
||||||
LogFlagModel.create(statsResult.flag, function() {
|
LogFlagModel.create(statsResult.flag, () => {
|
||||||
LogBudgetModel.create(statsResult.budget, function() {
|
LogBudgetModel.create(statsResult.budget, () => {
|
||||||
LogTransportModel.create(statsResult.transport, function() {
|
LogTransportModel.create(statsResult.transport, () => {
|
||||||
LogPointsModel.create(statsResult.points, function() {
|
LogPointsModel.create(statsResult.points, () => {
|
||||||
const folderName = __dirname + '/../resource/logs/' + war._id;
|
const folderName = __dirname + '/../resource/logs/' + war._id;
|
||||||
mkdirp(folderName, function(err) {
|
mkdirp(folderName, (err) => {
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
|
|
||||||
// save clean log file
|
// save clean log file
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
let mongoose = require('mongoose');
|
|
||||||
let AwardingModel = require('../models/awarding');
|
let AwardingModel = require('../models/awarding');
|
||||||
let urls = require('../config/api-url');
|
let urls = require('../config/api-url');
|
||||||
let codes = require('../routes/http-codes');
|
let codes = require('../routes/http-codes');
|
||||||
|
@ -8,7 +7,6 @@ let codes = require('../routes/http-codes');
|
||||||
let chai = require('chai');
|
let chai = require('chai');
|
||||||
let chaiHttp = require('chai-http');
|
let chaiHttp = require('chai-http');
|
||||||
let server = require('../server');
|
let server = require('../server');
|
||||||
let should = chai.should();
|
|
||||||
|
|
||||||
chai.use(chaiHttp);
|
chai.use(chaiHttp);
|
||||||
// Our parent block
|
// Our parent block
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
let mongoose = require('mongoose');
|
|
||||||
let AwardingModel = require('../models/awarding');
|
let AwardingModel = require('../models/awarding');
|
||||||
let urls = require('../config/api-url');
|
let urls = require('../config/api-url');
|
||||||
let codes = require('../routes/http-codes');
|
let codes = require('../routes/http-codes');
|
||||||
|
@ -8,7 +7,6 @@ let codes = require('../routes/http-codes');
|
||||||
let chai = require('chai');
|
let chai = require('chai');
|
||||||
let chaiHttp = require('chai-http');
|
let chaiHttp = require('chai-http');
|
||||||
let server = require('../server');
|
let server = require('../server');
|
||||||
let should = chai.should();
|
|
||||||
|
|
||||||
chai.use(chaiHttp);
|
chai.use(chaiHttp);
|
||||||
// Our parent block
|
// Our parent block
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
let mongoose = require('mongoose');
|
|
||||||
let DecorationModel = require('../models/decoration');
|
let DecorationModel = require('../models/decoration');
|
||||||
let urls = require('../config/api-url');
|
let urls = require('../config/api-url');
|
||||||
let codes = require('../routes/http-codes');
|
let codes = require('../routes/http-codes');
|
||||||
|
@ -8,7 +7,6 @@ let codes = require('../routes/http-codes');
|
||||||
let chai = require('chai');
|
let chai = require('chai');
|
||||||
let chaiHttp = require('chai-http');
|
let chaiHttp = require('chai-http');
|
||||||
let server = require('../server');
|
let server = require('../server');
|
||||||
let should = chai.should();
|
|
||||||
|
|
||||||
chai.use(chaiHttp);
|
chai.use(chaiHttp);
|
||||||
// Our parent block
|
// Our parent block
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
let mongoose = require('mongoose');
|
|
||||||
let RankModel = require('../models/rank');
|
let RankModel = require('../models/rank');
|
||||||
let urls = require('../config/api-url');
|
let urls = require('../config/api-url');
|
||||||
let codes = require('../routes/http-codes');
|
let codes = require('../routes/http-codes');
|
||||||
|
@ -8,7 +7,6 @@ let codes = require('../routes/http-codes');
|
||||||
let chai = require('chai');
|
let chai = require('chai');
|
||||||
let chaiHttp = require('chai-http');
|
let chaiHttp = require('chai-http');
|
||||||
let server = require('../server');
|
let server = require('../server');
|
||||||
let should = chai.should();
|
|
||||||
|
|
||||||
chai.use(chaiHttp);
|
chai.use(chaiHttp);
|
||||||
// Our parent block
|
// Our parent block
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
let mongoose = require('mongoose');
|
|
||||||
let SquadModel = require('../models/squad');
|
let SquadModel = require('../models/squad');
|
||||||
let urls = require('../config/api-url');
|
let urls = require('../config/api-url');
|
||||||
let codes = require('../routes/http-codes');
|
let codes = require('../routes/http-codes');
|
||||||
|
@ -8,7 +7,6 @@ let codes = require('../routes/http-codes');
|
||||||
let chai = require('chai');
|
let chai = require('chai');
|
||||||
let chaiHttp = require('chai-http');
|
let chaiHttp = require('chai-http');
|
||||||
let server = require('../server');
|
let server = require('../server');
|
||||||
let should = chai.should();
|
|
||||||
|
|
||||||
chai.use(chaiHttp);
|
chai.use(chaiHttp);
|
||||||
// Our parent block
|
// Our parent block
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
let mongoose = require('mongoose');
|
|
||||||
let UserModel = require('../models/user');
|
let UserModel = require('../models/user');
|
||||||
let AppUserModel = require('../models/app-user');
|
|
||||||
let urls = require('../config/api-url');
|
let urls = require('../config/api-url');
|
||||||
let codes = require('../routes/http-codes');
|
let codes = require('../routes/http-codes');
|
||||||
|
|
||||||
|
@ -9,7 +7,6 @@ let codes = require('../routes/http-codes');
|
||||||
let chai = require('chai');
|
let chai = require('chai');
|
||||||
let chaiHttp = require('chai-http');
|
let chaiHttp = require('chai-http');
|
||||||
let server = require('../server');
|
let server = require('../server');
|
||||||
let should = chai.should();
|
|
||||||
|
|
||||||
chai.use(chaiHttp);
|
chai.use(chaiHttp);
|
||||||
// Our parent block
|
// Our parent block
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
let mongoose = require('mongoose');
|
|
||||||
let AwardingModel = require('../models/awarding');
|
|
||||||
let urls = require('../config/api-url');
|
let urls = require('../config/api-url');
|
||||||
let codes = require('../routes/http-codes');
|
let codes = require('../routes/http-codes');
|
||||||
|
|
||||||
|
@ -8,7 +6,6 @@ let codes = require('../routes/http-codes');
|
||||||
let chai = require('chai');
|
let chai = require('chai');
|
||||||
let chaiHttp = require('chai-http');
|
let chaiHttp = require('chai-http');
|
||||||
let server = require('../server');
|
let server = require('../server');
|
||||||
let should = chai.should();
|
|
||||||
|
|
||||||
chai.use(chaiHttp);
|
chai.use(chaiHttp);
|
||||||
// Our parent block
|
// Our parent block
|
||||||
|
|
|
@ -48,10 +48,10 @@ const parseWarLog = (lineArray, war) => {
|
||||||
line = line.substring(line.indexOf(NAME_TOO_LONG_ERROR) + NAME_TOO_LONG_ERROR.length);
|
line = line.substring(line.indexOf(NAME_TOO_LONG_ERROR) + NAME_TOO_LONG_ERROR.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* KILLS & VEHICLE KILLS
|
|
||||||
*/
|
|
||||||
if (line.includes('(Abschuss)')) {
|
if (line.includes('(Abschuss)')) {
|
||||||
|
/**
|
||||||
|
* KILLS & VEHICLE KILLS
|
||||||
|
*/
|
||||||
stats.clean.push(line);
|
stats.clean.push(line);
|
||||||
|
|
||||||
const shooterString = line.substring(line.lastIndexOf(' von: ') + 6, line.lastIndexOf('."'));
|
const shooterString = line.substring(line.lastIndexOf(' von: ') + 6, line.lastIndexOf('."'));
|
||||||
|
@ -81,12 +81,10 @@ const parseWarLog = (lineArray, war) => {
|
||||||
fraction: shooter ? shooter.fraction : 'NONE',
|
fraction: shooter ? shooter.fraction : 'NONE',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
} else if (line.includes('(Budget)')) {
|
||||||
|
/**
|
||||||
/**
|
* BUDGET
|
||||||
* BUDGET
|
*/
|
||||||
*/
|
|
||||||
else if (line.includes('(Budget)')) {
|
|
||||||
stats.clean.push(line);
|
stats.clean.push(line);
|
||||||
const budg = line.split(WHITESPACE);
|
const budg = line.split(WHITESPACE);
|
||||||
if (line.includes('Startbudget')) {
|
if (line.includes('Startbudget')) {
|
||||||
|
@ -103,12 +101,10 @@ const parseWarLog = (lineArray, war) => {
|
||||||
} else {
|
} else {
|
||||||
stats.budget.push(getBudgetEntry(budg, war._id, war.date));
|
stats.budget.push(getBudgetEntry(budg, war._id, war.date));
|
||||||
}
|
}
|
||||||
}
|
} else if (line.includes('(Fahne)') && !line.includes('Dominator')) {
|
||||||
|
/**
|
||||||
/**
|
* FLAG
|
||||||
* FLAG
|
*/
|
||||||
*/
|
|
||||||
else if (line.includes('(Fahne)') && !line.includes('Dominator')) {
|
|
||||||
stats.clean.push(line);
|
stats.clean.push(line);
|
||||||
const playerName = line.substring(line.lastIndexOf('rt von ') + 7).slice(0, -2);
|
const playerName = line.substring(line.lastIndexOf('rt von ') + 7).slice(0, -2);
|
||||||
const flagFraction = line.includes('NATO Flagge') ? 'BLUFOR' : 'OPFOR';
|
const flagFraction = line.includes('NATO Flagge') ? 'BLUFOR' : 'OPFOR';
|
||||||
|
@ -121,12 +117,10 @@ const parseWarLog = (lineArray, war) => {
|
||||||
flagFraction: flagFraction,
|
flagFraction: flagFraction,
|
||||||
capture: capture,
|
capture: capture,
|
||||||
});
|
});
|
||||||
}
|
} else if (line.includes('(Punkte)')) {
|
||||||
|
/**
|
||||||
/**
|
* POINTS
|
||||||
* POINTS
|
*/
|
||||||
*/
|
|
||||||
else if (line.includes('(Punkte)')) {
|
|
||||||
stats.clean.push(line);
|
stats.clean.push(line);
|
||||||
const pt = line.split(WHITESPACE);
|
const pt = line.split(WHITESPACE);
|
||||||
|
|
||||||
|
@ -138,21 +132,17 @@ const parseWarLog = (lineArray, war) => {
|
||||||
} else {
|
} else {
|
||||||
stats.points.push(getPointsEntry(pt, line, war._id, war.date));
|
stats.points.push(getPointsEntry(pt, line, war._id, war.date));
|
||||||
}
|
}
|
||||||
}
|
} else if (line.includes('(Respawn)')) {
|
||||||
|
/**
|
||||||
/**
|
* RESPAWN
|
||||||
* RESPAWN
|
*/
|
||||||
*/
|
|
||||||
else if (line.includes('(Respawn)')) {
|
|
||||||
const resp = line.split(WHITESPACE);
|
const resp = line.split(WHITESPACE);
|
||||||
const playerName = line.substring(line.lastIndexOf('Spieler:') + 9, line.lastIndexOf('- Kosten') - 1);
|
const playerName = line.substring(line.lastIndexOf('Spieler:') + 9, line.lastIndexOf('- Kosten') - 1);
|
||||||
stats.respawn.push(getRespawnEntry(resp, playerName, war._id, war.date));
|
stats.respawn.push(getRespawnEntry(resp, playerName, war._id, war.date));
|
||||||
}
|
} else if (line.includes('(Revive)')) {
|
||||||
|
/**
|
||||||
/**
|
* REVIVE
|
||||||
* REVIVE
|
*/
|
||||||
*/
|
|
||||||
else if (line.includes('(Revive)')) {
|
|
||||||
stats.clean.push(line);
|
stats.clean.push(line);
|
||||||
const stabilized = !!line.includes('stabilisiert."');
|
const stabilized = !!line.includes('stabilisiert."');
|
||||||
const medicName = line.substring(line.lastIndexOf('wurde von ') + 10,
|
const medicName = line.substring(line.lastIndexOf('wurde von ') + 10,
|
||||||
|
@ -169,12 +159,10 @@ const parseWarLog = (lineArray, war) => {
|
||||||
patient: patient.name,
|
patient: patient.name,
|
||||||
fraction: medic.fraction,
|
fraction: medic.fraction,
|
||||||
});
|
});
|
||||||
}
|
} else if (line.includes('(Transport)')) {
|
||||||
|
/**
|
||||||
/**
|
* TRANSPORT
|
||||||
* TRANSPORT
|
*/
|
||||||
*/
|
|
||||||
else if (line.includes('(Transport)')) {
|
|
||||||
stats.clean.push(line);
|
stats.clean.push(line);
|
||||||
const driverString = line.substring(line.lastIndexOf('wurde von ') + 10, line.lastIndexOf(' eingeflogen'));
|
const driverString = line.substring(line.lastIndexOf('wurde von ') + 10, line.lastIndexOf(' eingeflogen'));
|
||||||
const driver = getPlayerAndFractionFromString(driverString);
|
const driver = getPlayerAndFractionFromString(driverString);
|
||||||
|
@ -190,12 +178,10 @@ const parseWarLog = (lineArray, war) => {
|
||||||
fraction: driver ? driver.fraction : 'NONE',
|
fraction: driver ? driver.fraction : 'NONE',
|
||||||
distance: distance,
|
distance: distance,
|
||||||
});
|
});
|
||||||
}
|
} else if (line.includes('(Fraktionsuebersicht)')) {
|
||||||
|
/**
|
||||||
/**
|
* PLAYERS
|
||||||
* PLAYERS
|
*/
|
||||||
*/
|
|
||||||
else if (line.includes('(Fraktionsuebersicht)')) {
|
|
||||||
const playerString = line.substring(line.lastIndexOf('--- ') + 4, line.lastIndexOf(', PUID'));
|
const playerString = line.substring(line.lastIndexOf('--- ') + 4, line.lastIndexOf(', PUID'));
|
||||||
const playerUUID = line.substring(line.lastIndexOf('PUID ') + 5, line.lastIndexOf('"'));
|
const playerUUID = line.substring(line.lastIndexOf('PUID ') + 5, line.lastIndexOf('"'));
|
||||||
addPlayerIfNotExists(playerString, playerUUID);
|
addPlayerIfNotExists(playerString, playerUUID);
|
||||||
|
@ -253,7 +239,10 @@ const getBudgetEntry = (budg, warId, warDate) => {
|
||||||
|
|
||||||
const getPlayerAndFractionFromString = (nameAndFractionString) => {
|
const getPlayerAndFractionFromString = (nameAndFractionString) => {
|
||||||
const nameArray = nameAndFractionString.split(WHITESPACE);
|
const nameArray = nameAndFractionString.split(WHITESPACE);
|
||||||
const fraction = nameArray[nameArray.length - 1] !== '(ENEMY)' ? nameArray[nameArray.length - 1] === '(WEST)' ? 'BLUFOR' : 'OPFOR' : undefined;
|
const fraction = nameArray[nameArray.length - 1] !== '(ENEMY)' ?
|
||||||
|
nameArray[nameArray.length - 1] === '(WEST)' ?
|
||||||
|
'BLUFOR' : 'OPFOR' :
|
||||||
|
undefined;
|
||||||
const name = nameAndFractionString.substring(0, nameAndFractionString.indexOf(nameArray[nameArray.length - 1]) - 1);
|
const name = nameAndFractionString.substring(0, nameAndFractionString.indexOf(nameArray[nameArray.length - 1]) - 1);
|
||||||
// do not return player for 'Selbstverschulden' or 'Error: No unit'
|
// do not return player for 'Selbstverschulden' or 'Error: No unit'
|
||||||
if (name && name !== 'Error: No unit') {
|
if (name && name !== 'Error: No unit') {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
const jimp = require('jimp');
|
const jimp = require('jimp');
|
||||||
const imagemin = require('imagemin');
|
const imagemin = require('imagemin');
|
||||||
const imageminpngquant = require('imagemin-pngquant');
|
const imageminpngquant = require('imagemin-pngquant');
|
||||||
const SHA1 = require('node-sha1');
|
const sha1 = require('node-sha1');
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
|
|
||||||
// Mongoose Model using mongoDB
|
// Mongoose Model using mongoDB
|
||||||
|
@ -63,7 +63,10 @@ let createSignature = (userId, res, next) => {
|
||||||
return font;
|
return font;
|
||||||
})
|
})
|
||||||
.then((font) => {
|
.then((font) => {
|
||||||
let rankH, rankW, rankX, rankY;
|
let rankH;
|
||||||
|
let rankW;
|
||||||
|
let rankX;
|
||||||
|
let rankY;
|
||||||
|
|
||||||
RankModel.findOne({'level': user.rankLvl, 'fraction': user.squadId.fraction}, (err, result) => {
|
RankModel.findOne({'level': user.rankLvl, 'fraction': user.squadId.fraction}, (err, result) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -110,10 +113,10 @@ let createSignature = (userId, res, next) => {
|
||||||
* query decorations according to user id and
|
* query decorations according to user id and
|
||||||
* add all graphics into given image
|
* add all graphics into given image
|
||||||
*
|
*
|
||||||
* @param userId
|
* @param {number} userId
|
||||||
* @param loadedImage - background image
|
* @param {Object} loadedImage - background image
|
||||||
* @param res
|
* @param {function} res
|
||||||
* @param next
|
* @param {function} next
|
||||||
*/
|
*/
|
||||||
let addDecorationsAndSave = (userId, loadedImage, res, next) => {
|
let addDecorationsAndSave = (userId, loadedImage, res, next) => {
|
||||||
const medalW = 21;
|
const medalW = 21;
|
||||||
|
@ -220,8 +223,8 @@ let compareImagesAndSave = (generatedImage, userId, res, next) => {
|
||||||
return jimp.read(resourceDir + 'signature/big/' + userId + fileExt)
|
return jimp.read(resourceDir + 'signature/big/' + userId + fileExt)
|
||||||
.then((oldImage) => {
|
.then((oldImage) => {
|
||||||
// compare hashes of image map to recognize difference
|
// compare hashes of image map to recognize difference
|
||||||
const sig1 = SHA1(generatedImage.bitmap.data);
|
const sig1 = sha1(generatedImage.bitmap.data);
|
||||||
const sig2 = SHA1(oldImage.bitmap.data);
|
const sig2 = sha1(oldImage.bitmap.data);
|
||||||
if (sig1 !== sig2) {
|
if (sig1 !== sig2) {
|
||||||
saveJimpImageAndCompress(generatedImage, userId, res, next);
|
saveJimpImageAndCompress(generatedImage, userId, res, next);
|
||||||
} else {
|
} else {
|
||||||
|
@ -235,14 +238,13 @@ let compareImagesAndSave = (generatedImage, userId, res, next) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Write Jimp image to file system
|
* Write Jimp image to file system
|
||||||
* Gets minified after 3 seconds timeout
|
* Gets minified after 3 seconds timeout
|
||||||
*
|
*
|
||||||
* @param image - Jimp image
|
* @param {Object} image - Jimp image
|
||||||
* @param userId - user id of signature owner
|
* @param {number} userId - user id of signature owner
|
||||||
* @param res - express response object
|
* @param {function} res - express response object
|
||||||
* @param next - express next-function
|
* @param {function} next - express next-function
|
||||||
*/
|
*/
|
||||||
let saveJimpImageAndCompress = (image, userId, res, next) => {
|
let saveJimpImageAndCompress = (image, userId, res, next) => {
|
||||||
image.write(resourceDir + 'signature/big/' + userId + fileExt);
|
image.write(resourceDir + 'signature/big/' + userId + fileExt);
|
||||||
|
|
Loading…
Reference in New Issue