Ordini
This commit is contained in:
21
src/server/models/cart.js
Normal file → Executable file
21
src/server/models/cart.js
Normal file → Executable 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()
|
||||
|
||||
Reference in New Issue
Block a user