Updated invoice schema to support dynamic reference types for 'from' and 'to' fields, and modified related service handlers to accommodate new 'fromType' and 'toType' properties.
All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good

This commit is contained in:
Tom Butcher 2026-06-21 19:08:20 +01:00
parent a25deb0de2
commit 6e7419da67
2 changed files with 8 additions and 2 deletions

View File

@ -33,8 +33,10 @@ const invoiceSchema = new Schema(
shippingAmountWithTax: { type: Number, required: true, default: 0 }, shippingAmountWithTax: { type: Number, required: true, default: 0 },
grandTotalAmount: { type: Number, required: true, default: 0 }, grandTotalAmount: { type: Number, required: true, default: 0 },
totalTaxAmount: { type: Number, required: true, default: 0 }, totalTaxAmount: { type: Number, required: true, default: 0 },
from: { type: Schema.Types.ObjectId, ref: 'vendor', required: false }, from: { type: Schema.Types.ObjectId, refPath: 'fromType', required: false },
to: { type: Schema.Types.ObjectId, ref: 'client', required: false }, fromType: { type: String, required: false },
to: { type: Schema.Types.ObjectId, refPath: 'toType', required: false },
toType: { type: String, required: false },
state: { state: {
type: { type: String, required: true, default: 'draft' }, type: { type: String, required: true, default: 'draft' },
}, },

View File

@ -142,6 +142,8 @@ export const editInvoiceRouteHandler = async (req, res) => {
invoiceShipments: req.body.invoiceShipments, invoiceShipments: req.body.invoiceShipments,
from: req.body.from, from: req.body.from,
to: req.body.to, to: req.body.to,
fromType: req.body.fromType,
toType: req.body.toType,
}; };
// Create audit log before updating // Create audit log before updating
const result = await editObject({ const result = await editObject({
@ -276,6 +278,8 @@ export const newInvoiceRouteHandler = async (req, res) => {
invoiceShipments: invoiceShipments, invoiceShipments: invoiceShipments,
from: req.body.from, from: req.body.from,
to: req.body.to, to: req.body.to,
fromType: req.body.fromType,
toType: req.body.toType,
}; };
const result = await newObject({ const result = await newObject({
model: invoiceModel, model: invoiceModel,