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

16 lines (15 loc) 675 B
import { createNotFound } from '@chubbyts/chubbyts-http-error/dist/http-error'; import { z } from 'zod'; import { stringifyResponseBody } from '../response.js'; const attributesSchema = z.object({ id: z.string() }); export const createDeleteHandler = (findModelById, removeModel, responseFactory) => { return async (request) => { const id = attributesSchema.parse(request.attributes).id; const model = await findModelById(id); if (!model) { throw createNotFound({ detail: `There is no entry with id "${id}"` }); } await removeModel(model); return stringifyResponseBody(request, responseFactory(204)); }; };