Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fb/asset ownership transfer api #345

Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions src/routes/programRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,8 @@ module.exports = function (app) {
app.route(BASE_URL + '/user/:userId')
.delete(requestMiddleware.createAndValidateRequestBody,
userService.deleteUser)

app.route(BASE_URL + '/user/transfer')
.post(requestMiddleware.createAndValidateRequestBody,
userService.transferAssetOfDeleteduser)
}
4 changes: 3 additions & 1 deletion src/service/messageUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,9 @@ exports.USER = {
MISSING_MESSAGE: "User id is not passed in the request",
FAILED_MESSAGE: 'Unable to delete given user',
EXCEPTION_CODE: 'USER_DEL',
INFO: 'Delete User'
INFO: 'Delete User',
OWNERSHIP_TRANSFER_FAIL: "Error on transfering assets",
OWNERSHIP_TRANSFER: "Transfering assets"
}
}

38 changes: 37 additions & 1 deletion src/service/userService.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,42 @@ function deleteOsUser (userDetails, callback) {
return registryService.updateRecord(regReq, callback);
}

async function transferAssetOfDeleteduser(req, response){
logObject['message'] = userMessages.DELETE.OWNERSHIP_TRANSFER
logObject['traceId'] = req.headers['x-request-id'] || '',
loggerService.entryLog(req.body, logObject);
try {
KafkaService.sendRecordWithTopic(req.rspObj.request, envVariables.COKREAT_USER_DELETE_KAFKA_TOPIC, function (err, res) {
if (err) {
handelAssetOwnershiptransfer(req, err);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name is not proper. You are not having the positive scenario here.

User the right method name lik "owershipTransferErrorHandler"

} else{
return response.status(200).send(successResponse(rspObj));
}
});
}catch(err) {
handelAssetOwnershiptransfer(req, err)
}
}

function handelAssetOwnershiptransfer(req, err){
var rspObj = req.rspObj
console.log('User transferAssetOfDeleteduser failed', JSON.stringify(err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these console logs, and user proper logger object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are printing the error log as soon as method hits.

if(err && err.response && err.response.data) {
console.log(`User transferAssetOfDeleteduser err ==> ${req.params.userId} ==>`, JSON.stringify(err.response.data));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User Logger object and remove console.log

}
const errCode = userMessages.DELETE.OWNERSHIP_TRANSFER_FAIL;
rspObj.errCode = userMessages.DELETE.FAILED_CODE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this DELETE.FAILED_CODE?

Check the error messages.

rspObj.errMsg = userMessages.DELETE.FAILED_MESSAGE
rspObj.responseCode = responseCode.SERVER_err
rspObj.result = err;
loggererr(rspObj, errCode);
loggerService.exitLog({responseCode: rspObj.responseCode}, logObject);
return response.status(400).send(errorResponse(rspObj,errCode))

}



function onIndividualUserDeletion (req, response, userDetails) {
const eventData = generateDeleteUserEvent (req, response, userDetails, []);
try {
Expand Down Expand Up @@ -366,4 +402,4 @@ function onOrgUserDeletion(req, response, userDetails) {
});
}

module.exports = { getSunbirdUserProfiles, deleteUser }
module.exports = { getSunbirdUserProfiles, deleteUser, transferAssetOfDeleteduser }