UNPKG

medusa-plugin-abandoned-cart

Version:
31 lines (30 loc) 1.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GET = GET; exports.POST = POST; async function GET(req, res) { try { const abandonedCartService = req.scope.resolve("abandonedCartService"); const { take, skip, dateLimit } = req.query; const carts = await abandonedCartService.retrieveAbandonedCarts(take, skip, +dateLimit, true); res .status(200) .json({ carts: carts.abandoned_carts, count: carts.total_carts }); } catch (error) { res.status(400).json({ error: error.message }); } } async function POST(req, res) { try { const abandonedCartService = req.scope.resolve("abandonedCartService"); if (!req.body.id) { throw new Error("No id provided"); } const r = await abandonedCartService.sendAbandonedCartEmail(req.body.id); res.status(200).json(r); } catch (error) { res.status(400).json({ error: error.message }); } }