Struttura Scheda Prodotti...

This commit is contained in:
Surya Paolo
2023-11-30 14:27:37 +01:00
parent e895e7dae2
commit e3ed2934ee
6 changed files with 181 additions and 117 deletions

View File

@@ -38,6 +38,7 @@ module.exports.findAllIdApp = async function(idapp, userId) {
}; };
module.exports.getCartByUserId = async function (uid, idapp) { module.exports.getCartByUserId = async function (uid, idapp) {
try {
let query = { userId: uid, idapp }; let query = { userId: uid, idapp };
const mycart = await Cart.findOne(query).lean(); const mycart = await Cart.findOne(query).lean();
@@ -60,6 +61,9 @@ module.exports.getCartByUserId = async function(uid, idapp) {
return mycart; return mycart;
} }
return null; return null;
} catch (e) {
console.log('getCartByUserId err', e);
}
}; };

View File

@@ -51,6 +51,9 @@ const orderSchema = new Schema({
weight: { weight: {
type: Number type: Number
}, },
unit: {
type: Number
},
stars: { stars: {
type: Number type: Number
}, },

View File

@@ -61,6 +61,9 @@ const productSchema = new Schema({
weight: { weight: {
type: Number type: Number
}, },
unit: {
type: Number
},
quantityAvailable: { quantityAvailable: {
type: Number type: Number
}, },

View File

@@ -30,17 +30,20 @@ const Cart = require('../models/cart');
const OrdersCart = require('../models/orderscart'); const OrdersCart = require('../models/orderscart');
//GET cart //GET cart
router.get('/:userId', authenticate, function (req, res, next) { router.get('/:userId', authenticate, async function (req, res, next) {
let userId = req.body.userId let userId = req.params.userId
let idapp = req.body.idapp let idapp = req.user.idapp
Cart.getCartByUserId(userId, idapp, function (err, cart) { return await Cart.getCartByUserId(userId, idapp)
if (err) return next(err) .then((cart) => {
if (cart) if (cart)
res.send({ code: server_constants.RIS_CODE_OK, cart }); return res.send({ code: server_constants.RIS_CODE_OK, cart });
else else
res.status(400).send(e); return res.status(400).send(e);
}) }).catch((err) => {
console.error('Err', err);
return res.send({ code: server_constants.RIS_CODE_ERR, cart: null });
});
}) })
//POST cart //POST cart
@@ -51,6 +54,8 @@ router.post('/:userId', authenticate, async function (req, res, next) {
let subqty = req.body.subqty; let subqty = req.body.subqty;
let order = req.body.order; let order = req.body.order;
try {
const mycart = await Cart.getCartByUserId(userId, idapp); const mycart = await Cart.getCartByUserId(userId, idapp);
// const myorder = Order.getOrderByID(order._id); // const myorder = Order.getOrderByID(order._id);
@@ -91,6 +96,12 @@ router.post('/:userId', authenticate, async function (req, res, next) {
}) })
*/ */
} catch (e) {
return res.send({ code: server_constants.RIS_CODE_ERR, cart: 0 });
}
}) })
router.delete('/:userId', authenticate, async function (req, res) { router.delete('/:userId', authenticate, async function (req, res) {
@@ -122,14 +133,17 @@ router.delete('/:userId', authenticate, async function (req, res) {
//PUT cart //PUT cart
router.put('/:userId', authenticate, function (req, res, next) { router.put('/:userId', authenticate, async function (req, res, next) {
let userId = req.params.userId let userId = req.params.userId
let requestProduct = req.body let requestProduct = req.body
let { productId, color, size } = requestProduct.product let { productId, color, size } = requestProduct.product
Cart.getCartByUserId(userId, function (err, c) { try {
await Cart.getCartByUserId(userId, function (err, c) {
if (err) return next(err) if (err) return next(err)
let oldCart = new CartClass(c[0] || {}) let oldCart = new CartClass(c[0] || {})
Product.getProductByID(productId, function (err, p) { Product.getProductByID(productId, function (err, p) {
if (err) return next(err) if (err) return next(err)
let newCart = oldCart.add(p, productId, { color, size }) let newCart = oldCart.add(p, productId, { color, size })
@@ -163,6 +177,12 @@ router.put('/:userId', authenticate, function (req, res, next) {
} }
}) })
}) })
return res.send({ code: server_constants.RIS_CODE_OK });
} catch (e) {
return res.send({ code: server_constants.RIS_CODE_ERR, status: 0 });
}
}) })
//POST cart //POST cart

View File

@@ -1573,6 +1573,8 @@ function load(req, res, version) {
myelems: arrdata[38], myelems: arrdata[38],
categories: arrdata[39], categories: arrdata[39],
}); });
const prova = 1;
} }
}).catch((e) => { }).catch((e) => {

View File

@@ -326,6 +326,38 @@ module.exports = {
OPZ1_2: 2, OPZ1_2: 2,
}, },
UNITS_OF_MEASURE: {
NESSUNO: 0,
GRAMMI: 1,
CHILI: 2,
LITRI: 3,
PEZZI: 4,
},
Units_Of_Measure_ListBox: [
{
label: '[Nessuno]',
value: 0,
},
{
label: 'Grammi (g)',
value: 1,
},
{
label: 'Chili (kg)',
value: 2,
},
{
label: 'Litri (l)',
value: 3,
},
{
label: 'Pezzi (p)',
value: 4,
},
],
CallFunz: { CallFunz: {
SOSTITUISCI: 345, SOSTITUISCI: 345,
AGGIUNGI_NUOVO_IMBARCO: 380, AGGIUNGI_NUOVO_IMBARCO: 380,