chore: Delete product config api (#2611)

chore: Add DELETE handler for product API endpoint
This commit is contained in:
Utkarsh Mehta 2024-04-24 02:03:30 +05:30 committed by GitHub
parent 6302e9e7c2
commit a5f4e8e730
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View File

@ -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;

View File

@ -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);
}
}