feat(medusa,types,core-flows,utils): added delete endpoints for campaigns and promotions (#6152)

what:

adds delete endpoints for:
- campaigns (RESOLVES CORE-1686)
- promotions (RESOLVES CORE-1680)
This commit is contained in:
Riqwan Thamir authored and GitHub committed 2024-01-22 13:06:49 +00:00
1 parent 76291823f4
commit 99045848fd
25 files changed
+699 -84

No files matched your search

@@ -1,4 +1,7 @@
import { updateCampaignsWorkflow } from "@medusajs/core-flows"
import {
deleteCampaignsWorkflow,
updateCampaignsWorkflow,
} from "@medusajs/core-flows"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { IPromotionModuleService } from "@medusajs/types"
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
@@ -39,3 +42,25 @@ export const POST = async (req: MedusaRequest, res: MedusaResponse) => {
res.status(200).json({ campaign: result[0] })
}
export const DELETE = async (req: MedusaRequest, res: MedusaResponse) => {
const id = req.params.id
const manager = req.scope.resolve("manager")
const deleteCampaigns = deleteCampaignsWorkflow(req.scope)
const { errors } = await deleteCampaigns.run({
input: { ids: [id] },
context: { manager },
throwOnError: false,
})
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({
id,
object: "campaign",
deleted: true,
})
}
@@ -1,4 +1,7 @@
import { updatePromotionsWorkflow } from "@medusajs/core-flows"
import {
deletePromotionsWorkflow,
updatePromotionsWorkflow,
} from "@medusajs/core-flows"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { IPromotionModuleService } from "@medusajs/types"
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
@@ -36,3 +39,25 @@ export const POST = async (req: MedusaRequest, res: MedusaResponse) => {
res.status(200).json({ promotion: result[0] })
}
export const DELETE = async (req: MedusaRequest, res: MedusaResponse) => {
const id = req.params.id
const manager = req.scope.resolve("manager")
const deletePromotions = deletePromotionsWorkflow(req.scope)
const { errors } = await deletePromotions.run({
input: { ids: [id] },
context: { manager },
throwOnError: false,
})
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({
id,
object: "promotion",
deleted: true,
})
}