Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**********************************************
- * EMBER MODELS
- ***********************************************/
- //Account model.
- export default DS.Model.extend({
- email: DS.String('string')
- policy: DS.belongsTo('policy') // one-to-one rel. with Policy model.
- roles: DS.hasMany('role') // one-to-many rel. with Role model.
- });
- // Role model.
- export default DS.Model.extend({
- roleName: DS.attr('string')
- });
- // Policy model.
- export default DS.Model.extend({
- policyNumber: DS.attr('string')
- });
- /**********************************************
- * REST OPERATIONS
- ***********************************************/
- 1. GET /accounts //Get all
- Response:
- {
- accounts: [
- {
- id: 1 // primary key is always called id
- email: '[email protected]'
- policy: 1 // policy foreign key
- roles: [1] // role foreign keys
- },
- {
- id: 1
- accountName: 'test2'
- policy: 2
- roles: [1,2]
- }
- ],
- //Sideloading relationship [Optional]
- roles: [
- {
- id: 1
- roleName: 'superAdmin'
- },
- {
- id: 2
- roleName: 'admin'
- }
- ],
- policy: {
- id: 1
- policyNumber: '9999999'
- }
- }
- 2. GET /accounts/:id
- Response:
- {
- account: {
- id: 1 // primary key is always called id
- email: '[email protected]'
- policy: 1 // policy foreign key
- roles: [1] // role foreign keys
- },
- //Sideloading relationship [Optional]
- roles: [
- {
- id: 1
- roleName: 'superAdmin'
- },
- {
- id: 2
- roleName: 'admin'
- }
- ],
- policy: {
- id: 1
- policyNumber: '9999999'
- }
- }
- 3. POST /accounts
- Request payload:
- {
- account: {
- email: '[email protected]'
- policy: 1 // policy foreign key
- roles: [1] // role foreign keys
- }
- }
- Response payload:
- {
- account: {
- id: 1 // return the id.
- email: '[email protected]'
- policy: 1 // policy foreign key
- roles: [1] // role foreign keys
- }
- }
- 4. PUT /accounts/:id
- Request payload:
- {
- account: {
- id: 1
- email: '[email protected]'
- policy: 1 // policy foreign key
- roles: [1] // role foreign keys
- }
- }
- Response payload:
- {
- account: {
- id: 1
- email: '[email protected]'
- policy: 1 // policy foreign key
- roles: [1] // role foreign keys
- }
- }
- /**********************************************
- * NOTES
- ***********************************************/
- 1. The primary key should always be named "id"
- 2. Foreign key should always be named by model it reference. (Ex: Instead of user_id, should be user)
- 3. Sideloading is optional, if the reference model is not part of the response ember will do GET to retrieve it if required.
Advertisement
Add Comment
Please, Sign In to add comment