Last active
August 29, 2015 14:15
-
-
Save identor/b07898de42fc3e376153 to your computer and use it in GitHub Desktop.
Recipe for Employee CRUD methods.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Get: all */ | |
Employee.query( | |
function success(employees, httpResponse) {}, | |
function error(error) {} | |
); | |
/* Query specify parameter. Resoves to /api/employees?firstName=Irvin123 */ | |
Employee.query({firstName: 'Irvin123'}, function success(data) { | |
console.log(data); | |
}); | |
/* Get /:id */ | |
Employee.get({ id: '3' }, | |
function success(employee, httpResponse) { | |
console.log({employee: employee, httpResponse: httpResponse}); | |
}, | |
function error(error) { | |
console.log(error.data); | |
console.log(error.status); | |
} | |
); | |
/* Creatin an Employee */ | |
var test = new Employee( | |
{ | |
firstName: 'Test', | |
lastName: 'User', | |
middleName: '123', | |
email: '[email protected]', | |
gender: 'Female', | |
username: 'testUser', | |
password: '12345', | |
admin: true | |
} | |
); | |
test.$save(function success(data, httpResponse) { | |
console.log(data, httpResponse); | |
}, function error(errorData) { | |
console.log(errorData); | |
} | |
); | |
/* Updating an Employee */ | |
Employee.get({id: '4'}, function success(data) { | |
data.firstName = 'Test Again 123'; | |
data.$save(function success(data) { | |
console.log(data); | |
}, function error(error) { | |
console.log(error); | |
}); | |
}); | |
/* OR Using the update function */ | |
Employee.update({id: '4'}, {firstName: 'Update FirstName'}, function success(data) { | |
console.log(data); | |
}, function error(error) { | |
console.log(error); | |
} | |
); | |
/* Deleting an Employee Record */ | |
Employee.delete({id: '4'}, function success(data) { | |
console.log(data); | |
}, function error(error) { | |
console.log(error); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment