- DashBoard, Profile, Order Menu

This commit is contained in:
Paolo Arena
2019-12-31 00:44:53 +01:00
parent c39a14bb9e
commit 892eccb4fc
12 changed files with 150 additions and 22 deletions

View File

@@ -0,0 +1,52 @@
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 { User } = require('../models/user');
const mongoose = require('mongoose');
const Subscription = mongoose.model('subscribers');
const _ = require('lodash');
const { ObjectID } = require('mongodb');
router.post('/', authenticate, async (req, res) => {
const idapp = req.body.idapp;
try {
const aportador_solidario = req.user.aportador_solidario;
// DATA: username, name, surname, email, intcode_cell, cell
const dashboard = {
aportador: {},
downline: []
};
// Data of my Aportador
dashboard.aportador = await User.getUserShortDataByUsername(idapp, aportador_solidario);
// Data of my Downline
dashboard.downline = await User.getDownlineByUsername(idapp, req.user.username);
for (let index = 0; index < dashboard.downline.length; ++index) {
dashboard.downline[index].downline = await User.getDownlineByUsername(idapp, dashboard.downline[index].username);
}
// Extract all the todos of the userId only
// tools.mylog('dashboard', dashboard);
res.send({ dashboard });
} catch (e) {
console.error(e);
res.status(400).send(e);
}
});
module.exports = router;

View File

@@ -244,7 +244,7 @@ router.patch('/chval', authenticate, (req, res) => {
const mytable = getTableByTableName(mydata.table);
const fieldsvalue = mydata.fieldsvalue;
tools.mylogshow('PATCH CHVAL: ', id, fieldsvalue);
// tools.mylogshow('PATCH CHVAL: ', id, fieldsvalue);
// If I change my record...
if ((!User.isAdmin(req.user) && !User.isManager(req.user)) && !(req.user._id.toString() === id)) {
@@ -253,7 +253,7 @@ router.patch('/chval', authenticate, (req, res) => {
}
mytable.findByIdAndUpdate(id, { $set: fieldsvalue }).then((rec) => {
tools.mylogshow(' REC TO MODIFY: ', rec);
// tools.mylogshow(' REC TO MODIFY: ', rec);
if (!rec) {
return res.status(404).send();
} else {

View File

@@ -33,7 +33,7 @@ function existSubScribe(userId, access, browser) {
// POST /users
router.post('/', async (req, res) => {
tools.mylog("POST /users");
const body = _.pick(req.body, ['email', 'password', 'username', 'name', 'surname', 'idapp', 'keyappid', 'lang', 'profile']);
const body = _.pick(req.body, ['email', 'password', 'username', 'name', 'surname', 'idapp', 'keyappid', 'lang', 'profile', 'aportador_solidario']);
const user = new User(body);
// tools.mylog("LANG PASSATO = " + user.lang, "IDAPP", user.idapp);
@@ -77,7 +77,7 @@ router.post('/', async (req, res) => {
User.findByUsername(user.idapp, user.username)
.then((usertrovato) => {
tools.mylog("TROVATO USERNAME ? ", user.username, usertrovato);
// tools.mylog("TROVATO USERNAME ? ", user.username, usertrovato);
if (usertrovato !== null) {
return user.generateAuthToken(req);
} else {