|
1 | 1 | import { status as httpStatus } from 'http-status' |
2 | 2 |
|
3 | 3 | import type { PayloadHandler } from '../../config/types.js' |
4 | | -import type { Where } from '../../types/index.js' |
5 | | -import type { JoinParams } from '../../utilities/sanitizeJoinParams.js' |
6 | 4 |
|
7 | 5 | import { getRequestCollection } from '../../utilities/getRequestEntity.js' |
8 | 6 | import { headersWithCors } from '../../utilities/headersWithCors.js' |
9 | | -import { isNumber } from '../../utilities/isNumber.js' |
10 | | -import { sanitizeJoinParams } from '../../utilities/sanitizeJoinParams.js' |
11 | | -import { sanitizePopulateParam } from '../../utilities/sanitizePopulateParam.js' |
12 | | -import { sanitizeSelectParam } from '../../utilities/sanitizeSelectParam.js' |
| 7 | +import { parseParams } from '../../utilities/parseParams/index.js' |
13 | 8 | import { findOperation } from '../operations/find.js' |
14 | 9 |
|
15 | 10 | export const findHandler: PayloadHandler = async (req) => { |
16 | 11 | const collection = getRequestCollection(req) |
| 12 | + |
17 | 13 | const { depth, draft, joins, limit, page, pagination, populate, select, sort, trash, where } = |
18 | | - req.query as { |
19 | | - depth?: string |
20 | | - draft?: string |
21 | | - joins?: JoinParams |
22 | | - limit?: string |
23 | | - page?: string |
24 | | - pagination?: string |
25 | | - populate?: Record<string, unknown> |
26 | | - select?: Record<string, unknown> |
27 | | - sort?: string |
28 | | - trash?: string |
29 | | - where?: Where |
30 | | - } |
| 14 | + parseParams(req.query) |
31 | 15 |
|
32 | 16 | const result = await findOperation({ |
33 | 17 | collection, |
34 | | - depth: isNumber(depth) ? Number(depth) : undefined, |
35 | | - draft: draft === 'true', |
36 | | - joins: sanitizeJoinParams(joins), |
37 | | - limit: isNumber(limit) ? Number(limit) : undefined, |
38 | | - page: isNumber(page) ? Number(page) : undefined, |
39 | | - pagination: pagination === 'false' ? false : undefined, |
40 | | - populate: sanitizePopulateParam(populate), |
| 18 | + depth, |
| 19 | + draft, |
| 20 | + joins, |
| 21 | + limit, |
| 22 | + page, |
| 23 | + pagination, |
| 24 | + populate, |
41 | 25 | req, |
42 | | - select: sanitizeSelectParam(select), |
43 | | - sort: typeof sort === 'string' ? sort.split(',') : undefined, |
44 | | - trash: trash === 'true', |
| 26 | + select, |
| 27 | + sort, |
| 28 | + trash, |
45 | 29 | where, |
46 | 30 | }) |
47 | 31 |
|
|
0 commit comments