From 8974d1e9da1c9d5320d52f7876e3a00ce6f343db Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sat, 22 Aug 2026 20:02:28 +0100 Subject: [PATCH] Add quantity field to document job schema and update related routes and services 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. --- src/database/schemas/management/documentjob.schema.js | 6 ++++++ src/routes/management/documentjobs.js | 3 ++- src/services/management/documentjobs.js | 4 ++++ src/utils.js | 11 ++++++++--- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/database/schemas/management/documentjob.schema.js b/src/database/schemas/management/documentjob.schema.js index 2e0a637..8fbaf7c 100644 --- a/src/database/schemas/management/documentjob.schema.js +++ b/src/database/schemas/management/documentjob.schema.js @@ -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, diff --git a/src/routes/management/documentjobs.js b/src/routes/management/documentjobs.js index 2d08c22..7bd279e 100644 --- a/src/routes/management/documentjobs.js +++ b/src/routes/management/documentjobs.js @@ -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, diff --git a/src/services/management/documentjobs.js b/src/services/management/documentjobs.js index f84d967..39b8bb6 100644 --- a/src/services/management/documentjobs.js +++ b/src/services/management/documentjobs.js @@ -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(), diff --git a/src/utils.js b/src/utils.js index b20ff60..43baa8a 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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; }