From b023d653b1f0d4b1968bc6b2448e6a21a1f95711 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Wed, 6 Mar 2024 14:39:04 -0500 Subject: [PATCH 1/6] fix: refactor validation --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4a77f8ad..5debd14b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cadt", - "version": "1.7.10", + "version": "1.7.11", "_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", From 4c742af78b324d2745fa844bbb5bc57bd7cc9c25 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Wed, 6 Mar 2024 14:40:21 -0500 Subject: [PATCH 2/6] fix: refactor validation --- src/validations/projects.validations.js | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/validations/projects.validations.js b/src/validations/projects.validations.js index f0d7cc76..181f0ed3 100644 --- a/src/validations/projects.validations.js +++ b/src/validations/projects.validations.js @@ -74,21 +74,12 @@ export const projectsGetQuerySchema = Joi.object({ 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(), + Joi.alternatives().try( + Joi.object({ warehouseProjectId: Joi.string().min(1) }), + Joi.object({ + projectIds: Joi.array().items(Joi.string()).single().min(1), }), - }, - ) - .when( - Joi.object({ - projectIds: Joi.array().items(Joi.string()).single().min(1), - }), + ), { then: Joi.object(), otherwise: Joi.object({ From 2c0a083a7dbeac26c077f72b36f03d58911bf065 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Wed, 6 Mar 2024 16:05:58 -0500 Subject: [PATCH 3/6] fix: projectIds --- src/validations/projects.validations.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/validations/projects.validations.js b/src/validations/projects.validations.js index 181f0ed3..03bea033 100644 --- a/src/validations/projects.validations.js +++ b/src/validations/projects.validations.js @@ -61,27 +61,22 @@ export const baseSchema = { }; export const projectsGetQuerySchema = Joi.object({ - page: Joi.number(), - limit: Joi.number(), + page: Joi.number().optional(), + limit: Joi.number().max(100).min(1).optional(), 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), + order: Joi.string().regex(genericSortColumnRegex), + filter: Joi.string().regex(genericFilterRegex), onlyMarketplaceProjects: Joi.boolean(), }) .when( - Joi.alternatives().try( - Joi.object({ warehouseProjectId: Joi.string().min(1) }), - Joi.object({ - projectIds: Joi.array().items(Joi.string()).single().min(1), - }), - ), + Joi.object({ projectIds: Joi.array().items(Joi.string()).single().min(1) }), { - then: Joi.object(), + then: Joi.object().options({ presence: 'optional' }), // Make page and limit optional otherwise: Joi.object({ page: Joi.number().required(), limit: Joi.number().required(), From ddf21be38cc04860029d8a5e587ef0f0da0e960d Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Thu, 7 Mar 2024 12:58:06 -0500 Subject: [PATCH 4/6] fix: allow other params when using projectids --- src/validations/projects.validations.js | 40 ++++++++++---------- src/validations/units.validations.js | 50 ++++++++++++------------- 2 files changed, 42 insertions(+), 48 deletions(-) diff --git a/src/validations/projects.validations.js b/src/validations/projects.validations.js index 03bea033..ad770f03 100644 --- a/src/validations/projects.validations.js +++ b/src/validations/projects.validations.js @@ -63,27 +63,25 @@ export const baseSchema = { export const projectsGetQuerySchema = Joi.object({ page: Joi.number().optional(), limit: Joi.number().max(100).min(1).optional(), - 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), - filter: Joi.string().regex(genericFilterRegex), - onlyMarketplaceProjects: Joi.boolean(), -}) - .when( - Joi.object({ projectIds: Joi.array().items(Joi.string()).single().min(1) }), - { - then: Joi.object().options({ presence: 'optional' }), // Make page and limit optional - otherwise: Joi.object({ - page: Joi.number().required(), - limit: Joi.number().required(), - }), - }, - ) - .and('page', 'limit'); + 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.object({ warehouseProjectId: Joi.string().required() }).unknown(), { + then: Joi.object({ + page: Joi.number().optional(), + limit: Joi.number().optional(), + }), + 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(), From f437359380bb2f24241c8611a22e5f5e68f730b1 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Thu, 7 Mar 2024 13:04:36 -0500 Subject: [PATCH 5/6] fix: joi --- src/validations/projects.validations.js | 26 +++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/validations/projects.validations.js b/src/validations/projects.validations.js index ad770f03..dd6a372e 100644 --- a/src/validations/projects.validations.js +++ b/src/validations/projects.validations.js @@ -72,16 +72,22 @@ export const projectsGetQuerySchema = Joi.object({ order: Joi.string().regex(genericSortColumnRegex).optional(), filter: Joi.string().regex(genericFilterRegex).optional(), onlyMarketplaceProjects: Joi.boolean().optional(), -}).when(Joi.object({ warehouseProjectId: Joi.string().required() }).unknown(), { - then: Joi.object({ - page: Joi.number().optional(), - limit: Joi.number().optional(), - }), - otherwise: Joi.object({ - page: Joi.number().required(), - limit: Joi.number().required(), - }), -}); +}).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(), + }), + otherwise: Joi.object({ + page: Joi.number().required(), + limit: Joi.number().required(), + }), + }, +); export const projectsPostSchema = Joi.object({ ...baseSchema, From d28d8ac885b42bc8e6e7f711612939f77baee545 Mon Sep 17 00:00:00 2001 From: Zachary Brown Date: Fri, 8 Mar 2024 11:29:52 -0800 Subject: [PATCH 6/6] chore: version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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",