Skip to content

Commit 7cb567b

Browse files
Merge pull request #172 from jd1378/fix_normalize_find
fix: handle unpaginated find response
2 parents 2ebcb19 + 3577275 commit 7cb567b

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/hooks/6-normalize-find.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ export function normalizeFind() {
2020

2121
next && await next()
2222

23-
if (context.method === 'find' && !context.result?.data) {
23+
// this makes sure it only affects finds that are not paginated and are not custom.
24+
// so the custom find responses fall through.
25+
if (context.method === 'find' && !context.result?.data && Array.isArray(context.result)) {
2426
context.result = {
25-
data: [],
26-
limit: context.params.$limit,
27-
skip: context.params.$skip,
28-
total: 0,
27+
data: context.result,
28+
limit: context.params.$limit || context.result.length,
29+
skip: context.params.$skip || 0,
30+
total: context.result.length,
2931
}
3032
}
3133
}

0 commit comments

Comments
 (0)