Some checks failed
farmcontrol/farmcontrol-api/pipeline/head There was a failure building this commit
38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
import mongoose from 'mongoose';
|
|
import { generateId } from '../../utils.js';
|
|
|
|
const addressSchema = new mongoose.Schema({
|
|
building: { required: false, type: String },
|
|
addressLine1: { required: false, type: String },
|
|
addressLine2: { required: false, type: String },
|
|
city: { required: false, type: String },
|
|
state: { required: false, type: String },
|
|
postcode: { required: false, type: String },
|
|
country: { required: false, type: String },
|
|
});
|
|
|
|
const clientSchema = new mongoose.Schema(
|
|
{
|
|
_reference: { type: String, default: () => generateId()() },
|
|
name: { required: true, type: String },
|
|
marketplace: { type: mongoose.Schema.Types.ObjectId, ref: 'marketplace', required: false },
|
|
email: { required: false, type: String },
|
|
phone: { required: false, type: String },
|
|
country: { required: false, type: String },
|
|
active: { required: true, type: Boolean, default: true },
|
|
address: { required: false, type: addressSchema },
|
|
tags: [{ required: false, type: String }],
|
|
},
|
|
{ timestamps: true }
|
|
);
|
|
|
|
clientSchema.index({ name: 'text', email: 'text', phone: 'text', country: 'text', tags: 'text' });
|
|
|
|
clientSchema.virtual('id').get(function () {
|
|
return this._id;
|
|
});
|
|
|
|
clientSchema.set('toJSON', { virtuals: true });
|
|
|
|
export const clientModel = mongoose.model('client', clientSchema);
|