Skip to content

Commit

Permalink
feat: add only tokenized units query param
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Mar 19, 2024
1 parent c7be273 commit 2fdf0b2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
12 changes: 12 additions & 0 deletions src/controllers/units.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const findAll = async (req, res) => {
hasMarketplaceIdentifier,
includeProjectInfoInSearch = false,
filter,
onlyTokenizedUnits = false,
} = req.query;

let where = orgUid != null && orgUid !== 'all' ? { orgUid } : undefined;
Expand Down Expand Up @@ -226,6 +227,17 @@ export const findAll = async (req, res) => {
where.marketplaceIdentifier = {
[Sequelize.Op.eq]: null,
};
} else if (onlyTokenizedUnits) {
if (!where) {
where = {};
}

where.marketplaceIdentifier = {
[Sequelize.Op.not]: true,
};
where.marketplace = {
[Sequelize.Op.eq]: 'Tokenized on Chia',
};
}

// default to DESC
Expand Down
29 changes: 15 additions & 14 deletions src/validations/units.validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export const unitsPostSchema = Joi.object({
});

export const unitsGetQuerySchema = Joi.object({
page: Joi.number().min(1),
limit: Joi.number().max(100).min(1),
page: Joi.number().min(1).required(),
limit: Joi.number().max(100).min(1).required(),
search: Joi.string(),
warehouseUnitId: Joi.string(),
columns: Joi.array().items(Joi.string()).single(),
Expand All @@ -67,21 +67,22 @@ export const unitsGetQuerySchema = Joi.object({
xls: Joi.boolean(),
marketplaceIdentifiers: Joi.array().items(Joi.string()).single(),
hasMarketplaceIdentifier: Joi.boolean(),
onlyTokenizedUnits: 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(),
}),
},
)
.when(Joi.object({ warehouseUnitId: Joi.exist() }).unknown(), {
then: Joi.object({
page: Joi.number().min(1).optional(),
limit: Joi.number().max(100).min(1).optional(),
}),
})
.when(Joi.object({ onlyTokenizedUnits: Joi.exist() }).unknown(), {
then: Joi.object({
page: Joi.number().min(1).optional(),
limit: Joi.number().max(100).min(1).optional(),
}),
})
.and('page', 'limit');

export const unitsUpdateSchema = Joi.object({
Expand Down

0 comments on commit 2fdf0b2

Please sign in to comment.