Skip to content

Commit

Permalink
Added org on-board feature APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
karthik-tarento committed Jun 24, 2022
1 parent b0905c3 commit b9144a1
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 3 deletions.
58 changes: 58 additions & 0 deletions src/proxies_v8/proxies_v8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios from 'axios'
import express from 'express'
import { UploadedFile } from 'express-fileupload'
import FormData from 'form-data'
import lodash from 'lodash'
import { axiosRequestConfig } from '../configs/request.config'
import { CONSTANTS } from '../utils/env'
import { logInfo } from '../utils/logger'
Expand All @@ -25,6 +26,9 @@ import { extractUserIdFromRequest, extractUserToken } from '../utils/requestExtr

const API_END_POINTS = {
contentNotificationEmail: `${CONSTANTS.NOTIFICATION_SERVIC_API_BASE}/v1/notification/send/sync`,
kongExtOrgSearch: `${CONSTANTS.KONG_API_BASE}/org/v1/cb/ext/search`,
kongSearchOrg: `${CONSTANTS.KONG_API_BASE}/org/v1/search`,
orgTypeListEndPoint: `${CONSTANTS.KONG_API_BASE}/data/v1/system/settings/get/orgTypeList`,
}

export const proxiesV8 = express.Router()
Expand All @@ -51,6 +55,7 @@ proxiesV8.post('/upload/*', (req, res) => {
Authorization: CONSTANTS.SB_API_KEY,
org: 'dopt',
rootorg: 'igot',
// tslint:disable-next-line: all
'x-authenticated-user-token': extractUserToken(req),
'x-authenticated-userid': extractUserIdFromRequest(req),
},
Expand Down Expand Up @@ -94,6 +99,7 @@ proxiesV8.post('/private/upload/*', (_req, _res) => {
Authorization: CONSTANTS.SB_API_KEY,
org: 'dopt',
rootorg: 'igot',
// tslint:disable-next-line: all
'x-authenticated-user-token': extractUserToken(_req),
'x-authenticated-userid': extractUserIdFromRequest(_req),
},
Expand Down Expand Up @@ -221,6 +227,28 @@ proxiesV8.use('/notification/*',
proxyCreatorSunbird(express.Router(), `${CONSTANTS.KONG_API_BASE}`)
)

proxiesV8.post('/org/v1/search', async (req, res) => {
const roleData = lodash.get(req, 'session.userRoles')
const rootOrgId = lodash.get(req, 'session.rootOrgId')
let urlPath = API_END_POINTS.kongSearchOrg
if (roleData.includes('STATE_ADMIN')) {
req.body.request.filters.sbRootOrgId = rootOrgId
urlPath = API_END_POINTS.kongExtOrgSearch
}
const searchResponse = await axios({
...axiosRequestConfig,
data: req.body,
headers: {
Authorization: CONSTANTS.SB_API_KEY,
// tslint:disable-next-line: all
'x-authenticated-user-token': extractUserToken(req),
},
method: 'POST',
url: urlPath,
})
res.status(200).send(searchResponse.data)
})

proxiesV8.use('/org/*',
proxyCreatorSunbird(express.Router(), `${CONSTANTS.KONG_API_BASE}`)
)
Expand Down Expand Up @@ -277,6 +305,36 @@ proxiesV8.use('/wat/dashboard/*',
proxyCreatorSunbird(express.Router(), `${CONSTANTS.DASHBOARD_API_BASE}`)
)

proxiesV8.get('/data/v1/system/settings/get/orgTypeList', async (req, res) => {
const roleData = lodash.get(req, 'session.userRoles')
logInfo('orgTypeList API call : Users Roles are...')
logInfo(roleData)
const response = await axios({
...axiosRequestConfig,
headers: {
Authorization: CONSTANTS.SB_API_KEY,
// tslint:disable-next-line: all
'x-authenticated-user-token': extractUserToken(req),
},
method: 'GET',
url: API_END_POINTS.orgTypeListEndPoint,
})
if (roleData.includes('STATE_ADMIN')) {
const hiddenList = ['CBC', 'CBP', 'STATE']
const orgTypeListObj = JSON.parse(response.data.result.response.value)
const orgTypeList = orgTypeListObj.orgTypeList
// tslint:disable-next-line: no-any
orgTypeList.forEach((element: any) => {
if (hiddenList.includes(element.name)) {
element.isHidden = true
}
})
orgTypeListObj.orgTypeList = orgTypeList
response.data.result.response.value = JSON.stringify(orgTypeListObj)
}
res.status(200).send(response.data)
})

proxiesV8.use('/data/*',
proxyCreatorSunbird(express.Router(), `${CONSTANTS.KONG_API_BASE}`)
)
Expand Down
2 changes: 2 additions & 0 deletions src/publicApi_v8/publicApiV8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ publicApiV8.use('/assets',
proxyCreatorRoute(express.Router(), CONSTANTS.WEB_HOST_PROXY + '/web-hosted/web-client-public-assets'))

publicApiV8.use('/workallocation', workallocationPublic)

publicApiV8.use('/org/v1/list', proxyCreatorRoute(express.Router(), CONSTANTS.KONG_API_BASE + '/org/v1/list'))
1 change: 1 addition & 0 deletions src/utils/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ export const ROLE = {
MDO_ADMIN: 'MDO_ADMIN',
PUBLIC: 'PUBLIC',
SPV_ADMIN: 'SPV_ADMIN',
STATE_ADMIN: 'STATE_ADMIN',
WAT_MEMBER: 'WAT_MEMBER',
}
58 changes: 55 additions & 3 deletions src/utils/whitelistApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ export const API_LIST = {
ROLE.PUBLIC, 'ALL',
],
},
'/proxies/v8/user/v1/updateLogin': {
checksNeeded: [CHECK.ROLE],
// tslint:disable-next-line: object-literal-sort-keys
ROLE_CHECK: [
ROLE.PUBLIC, 'ALL',
],
},
'/proxies/v8/event/v4/read/:do_id': {
checksNeeded: [CHECK.ROLE],
// tslint:disable-next-line: object-literal-sort-keys
Expand Down Expand Up @@ -233,6 +240,7 @@ export const API_LIST = {
checksNeeded: [CHECK.ROLE],
// tslint:disable-next-line: object-literal-sort-keys
ROLE_CHECK: [
ROLE.CONTENT_PUBLISHER,
ROLE.CONTENT_REVIEWER,
],
},
Expand Down Expand Up @@ -340,6 +348,7 @@ export const API_LIST = {
ROLE.CBC_ADMIN,
ROLE.MDO_ADMIN,
ROLE.SPV_ADMIN,
ROLE.STATE_ADMIN,
],
},
'/proxies/v8/org/v1/search': {
Expand All @@ -356,6 +365,7 @@ export const API_LIST = {
ROLE.MDO_ADMIN,
ROLE.SPV_ADMIN,
ROLE.CBP_ADMIN,
ROLE.STATE_ADMIN,
ROLE.CONTENT_CREATOR,
],
},
Expand All @@ -373,6 +383,27 @@ export const API_LIST = {
ROLE.CBC_ADMIN,
ROLE.MDO_ADMIN,
ROLE.SPV_ADMIN,
ROLE.STATE_ADMIN,
],
},
'/proxies/v8/org/v1/profile/read': {
checksNeeded: [CHECK.ROLE],
// tslint:disable-next-line: object-literal-sort-keys
ROLE_CHECK: [
ROLE.CBC_ADMIN,
ROLE.MDO_ADMIN,
ROLE.SPV_ADMIN,
ROLE.STATE_ADMIN,
],
},
'/proxies/v8/org/v1/profile/patch': {
checksNeeded: [CHECK.ROLE],
// tslint:disable-next-line: object-literal-sort-keys
ROLE_CHECK: [
ROLE.CBC_ADMIN,
ROLE.MDO_ADMIN,
ROLE.SPV_ADMIN,
ROLE.STATE_ADMIN,
],
},
'/proxies/v8/org/v1/update': {
Expand All @@ -382,6 +413,7 @@ export const API_LIST = {
ROLE.CBC_ADMIN,
ROLE.MDO_ADMIN,
ROLE.SPV_ADMIN,
ROLE.STATE_ADMIN,
],
},
'/proxies/v8/user/v1/block': {
Expand All @@ -391,6 +423,7 @@ export const API_LIST = {
ROLE.MDO_ADMIN,
ROLE.SPV_ADMIN,
ROLE.CBP_ADMIN,
ROLE.STATE_ADMIN,
ROLE.CONTENT_CREATOR,
],
},
Expand All @@ -401,6 +434,7 @@ export const API_LIST = {
ROLE.MDO_ADMIN,
ROLE.SPV_ADMIN,
ROLE.CBP_ADMIN,
ROLE.STATE_ADMIN,
ROLE.CONTENT_CREATOR,
],
},
Expand All @@ -411,6 +445,7 @@ export const API_LIST = {
ROLE.CBC_ADMIN,
ROLE.MDO_ADMIN,
ROLE.SPV_ADMIN,
ROLE.STATE_ADMIN,
],
},
'/proxies/v8/discussion/tags': {
Expand All @@ -427,6 +462,7 @@ export const API_LIST = {
ROLE.CBC_ADMIN,
ROLE.MDO_ADMIN,
ROLE.SPV_ADMIN,
ROLE.STATE_ADMIN,
],
},
'/proxies/v8/learnervm/private/content/v3/publish/:do_id': {
Expand Down Expand Up @@ -513,6 +549,7 @@ export const API_LIST = {
ROLE.CBC_ADMIN,
ROLE.MDO_ADMIN,
ROLE.SPV_ADMIN,
ROLE.STATE_ADMIN,
],
},
'/proxies/v8/user/private/v1/migrate': {
Expand Down Expand Up @@ -727,6 +764,7 @@ export const API_LIST = {
ROLE.SPV_ADMIN,
ROLE.CBP_ADMIN,
ROLE.CONTENT_CREATOR,
ROLE.STATE_ADMIN,
],
},
'/protected/v8/user/profileRegistry/getUserRegistryByUser/:id': {
Expand Down Expand Up @@ -767,6 +805,7 @@ export const API_LIST = {
ROLE.WAT_MEMBER,
ROLE.CBC_ADMIN,
ROLE.SPV_ADMIN,
ROLE.STATE_ADMIN,
],
},
'/protected/v8/user/autocomplete/:query': {
Expand Down Expand Up @@ -798,6 +837,7 @@ export const API_LIST = {
ROLE.WAT_MEMBER,
ROLE.CBC_ADMIN,
ROLE.SPV_ADMIN,
ROLE.STATE_ADMIN,
],
},
'/protected/v8/workallocation/getWorkOrders': {
Expand Down Expand Up @@ -1280,10 +1320,10 @@ export const API_LIST = {
],
},
'/reset': {
checksNeeded: [],
checksNeeded: [CHECK.ROLE],
// tslint:disable-next-line: object-literal-sort-keys
ROLE_CHECK: [
ROLE.PUBLIC,
ROLE.PUBLIC, 'ALL',
],
},
'/protected/v8/user/evaluate/assessment/submit/v2': {
Expand Down Expand Up @@ -1728,6 +1768,14 @@ export const API_LIST = {
ROLE.PUBLIC,
],
},
'/proxies/v8/org/ext/v1/create': {
checksNeeded: [CHECK.ROLE],
// tslint:disable-next-line: object-literal-sort-keys
ROLE_CHECK: [
ROLE.SPV_ADMIN,
ROLE.STATE_ADMIN,
],
},
},
URL_PATTERN:
[
Expand All @@ -1739,6 +1787,7 @@ export const API_LIST = {
'/authApi/readCert/:certId',
'/proxies/v8/api/user/v2/read',
'/proxies/v8/api/user/v2/read/:id',
'/proxies/v8/user/v1/updateLogin',
'/proxies/v8/event/v4/read/:do_id',
'/proxies/v8/event/v4/publish/:do_id',
'/proxies/v8/event/v4/create',
Expand Down Expand Up @@ -1783,6 +1832,8 @@ export const API_LIST = {
'/proxies/v8/user/private/v1/assign/role',
'/proxies/v8/user/v1/search',
'/proxies/v8/org/v1/read',
'/proxies/v8/org/v1/profile/read',
'/proxies/v8/org/v1/profile/patch',
'/proxies/v8/org/v1/create',
'/proxies/v8/discussion/tags',
'/proxies/v8/user/v1/block',
Expand Down Expand Up @@ -1958,6 +2009,7 @@ export const API_LIST = {
'/proxies/v8/ratings/v1/upsert',
'/proxies/v8/ratings/v1/summary/:activityId/:activityType',
'/proxies/v8/ratings/v1/ratingLookUp',
'/proxies/v8/user/v1/positions'
'/proxies/v8/user/v1/positions',
'/proxies/v8/org/ext/v1/create',
],
}

0 comments on commit b9144a1

Please sign in to comment.