Skip to content

Commit

Permalink
fix: handle unpaginated find response
Browse files Browse the repository at this point in the history
  • Loading branch information
jd1378 committed May 24, 2024
1 parent 2ebcb19 commit 62569af
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/hooks/6-normalize-find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,20 @@ export function normalizeFind() {
next && await next()

if (context.method === 'find' && !context.result?.data) {
context.result = {
data: [],
limit: context.params.$limit,
skip: context.params.$skip,
total: 0,
if (Array.isArray(context.result)) {
context.result = {
data: context.result,
limit: context.result.length,
skip: 0,
total: context.result.length,
}
} else {
context.result = {
data: [],
limit: context.params.$limit,
skip: context.params.$skip,
total: 0,
}
}
}
}
Expand Down

0 comments on commit 62569af

Please sign in to comment.