chore(medusa,types): [11] Add request types to API routes (#8572)
This commit is contained in:
13
packages/core/types/src/http/promotion/admin/entities.ts
Normal file
13
packages/core/types/src/http/promotion/admin/entities.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import {
|
||||
BasePromotion,
|
||||
BasePromotionRule,
|
||||
BaseRuleAttributeOptions,
|
||||
BaseRuleOperatorOptions,
|
||||
BaseRuleValueOptions
|
||||
} from "../common";
|
||||
|
||||
export interface AdminPromotion extends BasePromotion {}
|
||||
export interface AdminPromotionRule extends BasePromotionRule {}
|
||||
export interface AdminRuleAttributeOption extends BaseRuleAttributeOptions {}
|
||||
export interface AdminRuleOperatorOption extends BaseRuleOperatorOptions {}
|
||||
export interface AdminRuleValueOption extends BaseRuleValueOptions {}
|
||||
@@ -1,4 +1,2 @@
|
||||
export * from "./promotion-rule"
|
||||
export * from "./rule-attribute-options"
|
||||
export * from "./rule-operator-options"
|
||||
export * from "./rule-value-options"
|
||||
export * from "./entities"
|
||||
export * from "./responses"
|
||||
@@ -1,15 +0,0 @@
|
||||
export interface PromotionRuleResponse {
|
||||
id: string
|
||||
attribute: string
|
||||
attribute_label: string
|
||||
field_type: string
|
||||
operator: string
|
||||
operator_label: string
|
||||
values: { value: string }[]
|
||||
disguised: boolean
|
||||
required: boolean
|
||||
}
|
||||
|
||||
export interface AdminPromotionRuleListResponse {
|
||||
rules: PromotionRuleResponse[]
|
||||
}
|
||||
57
packages/core/types/src/http/promotion/admin/responses.ts
Normal file
57
packages/core/types/src/http/promotion/admin/responses.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { BatchMethodResponse } from "../../../common";
|
||||
import { PaginatedResponse } from "../../common";
|
||||
import {
|
||||
AdminPromotion,
|
||||
AdminPromotionRule,
|
||||
AdminRuleAttributeOption,
|
||||
AdminRuleOperatorOption,
|
||||
AdminRuleValueOption
|
||||
} from "./entities";
|
||||
|
||||
export interface AdminPromotionResponse {
|
||||
promotion: AdminPromotion
|
||||
}
|
||||
|
||||
export type AdminPromotionListResponse = PaginatedResponse<{
|
||||
promotions: AdminPromotion[]
|
||||
}>
|
||||
|
||||
export interface PromotionRuleResponse {
|
||||
rule: AdminPromotionRule
|
||||
}
|
||||
|
||||
export type AdminPromotionRuleListResponse = {
|
||||
rules: AdminPromotionRule[]
|
||||
}
|
||||
|
||||
export interface RuleAttributeOptionsResponse {
|
||||
attribute: AdminRuleAttributeOption[]
|
||||
}
|
||||
|
||||
export type AdminRuleAttributeOptionsListResponse = {
|
||||
attributes: AdminRuleAttributeOption[]
|
||||
}
|
||||
|
||||
export interface RuleOperatorOptionsResponse {
|
||||
operator: AdminRuleOperatorOption
|
||||
}
|
||||
|
||||
export type AdminRuleOperatorOptionsListResponse = PaginatedResponse<{
|
||||
operators: AdminRuleOperatorOption[]
|
||||
}>
|
||||
|
||||
/**
|
||||
* @experimental
|
||||
*/
|
||||
export interface RuleValueOptionsResponse {
|
||||
value: AdminRuleValueOption
|
||||
}
|
||||
|
||||
/**
|
||||
* @experimental
|
||||
*/
|
||||
export type AdminRuleValueOptionsListResponse = {
|
||||
values: AdminRuleValueOption[]
|
||||
}
|
||||
|
||||
export type AdminPromotionRuleBatchResponse = BatchMethodResponse<AdminPromotionRule>
|
||||
@@ -1,17 +0,0 @@
|
||||
export interface RuleAttributeOptionsResponse {
|
||||
id: string
|
||||
value: string
|
||||
label: string
|
||||
field_type: string
|
||||
required: boolean
|
||||
disguised: boolean
|
||||
operators: {
|
||||
id: string
|
||||
value: string
|
||||
label: string
|
||||
}[]
|
||||
}
|
||||
|
||||
export interface AdminRuleAttributeOptionsListResponse {
|
||||
attributes: RuleAttributeOptionsResponse[]
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
export interface RuleOperatorOptionsResponse {
|
||||
id: string
|
||||
value: string
|
||||
label: string
|
||||
}
|
||||
|
||||
export interface AdminRuleOperatorOptionsListResponse {
|
||||
operators: RuleOperatorOptionsResponse[]
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
/**
|
||||
* @experimental
|
||||
*/
|
||||
export interface RuleValueOptionsResponse {
|
||||
id: string
|
||||
value: string
|
||||
label: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @experimental
|
||||
*/
|
||||
export interface AdminRuleValueOptionsListResponse {
|
||||
values: RuleValueOptionsResponse[]
|
||||
}
|
||||
@@ -1,12 +1,69 @@
|
||||
import { ApplicationMethodTypeValues } from "../../promotion"
|
||||
import {
|
||||
ApplicationMethodAllocationValues,
|
||||
ApplicationMethodTargetTypeValues,
|
||||
ApplicationMethodTypeValues,
|
||||
PromotionRuleOperatorValues,
|
||||
PromotionTypeValues
|
||||
} from "../../promotion"
|
||||
import { CampaignResponse } from "../campaign"
|
||||
|
||||
export interface BasePromotionRule {
|
||||
id: string
|
||||
description?: string | null
|
||||
attribute?: string
|
||||
operator?: PromotionRuleOperatorValues
|
||||
values: BasePromotionRuleValue[]
|
||||
}
|
||||
|
||||
export interface BaseApplicationMethod {
|
||||
id: string
|
||||
type?: ApplicationMethodTypeValues
|
||||
target_type?: ApplicationMethodTargetTypeValues
|
||||
allocation?: ApplicationMethodAllocationValues
|
||||
value?: number
|
||||
currency_code?: string
|
||||
max_quantity?: number | null
|
||||
buy_rules_min_quantity?: number | null
|
||||
apply_to_quantity?: number | null
|
||||
promotion?: BasePromotion
|
||||
target_rules?: BasePromotionRule[]
|
||||
buy_rules?: BasePromotionRule[]
|
||||
}
|
||||
|
||||
export interface BasePromotion {
|
||||
id: string
|
||||
code?: string
|
||||
type?: PromotionTypeValues
|
||||
is_automatic?: boolean
|
||||
application_method?: {
|
||||
type?: ApplicationMethodTypeValues
|
||||
value?: number
|
||||
currency_code?: string
|
||||
}
|
||||
application_method?: BaseApplicationMethod
|
||||
rules?: BasePromotionRule[]
|
||||
campaign_id?: string
|
||||
campaign?: CampaignResponse
|
||||
}
|
||||
|
||||
export interface BasePromotionRuleValue {
|
||||
id: string
|
||||
value?: string
|
||||
}
|
||||
|
||||
export interface BaseRuleAttributeOptions {
|
||||
id: string
|
||||
value: string
|
||||
label: string
|
||||
field_type: string
|
||||
required: boolean
|
||||
disguised: boolean
|
||||
operators: BaseRuleOperatorOptions[]
|
||||
}
|
||||
|
||||
export interface BaseRuleOperatorOptions {
|
||||
id: string
|
||||
value: string
|
||||
label: string
|
||||
}
|
||||
|
||||
export interface BaseRuleValueOptions {
|
||||
id: string
|
||||
value: string
|
||||
label: string
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AdminGetPromotionRulesRes } from "@medusajs/types"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminPromotionRuleListResponse>
|
||||
) => {
|
||||
const { id, rule_type: ruleType } = req.params
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
@@ -48,7 +48,7 @@ export const GET = async (
|
||||
promotionRules.push(...(promotion?.application_method?.buy_rules || []))
|
||||
}
|
||||
|
||||
const transformedRules: AdminGetPromotionRulesRes = []
|
||||
const transformedRules: HttpTypes.AdminPromotionRule[] = []
|
||||
const disguisedRules = ruleAttributes.filter((attr) => !!attr.disguised)
|
||||
|
||||
for (const disguisedRule of disguisedRules) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../../types/routing"
|
||||
import { BatchMethodRequest } from "@medusajs/types"
|
||||
import { BatchMethodRequest, HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
AdminCreatePromotionRuleType,
|
||||
AdminUpdatePromotionRuleType,
|
||||
@@ -18,7 +18,7 @@ export const POST = async (
|
||||
AdminUpdatePromotionRuleType
|
||||
>
|
||||
>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse>
|
||||
) => {
|
||||
const id = req.params.id
|
||||
const { result } = await batchPromotionRulesWorkflow(req.scope).run({
|
||||
|
||||
@@ -16,11 +16,11 @@ import {
|
||||
AdminGetPromotionParamsType,
|
||||
AdminUpdatePromotionType,
|
||||
} from "../validators"
|
||||
import { AdditionalData } from "@medusajs/types"
|
||||
import { AdditionalData, DeleteResponse, HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest<AdminGetPromotionParamsType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminPromotionResponse>
|
||||
) => {
|
||||
const idOrCode = req.params.id
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
@@ -45,7 +45,7 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminUpdatePromotionType & AdditionalData>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminPromotionResponse>
|
||||
) => {
|
||||
const { additional_data, ...rest } = req.validatedBody
|
||||
const updatePromotions = updatePromotionsWorkflow(req.scope)
|
||||
@@ -71,7 +71,7 @@ export const POST = async (
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<DeleteResponse<"promotion">>
|
||||
) => {
|
||||
const id = req.params.id
|
||||
const deletePromotions = deletePromotionsWorkflow(req.scope)
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../../types/routing"
|
||||
import { BatchMethodRequest } from "@medusajs/types"
|
||||
import { BatchMethodRequest, HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
AdminCreatePromotionRuleType,
|
||||
AdminUpdatePromotionRuleType,
|
||||
@@ -18,7 +18,7 @@ export const POST = async (
|
||||
AdminUpdatePromotionRuleType
|
||||
>
|
||||
>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse>
|
||||
) => {
|
||||
const id = req.params.id
|
||||
const { result } = await batchPromotionRulesWorkflow(req.scope).run({
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../../types/routing"
|
||||
import { BatchMethodRequest } from "@medusajs/types"
|
||||
import { BatchMethodRequest, HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
AdminCreatePromotionRuleType,
|
||||
AdminUpdatePromotionRuleType,
|
||||
@@ -18,7 +18,7 @@ export const POST = async (
|
||||
AdminUpdatePromotionRuleType
|
||||
>
|
||||
>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse>
|
||||
) => {
|
||||
const id = req.params.id
|
||||
const { result } = await batchPromotionRulesWorkflow(req.scope).run({
|
||||
|
||||
@@ -12,11 +12,11 @@ import {
|
||||
AdminCreatePromotionType,
|
||||
AdminGetPromotionsParamsType,
|
||||
} from "./validators"
|
||||
import { AdditionalData } from "@medusajs/types"
|
||||
import { AdditionalData, HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest<AdminGetPromotionsParamsType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminPromotionListResponse>
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
@@ -41,7 +41,7 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminCreatePromotionType & AdditionalData>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminPromotionResponse>
|
||||
) => {
|
||||
const { additional_data, ...rest } = req.validatedBody
|
||||
const createPromotions = createPromotionsWorkflow(req.scope)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
@@ -7,7 +8,7 @@ import { AdminGetPromotionRuleParamsType } from "../../validators"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest<AdminGetPromotionRuleParamsType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminRuleAttributeOptionsListResponse>
|
||||
) => {
|
||||
const { rule_type: ruleType } = req.params
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
validateRuleType,
|
||||
} from "../../../utils"
|
||||
import { AdminGetPromotionRuleParamsType } from "../../../validators"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
/*
|
||||
This endpoint returns all the potential values for rules (promotion rules, target rules and buy rules)
|
||||
@@ -22,7 +23,7 @@ import { AdminGetPromotionRuleParamsType } from "../../../validators"
|
||||
*/
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest<AdminGetPromotionRuleParamsType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminRuleValueOptionsListResponse>
|
||||
) => {
|
||||
const {
|
||||
rule_type: ruleType,
|
||||
|
||||
@@ -2,7 +2,7 @@ import {
|
||||
deleteReturnReasonsWorkflow,
|
||||
updateRefundReasonsWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { RefundReasonResponse } from "@medusajs/types"
|
||||
import { DeleteResponse, RefundReasonResponse } from "@medusajs/types"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
@@ -51,7 +51,7 @@ export const POST = async (
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<DeleteResponse<"refund_reason">>
|
||||
) => {
|
||||
const { id } = req.params
|
||||
const input = { ids: [id] }
|
||||
|
||||
Reference in New Issue
Block a user