Skip to content

Commit

Permalink
Merge pull request #17 from sunbird-cb/4.8.16-dev
Browse files Browse the repository at this point in the history
4.8.16 dev
  • Loading branch information
karthik-tarento authored Jul 31, 2024
2 parents 0894f13 + 66800cc commit c17dcc3
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/config/contentProviderApiConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"FRAMEWORK_TERM_SEARCH_URI": "/framework/v3/term/search",
"FRAMEWORK_TERM_CREATE_URI": "/framework/v3/term/create",
"FRAMEWORK_TERM_UPDATE_URI": "/framework/v3/term/update",
"FRAMEWORK_Term_Retire_URI": "/framework/v3/term/retire",

"FRAMEWORK_CATEGORY_INSTANCE_URI": "/framework/v3/category/read",
"FRAMEWORK_CATEGORY_INSTANCE_SEARCH_URI": "/framework/v3/category/search",
Expand Down
2 changes: 1 addition & 1 deletion src/libs
6 changes: 6 additions & 0 deletions src/routes/frameworkTermRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ module.exports = function (app) {
.patch(healthService.checkDependantServiceHealth(dependentServiceHealth),
requestMiddleware.gzipCompression(),
requestMiddleware.createAndValidateRequestBody, frameworkTermService.frameworkTermUpdate)

app.route(baseUrl + '/retire')
.post(healthService.checkDependantServiceHealth(dependentServiceHealth),
requestMiddleware.gzipCompression(),
requestMiddleware.createAndValidateRequestBody, frameworkTermService.frameworkTermRetire)

}
81 changes: 80 additions & 1 deletion src/service/frameworkTermService.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var ekStepUtil = require('sb_content_provider_util')
var logger = require('sb_logger_util_v2')
var messageUtils = require('./messageUtil')
var utilsService = require('../service/utilsService')

var contentMessage = messageUtils.CONTENT
var filename = path.basename(__filename)
var responseCode = messageUtils.RESPONSE_CODE

Expand Down Expand Up @@ -231,7 +231,86 @@ function frameworkTermUpdate (req, response) {
])
}


function frameworkTermRetire(req, response) {
var data = req.body;
var rspObj = req.rspObj;
data.queryParams = req.query;
var failedContent = [];
var userId = req.headers['x-authenticated-userid'];
var errCode, errMsg, respCode, httpStatus;

logger.debug({
msg: 'frameworkTermService.frameworkTermRetire() called', additionalInfo: { rspObj }
}, req);

if (!data.request || !data.request.contentIds) {
rspObj.errCode = contentMessage.RETIRE.MISSING_CODE;
rspObj.errMsg = contentMessage.RETIRE.MISSING_MESSAGE;
rspObj.responseCode = responseCode.CLIENT_ERROR;
logger.error({
msg: 'Error due to required request || request.contentIds are missing',
err: {
errCode: rspObj.errCode,
errMsg: rspObj.errMsg,
responseCode: rspObj.responseCode
},
additionalInfo: { data }
}, req);
return response.status(400).send(respUtil.errorResponse(rspObj));
}

async.each(data.request.contentIds, function (contentId, CBE) {
logger.debug({
msg: 'Request to retire the term',
additionalInfo: { contentId: contentId }
}, req);

// Adding objectData in telemetry
if (rspObj.telemetryData) {
rspObj.telemetryData.object = utilsService.getObjectData(contentId, 'term', '', {});
}

ekStepUtil.frameworkTermRetire(contentId, req.headers, data.queryParams, function (err, res) {
if (err || res.responseCode !== responseCode.SUCCESS) {
errCode = res && res.params ? res.params.err : contentMessage.GET_MY.FAILED_CODE;
errMsg = res && res.params ? res.params.errmsg : contentMessage.GET_MY.FAILED_MESSAGE;
respCode = res && res.responseCode ? res.responseCode : responseCode.SERVER_ERROR;
logger.error({
msg: 'Getting error from framework term provider while retiring term',
err: {
err,
errCode: rspObj.errCode,
errMsg: rspObj.errMsg,
responseCode: rspObj.responseCode
},
additionalInfo: { contentId }
}, req);
httpStatus = res && res.statusCode >= 100 && res.statusCode < 600 ? res.statusCode : 500;
rspObj.result = res && res.result ? res.result : {};
failedContent.push({ contentId: contentId, errCode: errCode, errMsg: errMsg });
}
CBE(null, null);
});
}, function () {
if (failedContent.length > 0) {
rspObj.errCode = errCode;
rspObj.errMsg = errMsg;
rspObj.responseCode = respCode;
rspObj.result = failedContent;
return response.status(httpStatus).send(respUtil.errorResponse(rspObj));
} else {
rspObj.result = failedContent;
logger.debug({ msg: 'Sending response back to user', res: rspObj }, req);
return response.status(200).send(respUtil.successResponse(rspObj));
}
});
}



module.exports.getFrameworkTerm = getFrameworkTerm
module.exports.frameworkTermSearch = frameworkTermSearch
module.exports.frameworkTermCreate = frameworkTermCreate
module.exports.frameworkTermUpdate = frameworkTermUpdate
module.exports.frameworkTermRetire = frameworkTermRetire

0 comments on commit c17dcc3

Please sign in to comment.