| 13 | |
| 14 | // Embed function used in GET /name and GET /name/id |
| 15 | function embed(resource, e) { |
| 16 | e && |
| 17 | [].concat(e).forEach((externalResource) => { |
| 18 | if (db.get(externalResource).value) { |
| 19 | const query = {} |
| 20 | const singularResource = pluralize.singular(name) |
| 21 | query[`${singularResource}${opts.foreignKeySuffix}`] = resource.id |
| 22 | resource[externalResource] = db |
| 23 | .get(externalResource) |
| 24 | .filter(query) |
| 25 | .value() |
| 26 | } |
| 27 | }) |
| 28 | } |
| 29 | |
| 30 | // Expand function used in GET /name and GET /name/id |
| 31 | function expand(resource, e) { |