From b14583ac9d946342e1f1bc451c824661ddee97b2 Mon Sep 17 00:00:00 2001 From: Mike Keen Date: Tue, 11 Jan 2022 15:48:49 -0500 Subject: [PATCH 1/3] feat: orgId filtering in units & projects --- src/controllers/project.controller.js | 8 ++++++-- src/controllers/units.controller.js | 6 ++++-- src/routes/v1/resources/projects.js | 1 + src/routes/v1/resources/units.js | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/controllers/project.controller.js b/src/controllers/project.controller.js index 96823853..7ed90acf 100644 --- a/src/controllers/project.controller.js +++ b/src/controllers/project.controller.js @@ -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, @@ -98,8 +99,11 @@ export const findAll = async (req, res) => { ...paginationParams(page, limit), }; + console.log(query) + results = await Project.findAndCountAll({ distinct: true, + where, ...query, }); } diff --git a/src/controllers/units.controller.js b/src/controllers/units.controller.js index 1ebc7892..d4f303e4 100644 --- a/src/controllers/units.controller.js +++ b/src/controllers/units.controller.js @@ -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) { @@ -84,6 +85,7 @@ export const findAll = async (req, res) => { ...paginationParams(page, limit), }), page, + where, limit, ), ); diff --git a/src/routes/v1/resources/projects.js b/src/routes/v1/resources/projects.js index 4bc1df57..a3d3018b 100644 --- a/src/routes/v1/resources/projects.js +++ b/src/routes/v1/resources/projects.js @@ -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'); diff --git a/src/routes/v1/resources/units.js b/src/routes/v1/resources/units.js index 924e0e11..30391eb9 100644 --- a/src/routes/v1/resources/units.js +++ b/src/routes/v1/resources/units.js @@ -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'); From 046d72eec3e0bb8837be67b112e9e1bb59b0734e Mon Sep 17 00:00:00 2001 From: Mike Keen Date: Tue, 11 Jan 2022 15:55:54 -0500 Subject: [PATCH 2/3] fix: remove console.log --- src/controllers/project.controller.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/controllers/project.controller.js b/src/controllers/project.controller.js index 7ed90acf..fe89fa39 100644 --- a/src/controllers/project.controller.js +++ b/src/controllers/project.controller.js @@ -98,8 +98,6 @@ export const findAll = async (req, res) => { ...columnsToInclude(columns, includes), ...paginationParams(page, limit), }; - - console.log(query) results = await Project.findAndCountAll({ distinct: true, From 48fb5303e2f25c5cf5d278671180029073da911a Mon Sep 17 00:00:00 2001 From: Mike Keen Date: Tue, 11 Jan 2022 16:01:37 -0500 Subject: [PATCH 3/3] fix: move where --- src/controllers/units.controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/units.controller.js b/src/controllers/units.controller.js index d4f303e4..22f3fe18 100644 --- a/src/controllers/units.controller.js +++ b/src/controllers/units.controller.js @@ -80,12 +80,12 @@ export const findAll = async (req, res) => { res.json( optionallyPaginatedResponse( await Unit.findAndCountAll({ + where, distinct: true, ...columnsToInclude(columns, includes), ...paginationParams(page, limit), }), page, - where, limit, ), );