mirror of https://github.com/boxyhq/jackson.git
chore: Delete product config api (#2611)
chore: Add DELETE handler for product API endpoint
This commit is contained in:
parent
6302e9e7c2
commit
a5f4e8e730
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue