101 lines
2.2 KiB
JavaScript
101 lines
2.2 KiB
JavaScript
import mongoose from "mongoose";
|
|
import AutoIncrement from "mongoose-sequence";
|
|
|
|
const connection = mongoose.connection;
|
|
|
|
const OrderSchema = new mongoose.Schema({
|
|
orderId: { type: Number, unique: true },
|
|
|
|
vendorId: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
ref: "Vendor",
|
|
required: true,
|
|
},
|
|
storeId: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
ref: "Store",
|
|
required: true,
|
|
},
|
|
|
|
pgpAddress: { type: String, required: true },
|
|
orderDate: { type: Date, default: Date.now, },
|
|
txid: { type: Array, default: [] },
|
|
|
|
products: [
|
|
{
|
|
productId: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
ref: "Product",
|
|
required: true,
|
|
},
|
|
quantity: { type: Number, required: true, min: 0.1 },
|
|
pricePerUnit: { type: Number, required: true, min: 0.01 },
|
|
totalItemPrice: { type: Number, required: true, min: 0.01 },
|
|
},
|
|
],
|
|
|
|
shippingMethod: { type: Object },
|
|
|
|
totalPrice: { type: Number, required: true, min: 0.01 },
|
|
|
|
// Promotion fields
|
|
promotion: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
ref: "Promotion",
|
|
default: null
|
|
},
|
|
promotionCode: {
|
|
type: String,
|
|
default: null
|
|
},
|
|
discountAmount: {
|
|
type: Number,
|
|
default: 0,
|
|
min: 0
|
|
},
|
|
subtotalBeforeDiscount: {
|
|
type: Number,
|
|
default: 0,
|
|
min: 0
|
|
},
|
|
|
|
status: {
|
|
type: String,
|
|
enum: [
|
|
"unpaid",
|
|
"cancelled",
|
|
"confirming",
|
|
"paid",
|
|
"shipped",
|
|
"disputed",
|
|
"completed",
|
|
"acknowledged"
|
|
],
|
|
default: "unpaid",
|
|
},
|
|
|
|
paymentAddress: { type: String, required: true },
|
|
|
|
wallet: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
ref: "Wallet",
|
|
},
|
|
|
|
cryptoTotal: { type: Number, required: true, default: 0 },
|
|
//txid: { type: String, default: null },
|
|
|
|
telegramChatId: { type: String, default: null },
|
|
telegramBuyerId: { type: String, default: null },
|
|
telegramUsername: { type: String, default: null },
|
|
trackingNumber: { type: String, default: null },
|
|
|
|
escrowExpiresAt: {
|
|
type: Date,
|
|
required: true,
|
|
default: () => new Date(Date.now() + 8 * 24 * 60 * 60 * 1000),
|
|
},
|
|
});
|
|
|
|
OrderSchema.plugin(AutoIncrement(connection), { inc_field: "orderId" });
|
|
export default mongoose.model("Order", OrderSchema);
|