Guest User

Untitled

a guest
Mar 29th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1.  
  2. /**********************************************
  3. * EMBER MODELS
  4. ***********************************************/
  5.  
  6. //Account model.
  7. export default DS.Model.extend({
  8. email: DS.String('string')
  9. policy: DS.belongsTo('policy') // one-to-one rel. with Policy model.
  10. roles: DS.hasMany('role') // one-to-many rel. with Role model.
  11. });
  12.  
  13. // Role model.
  14. export default DS.Model.extend({
  15. roleName: DS.attr('string')
  16. });
  17.  
  18. // Policy model.
  19. export default DS.Model.extend({
  20. policyNumber: DS.attr('string')
  21. });
  22.  
  23. /**********************************************
  24. * REST OPERATIONS
  25. ***********************************************/
  26. 1. GET /accounts //Get all
  27.  
  28. Response:
  29.  
  30. {
  31. accounts: [
  32. {
  33. id: 1 // primary key is always called id
  34. policy: 1 // policy foreign key
  35. roles: [1] // role foreign keys
  36. },
  37. {
  38. id: 1
  39. accountName: 'test2'
  40. policy: 2
  41. roles: [1,2]
  42. }
  43. ],
  44.  
  45. //Sideloading relationship [Optional]
  46.  
  47. roles: [
  48. {
  49. id: 1
  50. roleName: 'superAdmin'
  51. },
  52. {
  53. id: 2
  54. roleName: 'admin'
  55. }
  56. ],
  57.  
  58. policy: {
  59. id: 1
  60. policyNumber: '9999999'
  61. }
  62. }
  63.  
  64. 2. GET /accounts/:id
  65.  
  66. Response:
  67.  
  68. {
  69. account: {
  70. id: 1 // primary key is always called id
  71. policy: 1 // policy foreign key
  72. roles: [1] // role foreign keys
  73. },
  74.  
  75. //Sideloading relationship [Optional]
  76.  
  77. roles: [
  78. {
  79. id: 1
  80. roleName: 'superAdmin'
  81. },
  82. {
  83. id: 2
  84. roleName: 'admin'
  85. }
  86. ],
  87.  
  88. policy: {
  89. id: 1
  90. policyNumber: '9999999'
  91. }
  92. }
  93.  
  94. 3. POST /accounts
  95.  
  96. Request payload:
  97.  
  98. {
  99. account: {
  100. policy: 1 // policy foreign key
  101. roles: [1] // role foreign keys
  102. }
  103. }
  104.  
  105. Response payload:
  106.  
  107. {
  108. account: {
  109. id: 1 // return the id.
  110. policy: 1 // policy foreign key
  111. roles: [1] // role foreign keys
  112. }
  113. }
  114.  
  115. 4. PUT /accounts/:id
  116.  
  117. Request payload:
  118.  
  119. {
  120. account: {
  121. id: 1
  122. policy: 1 // policy foreign key
  123. roles: [1] // role foreign keys
  124. }
  125. }
  126.  
  127. Response payload:
  128.  
  129. {
  130. account: {
  131. id: 1
  132. policy: 1 // policy foreign key
  133. roles: [1] // role foreign keys
  134. }
  135. }
  136.  
  137. /**********************************************
  138. * NOTES
  139. ***********************************************/
  140.  
  141. 1. The primary key should always be named "id"
  142. 2. Foreign key should always be named by model it reference. (Ex: Instead of user_id, should be user)
  143. 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