Skip to content

Commit 3710dce

Browse files
committed
fix: pagination
1 parent 9a25584 commit 3710dce

File tree

3 files changed

+205
-182
lines changed

3 files changed

+205
-182
lines changed

src/app.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,17 @@ export function createApp(db: Low<Data>, options: AppOptions = {}) {
4848

4949
app.get('/:name', (req, res, next) => {
5050
const { name = '' } = req.params
51-
res.locals['data'] = service.find(name, req.query)
51+
const query = Object.fromEntries(Object.entries(req.query)
52+
.map(([key, value]) => {
53+
if (['_start', '_end', '_limit', '_page', '_per_page'].includes(key) && typeof value === 'string') {
54+
return [key, parseInt(value)]
55+
} else {
56+
return [key, value]
57+
}
58+
})
59+
.filter(([_, value]) => !Number.isNaN(value))
60+
)
61+
res.locals['data'] = service.find(name, query)
5262
next()
5363
})
5464

0 commit comments

Comments
 (0)