Skip to content

Instantly share code, notes, and snippets.

@wesleytodd
Last active January 19, 2016 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesleytodd/1b386885186bce9ed358 to your computer and use it in GitHub Desktop.
Save wesleytodd/1b386885186bce9ed358 to your computer and use it in GitHub Desktop.
var http = require('v-http');
module.exports = function updateAccount (acct) {
return new Promise(function (resolve, reject) {
http({
method: 'PUT',
url: '/api-user/v1/me',
data: {
username: acct.username,
displayName: acct.displayName,
email: acct.email,
location: acct.location,
birthdate: acct.birthdate,
gender: acct.gender
}
}, function (err, resp) {
if (err) {
return reject({
type: 'updateAccountError',
error: {
message: err.message,
code: 'update-account-error',
level: 'error'
}
});
}
if (resp.statusCode >= 400) {
return reject({
type: 'updateAccountError',
error: {
message: 'Failed to update account',
code: 'update-account-error',
level: 'error'
}
});
}
resolve({
type: 'updateAccount',
user: resp.data
});
});
});
};
var defaultAction = require('v-default-action');
module.exports = function updateAccount (acct) {
return defaultAction({
method: 'PUT',
url: '/api-user/v1/me',
data: {
username: acct.username,
displayName: acct.displayName,
email: acct.email,
location: acct.location,
birthdate: acct.birthdate,
gender: acct.gender
}
}, function (err, resp) {
if (err || resp.statusCode >= 400) {
return defaultError(err, resp, 'updateAccountError', 'Failed to update Account');
}
return {
type: 'updateAccount',
user: resp.data
};
});
};
var http = require('v-http');
var defaultError = require('v-default-error');
module.exports = function updateAccount (acct) {
return new Promise(function (resolve, reject) {
http({
method: 'PUT',
url: '/api-user/v1/me',
data: {
username: acct.username,
displayName: acct.displayName,
email: acct.email,
location: acct.location,
birthdate: acct.birthdate,
gender: acct.gender
}
}, function (err, resp) {
if (err || resp.statusCode >= 400) {
return reject(defaultError(err, resp, 'updateAccountError', 'Failed to update Account'));
}
resolve({
type: 'updateAccount',
user: resp.data
});
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment