Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions sunbird-self-creation-portal/constants/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@
*/

module.exports = {
PROJECT_STATUS_PUBLISHED: 'published',
PROJECT_PROJECTION_FIELDS: ['_id', 'title', 'createdBy', 'createdAt', 'description'],
RESOURCE_TYPE_PROJECT: 'projects',
PROJECT_TRANSFORM_KEYS: {
_id: 'id',
createdAt: 'created_at',
createdBy: 'created_by',
},
AUTH_TOKEN_KEY: 'X-auth-token',
AUTH_TOKEN_KEY: 'x-authenticated-user-token',
HEADER_CONTENT_TYPE: 'content-type',
INTERNAL_ACCESS_TOKEN: 'internal-access-token',
}
39 changes: 18 additions & 21 deletions sunbird-self-creation-portal/controllers/scp.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,12 @@ const accountList = async (req, res, selectedConfig) => {
body.request.filters.id = userIds
}

if (req.query.organisation_id) {
body.request.filters['organisations.organisationId'] = req.query.organisation_id
if (req.query.organization_id) {
body.request.filters['organisations.organisationId'] = req.query.organization_id
}

if (req.query.organisation_code) {
body.request.filters['organisations.organisationId'] = req.query.organisation_code
if (req.query.organization_code) {
body.request.filters['organisations.organisationId'] = req.query.organization_code
}

if (req.query.type && req.query.type != 'all') {
Expand All @@ -362,11 +362,6 @@ const accountList = async (req, res, selectedConfig) => {
body.request['limit'] = parseInt(req.query.limit)
}

if (process.env.DEBUG_MODE == 'true') {
console.log('------- ================ -------', req.body)
console.log(body, 'Req body')
}

// Format token removes "Bearer " if present at the start
const authToken = req.headers['x-auth-token'] || ''
const cleanToken = authToken.replace(/^bearer\s+/i, '')
Expand All @@ -376,8 +371,13 @@ const accountList = async (req, res, selectedConfig) => {
Authorization: `Bearer ${process.env.SUNBIRD_BEARER_TOKEN}`, // Authorization token from environment variables
'x-authenticated-user-token': cleanToken,
})
console.log(userSearchResponse, 'userSearchResponse')
console.log(cleanToken, body, 'Req body')

if (process.env.DEBUG_MODE == 'true') {
console.log('------- ================ -------', req.body)
console.log(body, 'Req body---')
console.log(userSearchResponse, 'userSearchResponse')
console.log(cleanToken, 'Token')
}

if (userSearchResponse?.responseCode != 'OK') {
throw new Error('User Search Failed')
Expand Down Expand Up @@ -426,11 +426,6 @@ const organizationList = async (req, res, selectedConfig) => {
body.request['limit'] = parseInt(req.query.limit)
}

if (process.env.DEBUG_MODE == 'true') {
console.log('------- ================ -------', req.body)
console.log(body, 'Req body')
}

// Format token removes "Bearer " if present at the start
const authToken = req.headers['x-auth-token'] || ''
const cleanToken = authToken.replace(/^bearer\s+/i, '')
Expand All @@ -440,18 +435,21 @@ const organizationList = async (req, res, selectedConfig) => {
Authorization: `Bearer ${process.env.SUNBIRD_BEARER_TOKEN}`, // Authorization token from environment variables
'x-authenticated-user-token': cleanToken,
})
console.log(orgSearchResponse, 'orgSearchResponse')
console.log(cleanToken, body, 'Req body')

if (process.env.DEBUG_MODE == 'true') {
console.log('------- ================ -------', req.body)
console.log(body, 'Req body')
console.log(orgSearchResponse, 'orgSearchResponse')
console.log(cleanToken, body, 'Req body')
}

if (orgSearchResponse?.responseCode != 'OK') {
throw new Error('User Search Failed')
}

let data = processOrgSearchResponse(orgSearchResponse.result.response.content) || []
// return res.json(orgSearchResponse)
return res.json({ result: data?.result })
} catch (error) {
console.log(error, 'error')
if (process.env.DEBUG_MODE == 'true') {
console.error('Error fetching user details:', error)
}
Expand All @@ -465,7 +463,6 @@ const processOrgSearchResponse = (content) => {
}
return {
result: content.map((org) => {
console.log(org, 'org')
return {
id: org.id,
name: org?.orgName,
Expand Down