chore: fixes to HTTP and request types for promotions (#13820)
This commit is contained in:
1 parent
5b0c6e6a94
commit
24ff9d3382
12 files changed
+43
-53
No files matched your search
@@ -4,22 +4,15 @@ export interface AdminCreateCampaign {
|
|||||||
/**
|
/**
|
||||||
* The campaign's name.
|
* The campaign's name.
|
||||||
*/
|
*/
|
||||||
name?: string
|
name: string
|
||||||
/**
|
/**
|
||||||
* The campaign's description.
|
* The campaign's description.
|
||||||
*/
|
*/
|
||||||
description?: string
|
description?: string | null
|
||||||
/**
|
|
||||||
* The campaign's currency code.
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* usd
|
|
||||||
*/
|
|
||||||
currency?: string | null
|
|
||||||
/**
|
/**
|
||||||
* The campaign's identifier.
|
* The campaign's identifier.
|
||||||
*/
|
*/
|
||||||
campaign_identifier?: string
|
campaign_identifier: string
|
||||||
/**
|
/**
|
||||||
* The date the campaign and its promotions start at.
|
* The date the campaign and its promotions start at.
|
||||||
*/
|
*/
|
||||||
@@ -70,14 +63,7 @@ export interface AdminUpdateCampaign {
|
|||||||
/**
|
/**
|
||||||
* The campaign's description.
|
* The campaign's description.
|
||||||
*/
|
*/
|
||||||
description?: string
|
description?: string | null
|
||||||
/**
|
|
||||||
* The campaign's currency code.
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* usd
|
|
||||||
*/
|
|
||||||
currency?: string | null
|
|
||||||
/**
|
/**
|
||||||
* The campaign's identifier.
|
* The campaign's identifier.
|
||||||
*/
|
*/
|
||||||
@@ -94,21 +80,9 @@ export interface AdminUpdateCampaign {
|
|||||||
* The campaign's budget.
|
* The campaign's budget.
|
||||||
*/
|
*/
|
||||||
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.
|
* The budget's limit.
|
||||||
*/
|
*/
|
||||||
limit?: number | null
|
limit?: number | null
|
||||||
} | null
|
}
|
||||||
}
|
}
|
||||||
@@ -78,7 +78,7 @@ export interface AdminGetPromotionRuleParams {
|
|||||||
*/
|
*/
|
||||||
application_method_type?: ApplicationMethodTypeValues
|
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
|
application_method_target_type?: ApplicationMethodTargetTypeValues
|
||||||
}
|
}
|
||||||
@@ -92,6 +92,10 @@ export interface AdminGetPromotionRuleTypeParams extends SelectParams {
|
|||||||
* The type of application method to retrieve the attributes for.
|
* The type of application method to retrieve the attributes for.
|
||||||
*/
|
*/
|
||||||
application_method_type?: ApplicationMethodTypeValues
|
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 {
|
export interface AdminGetPromotionsRuleValueParams extends FindParams {
|
||||||
@@ -103,5 +107,8 @@ export interface AdminGetPromotionsRuleValueParams extends FindParams {
|
|||||||
* Filter by rule value.
|
* Filter by rule value.
|
||||||
*/
|
*/
|
||||||
value?: string | string[]
|
value?: string | string[]
|
||||||
|
/**
|
||||||
|
* The target type of application method to retrieve the attributes for.
|
||||||
|
*/
|
||||||
application_method_target_type?: ApplicationMethodTargetTypeValues
|
application_method_target_type?: ApplicationMethodTargetTypeValues
|
||||||
}
|
}
|
||||||
@@ -4,11 +4,14 @@ import {
|
|||||||
} from "@medusajs/framework/http"
|
} from "@medusajs/framework/http"
|
||||||
|
|
||||||
import { addOrRemoveCampaignPromotionsWorkflow } from "@medusajs/core-flows"
|
import { addOrRemoveCampaignPromotionsWorkflow } from "@medusajs/core-flows"
|
||||||
import { HttpTypes, LinkMethodRequest } from "@medusajs/framework/types"
|
import { HttpTypes } from "@medusajs/framework/types"
|
||||||
import { refetchCampaign } from "../../helpers"
|
import { refetchCampaign } from "../../helpers"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<LinkMethodRequest>,
|
req: AuthenticatedMedusaRequest<
|
||||||
|
HttpTypes.AdminBatchLink,
|
||||||
|
HttpTypes.AdminGetCampaignParams
|
||||||
|
>,
|
||||||
res: MedusaResponse<HttpTypes.AdminCampaignResponse>
|
res: MedusaResponse<HttpTypes.AdminCampaignResponse>
|
||||||
) => {
|
) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
|
|||||||
@@ -8,12 +8,11 @@ import {
|
|||||||
} from "@medusajs/core-flows"
|
} from "@medusajs/core-flows"
|
||||||
|
|
||||||
import { refetchCampaign } from "../helpers"
|
import { refetchCampaign } from "../helpers"
|
||||||
import { AdminUpdateCampaignType } from "../validators"
|
|
||||||
import { MedusaError } from "@medusajs/framework/utils"
|
import { MedusaError } from "@medusajs/framework/utils"
|
||||||
import { AdditionalData, HttpTypes } from "@medusajs/framework/types"
|
import { AdditionalData, HttpTypes } from "@medusajs/framework/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest<HttpTypes.AdminGetCampaignParams>,
|
||||||
res: MedusaResponse<HttpTypes.AdminCampaignResponse>
|
res: MedusaResponse<HttpTypes.AdminCampaignResponse>
|
||||||
) => {
|
) => {
|
||||||
const campaign = await refetchCampaign(
|
const campaign = await refetchCampaign(
|
||||||
@@ -33,7 +32,10 @@ export const GET = async (
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminUpdateCampaignType & AdditionalData>,
|
req: AuthenticatedMedusaRequest<
|
||||||
|
HttpTypes.AdminUpdateCampaign & AdditionalData,
|
||||||
|
HttpTypes.AdminGetCampaignParams
|
||||||
|
>,
|
||||||
res: MedusaResponse<HttpTypes.AdminCampaignResponse>
|
res: MedusaResponse<HttpTypes.AdminCampaignResponse>
|
||||||
) => {
|
) => {
|
||||||
const existingCampaign = await refetchCampaign(req.params.id, req.scope, [
|
const existingCampaign = await refetchCampaign(req.params.id, req.scope, [
|
||||||
|
|||||||
@@ -7,12 +7,11 @@ import {
|
|||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
remoteQueryObjectFromString,
|
remoteQueryObjectFromString,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
import { AdminCreateCampaignType } from "./validators"
|
|
||||||
import { refetchCampaign } from "./helpers"
|
import { refetchCampaign } from "./helpers"
|
||||||
import { AdditionalData, HttpTypes } from "@medusajs/framework/types"
|
import { AdditionalData, HttpTypes } from "@medusajs/framework/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<HttpTypes.AdminGetCampaignParams>,
|
req: AuthenticatedMedusaRequest<HttpTypes.AdminGetCampaignsParams>,
|
||||||
res: MedusaResponse<HttpTypes.AdminCampaignListResponse>
|
res: MedusaResponse<HttpTypes.AdminCampaignListResponse>
|
||||||
) => {
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
@@ -37,7 +36,10 @@ export const GET = async (
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminCreateCampaignType & AdditionalData>,
|
req: AuthenticatedMedusaRequest<
|
||||||
|
HttpTypes.AdminCreateCampaign & AdditionalData,
|
||||||
|
HttpTypes.AdminGetCampaignParams
|
||||||
|
>,
|
||||||
res: MedusaResponse<HttpTypes.AdminCampaignResponse>
|
res: MedusaResponse<HttpTypes.AdminCampaignResponse>
|
||||||
) => {
|
) => {
|
||||||
const { additional_data, ...rest } = req.validatedBody
|
const { additional_data, ...rest } = req.validatedBody
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
} from "../../utils"
|
} from "../../utils"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest<HttpTypes.AdminGetPromotionRuleTypeParams>,
|
||||||
res: MedusaResponse<HttpTypes.AdminPromotionRuleListResponse>
|
res: MedusaResponse<HttpTypes.AdminPromotionRuleListResponse>
|
||||||
) => {
|
) => {
|
||||||
const { id, rule_type: ruleType } = req.params
|
const { id, rule_type: ruleType } = req.params
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ export const POST = async (
|
|||||||
BatchMethodRequest<
|
BatchMethodRequest<
|
||||||
HttpTypes.AdminCreatePromotionRule,
|
HttpTypes.AdminCreatePromotionRule,
|
||||||
HttpTypes.AdminUpdatePromotionRule
|
HttpTypes.AdminUpdatePromotionRule
|
||||||
>
|
>,
|
||||||
|
HttpTypes.AdminGetPromotionRuleParams
|
||||||
>,
|
>,
|
||||||
res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse>
|
res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse>
|
||||||
) => {
|
) => {
|
||||||
|
|||||||
@@ -12,14 +12,10 @@ import {
|
|||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
} from "@medusajs/framework/http"
|
} from "@medusajs/framework/http"
|
||||||
import { refetchPromotion } from "../helpers"
|
import { refetchPromotion } from "../helpers"
|
||||||
import {
|
|
||||||
AdminGetPromotionParamsType,
|
|
||||||
AdminUpdatePromotionType,
|
|
||||||
} from "../validators"
|
|
||||||
import { AdditionalData, HttpTypes } from "@medusajs/framework/types"
|
import { AdditionalData, HttpTypes } from "@medusajs/framework/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminGetPromotionParamsType>,
|
req: AuthenticatedMedusaRequest<HttpTypes.AdminGetPromotionParams>,
|
||||||
res: MedusaResponse<HttpTypes.AdminPromotionResponse>
|
res: MedusaResponse<HttpTypes.AdminPromotionResponse>
|
||||||
) => {
|
) => {
|
||||||
const idOrCode = req.params.id
|
const idOrCode = req.params.id
|
||||||
@@ -44,7 +40,10 @@ export const GET = async (
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminUpdatePromotionType & AdditionalData>,
|
req: AuthenticatedMedusaRequest<
|
||||||
|
HttpTypes.AdminUpdatePromotion & AdditionalData,
|
||||||
|
HttpTypes.AdminGetPromotionParams
|
||||||
|
>,
|
||||||
res: MedusaResponse<HttpTypes.AdminPromotionResponse>
|
res: MedusaResponse<HttpTypes.AdminPromotionResponse>
|
||||||
) => {
|
) => {
|
||||||
const { additional_data, ...rest } = req.validatedBody
|
const { additional_data, ...rest } = req.validatedBody
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ export const POST = async (
|
|||||||
BatchMethodRequest<
|
BatchMethodRequest<
|
||||||
HttpTypes.AdminCreatePromotionRule,
|
HttpTypes.AdminCreatePromotionRule,
|
||||||
HttpTypes.AdminUpdatePromotionRule
|
HttpTypes.AdminUpdatePromotionRule
|
||||||
>
|
>,
|
||||||
|
HttpTypes.AdminGetPromotionRuleParams
|
||||||
>,
|
>,
|
||||||
res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse>
|
res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse>
|
||||||
) => {
|
) => {
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ export const POST = async (
|
|||||||
BatchMethodRequest<
|
BatchMethodRequest<
|
||||||
HttpTypes.AdminCreatePromotionRule,
|
HttpTypes.AdminCreatePromotionRule,
|
||||||
HttpTypes.AdminUpdatePromotionRule
|
HttpTypes.AdminUpdatePromotionRule
|
||||||
>
|
>,
|
||||||
|
HttpTypes.AdminGetPromotionRuleParams
|
||||||
>,
|
>,
|
||||||
res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse>
|
res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse>
|
||||||
) => {
|
) => {
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ export const GET = async (
|
|||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<
|
req: AuthenticatedMedusaRequest<
|
||||||
HttpTypes.AdminCreatePromotion & AdditionalData
|
HttpTypes.AdminCreatePromotion & AdditionalData,
|
||||||
|
HttpTypes.AdminGetPromotionParams
|
||||||
>,
|
>,
|
||||||
res: MedusaResponse<HttpTypes.AdminPromotionResponse>
|
res: MedusaResponse<HttpTypes.AdminPromotionResponse>
|
||||||
) => {
|
) => {
|
||||||
|
|||||||
+1
-2
@@ -12,7 +12,6 @@ import {
|
|||||||
validateRuleAttribute,
|
validateRuleAttribute,
|
||||||
validateRuleType,
|
validateRuleType,
|
||||||
} from "../../../utils"
|
} from "../../../utils"
|
||||||
import { AdminGetPromotionRuleParamsType } from "../../../validators"
|
|
||||||
import {
|
import {
|
||||||
ApplicationMethodTargetTypeValues,
|
ApplicationMethodTargetTypeValues,
|
||||||
RuleTypeValues,
|
RuleTypeValues,
|
||||||
@@ -26,7 +25,7 @@ import {
|
|||||||
from the currency module.
|
from the currency module.
|
||||||
*/
|
*/
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminGetPromotionRuleParamsType>,
|
req: AuthenticatedMedusaRequest<HttpTypes.AdminGetPromotionsRuleValueParams>,
|
||||||
res: MedusaResponse<HttpTypes.AdminRuleValueOptionsListResponse>
|
res: MedusaResponse<HttpTypes.AdminRuleValueOptionsListResponse>
|
||||||
) => {
|
) => {
|
||||||
const { rule_type: ruleType, rule_attribute_id: ruleAttributeId } = req.params
|
const { rule_type: ruleType, rule_attribute_id: ruleAttributeId } = req.params
|
||||||
|
|||||||
Reference in new issue
Block a user