Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request js-data#4 from nickescallon/pass-meta-to-findAll
Browse files Browse the repository at this point in the history
fix(findAll): passes response metadata to findAll
  • Loading branch information
jmdobry authored Aug 11, 2016
2 parents 43c5702 + bd796a0 commit e4d335f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ Component.extend({
*/
find (mapper, id, opts) {
let record, op
let meta = {}
opts || (opts = {})
opts.with || (opts.with = [])

Expand All @@ -859,11 +860,12 @@ Component.extend({
return utils.resolve(this._find(mapper, id, opts))
})
.then((results) => {
let [_record] = results
let [_record, _meta] = results
if (!_record) {
return
}
record = _record
meta = _meta
const tasks = []

utils.forEachRelation(mapper, opts, (def, __opts) => {
Expand All @@ -889,7 +891,7 @@ Component.extend({
return utils.Promise.all(tasks)
})
.then(() => {
let response = new Response(record, {}, 'find')
let response = new Response(record, meta, 'find')
response.found = record ? 1 : 0
response = this.respond(response, opts)

Expand Down Expand Up @@ -924,6 +926,7 @@ Component.extend({
opts.with || (opts.with = [])

let records = []
let meta = {}
let op
const activeWith = opts._activeWith

Expand All @@ -945,9 +948,10 @@ Component.extend({
return utils.resolve(this._findAll(mapper, query, opts))
})
.then((results) => {
let [_records] = results
let [_records, _meta] = results
_records || (_records = [])
records = _records
meta = _meta
const tasks = []
utils.forEachRelation(mapper, opts, (def, __opts) => {
let task
Expand All @@ -971,7 +975,7 @@ Component.extend({
return utils.Promise.all(tasks)
})
.then(() => {
let response = new Response(records, {}, 'findAll')
let response = new Response(records, meta, 'findAll')
response.found = records.length
response = this.respond(response, opts)

Expand Down

0 comments on commit e4d335f

Please sign in to comment.