/
home
/
infinitibizsol
/
.trash
/
model.3
/
policy
/
File Upload :
llllll
Current File: /home/infinitibizsol/.trash/model.3/policy/policy.js
import db from "../../model/index"; import mongoose from "mongoose"; const Policy = new mongoose.Schema( { policy_type: { type: String, required: false, default: "" }, line_of_business: { type: String, required: false, default: "" }, effective_date: { type: String, required: false, default: "" }, policy_number: { type: String, required: false, default: "" }, term: { type: String, required: false, default: "" }, status: { type: String, enum: ["pending", "in_progress", "completed"], default: "pending", }, estimated_premium: { type: String, required: false, default: "" }, contact_id: { type: mongoose.Schema.ObjectId, ref: "Contact", }, user_id: { type: mongoose.Schema.ObjectId, ref: "User", }, createdOn: { type: Date, default: Date.now }, modifiedOn: { type: Date, default: Date.now }, }, { toJSON: { virtuals: true }, toObject: { virtuals: true }, } ); Policy.index({ policy_type: "text", line_of_business: "text", }); Policy.pre("remove", async function (next) { try { await db.AdditionalInfo.deleteMany({ policy_id: this._id }); await db.AdditionalInterest.deleteMany({ policy_id: this._id }); await db.BinderInfo.deleteMany({ policy_id: this._id }); await db.ContractorUnderwriting.deleteMany({ policy_id: this._id }); await db.ExtendedPolicyInfo.deleteMany({ policy_id: this._id }); await db.GeneralLiabilityUnderwriting.deleteMany({ policy_id: this._id }); await db.LocationSchedule.deleteMany({ policy_id: this._id }); await db.NamedInsured.deleteMany({ policy_id: this._id }); await db.NatureOfBusiness.deleteMany({ policy_id: this._id }); await db.PaymentPlan.deleteMany({ policy_id: this._id }); await db.PolicyAttachment.deleteMany({ policy_id: this._id }); await db.PolicyForm.deleteMany({ policy_id: this._id }); await db.PolicyInfo.deleteMany({ policy_id: this._id }); await db.PriorPolicyInfo.deleteMany({ policy_id: this._id }); await db.Product.deleteMany({ policy_id: this._id }); await db.UnderwritingQuestion.deleteMany({ policy_id: this._id }); next(); } catch (err) { next(err); } }); export default mongoose.model("Policy", Policy);
Copyright ©2k19 -
Hexid
|
Tex7ure