Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.update = function (customer, callback) {
console.log('update customer:', customer);
var err = Customer.update(customer);
if (err) {
console.error('There was an error!', err);
callback(err, null);
return;
}
callback(null, 'Success!');
// Let other sockets know the customer was updated.
socket.broadcast.emit('customer updated', customer);
};
this.create = function (customer, callback) {
console.log('new customer:', customer);
// TODO: Need to handle failures in saving.
var cust = Customer.create({
name: customer.name,
email: customer.email
});
var err;
if (err) {
console.error('There was an error!', err);
callback(err, null);
return;
}
callback(null, cust);
// Let other sockets know the customer was created.
socket.broadcast.emit('customer created', cust);
};
this.destroy = function (id, callback) {
console.log('delete customer:', id);
var err = Customer.destroy(id);
if (err) {
console.error('There was an error!', err);
callback(err, null);
return;
}
callback(null, 'Success!');
// Let other sockets know the customer was destroyed.
socket.broadcast.emit('customer destroyed', id);
};
function (err, message) {
console.log('UPDATE!');
if (err) {
console.error(err);
// TODO: Handle errors...
}
this.updateCustomer(customer);
}.bind(this)
);