Circuit go on...
This commit is contained in:
76
src/server/router/circuits_router.js
Executable file
76
src/server/router/circuits_router.js
Executable file
@@ -0,0 +1,76 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const server_constants = require('../tools/server_constants');
|
||||
|
||||
const {authenticate} = require('../middleware/authenticate');
|
||||
|
||||
const mongoose = require('mongoose').set('debug', false);
|
||||
|
||||
const {User} = require('../models/user');
|
||||
const {Circuit} = require('../models/circuit');
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
|
||||
async function getCircuitRecAdminsInfo(idapp, data) {
|
||||
|
||||
if (data && data.admins) {
|
||||
for (const admin of data.admins) {
|
||||
const myuser = await User.findOne({idapp, username: admin.username}, {'profile.img': 1}).lean();
|
||||
admin.profile = {img: myuser.profile.img};
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
router.post('/load', authenticate, async (req, res) => {
|
||||
const idapp = req.body.idapp;
|
||||
const path = req.body.path;
|
||||
const circuitId = req.body.circuitId;
|
||||
const usernameOrig = req.user.username;
|
||||
|
||||
try {
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
|
||||
// Check if ìs a Notif to read
|
||||
const idnotif = req.body['idnotif'] ? req.body['idnotif'] : '';
|
||||
SendNotif.setNotifAsRead(idapp, usernameOrig, idnotif);
|
||||
|
||||
const whatshow = Circuit.getWhatToShow(idapp, req.user.username);
|
||||
let data = await Circuit.findOne({idapp, path}, whatshow).lean();
|
||||
|
||||
let cities = [];
|
||||
let users_in_circuit = [];
|
||||
if (data && data.circuitId) {
|
||||
users_in_circuit = await User.find(
|
||||
{
|
||||
idapp,
|
||||
circuitId: data.circuitId,
|
||||
},
|
||||
whatshowUsers,
|
||||
).lean();
|
||||
|
||||
}
|
||||
|
||||
data = await getCircuitRecAdminsInfo(idapp, data);
|
||||
|
||||
const whatshowUsers = await User.getWhatToShow_IfFriends(idapp, req.user.username);
|
||||
|
||||
res.send({circuit: data, users_in_circuit});
|
||||
|
||||
} catch (e) {
|
||||
console.error('Error in Circuits', e);
|
||||
return res.status(400).send(e);
|
||||
}
|
||||
|
||||
const ris = null;
|
||||
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user