Add endpoint for unprocessed awarding by squad
parent
1bf7d17615
commit
43a3f219b3
|
@ -3,6 +3,8 @@
|
|||
// modules
|
||||
const express = require('express');
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
// HTTP status codes by name
|
||||
const codes = require('./http-codes');
|
||||
|
||||
|
@ -10,9 +12,11 @@ const routerHandling = require('../middleware/router-handling');
|
|||
|
||||
const apiAuthenticationMiddleware = require('../middleware/auth-middleware');
|
||||
const checkHl = require('../middleware/permission-check').checkHl;
|
||||
const checkSql = require('../middleware/permission-check').checkSql;
|
||||
|
||||
// Mongoose Model using mongoDB
|
||||
const AwardingModel = require('../models/awarding');
|
||||
const UserModel = require('../models/user');
|
||||
|
||||
// result set for proposer(appUser) population
|
||||
const resultSet = {
|
||||
|
@ -77,8 +81,23 @@ awarding.route('/')
|
|||
|
||||
.all(routerHandling.httpMethodNotAllowed);
|
||||
|
||||
awarding.route('/:id')
|
||||
awarding.route('/unprocessed/:squadId')
|
||||
.get(apiAuthenticationMiddleware, checkSql, (req, res, next) => {
|
||||
console.log(req.params.squadId)
|
||||
const filter = {squadId: req.params.squadId};
|
||||
UserModel.find(filter, (err, users) => {
|
||||
if (!users || users.length === 0) {
|
||||
return next();
|
||||
}
|
||||
const squadUserIds = users.map(user => mongoose.Types.ObjectId(user._id));
|
||||
AwardingModel.find({userId: {$in: squadUserIds}, confirmed: 0}, (err, awards) => {
|
||||
res.locals.items = awards;
|
||||
next();
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
awarding.route('/:id')
|
||||
.patch(apiAuthenticationMiddleware, checkHl, (req, res, next) => {
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue