const mongoose = require("mongoose");
const paymentStatues = {
0: "Normal",
1: "Internal Collection",
2: "External Collection",
3: "Legal Collection",
}
const requestSchema = mongoose.Schema({
customer: {
type: mongoose.Schema.Types.ObjectId,
ref: "Customer",
},
product: {
type: mongoose.Schema.Types.ObjectId,
ref: "Product",
},
profit: {
type: Number
},
downPayment: {
type: Number,
default: 0
},
planOfInstallment: {
type: Number
},
moneyRequiredToPay: { // This will be the whole money which i need from the customer exclude the downpayment and add the profit
type: Number,
default: 0,
},
paymentschedule: [
{
monthName: String,
dateToPay: {
type: Date,
},
paid: {
type: Boolean,
default: false
},
payment: {
type: Number
},
paymentRecieveDate: {
type: Date,
},
}
],
contractInitiated: {
type:Boolean,
default: false
},
contractStatus: {
type: String,
default: "Normal"
},
moneyRecieved: { // calculator
type: Number,
default: 0,
},
moneyLeft: {
type: Number,
},
investor: [{
investorDetail: {
type: mongoose.Schema.Types.ObjectId,
ref: "Investor",
},
money: {
type: Number,
default: 0
},
date: {
type: Date,
default: Date.now()
}
}],
documentContract: [
{
dept: {
type: String,
},
recieveForm: {
type: String
},
aggrement: {
type: String
}
}
],
createdDate: {
type: Date,
default: Date.now()
}
});
requestSchema.virtual("id").get(function () {
return this._id.toHexString();
});
requestSchema.set("toJSON", {
virtuals: true,
});
exports.Request = mongoose.model("Request", requestSchema);
This is my schema and i want that in this schema some fields are like if on the field is updated from frontend so the other fields is updated automatically like subtracting or adding some money in field etc etc.