Project e Todos sistemati...
aggiunti Gruppi
This commit is contained in:
@@ -56,7 +56,9 @@ const Producer = require('../models/producer');
|
||||
const Cart = require('../models/cart');
|
||||
const OrdersCart = require('../models/orderscart');
|
||||
const Storehouse = require('../models/storehouse');
|
||||
const Department = require('../models/department');
|
||||
const ShareWithUs = require('../models/sharewithus');
|
||||
const Group = require('../models/group');
|
||||
const Order = require('../models/order');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
@@ -202,14 +204,20 @@ function getTableByTableName(tablename) {
|
||||
mytable = Product;
|
||||
else if (tablename === 'storehouses')
|
||||
mytable = Storehouse;
|
||||
else if (tablename === 'departments')
|
||||
mytable = Department;
|
||||
else if (tablename === 'sharewithus')
|
||||
mytable = ShareWithUs;
|
||||
else if (tablename === 'groups')
|
||||
mytable = Group;
|
||||
else if (tablename === 'orders')
|
||||
mytable = Order;
|
||||
else if (tablename === 'producers')
|
||||
mytable = Producer;
|
||||
else if (tablename === 'carts')
|
||||
mytable = Cart;
|
||||
else if (tablename === 'orderscart')
|
||||
mytable = OrdersCart;
|
||||
else if (tablename === 'sendmsgs')
|
||||
mytable = SendMsg;
|
||||
else if (tablename === 'wheres')
|
||||
@@ -1111,7 +1119,9 @@ router.get('/loadsite/:userId/:idapp/:sall', authenticate_noerror, (req, res) =>
|
||||
let calzoom = CalZoom.findAllIdApp(idapp);
|
||||
let gallery = Gallery.findAllIdApp(idapp);
|
||||
let producers = Producer.findAllIdApp(idapp);
|
||||
let groups = Group.findAllIdApp(idapp);
|
||||
let storehouses = Storehouse.findAllIdApp(idapp);
|
||||
let departments = Department.findAllIdApp(idapp);
|
||||
let cart = null;
|
||||
let orderscart = null;
|
||||
if (sall) {
|
||||
@@ -1126,7 +1136,7 @@ router.get('/loadsite/:userId/:idapp/:sall', authenticate_noerror, (req, res) =>
|
||||
}
|
||||
|
||||
|
||||
return Promise.all([bookedevent, eventlist, operators, wheres, contribtype, settings, permissions, disciplines, newstosent, mailinglist, mypage, gallery, paymenttype, calcstat, calzoom, producers, cart, storehouses, orderscart])
|
||||
return Promise.all([bookedevent, eventlist, operators, wheres, contribtype, settings, permissions, disciplines, newstosent, mailinglist, mypage, gallery, paymenttype, calcstat, calzoom, producers, cart, storehouses, departments, orderscart, groups])
|
||||
.then((arrdata) => {
|
||||
// console.table(arrdata);
|
||||
const myuser = req.user;
|
||||
@@ -1153,7 +1163,9 @@ router.get('/loadsite/:userId/:idapp/:sall', authenticate_noerror, (req, res) =>
|
||||
producers: arrdata[15],
|
||||
cart: arrdata[16],
|
||||
storehouses: arrdata[17],
|
||||
orders: arrdata[18],
|
||||
departments: arrdata[18],
|
||||
orders: arrdata[19],
|
||||
groups: arrdata[20],
|
||||
myuser,
|
||||
});
|
||||
})
|
||||
|
||||
43
src/server/router/orders_router.js
Executable file
43
src/server/router/orders_router.js
Executable file
@@ -0,0 +1,43 @@
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
var server_constants = require('../tools/server_constants');
|
||||
|
||||
var { Project } = require('../models/project');
|
||||
|
||||
var { authenticate, auth_default } = require('../middleware/authenticate');
|
||||
|
||||
var mongoose = require('mongoose');
|
||||
const Subscription = mongoose.model('subscribers');
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
const Product = require('../models/product');
|
||||
const Order = require('../models/order');
|
||||
const Variant = require('../models/variant');
|
||||
|
||||
const CartClass = require('../modules/Cart')
|
||||
const Cart = require('../models/cart');
|
||||
const OrdersCart = require('../models/orderscart');
|
||||
|
||||
//GET orders
|
||||
router.get('/:userId', authenticate, function (req, res, next) {
|
||||
let userId = req.body.userId
|
||||
let idapp = req.body.idapp
|
||||
OrdersCart.getOrdersCartByUserId(userId, idapp, function (err, cart) {
|
||||
if (err) return next(err)
|
||||
|
||||
if (cart)
|
||||
res.send({ code: server_constants.RIS_CODE_OK, cart });
|
||||
else
|
||||
res.status(400).send(e);
|
||||
})
|
||||
})
|
||||
|
||||
module.exports = router;
|
||||
@@ -47,6 +47,9 @@ router.post('/', authenticate, (req, res) => {
|
||||
.then(record => {
|
||||
// tools.mylog('REC SAVED :', record.descr);
|
||||
|
||||
res.send({ record });
|
||||
|
||||
/*
|
||||
tools.sendNotificationToUser(project.userId, 'Project: ' + record.descr, record.descr, '/project/' + project.category, '', 'project', [])
|
||||
.then(ris => {
|
||||
if (ris) {
|
||||
@@ -55,6 +58,8 @@ router.post('/', authenticate, (req, res) => {
|
||||
// already sent the error on calling sendNotificationToUser
|
||||
}
|
||||
})
|
||||
|
||||
*/
|
||||
})
|
||||
}).catch((e) => {
|
||||
console.log('ERRORE in PROJECT POST', e.message);
|
||||
@@ -119,8 +124,9 @@ router.patch('/:id', authenticate, (req, res) => {
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
tools.mylog('GET ALL PROJECTS: ');
|
||||
const idapp = req.query.idapp;
|
||||
|
||||
return Project.getAllProjects('').then((objprojects) => {
|
||||
return Project.getAllProjects('', idapp).then((objprojects) => {
|
||||
if (!!objprojects.arrproj)
|
||||
tools.mylog('projects', objprojects.arrproj.length);
|
||||
|
||||
@@ -135,6 +141,7 @@ router.get('/', (req, res) => {
|
||||
|
||||
router.get('/:userId', authenticate, (req, res) => {
|
||||
const userId = req.params.userId;
|
||||
const idapp = req.query.idapp;
|
||||
|
||||
tools.mylog('GET PROJECTS : ', req.params);
|
||||
|
||||
@@ -148,7 +155,7 @@ router.get('/:userId', authenticate, (req, res) => {
|
||||
}
|
||||
|
||||
// Extract all the projects of the userId only
|
||||
return Project.getAllProjects(userId).then((objprojects) => {
|
||||
return Project.getAllProjects(userId, idapp).then((objprojects) => {
|
||||
if (!!objprojects.arrproj)
|
||||
tools.mylog('projects', objprojects.arrproj.length);
|
||||
|
||||
@@ -202,21 +209,36 @@ async function calcSingleProject(userId, myproj) {
|
||||
router.delete('/:id', authenticate, (req, res) => {
|
||||
var id = req.params.id;
|
||||
|
||||
let hide = true;
|
||||
|
||||
if (!ObjectID.isValid(id)) {
|
||||
return res.status(404).send();
|
||||
}
|
||||
|
||||
Project.findByIdAndRemove(id).then((project) => {
|
||||
if (!project) {
|
||||
return res.status(404).send();
|
||||
}
|
||||
if (hide) {
|
||||
Project.findByIdAndUpdate(id, { $set: { deleted: true } }).then((project) => {
|
||||
if (!project) {
|
||||
return res.status(404).send();
|
||||
}
|
||||
res.send({ project });
|
||||
}).catch((e) => {
|
||||
res.status(400).send();
|
||||
});
|
||||
|
||||
tools.mylog('DELETED ', project.descr, project._id);
|
||||
} else {
|
||||
|
||||
res.send({ project });
|
||||
}).catch((e) => {
|
||||
res.status(400).send();
|
||||
});
|
||||
Project.findByIdAndRemove(id).then((project) => {
|
||||
if (!project) {
|
||||
return res.status(404).send();
|
||||
}
|
||||
|
||||
tools.mylog('DELETED ', project.descr, project._id);
|
||||
|
||||
res.send({ project });
|
||||
}).catch((e) => {
|
||||
res.status(400).send();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ router.get('/', (req, res) => {
|
||||
descr: "Primo Task Esempio",
|
||||
enableExpiring: false,
|
||||
expiring_at: new Date(),
|
||||
id_prev: null,
|
||||
modified: false,
|
||||
modify_at: new Date(),
|
||||
pos: 1,
|
||||
|
||||
@@ -152,7 +152,6 @@ router.get('/test', (req, res) => {
|
||||
descr: "Primo Task Esempio",
|
||||
enableExpiring: false,
|
||||
expiring_at: new Date(),
|
||||
id_prev: null,
|
||||
modified: false,
|
||||
modify_at: new Date(),
|
||||
pos: 1,
|
||||
@@ -193,22 +192,38 @@ router.get('/', (req, res) => {
|
||||
|
||||
router.delete('/:id', authenticate, (req, res) => {
|
||||
var id = req.params.id;
|
||||
// var hide = req.params.hide;
|
||||
|
||||
let hide = true;
|
||||
|
||||
if (!ObjectID.isValid(id)) {
|
||||
return res.status(404).send();
|
||||
}
|
||||
|
||||
Todo.findByIdAndRemove(id).then((todo) => {
|
||||
if (!todo) {
|
||||
return res.status(404).send();
|
||||
}
|
||||
if (hide) {
|
||||
Todo.findByIdAndUpdate(id, { $set: { deleted: true } }).then((todo) => {
|
||||
if (!todo) {
|
||||
return res.status(404).send();
|
||||
}
|
||||
res.send({ todo });
|
||||
}).catch((e) => {
|
||||
res.status(400).send();
|
||||
});
|
||||
|
||||
// tools.mylog('DELETED ', todo.descr, todo._id);
|
||||
} else {
|
||||
Todo.findByIdAndRemove(id).then((todo) => {
|
||||
if (!todo) {
|
||||
return res.status(404).send();
|
||||
}
|
||||
|
||||
// tools.mylog('DELETED ', todo.descr, todo._id);
|
||||
|
||||
res.send({ todo });
|
||||
}).catch((e) => {
|
||||
res.status(400).send();
|
||||
});
|
||||
}
|
||||
|
||||
res.send({ todo });
|
||||
}).catch((e) => {
|
||||
res.status(400).send();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user