UNPKG

@websolutespa/payload-plugin-bowl

Version:

Bowl PayloadCms plugin of the BOM Repository

31 lines (30 loc) 1.28 kB
import { isNumber } from '@websolutespa/bom-core'; import { status as HttpStatus } from 'http-status'; import { findOperation, headersWithCors, sanitizeJoinParams, sanitizePopulateParam, sanitizeSelectParam } from 'payload'; import { getRequestCollection } from './getRequestCollection'; export const findHandler = async (req)=>{ const collection = getRequestCollection(req); const { depth, draft, joins, limit, page, pagination, populate, select, sort, where } = req.query; const result = await findOperation({ collection, depth: isNumber(depth) ? Number(depth) : undefined, draft: draft === 'true', joins: sanitizeJoinParams(joins), limit: isNumber(limit) ? Number(limit) : undefined, page: isNumber(page) ? Number(page) : undefined, pagination: pagination === 'false' ? false : undefined, populate: sanitizePopulateParam(populate), req, select: sanitizeSelectParam(select), sort: typeof sort === 'string' ? sort.split(',') : undefined, where }); return Response.json(result, { headers: headersWithCors({ headers: new Headers(), req }), status: HttpStatus.OK }); }; //# sourceMappingURL=findHandler.js.map