Add quantity field to document job schema and update related routes and services
All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good

This commit introduces a new `quantity` field to the document job schema, ensuring it is required with a default value of 1. The routes and services for managing document jobs are updated to include this new field, allowing for its inclusion in both creation and editing processes. Additionally, the allowed filters and sorters are modified to accommodate the new `quantity` field, enhancing the overall functionality and flexibility of document job management.
This commit is contained in:
Tom Butcher 2026-08-22 20:02:28 +01:00
parent 0470f62e05
commit 8974d1e9da
4 changed files with 20 additions and 4 deletions

View File

@ -31,6 +31,12 @@ const documentJobSchema = new Schema(
ref: 'documentPrinter',
required: true,
},
quantity: {
type: Number,
required: true,
default: 1,
min: 1,
},
content: {
type: String,
required: false,

View File

@ -7,6 +7,7 @@ const router = express.Router();
const listAllowedFilters = [
'name',
'quantity',
'width',
'height',
'state',
@ -14,7 +15,7 @@ const listAllowedFilters = [
'updatedAt',
'_reference',
];
const listAllowedSorters = ['name', 'state', 'createdAt', 'updatedAt'];
const listAllowedSorters = ['name', 'quantity', 'state', 'createdAt', 'updatedAt'];
const propertiesAllowedFilters = [];
import {
listDocumentJobsRouteHandler,

View File

@ -113,6 +113,9 @@ export const editDocumentJobRouteHandler = async (req, res) => {
logger.trace(`Document Job with ID: ${id}`);
const updateData = {};
if (req.body.quantity != null) {
updateData.quantity = req.body.quantity;
}
// Create audit log before updating
const result = await editObject({
model: documentJobModel,
@ -142,6 +145,7 @@ export const newDocumentJobRouteHandler = async (req, res) => {
objectType: req.body.objectType,
object: req.body.object,
content: req.body.content,
quantity: req.body.quantity ?? 1,
state: { type: 'draft' },
createdAt: new Date(),
updatedAt: new Date(),

View File

@ -1278,6 +1278,7 @@ function filterDistributeKeys(value, keys = DISTRIBUTE_KEYS) {
result[key] = val;
}
}
console.log('filterDistributeKeys', result);
return result;
}
@ -1290,11 +1291,11 @@ async function distributeStats(value, type) {
}
async function distributeNew(value, type) {
await natsServer.publish(`${type}s.new`, filterDistributeKeys(value));
await natsServer.publish(`${type}s.new`, value);
}
async function distributeDelete(value, type) {
await natsServer.publish(`${type}s.delete`, filterDistributeKeys(value));
await natsServer.publish(`${type}s.delete`, value);
}
function getReferenceId(value) {
@ -1603,7 +1604,11 @@ function normalizeFilterQuery(query = {}) {
// qs turns `order._id=` into `{ order: { _id } }`. Lift it so it can be parsed
// as the order object filter instead of a nested query object.
if (queryClean.order && typeof queryClean.order === 'object' && !Array.isArray(queryClean.order)) {
if (
queryClean.order &&
typeof queryClean.order === 'object' &&
!Array.isArray(queryClean.order)
) {
if (queryClean.order._id !== undefined) {
queryClean['order._id'] = queryClean.order._id;
}