All checks were successful
farmcontrol/farmcontrol-ws/pipeline/head This commit looks good
- Updated the `notificationUserFromOwner` function to support 'marketplace' as a valid owner type. - Added a new `marketplaceEvent` schema to manage marketplace events, including fields for `externalReference`, `topic`, and `status`. - Enhanced existing schemas (e.g., `orderitem`, `shipment`, `client`, `listing`, `listingVarient`, `salesOrder`, `courierService`) to include `externalReference` fields for better integration with external systems. - Introduced unique indexes for `externalReference` in relevant schemas to ensure data integrity and prevent duplicates. - Improved the `marketplace` schema to include additional fields for eBay shipping services, enhancing its configurability.
40 lines
1.4 KiB
JavaScript
40 lines
1.4 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 },
|
|
externalReference: { type: String, 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.index({ marketplace: 1, externalReference: 1 }, { unique: true, sparse: true });
|
|
|
|
clientSchema.virtual('id').get(function () {
|
|
return this._id;
|
|
});
|
|
|
|
clientSchema.set('toJSON', { virtuals: true });
|
|
|
|
export const clientModel = mongoose.model('client', clientSchema);
|