Skip to content

Instantly share code, notes, and snippets.

@mickhansen
Created February 17, 2015 09:22
Show Gist options
  • Save mickhansen/6fa68598215479888f18 to your computer and use it in GitHub Desktop.
Save mickhansen/6fa68598215479888f18 to your computer and use it in GitHub Desktop.
var deviceToSave = Device.build({});
Device.findOrCreate({
where: {device_id: deviceToSave.device_id},
defaults: deviceToSave.get()
}).spread(function(device, created) {
if (created) return device;
return device.updateAttributes(deviceToSave.get());
}).then(function (item) {
response.code(201).send(item.get());
}).catch(function(error){
return response.code(400);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment