@furystack/rest-service
Version:
Repository implementation for FuryStack
19 lines • 803 B
JavaScript
import { JsonResult } from '../request-action-implementation.js';
import { getRepository } from '@furystack/repository';
/**
* Creates a DELETE endpoint for removing entities
* @param options The options for endpoint creation
* @param options.model The Model class
* @param options.primaryKey The field used as primary key on the model
* @returns a boolean that indicates the success
*/
export const createDeleteEndpoint = (options) => {
const endpoint = async ({ injector, getUrlParams }) => {
const { id } = getUrlParams();
const dataSet = getRepository(injector).getDataSetFor(options.model, options.primaryKey);
await dataSet.remove(injector, id);
return JsonResult({}, 204);
};
return endpoint;
};
//# sourceMappingURL=create-delete-endpoint.js.map