chore: fixes to HTTP and request types for promotions (#13820)

This commit is contained in:
Shahed Nasser
2025-10-28 11:03:41 +02:00
committed by GitHub
parent 5b0c6e6a94
commit 24ff9d3382
12 changed files with 43 additions and 53 deletions

View File

@@ -4,22 +4,15 @@ export interface AdminCreateCampaign {
/**
* The campaign's name.
*/
name?: string
name: string
/**
* The campaign's description.
*/
description?: string
/**
* The campaign's currency code.
*
* @example
* usd
*/
currency?: string | null
description?: string | null
/**
* The campaign's identifier.
*/
campaign_identifier?: string
campaign_identifier: string
/**
* The date the campaign and its promotions start at.
*/
@@ -70,14 +63,7 @@ export interface AdminUpdateCampaign {
/**
* The campaign's description.
*/
description?: string
/**
* The campaign's currency code.
*
* @example
* usd
*/
currency?: string | null
description?: string | null
/**
* The campaign's identifier.
*/
@@ -94,21 +80,9 @@ export interface AdminUpdateCampaign {
* The campaign's budget.
*/
budget?: {
/**
* The budget's type. `spend` means the limit is set on the total amount discounted by the campaign's promotions;
* `usage` means the limit is set on the total number of times the campaign's promotions can be used.
*/
type?: CampaignBudgetTypeValues
/**
* The budget's currency code.
*
* @example
* usd
*/
currency_code?: string | null
/**
* The budget's limit.
*/
limit?: number | null
} | null
}
}

View File

@@ -78,7 +78,7 @@ export interface AdminGetPromotionRuleParams {
*/
application_method_type?: ApplicationMethodTypeValues
/**
* The type of application method to retrieve the attributes for.
* The target type of application method to retrieve the attributes for.
*/
application_method_target_type?: ApplicationMethodTargetTypeValues
}
@@ -92,6 +92,10 @@ export interface AdminGetPromotionRuleTypeParams extends SelectParams {
* The type of application method to retrieve the attributes for.
*/
application_method_type?: ApplicationMethodTypeValues
/**
* The target type of application method to retrieve the attributes for.
*/
application_method_target_type?: ApplicationMethodTargetTypeValues
}
export interface AdminGetPromotionsRuleValueParams extends FindParams {
@@ -103,5 +107,8 @@ export interface AdminGetPromotionsRuleValueParams extends FindParams {
* Filter by rule value.
*/
value?: string | string[]
/**
* The target type of application method to retrieve the attributes for.
*/
application_method_target_type?: ApplicationMethodTargetTypeValues
}

View File

@@ -4,11 +4,14 @@ import {
} from "@medusajs/framework/http"
import { addOrRemoveCampaignPromotionsWorkflow } from "@medusajs/core-flows"
import { HttpTypes, LinkMethodRequest } from "@medusajs/framework/types"
import { HttpTypes } from "@medusajs/framework/types"
import { refetchCampaign } from "../../helpers"
export const POST = async (
req: AuthenticatedMedusaRequest<LinkMethodRequest>,
req: AuthenticatedMedusaRequest<
HttpTypes.AdminBatchLink,
HttpTypes.AdminGetCampaignParams
>,
res: MedusaResponse<HttpTypes.AdminCampaignResponse>
) => {
const { id } = req.params

View File

@@ -8,12 +8,11 @@ import {
} from "@medusajs/core-flows"
import { refetchCampaign } from "../helpers"
import { AdminUpdateCampaignType } from "../validators"
import { MedusaError } from "@medusajs/framework/utils"
import { AdditionalData, HttpTypes } from "@medusajs/framework/types"
export const GET = async (
req: AuthenticatedMedusaRequest,
req: AuthenticatedMedusaRequest<HttpTypes.AdminGetCampaignParams>,
res: MedusaResponse<HttpTypes.AdminCampaignResponse>
) => {
const campaign = await refetchCampaign(
@@ -33,7 +32,10 @@ export const GET = async (
}
export const POST = async (
req: AuthenticatedMedusaRequest<AdminUpdateCampaignType & AdditionalData>,
req: AuthenticatedMedusaRequest<
HttpTypes.AdminUpdateCampaign & AdditionalData,
HttpTypes.AdminGetCampaignParams
>,
res: MedusaResponse<HttpTypes.AdminCampaignResponse>
) => {
const existingCampaign = await refetchCampaign(req.params.id, req.scope, [

View File

@@ -7,12 +7,11 @@ import {
ContainerRegistrationKeys,
remoteQueryObjectFromString,
} from "@medusajs/framework/utils"
import { AdminCreateCampaignType } from "./validators"
import { refetchCampaign } from "./helpers"
import { AdditionalData, HttpTypes } from "@medusajs/framework/types"
export const GET = async (
req: AuthenticatedMedusaRequest<HttpTypes.AdminGetCampaignParams>,
req: AuthenticatedMedusaRequest<HttpTypes.AdminGetCampaignsParams>,
res: MedusaResponse<HttpTypes.AdminCampaignListResponse>
) => {
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
@@ -37,7 +36,10 @@ export const GET = async (
}
export const POST = async (
req: AuthenticatedMedusaRequest<AdminCreateCampaignType & AdditionalData>,
req: AuthenticatedMedusaRequest<
HttpTypes.AdminCreateCampaign & AdditionalData,
HttpTypes.AdminGetCampaignParams
>,
res: MedusaResponse<HttpTypes.AdminCampaignResponse>
) => {
const { additional_data, ...rest } = req.validatedBody

View File

@@ -17,7 +17,7 @@ import {
} from "../../utils"
export const GET = async (
req: AuthenticatedMedusaRequest,
req: AuthenticatedMedusaRequest<HttpTypes.AdminGetPromotionRuleTypeParams>,
res: MedusaResponse<HttpTypes.AdminPromotionRuleListResponse>
) => {
const { id, rule_type: ruleType } = req.params

View File

@@ -12,7 +12,8 @@ export const POST = async (
BatchMethodRequest<
HttpTypes.AdminCreatePromotionRule,
HttpTypes.AdminUpdatePromotionRule
>
>,
HttpTypes.AdminGetPromotionRuleParams
>,
res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse>
) => {

View File

@@ -12,14 +12,10 @@ import {
MedusaResponse,
} from "@medusajs/framework/http"
import { refetchPromotion } from "../helpers"
import {
AdminGetPromotionParamsType,
AdminUpdatePromotionType,
} from "../validators"
import { AdditionalData, HttpTypes } from "@medusajs/framework/types"
export const GET = async (
req: AuthenticatedMedusaRequest<AdminGetPromotionParamsType>,
req: AuthenticatedMedusaRequest<HttpTypes.AdminGetPromotionParams>,
res: MedusaResponse<HttpTypes.AdminPromotionResponse>
) => {
const idOrCode = req.params.id
@@ -44,7 +40,10 @@ export const GET = async (
}
export const POST = async (
req: AuthenticatedMedusaRequest<AdminUpdatePromotionType & AdditionalData>,
req: AuthenticatedMedusaRequest<
HttpTypes.AdminUpdatePromotion & AdditionalData,
HttpTypes.AdminGetPromotionParams
>,
res: MedusaResponse<HttpTypes.AdminPromotionResponse>
) => {
const { additional_data, ...rest } = req.validatedBody

View File

@@ -12,7 +12,8 @@ export const POST = async (
BatchMethodRequest<
HttpTypes.AdminCreatePromotionRule,
HttpTypes.AdminUpdatePromotionRule
>
>,
HttpTypes.AdminGetPromotionRuleParams
>,
res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse>
) => {

View File

@@ -12,7 +12,8 @@ export const POST = async (
BatchMethodRequest<
HttpTypes.AdminCreatePromotionRule,
HttpTypes.AdminUpdatePromotionRule
>
>,
HttpTypes.AdminGetPromotionRuleParams
>,
res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse>
) => {

View File

@@ -37,7 +37,8 @@ export const GET = async (
export const POST = async (
req: AuthenticatedMedusaRequest<
HttpTypes.AdminCreatePromotion & AdditionalData
HttpTypes.AdminCreatePromotion & AdditionalData,
HttpTypes.AdminGetPromotionParams
>,
res: MedusaResponse<HttpTypes.AdminPromotionResponse>
) => {

View File

@@ -12,7 +12,6 @@ import {
validateRuleAttribute,
validateRuleType,
} from "../../../utils"
import { AdminGetPromotionRuleParamsType } from "../../../validators"
import {
ApplicationMethodTargetTypeValues,
RuleTypeValues,
@@ -26,7 +25,7 @@ import {
from the currency module.
*/
export const GET = async (
req: AuthenticatedMedusaRequest<AdminGetPromotionRuleParamsType>,
req: AuthenticatedMedusaRequest<HttpTypes.AdminGetPromotionsRuleValueParams>,
res: MedusaResponse<HttpTypes.AdminRuleValueOptionsListResponse>
) => {
const { rule_type: ruleType, rule_attribute_id: ruleAttributeId } = req.params