F
F
fsamorodov2015-12-17 15:05:41
Ember.js
fsamorodov, 2015-12-17 15:05:41

How to frame response from server via JSONAPIAdapter in Emberjs?

As far as I understood, this adapter uses JSONAPISerializer.
Will the response from the server have the same structure as in the example?

// models/report.js  - отчеты
 export default DS.Model.extend({
     date: attr('string'),
     lists: hasMany('report-list', {
         async: true
     }),
     is_sending: attr('boolean'),
     status: attr('string'),
     checks: attr('number'),
     acquiring: attr('string'),
     cash: attr('string'),
     sent_at: attr('string'),
     status_title: attr('string')
 });

 // models/report-list.js - статьи расходов в отчете

 export default DS.Model.extend({
     summ: DS.attr('string'),
     unit: DS.belongsTo('financial-item', {
         async: true
     }),
     comment: DS.attr('string')
 });

// financial-items  - справочник статей
 export default DS.Model.extend({
     title: DS.attr('string'),
     description: DS.attr('string')
 });

 { //загружаем отчеты   api/reports GET
     "data": [{
         "id": "1",
         "type": "reports",
         "attributes": {
             "date": "21 декабря 2015",
             "is_sending": "true",
             "status": "success",
             "checks": "245",
             "acquiring": "245.00",
             "cash": "1234.00",
             "sent_at": "15:20",
             "status_title": "Отправлено"
         },
         "relationships": {
             "lists": {
                 "data": [{
                     "id": "1",
                     "type": "repost-lists"
                 }]
             }
         }

     }],
     "included": [{
             "id": "1",
             "attributes": {
                 "summ": "23",
                 "comment": "Дал зп"
             },

             "relationships": {
                 "unit": {
                     "data": [{
                         "id": "1",
                         "type": "financial-items"
                     }],
                     "included": [{
                         "id": "1",
                         "attributes": {
                             "title": "1 статья",
                             "description": "Расходы по банку"
                         },
                         "type": "financial-items"
                     }]
                 }
             },
             "type": "report-lists"
     }]
 }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question