Skip to content

Commit

Permalink
Merge pull request #142 from Chia-Network/feat/orgId-filter
Browse files Browse the repository at this point in the history
feat: orgId filtering in units & projects
  • Loading branch information
MichaelTaylor3D authored Jan 11, 2022
2 parents 8da5a8b + 48fb530 commit b66f061
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/controllers/project.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ export const create = async (req, res) => {
};

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

let { page, limit, search, orgUid, columns } = req.query;
let where = orgUid ? { orgUid } : undefined;

const includes = [
ProjectLocation,
Qualification,
Expand Down Expand Up @@ -97,9 +98,10 @@ export const findAll = async (req, res) => {
...columnsToInclude(columns, includes),
...paginationParams(page, limit),
};

results = await Project.findAndCountAll({
distinct: true,
where,
...query,
});
}
Expand Down
6 changes: 4 additions & 2 deletions src/controllers/units.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ export const create = async (req, res, next) => {
};

export const findAll = async (req, res) => {
let { page, limit, columns } = req.query;

let { page, limit, columns, orgUid } = req.query;
let where = orgUid ? { orgUid } : undefined;

const includes = [Qualification];

if (columns) {
Expand All @@ -79,6 +80,7 @@ export const findAll = async (req, res) => {
res.json(
optionallyPaginatedResponse(
await Unit.findAndCountAll({
where,
distinct: true,
...columnsToInclude(columns, includes),
...paginationParams(page, limit),
Expand Down
1 change: 1 addition & 0 deletions src/routes/v1/resources/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const querySchema = Joi.object()
limit: Joi.number(),
search: Joi.string(),
columns: Joi.array().items(Joi.string()).single(),
orgUid: Joi.string(),
})
.with('page', 'limit');

Expand Down
1 change: 1 addition & 0 deletions src/routes/v1/resources/units.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const querySchema = Joi.object()
search: Joi.string(),
warehouseUnitId: Joi.string(),
columns: Joi.array().items(Joi.string()).single(),
orgUid: Joi.string(),
})
.with('page', 'limit');

Expand Down

0 comments on commit b66f061

Please sign in to comment.