2023-11-29 20:05:48 +00:00
|
|
|
const mongoose = require('../db/connect')
|
|
|
|
|
|
|
|
const { Schema } = mongoose
|
|
|
|
|
|
|
|
const crmContactSchema = new Schema({
|
|
|
|
companyId: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
crm: {
|
|
|
|
type: mongoose.Schema.ObjectId,
|
|
|
|
ref: 'crm',
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
crmBaseURL: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
contactId: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
phone: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
}
|
|
|
|
}, { timestamps: true })
|
|
|
|
|
2024-07-19 18:48:34 +00:00
|
|
|
|
|
|
|
crmContactSchema.virtual('crm_tickets', {
|
|
|
|
ref: 'CRM_Ticket',
|
|
|
|
localField: '_id',
|
|
|
|
foreignField: 'contact',
|
|
|
|
justOne: false,
|
|
|
|
// match: { rating: 4 }
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
crmContactSchema.pre('deleteOne', { document: true, query: false }, async function () {
|
|
|
|
await this.model('CRM_Ticket').deleteMany({ contact: this._id })
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-11-29 20:05:48 +00:00
|
|
|
const CRM_Contact = mongoose.model('CRM_Contact', crmContactSchema)
|
|
|
|
|
|
|
|
module.exports = CRM_Contact
|