Skip to content

Commit

Permalink
feat: query units by marketplace identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Sep 19, 2022
1 parent 32cd68f commit e333a16
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/controllers/units.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,17 @@ export const create = async (req, res) => {

export const findAll = async (req, res) => {
try {
let { page, limit, columns, orgUid, search, xls, order } = req.query;
let {
page,
limit,
columns,
orgUid,
search,
xls,
order,
marketplaceIdentifier,
} = req.query;

let where = orgUid != null && orgUid !== 'all' ? { orgUid } : undefined;

const includes = Unit.getAssociatedModels();
Expand Down Expand Up @@ -159,6 +169,16 @@ export const findAll = async (req, res) => {
};
}

if (marketplaceIdentifier) {
if (!where) {
where = {};
}

where.marketplaceIdentifier = {
[Sequelize.Op.in]: marketplaceIdentifier,
};
}

// default to DESC
let resultOrder = [['timeStaged', 'DESC']];

Expand Down
1 change: 1 addition & 0 deletions src/validations/units.validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const unitsGetQuerySchema = Joi.object()
orgUid: Joi.string(),
order: Joi.string().valid('SERIALNUMBER', 'ASC', 'DESC'),
xls: Joi.boolean(),
marketplaceIdentifier: Joi.array().items(Joi.string()).single(),
})
.with('page', 'limit');

Expand Down

0 comments on commit e333a16

Please sign in to comment.