Skip to content

Instantly share code, notes, and snippets.

@alduro
Last active December 28, 2015 03:28
Show Gist options
  • Save alduro/7434877 to your computer and use it in GitHub Desktop.
Save alduro/7434877 to your computer and use it in GitHub Desktop.
AddressController.setDefault = function () {
var this_ = this;
var addressId = this_.params('id');
if (!this.req.isAuthenticated()) { return this.res.json(generateResponse(false, 'Cant Get Addresses, Not Logged In' , null)) };
var conditions = { userId: this.req.user.id,
id: addressId }
Addresses.find({ where: conditions })
.success(function (address) {
address.def = 1;
address.save().success(function() {
Addresses.update({ 'def': 0 }, { where: [ "id <> ?", addressId ] } ).success(function() {
this_.res.json(generateResponse(true, 'Address set up as default', addressId))
}).error(function(error) {
console.log(' Error updatind Address ');
console.log(error);
this_.res.json(generateResponse(false, 'Error setting up Address as default', error))
});
}).error(function(error) {
this_.res.json(generateResponse(false, 'Error setting up Address as default', error))
});
})
.error(function (error) {
this_.res.json(generateResponse(false, 'Error setting up Address as default', error))
})
Executing: UPDATE `Addresses` SET `firstName`='Aldo',`lastName`='Nievas',`street1`='Moldes 2678 piso 3 depto 7',`street2`=NULL,`city`='CABA',`state`='BA',`zip`=12345,`zipExtra`=NULL,`country`='United States',`phone`=2147483647,`userId`=101,`def`=1,`id`=101,`createdAt`='2013-11-12 15:59:10',`updatedAt`='2013-11-12 17:26:46' WHERE `id`=101
Error updatind Address
{ firstName: [ 'String is empty' ],
lastName: [ 'String is empty' ],
street1: [ 'String is empty' ],
city: [ 'String is empty' ],
state: [ 'String is empty' ],
zip: [ 'must have 5 characters' ],
phone: [ 'String is empty' ],
userId: [ 'String is empty' ] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment