diff --git a/package.json b/package.json index e12ef64..43ded25 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "express-rate-limit": "^7.2.0", "express-validator": "^7.0.1", "graphql": "^16.8.1", - "graphql-http": "^1.22.0", + "graphql-http": "^1.22.1", "graphql-tag": "^2.12.6", "helmet": "^7.1.0", "jsonwebtoken": "^9.0.2", @@ -67,6 +67,9 @@ "sinon": "^17.0.1", "supertest": "^6.3.4" }, + "overrides": { + "formidable": "^3.5.1" + }, "repository": { "type": "git", "url": "https://github.com/switcherapi/switcher-api" diff --git a/src/routers/group-config.js b/src/routers/group-config.js index d5b6044..69a25f3 100644 --- a/src/routers/group-config.js +++ b/src/routers/group-config.js @@ -9,6 +9,7 @@ import * as Services from '../services/group-config.js'; import { getHistory, deleteHistory } from '../services/history.js'; import { getDomainById } from '../services/domain.js'; import { SwitcherKeys } from '../external/switcher-api-facade.js'; +import { getFields } from './common/index.js'; const router = new express.Router(); @@ -25,7 +26,11 @@ router.post('/groupconfig/create', auth, async (req, res) => { // GET /groupconfig?domain=ID&sortBy=createdAt:desc // GET /groupconfig?domain=ID router.get('/groupconfig', auth, [ - query('domain', 'Please, specify the \'domain\' id').isMongoId() + query('domain', 'Please, specify the \'domain\' id').isMongoId(), + query('fields').isString().optional(), + query('limit').isInt().optional(), + query('skip').isInt().optional(), + query('sortBy').isString().optional() ], validate, async (req, res) => { try { const domain = await getDomainById(req.query.domain); @@ -42,6 +47,10 @@ router.get('/groupconfig', auth, [ groups = await verifyOwnership(req.admin, groups, domain._id, ActionTypes.READ, RouterTypes.GROUP, true); await Services.populateAdmin(groups); + if (req.query.fields) { + groups = getFields(groups, req.query.fields); + } + res.send(groups); } catch (e) { responseException(res, e, 500); diff --git a/tests/group-config.test.js b/tests/group-config.test.js index 6804172..999061a 100644 --- a/tests/group-config.test.js +++ b/tests/group-config.test.js @@ -137,6 +137,18 @@ describe('Testing fetch Group info', () => { expect(response.body.length).toEqual(2); }); + test('GROUP_SUITE - Should get Group Config information - only fields (name, activated.default)', async () => { + let response = await request(app) + .get('/groupconfig?domain=' + domainId + '&fields=name,activated.default') + .set('Authorization', `Bearer ${adminMasterAccountToken}`) + .send().expect(200); + + expect(response.body[0].name).toBeDefined(); + expect(response.body[0].activated.default).toBeDefined(); + expect(response.body[0].description).toBeUndefined(); + expect(response.body[0].owner).toBeUndefined(); + }); + test('GROUP_SUITE - Should get Group Config information by Id', async () => { let response = await request(app) .get('/groupconfig/' + groupConfigId)