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
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:
parent
0470f62e05
commit
8974d1e9da
@ -31,6 +31,12 @@ const documentJobSchema = new Schema(
|
|||||||
ref: 'documentPrinter',
|
ref: 'documentPrinter',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
quantity: {
|
||||||
|
type: Number,
|
||||||
|
required: true,
|
||||||
|
default: 1,
|
||||||
|
min: 1,
|
||||||
|
},
|
||||||
content: {
|
content: {
|
||||||
type: String,
|
type: String,
|
||||||
required: false,
|
required: false,
|
||||||
|
|||||||
@ -7,6 +7,7 @@ const router = express.Router();
|
|||||||
|
|
||||||
const listAllowedFilters = [
|
const listAllowedFilters = [
|
||||||
'name',
|
'name',
|
||||||
|
'quantity',
|
||||||
'width',
|
'width',
|
||||||
'height',
|
'height',
|
||||||
'state',
|
'state',
|
||||||
@ -14,7 +15,7 @@ const listAllowedFilters = [
|
|||||||
'updatedAt',
|
'updatedAt',
|
||||||
'_reference',
|
'_reference',
|
||||||
];
|
];
|
||||||
const listAllowedSorters = ['name', 'state', 'createdAt', 'updatedAt'];
|
const listAllowedSorters = ['name', 'quantity', 'state', 'createdAt', 'updatedAt'];
|
||||||
const propertiesAllowedFilters = [];
|
const propertiesAllowedFilters = [];
|
||||||
import {
|
import {
|
||||||
listDocumentJobsRouteHandler,
|
listDocumentJobsRouteHandler,
|
||||||
|
|||||||
@ -113,6 +113,9 @@ export const editDocumentJobRouteHandler = async (req, res) => {
|
|||||||
logger.trace(`Document Job with ID: ${id}`);
|
logger.trace(`Document Job with ID: ${id}`);
|
||||||
|
|
||||||
const updateData = {};
|
const updateData = {};
|
||||||
|
if (req.body.quantity != null) {
|
||||||
|
updateData.quantity = req.body.quantity;
|
||||||
|
}
|
||||||
// Create audit log before updating
|
// Create audit log before updating
|
||||||
const result = await editObject({
|
const result = await editObject({
|
||||||
model: documentJobModel,
|
model: documentJobModel,
|
||||||
@ -142,6 +145,7 @@ export const newDocumentJobRouteHandler = async (req, res) => {
|
|||||||
objectType: req.body.objectType,
|
objectType: req.body.objectType,
|
||||||
object: req.body.object,
|
object: req.body.object,
|
||||||
content: req.body.content,
|
content: req.body.content,
|
||||||
|
quantity: req.body.quantity ?? 1,
|
||||||
state: { type: 'draft' },
|
state: { type: 'draft' },
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
|
|||||||
11
src/utils.js
11
src/utils.js
@ -1278,6 +1278,7 @@ function filterDistributeKeys(value, keys = DISTRIBUTE_KEYS) {
|
|||||||
result[key] = val;
|
result[key] = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log('filterDistributeKeys', result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1290,11 +1291,11 @@ async function distributeStats(value, type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function distributeNew(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) {
|
async function distributeDelete(value, type) {
|
||||||
await natsServer.publish(`${type}s.delete`, filterDistributeKeys(value));
|
await natsServer.publish(`${type}s.delete`, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getReferenceId(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
|
// 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.
|
// 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) {
|
if (queryClean.order._id !== undefined) {
|
||||||
queryClean['order._id'] = queryClean.order._id;
|
queryClean['order._id'] = queryClean.order._id;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user