Added address to Vendor

This commit is contained in:
Tom Butcher 2025-12-03 23:47:22 +00:00
parent f4681e917b
commit 9f2341c613
3 changed files with 18 additions and 2 deletions

View File

@ -15,14 +15,14 @@ import {
// list of vendors
router.get('/', isAuthenticated, (req, res) => {
const { page, limit, property, search, sort, order } = req.query;
const allowedFilters = ['country'];
const allowedFilters = ['country', 'active', 'createdAt', 'updatedAt'];
const filter = getFilter(req.query, allowedFilters);
listVendorsRouteHandler(req, res, page, limit, property, filter, search, sort, order);
});
router.get('/properties', isAuthenticated, (req, res) => {
let properties = convertPropertiesString(req.query.properties);
const allowedFilters = ['country'];
const allowedFilters = ['country', 'active', 'createdAt', 'updatedAt'];
const filter = getFilter(req.query, allowedFilters, false);
listVendorsByPropertiesRouteHandler(req, res, properties, filter);
});

View File

@ -1,6 +1,16 @@
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 vendorSchema = new mongoose.Schema(
{
_reference: { type: String, default: () => generateId()() },
@ -10,6 +20,8 @@ const vendorSchema = new mongoose.Schema(
phone: { required: false, type: String },
contact: { required: false, type: String },
country: { required: false, type: String },
active: { required: true, type: Boolean, default: true },
address: { required: false, type: addressSchema },
},
{ timestamps: true }
);

View File

@ -97,6 +97,8 @@ export const editVendorRouteHandler = async (req, res) => {
website: req.body.website,
phone: req.body.phone,
email: req.body.email,
address: req.body.address,
active: req.body.active,
};
// Create audit log before updating
const result = await editObject({
@ -126,6 +128,8 @@ export const newVendorRouteHandler = async (req, res) => {
website: req.body.website,
phone: req.body.phone,
email: req.body.email,
address: req.body.address,
active: req.body.active,
};
const result = await newObject({
model: vendorModel,