@chubbyts/chubbyts-api
Version:
[](https://github.com/chubbyts/chubbyts-api/actions?query=workflow%3ACI) [ • 675 B
JavaScript
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));
};
};