Skip to content

Commit

Permalink
Route ok
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaireLozano committed Jul 19, 2018
1 parent b61fa5d commit 89f787f
Showing 1 changed file with 33 additions and 30 deletions.
63 changes: 33 additions & 30 deletions lib/api.transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,32 @@

var RestUtil = require('./util');

var TransferConstants = require('oae-transfer/lib/constants').TransferConstants;


////////////////////
// TRANSFER //
////////////////////

/**
* Create a transfer.
* Initiate a transfer.
*
* @param {RestContext} restCtx Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in.
* @param {String} originalEmail The user email
* @param {String} targetEmail The new email
* @param {String} originalUserId The id of the user who create the transfer
* @param {RestContext} RestContext Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in.
* @param {String} originalEmail The email of the account from which the data will be transferred
* @param {String} targetEmail The email of the account to which the data will be transferred
* @param {String} originalUserId The account identifier from which the data will be transferred
* @param {Function} callback Standard callback function
* @param {Object} callback.err An error that occurred, if any
* @param {Transfer} callback.transfer The transfer that was created
*/
var createTransfer = module.exports.createTransfer = function(RestContext, originalUserId, originalEmail, targetEmail, callback) {
var initiateTransfer = module.exports.initiateTransfer = function(RestContext, originalUserId, originalEmail, targetEmail, callback) {
var params = {
'originalUserId': originalUserId,
'originalEmail': originalEmail,
'targetEmail': targetEmail
};

RestUtil.RestRequest(RestContext, '/api/transfer/create', 'post', params, function(err, transfer) {
RestUtil.RestRequest(RestContext, '/api/transfer', 'post', params, function(err, transfer) {
if (err) {
return callback(err);
}
Expand All @@ -49,14 +51,14 @@ var createTransfer = module.exports.createTransfer = function(RestContext, origi
/**
* Get a transfer by Id.
*
* @param {RestContext} restCtx Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in.
* @param {String} originalUserId The id of the user who created the transfer
* @param {RestContext} RestContext Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in.
* @param {String} originalUserId The account identifier from which the data will be transferred
* @param {Function} callback Standard callback function
* @param {Object} callback.err An error that occurred, if any
* @param {Transfer} callback.transfer The transfer that was created
*/
var getTransferById = module.exports.getTransferById = function(RestContext, originalUserId, callback) {
RestUtil.RestRequest(RestContext, '/api/transfer/getTransferById/'+ RestUtil.encodeURIComponent(originalUserId), 'get', {'originalUserId' : originalUserId} , function(err, transfer) {
RestUtil.RestRequest(RestContext, '/api/transfer/' + RestUtil.encodeURIComponent(originalUserId), 'get', {'originalUserId' : originalUserId} , function(err, transfer) {
if (err) {
return callback(err);
}
Expand All @@ -65,26 +67,26 @@ var getTransferById = module.exports.getTransferById = function(RestContext, ori
};

/**
* Make a transfer.
* Complete a transfer.
*
* @param {RestContext} restCtx Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in.
* @param {String} originalEmail The user email
* @param {String} code The generated code
* @param {String} targetEmail The new email
* @param {String} targetUserId The id new user
* @param {RestContext} RestContext Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in.
* @param {String} originalEmail The email of the account from which the data will be transferred
* @param {String} code The code used by the user to secure the transfer
* @param {String} targetEmail The email of the account to which the data will be transferred
* @param {String} targetUserId The identifier of the account to which the data will be transferred
* @param {Function} callback Standard callback function
* @param {Object} callback.err An error that occurred, if any
* @param {Transfer} callback.transfer The transfer that was created
*/
var makeTransfer = module.exports.makeTransfer = function(RestContext, originalEmail, code, targetEmail, targetUserId, callback) {
var completeTransfer = module.exports.completeTransfer = function(RestContext, originalEmail, code, targetEmail, targetUserId, callback) {
var params = {
'originalEmail': originalEmail,
'code': code,
'targetEmail': targetEmail,
'targetUserId': targetUserId
'status': TransferConstants.status.COMPLETED
};

RestUtil.RestRequest(RestContext, '/api/transfer/makeTransfer', 'post', params, function(err, managers) {
RestUtil.RestRequest(RestContext, '/api/transfer/' + targetUserId, 'put', params, function(err, managers) {
if (err) {
return callback(err);
}
Expand All @@ -93,26 +95,27 @@ var makeTransfer = module.exports.makeTransfer = function(RestContext, originalE
};

/**
* Delete a transfer.
* Cancel a transfer.
*
* @param {RestContext} restCtx Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in.
* @param {String} originalEmail The user email
* @param {String} code The generated code
* @param {String} originalUserId The id user
* @param {RestContext} RestContext Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in.
* @param {String} originalEmail The email of the account from which the data will be transferred
* @param {String} code The code used by the user to secure the transfer
* @param {String} originalUserId The account identifier from which the data will be transferred
* @param {Function} callback Standard callback function
* @param {Object} callback.err An error that occurred, if any
* @param {Transfer} callback.transfer The transfer that was created
*/
var deleteTransfer = module.exports.deleteTransfer = function(RestContext, originalEmail, code, originalUserId, callback) {
var cancelTransfer = module.exports.cancelTransfer = function(RestContext, originalEmail, code, originalUserId, callback) {
var params = {
'originalEmail': originalEmail,
'code': code,
'originalUserId': originalUserId
'originalUserId': originalUserId,
'status': TransferConstants.status.CANCELED
};
RestUtil.RestRequest(RestContext, '/api/transfer/deleteTransfer', 'POST', params, function(err) {

RestUtil.RestRequest(RestContext, '/api/transfer/' + originalUserId, 'put', params, function(err) {
if (err) {
return callback(err);
}
return callback(null);
return callback();
});
};

0 comments on commit 89f787f

Please sign in to comment.