Add batch delete w/ keys in body

Fixes #819
This commit is contained in:
rijkvanzanten
2020-11-05 14:47:57 -05:00
parent 9471bc1c95
commit a432640ecb
10 changed files with 148 additions and 9 deletions

View File

@@ -1,9 +1,10 @@
import express from 'express';
import asyncHandler from 'express-async-handler';
import { WebhooksService, MetaService } from '../services';
import { ForbiddenException } from '../exceptions';
import { ForbiddenException, InvalidPayloadException } from '../exceptions';
import useCollection from '../middleware/use-collection';
import { respond } from '../middleware/respond';
import { PrimaryKey } from '../types';
const router = express.Router();
@@ -82,6 +83,21 @@ router.patch(
respond
);
router.delete(
'/',
asyncHandler(async (req, res, next) => {
if (!req.body || Array.isArray(req.body) === false) {
throw new InvalidPayloadException(`Body has to be an array of primary keys`);
}
const service = new WebhooksService({ accountability: req.accountability });
await service.delete(req.body as PrimaryKey[]);
return next();
}),
respond
);
router.delete(
'/:pk',
asyncHandler(async (req, res, next) => {