Skip to content

Commit

Permalink
fix: allow other params when using projectids
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Mar 7, 2024
1 parent 8dc1874 commit ddf21be
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 48 deletions.
40 changes: 19 additions & 21 deletions src/validations/projects.validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
50 changes: 23 additions & 27 deletions src/validations/units.validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit ddf21be

Please sign in to comment.