This commit is contained in:
Paolo Arena
2021-01-18 00:48:17 +01:00
parent 142380e54b
commit 5493953b58
22 changed files with 9749 additions and 231 deletions

21
src/server/models/cart.js Normal file → Executable file
View File

@@ -1,6 +1,9 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const shared_consts = require('../tools/shared_nodejs');
const Order = require('../models/order');
const CartSchema = new Schema({
@@ -16,6 +19,9 @@ const CartSchema = new Schema({
{ type: Schema.Types.ObjectId, ref: 'Order' }
}
],
note: {
type: String
},
modify_at: {
type: Date
},
@@ -89,7 +95,16 @@ module.exports.updateCartByCartId = async function (cartId, newCart) {
const totalQty = newCart.totalQty;
const totalPrice = newCart.totalPrice;
return await Cart.findOneAndUpdate({ _id: cartId }, { $set: { items, totalPrice, totalQty } }, { new: false })
const modify_at = new Date();
return await Cart.findOneAndUpdate({ _id: cartId }, {
$set: {
items,
totalPrice,
totalQty,
modify_at
}
}, { new: false })
.then((ris) => {
return ris;
}).catch(err => {
@@ -99,6 +114,10 @@ module.exports.updateCartByCartId = async function (cartId, newCart) {
}
module.exports.deleteCartByCartId = async function (cartId) {
return await Cart.remove({ _id: cartId });
}
module.exports.createCart = async function (newCart) {
return await newCart.save()