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

feat:ownership transfer api #188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
77 changes: 77 additions & 0 deletions controllers/v1/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,81 @@ module.exports = class Assets {
}
});
}

/**
* Transfer ownership of assets(program and solution).
* @name ownershipTransfer
* @api {get} /kendra/api/v1/assets/ownershipTransfer
* @apiHeader {String} X-authenticated-user-token Authenticity token
* @apiSampleRequest v1/assets/ownershipTransfer
* @apiParamExample {Object:} Request-Body:
{
"action": "ownership-transfer",
"organisationId": "01269934121990553633",
"context": "Ownership Transfer",
"actionBy": {
"userId": "86d2d978-5b20-4453-8a76-82b5a4c728c9",
"userName": ""
},
"toUserProfile": {
"userId": "3b200146-5c0c-4e95-ae06-dacb89460d99",
"userName": "sdfsdsd",
"channel": "",
"organisationId": "",
"roles": [
"CONTENT_CREATOR",
"PROGRAM_MANAGER",
"PROGRAM_DESIGNER"
]
},
"fromUserProfile": {
"userId": "fca2925f-1eee-4654-9177-fece3fd6afc9",
"userName": "test",
"firstName": "test",
"lastName": "",
"roles": [
"PROGRAM_DESIGNER"


]

},
"assetInformation": {
"objectType": "Program",
"identifier": "62205480a81abe61c07e5058"
},
"iteration": 1
}
* @apiUse successBody
* @apiUse errorBody
* @apiParamExample {json} Response:
{
"message": "Ownership transfered successfully",
"status": 200
}
*/

ownershipTransfer(req){
return new Promise(async (resolve, reject) => {
try{
let transferOwnerShipStatus = await assetsHelper.ownershipTransfer(
req.body
);
if ( !transferOwnerShipStatus.success ) {
return resolve({
status: httpStatusCode.bad_request.status,
message: constants.apiResponses.OWNERSHIP_TANSFER_FAILED
})
}else {
return resolve({
status: httpStatusCode.ok.status,
message: constants.apiResponses.OWNERSHIP_TANSFER_SUCCESS,
success: true
})
}
}catch(error){
console.log(error);
}
});
}
};
4 changes: 3 additions & 1 deletion generics/constants/api-responses.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,7 @@ module.exports = {
"KEYS_INDEXED_SUCCESSFULLY": 'Keys indexed successfully',
"KEYS_ALREADY_INDEXED": 'Keys already indexed',
"ASSETS_FETCHED_SUCCESSFULLY": "Assets fetched successfully ",
"FAILED_TO_FETCH_ASSETS": "Failed to fetch assets"
"FAILED_TO_FETCH_ASSETS": "Failed to fetch assets",
"OWNERSHIP_TANSFER_SUCCESS":"Ownership transfered successfully",
"OWNERSHIP_TANSFER_FAILED":"Ownership transfered failed"
};
13 changes: 9 additions & 4 deletions module/assets/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@ module.exports = class AssetsHelper {
* @returns {Promise} success Data.
*/
static ownershipTransfer(ownershipTransferEvent) {

return new Promise(async (resolve, reject) => {
try {
let reqData = ownershipTransferEvent.edata;
let reqData = ownershipTransferEvent;

//
let updateUserAssetDataResult = false;
//Check if the users has identical Role or not, and return boolean
let checkUsersRoleAreIdentical = await this.checkRolesPresence(
Expand All @@ -134,7 +137,7 @@ module.exports = class AssetsHelper {
reqData.assetInformation ? reqData.assetInformation.objectType : "" // "Program" or "Soultion"
);
if (checkUsersRoleAreIdentical) {
let hasAssetInformation = reqData.hasOwnProperty("assetInformation");
let hasAssetInformation = reqData.hasOwnProperty("assetInformation");
//condition for if there is no assetInformation in ownershipTransferEvent
if (!hasAssetInformation) {
if (
Expand Down Expand Up @@ -252,12 +255,14 @@ module.exports = class AssetsHelper {
edata of Event
//return
promise
*/
*/
let transferResult = await this.transferPlatformRoles(
fromUserData,
toUserData,
reqData
);

//
if (!transferResult.success) {
throw {
message: constants.apiResponses.PROGRAM_TRANSFER_FAILED,
Expand Down Expand Up @@ -692,7 +697,7 @@ module.exports = class AssetsHelper {
});
} else {
return resolve({
success: true,
success: false,
});
}
} catch (error) {
Expand Down