Skip to content

Commit

Permalink
feat: require pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Dec 11, 2023
1 parent edcbc11 commit 86e073a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 37 deletions.
42 changes: 26 additions & 16 deletions src/validations/projects.validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,32 @@ export const baseSchema = {
timeStaged: Joi.date().timestamp().allow(null).optional(),
};

export const projectsGetQuerySchema = Joi.object()
.keys({
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),
filter: Joi.string().regex(genericFilterRegex),
onlyMarketplaceProjects: Joi.boolean(),
})
.with('page', 'limit')
.with('limit', 'page');
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),
filter: Joi.string().regex(genericFilterRegex),
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(),
}),
},
)
.and('page', 'limit');

export const projectsPostSchema = Joi.object({
...baseSchema,
Expand Down
51 changes: 30 additions & 21 deletions src/validations/units.validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,36 @@ export const unitsPostSchema = Joi.object({
...unitsBaseSchema,
});

export const unitsGetQuerySchema = Joi.object()
.keys({
page: Joi.number(),
limit: Joi.number(),
search: Joi.string(),
warehouseUnitId: Joi.string(),
columns: Joi.array().items(Joi.string()).single(),
orgUid: Joi.string(),
order: Joi.alternatives().try(
// backwards compatibility for old order usage
Joi.string().valid('SERIALNUMBER', 'ASC', 'DESC'),
// new order usage
Joi.string().regex(genericSortColumnRegex),
),
xls: Joi.boolean(),
marketplaceIdentifiers: Joi.array().items(Joi.string()).single(),
hasMarketplaceIdentifier: Joi.boolean(),
includeProjectInfoInSearch: Joi.boolean(),
filter: Joi.string().regex(genericFilterRegex),
})
.with('page', 'limit');
export const unitsGetQuerySchema = Joi.object({
page: Joi.number(),
limit: Joi.number(),
search: Joi.string(),
warehouseUnitId: Joi.string(),
columns: Joi.array().items(Joi.string()).single(),
orgUid: Joi.string(),
order: Joi.alternatives().try(
Joi.string().valid('SERIALNUMBER', 'ASC', 'DESC'),
Joi.string().regex(genericSortColumnRegex),
),
xls: Joi.boolean(),
marketplaceIdentifiers: Joi.array().items(Joi.string()).single(),
hasMarketplaceIdentifier: Joi.boolean(),
includeProjectInfoInSearch: Joi.boolean(),
filter: Joi.string().regex(genericFilterRegex),
})
.when(
Joi.object({
warehouseUnitId: Joi.string().min(1),
}).or('warehouseUnitId'),
{
then: Joi.object(),
otherwise: Joi.object({
page: Joi.number().required(),
limit: Joi.number().required(),
}),
},
)
.and('page', 'limit');

export const unitsUpdateSchema = Joi.object({
warehouseUnitId: Joi.string().required(),
Expand Down

0 comments on commit 86e073a

Please sign in to comment.