Skip to content

Commit

Permalink
Merge pull request #8 from sunbird-cb/4.8.11-retireFix
Browse files Browse the repository at this point in the history
Retire API fix for draft courses
  • Loading branch information
karthik-tarento authored Mar 20, 2024
2 parents 61f4914 + 20ffd9d commit 0894f13
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/service/contentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var contentMessage = messageUtils.CONTENT
var compositeMessage = messageUtils.COMPOSITE
var responseCode = messageUtils.RESPONSE_CODE
var reqMsg = messageUtils.REQUEST
var reqMsgRetire = messageUtils.DOMAIN

/**
* This function helps to generate code for create course
Expand Down Expand Up @@ -993,7 +994,7 @@ function retireContentAPI (req, response) {
function (res, CBW) {
var createdByOfContents = _.uniq(_.pluck(res.result.content, 'createdBy'))
if (createdByOfContents.length === 1 && createdByOfContents[0] === userId) {
CBW()
CBW(null, res)
} else {
rspObj.errCode = reqMsg.TOKEN.INVALID_CODE
rspObj.errMsg = reqMsg.TOKEN.INVALID_MESSAGE
Expand All @@ -1002,6 +1003,18 @@ function retireContentAPI (req, response) {
}
},

function (res, CBW) {
var status = _.uniq(_.pluck(res.result.content, 'status'))
if (status.length === 1 && status[0] === 'Draft') {
CBW()
} else {
rspObj.errCode = reqMsgRetire.RETIRE_OBJECT_TYPE.RETIRE_ONLY_DRAFT_CODE
rspObj.errMsg = reqMsgRetire.RETIRE_OBJECT_TYPE.RETIRE_ONLY_DRAFT_MESSAGE
rspObj.responseCode = responseCode.CLIENT_ERROR
return response.status(400).send(respUtil.errorResponse(rspObj))
}
},

function (CBW) {
async.each(data.request.contentIds, function (contentId, CBE) {
logger.debug({
Expand Down
4 changes: 3 additions & 1 deletion src/service/messageUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@ exports.DOMAIN = {
MISSING_CODE: 'ERR_RETIRE_OBJECT_TYPE_FIELDS_MISSING',
MISSING_MESSAGE: 'Required fields for retire object type are missing',
FAILED_CODE: 'ERR_RETIRE_OBJECT_TYPE_FAILED',
FAILED_MESSAGE: 'Retire object type failed'
FAILED_MESSAGE: 'Retire object type failed',
RETIRE_ONLY_DRAFT_CODE: 'ERR_RETIRE_OBJECT_FAILED_DRAFT',
RETIRE_ONLY_DRAFT_MESSAGE: 'Status should be draft to retire'
}
}

Expand Down

0 comments on commit 0894f13

Please sign in to comment.