From a5f4e8e730f92d690111cf1713e977b94e3d1126 Mon Sep 17 00:00:00 2001 From: Utkarsh Mehta Date: Wed, 24 Apr 2024 02:03:30 +0530 Subject: [PATCH] chore: Delete product config api (#2611) chore: Add DELETE handler for product API endpoint --- ee/product/api/[productId].ts | 16 +++++++++++++++- npm/src/ee/product/index.ts | 6 ++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ee/product/api/[productId].ts b/ee/product/api/[productId].ts index 71d96a267..a3006a0cf 100644 --- a/ee/product/api/[productId].ts +++ b/ee/product/api/[productId].ts @@ -8,8 +8,11 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { case 'GET': await handleGET(req, res); break; + case 'DELETE': + await handleDELETE(req, res); + break; default: - res.setHeader('Allow', 'GET'); + res.setHeader('Allow', 'GET,DELETE'); res.status(405).json({ error: { message: `Method ${req.method} Not Allowed` } }); } } catch (error: any) { @@ -29,4 +32,15 @@ const handleGET = async (req: NextApiRequest, res: NextApiResponse) => { res.json({ data: product }); }; +// delete product configuration +const handleDELETE = async (req: NextApiRequest, res: NextApiResponse) => { + const { productController } = await jackson(); + + const { productId } = req.query as { productId: string }; + + await productController.delete(productId); + + res.status(204).end(); +}; + export default handler; diff --git a/npm/src/ee/product/index.ts b/npm/src/ee/product/index.ts index db00e4838..b2c589a4a 100644 --- a/npm/src/ee/product/index.ts +++ b/npm/src/ee/product/index.ts @@ -46,4 +46,10 @@ export class ProductController { await this.productStore.put(params.id, toUpdate); } + + public async delete(productId: string) { + await throwIfInvalidLicense(this.opts.boxyhqLicenseKey); + + await this.productStore.delete(productId); + } }