From bd2d7d5a8239338d772962d416731c5ad27acad1 Mon Sep 17 00:00:00 2001 From: Kamaleeswary Date: Wed, 22 Dec 2021 12:26:13 +0530 Subject: [PATCH 1/2] Issue #SB-27440 feat: Call notification service api call on each action form DF --- index.js | 19 ++++++++++++++++++- lib/constants.js | 6 ++++++ package.json | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index bd328b2..bd5f46f 100644 --- a/index.js +++ b/index.js @@ -38,6 +38,7 @@ const privileges = require.main.require('./src/privileges'); const _ = require('lodash'); const copyPrivilages = '/api/privileges/v2/copy' const getUids = '/api/forum/v2/uids'; +const sbUserIds = '/api/forum/v2/sunbird/uids'; const addUserIntoGroup = '/api/forum/v3/group/membership'; const groupsPriveleges = '/api/forum/v3/category/:cid/privileges'; const oidcPlugin = require.main.require('./node_modules/nodebb-plugin-sunbird-oidc/library.js'); @@ -1341,6 +1342,22 @@ function healthCheck (req, res) { } } } +async function getSBUserIds (req, res) { + const data = { ...req.body.request }; + const requiredParams = jsonConstants.requiredParams[req.route.path]; + const isPayloadCorrect = await util.checkRequiredParameters(req, res, requiredParams, data); + if (isPayloadCorrect) { + let sbuids = []; + data.uids.forEach(async (uid, index) => { + const userObj = await Users.getUserFields(uid, ['sunbird-oidcId', 'username']); + sbuids.push(userObj); + if(index === (data.uids.length - 1)) { + const responseObj = await util.responseData(req, res, sbuids, null); + res.send(responseObj); + } + }); + } +} Plugin.load = function (params, callback) { var router = params.router @@ -1359,7 +1376,7 @@ Plugin.load = function (params, callback) { router.post(listOfGroupUsers, getContextUserGroups); router.post(groupsPriveleges, getContextGroupPriveleges); router.post(updateUserProfile, updateUserProfileData); - + router.post(sbUserIds, getSBUserIds); router.get('/api/forum/test/user/:userslug', getUserDetails); router.get('/api/forum/health', healthCheck); diff --git a/lib/constants.js b/lib/constants.js index f6d1e02..3eb4fd8 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -141,6 +141,12 @@ module.exports = { name: 'sbIdentifier', type: 'any' } + ], + '/api/forum/v2/sunbird/uids': [ + { + name: 'uids', + type: 'array' + } ] }, forumStrings: { diff --git a/package.json b/package.json index a0f60f0..3b792cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodebb-plugin-create-forum", - "version": "1.0.29", + "version": "1.0.30", "description": "", "main": "index.js", "scripts": { From e78043f6cb62f24426d8109817cdb70292723b2f Mon Sep 17 00:00:00 2001 From: Kamaleeswary Date: Wed, 5 Jan 2022 14:56:05 +0530 Subject: [PATCH 2/2] Issue #SB-27440 feat: minor changes --- index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index bd5f46f..e0860df 100644 --- a/index.js +++ b/index.js @@ -1348,14 +1348,15 @@ async function getSBUserIds (req, res) { const isPayloadCorrect = await util.checkRequiredParameters(req, res, requiredParams, data); if (isPayloadCorrect) { let sbuids = []; - data.uids.forEach(async (uid, index) => { - const userObj = await Users.getUserFields(uid, ['sunbird-oidcId', 'username']); + const uids = data.uids; + for(let i=0; i< uids.length; i++) { + const userObj = await Users.getUserFields(uids[i], ['sunbird-oidcId', 'username']); sbuids.push(userObj); - if(index === (data.uids.length - 1)) { + if(i === (uids.length - 1)) { const responseObj = await util.responseData(req, res, sbuids, null); res.send(responseObj); } - }); + } } }