diff --git a/package.json b/package.json index 80e89e50..c5de0dbb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cadt", - "version": "1.7.11", + "version": "1.7.12", "_comment": "DONT CHANGE MAJOR UNLESS DATAMODEL CHANGES: The major version corresponds to the datamodel version your using, so 2.0.0 means it'll use datamodel v2", "private": true, "bin": "build/server.js", diff --git a/src/validations/projects.validations.js b/src/validations/projects.validations.js index f0d7cc76..dd6a372e 100644 --- a/src/validations/projects.validations.js +++ b/src/validations/projects.validations.js @@ -61,43 +61,33 @@ export const baseSchema = { }; export const projectsGetQuerySchema = Joi.object({ - page: Joi.number(), - limit: Joi.number(), - search: Joi.string(), - columns: Joi.array().items(Joi.string()).single(), - orgUid: Joi.string(), - warehouseProjectId: Joi.string(), - xls: Joi.boolean(), - projectIds: Joi.array().items(Joi.string()).single(), - order: Joi.string().regex(genericSortColumnRegex).max(100).min(1), - filter: Joi.string().regex(genericFilterRegex).max(100).min(1), - onlyMarketplaceProjects: Joi.boolean(), -}) - .when( - Joi.object({ - warehouseProjectId: Joi.string().min(1), - }).or('warehouseProjectId'), - { - then: Joi.object(), - otherwise: Joi.object({ - page: Joi.number().required(), - limit: Joi.number().required(), - }), - }, - ) - .when( - Joi.object({ - projectIds: Joi.array().items(Joi.string()).single().min(1), + page: Joi.number().optional(), + limit: Joi.number().max(100).min(1).optional(), + search: Joi.string().optional(), + columns: Joi.array().items(Joi.string()).single().optional(), + orgUid: Joi.string().optional(), + warehouseProjectId: Joi.string().optional(), + xls: Joi.boolean().optional(), + projectIds: Joi.array().items(Joi.string()).single().optional(), + order: Joi.string().regex(genericSortColumnRegex).optional(), + filter: Joi.string().regex(genericFilterRegex).optional(), + onlyMarketplaceProjects: Joi.boolean().optional(), +}).when( + Joi.alternatives([ + Joi.object({ projectIds: Joi.string().required() }).unknown(), + Joi.object({ warehouseProjectId: Joi.string().required() }).unknown(), + ]), + { + then: Joi.object({ + page: Joi.number().optional(), + limit: Joi.number().optional(), }), - { - then: Joi.object(), - otherwise: Joi.object({ - page: Joi.number().required(), - limit: Joi.number().required(), - }), - }, - ) - .and('page', 'limit'); + otherwise: Joi.object({ + page: Joi.number().required(), + limit: Joi.number().required(), + }), + }, +); export const projectsPostSchema = Joi.object({ ...baseSchema, diff --git a/src/validations/units.validations.js b/src/validations/units.validations.js index 31833090..0f459971 100644 --- a/src/validations/units.validations.js +++ b/src/validations/units.validations.js @@ -54,35 +54,31 @@ export const unitsPostSchema = Joi.object({ }); export const unitsGetQuerySchema = Joi.object({ - page: Joi.number().min(1), - limit: Joi.number().max(100).min(1), - search: Joi.string(), - warehouseUnitId: Joi.string(), - columns: Joi.array().items(Joi.string()).single(), - orgUid: Joi.string(), + page: Joi.number().min(1).optional(), + limit: Joi.number().max(100).min(1).optional(), + search: Joi.string().optional(), + warehouseUnitId: Joi.string().optional(), + columns: Joi.array().items(Joi.string()).single().optional(), + orgUid: Joi.string().optional(), order: Joi.alternatives().try( - Joi.string().valid('SERIALNUMBER', 'ASC', 'DESC'), - Joi.string().regex(genericSortColumnRegex).min(1).max(100), + Joi.string().valid('SERIALNUMBER', 'ASC', 'DESC').optional(), + Joi.string().regex(genericSortColumnRegex).min(1).max(100).optional(), ), - xls: Joi.boolean(), - marketplaceIdentifiers: Joi.array().items(Joi.string()).single(), - hasMarketplaceIdentifier: Joi.boolean(), - includeProjectInfoInSearch: Joi.boolean(), - filter: Joi.string().regex(genericFilterRegex).min(1).max(100), -}) - .when( - Joi.object({ - warehouseUnitId: Joi.string().min(1), - }).or('warehouseUnitId'), - { - then: Joi.object(), - otherwise: Joi.object({ - page: Joi.number().min(1).required(), - limit: Joi.number().max(100).min(1).required(), - }), - }, - ) - .and('page', 'limit'); + xls: Joi.boolean().optional(), + marketplaceIdentifiers: Joi.array().items(Joi.string()).single().optional(), + hasMarketplaceIdentifier: Joi.boolean().optional(), + includeProjectInfoInSearch: Joi.boolean().optional(), + filter: Joi.string().regex(genericFilterRegex).min(1).max(100).optional(), +}).when(Joi.object({ warehouseUnitId: Joi.string().required() }).unknown(), { + then: Joi.object({ + page: Joi.number().optional(), + limit: Joi.number().optional(), + }), + otherwise: Joi.object({ + page: Joi.number().min(1).required(), + limit: Joi.number().max(100).min(1).required(), + }), +}); export const unitsUpdateSchema = Joi.object({ warehouseUnitId: Joi.string().required(),