diff --git a/controllers/v1/assets.js b/controllers/v1/assets.js index 0d026e8d..50df619b 100644 --- a/controllers/v1/assets.js +++ b/controllers/v1/assets.js @@ -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); + } + }); + } }; diff --git a/generics/constants/api-responses.js b/generics/constants/api-responses.js index 7e7331a4..93e53e46 100644 --- a/generics/constants/api-responses.js +++ b/generics/constants/api-responses.js @@ -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" }; diff --git a/module/assets/helper.js b/module/assets/helper.js index 22cd2414..efa1d16b 100644 --- a/module/assets/helper.js +++ b/module/assets/helper.js @@ -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( @@ -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 ( @@ -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, @@ -692,7 +697,7 @@ module.exports = class AssetsHelper { }); } else { return resolve({ - success: true, + success: false, }); } } catch (error) {