UNPKG

@chubbyts/chubbyts-api

Version:

[![CI](https://github.com/chubbyts/chubbyts-api/workflows/CI/badge.svg?branch=master)](https://github.com/chubbyts/chubbyts-api/actions?query=workflow%3ACI) [![Coverage Status](https://coveralls.io/repos/github/chubbyts/chubbyts-api/badge.svg?branch=maste

13 lines (12 loc) 816 B
import { createBadRequest } from '@chubbyts/chubbyts-http-error/dist/http-error'; import { stringifyResponseBody, valueToData } from '../response.js'; import { zodToInvalidParameters } from '../zod-to-invalid-parameters.js'; export const createListHandler = (querySchema, resolveModelList, responseFactory, modelListResponseSchema, encoder, enrichList = async (list) => list) => { return async (request) => { const result = querySchema.safeParse(request.uri.query); if (!result.success) { throw createBadRequest({ invalidParameters: zodToInvalidParameters(result.error) }); } return stringifyResponseBody(request, responseFactory(200), encoder, modelListResponseSchema.parse(valueToData(await enrichList(await resolveModelList(result.data), { request })))); }; };