Skip to content
This repository was archived by the owner on Jul 5, 2022. It is now read-only.

Commit f71e05d

Browse files
committed
fix: empty list should not be handled as object
1 parent 5d97df2 commit f71e05d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/jsonapi.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function links(req, res, baseUrl) {
2222
const body = res.body
2323

2424
// resource objects
25-
if (_.isArray(body.data) && body.data.length > 0) {
25+
if (_.isArray(body.data)) {
2626
body.data.forEach(document => {
2727
document.links = documentLinks(req, baseUrl, document)
2828
if (document.relationships) {
@@ -48,10 +48,12 @@ function links(req, res, baseUrl) {
4848
}
4949

5050
// body
51-
if (_.isArray(body.data) && body.data.length > 0) {
52-
const type = body.data[0].type
53-
return {
54-
self: `${req.protocol}://${req.get('host')}${baseUrl}/${pluralize(type)}`
51+
if (_.isArray(body.data)) {
52+
if (body.data.length > 0) {
53+
const type = body.data[0].type
54+
return {
55+
self: `${req.protocol}://${req.get('host')}${baseUrl}/${pluralize(type)}`
56+
}
5557
}
5658
} else if (_.isObject(res.body.data)) {
5759
const {id, type} = res.body.data

0 commit comments

Comments
 (0)