- Introduced new schemas for clients and sales orders. - Implemented route handlers for CRUD operations on clients and sales orders. - Updated the main application routes to include client and sales order routes. - Enhanced the models to support new data structures and relationships.
35 lines
1.1 KiB
JavaScript
35 lines
1.1 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 },
|
|
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.virtual('id').get(function () {
|
|
return this._id;
|
|
});
|
|
|
|
clientSchema.set('toJSON', { virtuals: true });
|
|
|
|
export const clientModel = mongoose.model('client', clientSchema);
|