From 2fdf0b21798a66af1d7b9a4d84d8ded2cc09472f Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Tue, 19 Mar 2024 13:28:44 -0400 Subject: [PATCH] feat: add only tokenized units query param --- src/controllers/units.controller.js | 12 ++++++++++++ src/validations/units.validations.js | 29 ++++++++++++++-------------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/controllers/units.controller.js b/src/controllers/units.controller.js index 2ebbd94a..cda9278e 100644 --- a/src/controllers/units.controller.js +++ b/src/controllers/units.controller.js @@ -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; @@ -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 diff --git a/src/validations/units.validations.js b/src/validations/units.validations.js index 31833090..4b5aeef8 100644 --- a/src/validations/units.validations.js +++ b/src/validations/units.validations.js @@ -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(), @@ -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({