Skip to content

Commit

Permalink
Merge pull request #172 from jd1378/fix_normalize_find
Browse files Browse the repository at this point in the history
fix: handle unpaginated find response
  • Loading branch information
marshallswain authored May 24, 2024
2 parents 2ebcb19 + 3577275 commit 7cb567b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/hooks/6-normalize-find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ export function normalizeFind() {

next && await next()

if (context.method === 'find' && !context.result?.data) {
// this makes sure it only affects finds that are not paginated and are not custom.
// so the custom find responses fall through.
if (context.method === 'find' && !context.result?.data && Array.isArray(context.result)) {
context.result = {
data: [],
limit: context.params.$limit,
skip: context.params.$skip,
total: 0,
data: context.result,
limit: context.params.$limit || context.result.length,
skip: context.params.$skip || 0,
total: context.result.length,
}
}
}
Expand Down

0 comments on commit 7cb567b

Please sign in to comment.