chore(medusa,types): [11] Add request types to API routes (#8572)
This commit is contained in:
@@ -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 "./entities"
|
||||||
export * from "./rule-attribute-options"
|
export * from "./responses"
|
||||||
export * from "./rule-operator-options"
|
|
||||||
export * from "./rule-value-options"
|
|
||||||
@@ -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[]
|
|
||||||
}
|
|
||||||
@@ -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 {
|
export interface BasePromotion {
|
||||||
id: string
|
id: string
|
||||||
code?: string
|
code?: string
|
||||||
|
type?: PromotionTypeValues
|
||||||
is_automatic?: boolean
|
is_automatic?: boolean
|
||||||
application_method?: {
|
application_method?: BaseApplicationMethod
|
||||||
type?: ApplicationMethodTypeValues
|
rules?: BasePromotionRule[]
|
||||||
value?: number
|
campaign_id?: string
|
||||||
currency_code?: 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 {
|
import {
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
remoteQueryObjectFromString,
|
remoteQueryObjectFromString,
|
||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminPromotionRuleListResponse>
|
||||||
) => {
|
) => {
|
||||||
const { id, rule_type: ruleType } = req.params
|
const { id, rule_type: ruleType } = req.params
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
@@ -48,7 +48,7 @@ export const GET = async (
|
|||||||
promotionRules.push(...(promotion?.application_method?.buy_rules || []))
|
promotionRules.push(...(promotion?.application_method?.buy_rules || []))
|
||||||
}
|
}
|
||||||
|
|
||||||
const transformedRules: AdminGetPromotionRulesRes = []
|
const transformedRules: HttpTypes.AdminPromotionRule[] = []
|
||||||
const disguisedRules = ruleAttributes.filter((attr) => !!attr.disguised)
|
const disguisedRules = ruleAttributes.filter((attr) => !!attr.disguised)
|
||||||
|
|
||||||
for (const disguisedRule of disguisedRules) {
|
for (const disguisedRule of disguisedRules) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
} from "../../../../../../types/routing"
|
} from "../../../../../../types/routing"
|
||||||
import { BatchMethodRequest } from "@medusajs/types"
|
import { BatchMethodRequest, HttpTypes } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
AdminCreatePromotionRuleType,
|
AdminCreatePromotionRuleType,
|
||||||
AdminUpdatePromotionRuleType,
|
AdminUpdatePromotionRuleType,
|
||||||
@@ -18,7 +18,7 @@ export const POST = async (
|
|||||||
AdminUpdatePromotionRuleType
|
AdminUpdatePromotionRuleType
|
||||||
>
|
>
|
||||||
>,
|
>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse>
|
||||||
) => {
|
) => {
|
||||||
const id = req.params.id
|
const id = req.params.id
|
||||||
const { result } = await batchPromotionRulesWorkflow(req.scope).run({
|
const { result } = await batchPromotionRulesWorkflow(req.scope).run({
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ import {
|
|||||||
AdminGetPromotionParamsType,
|
AdminGetPromotionParamsType,
|
||||||
AdminUpdatePromotionType,
|
AdminUpdatePromotionType,
|
||||||
} from "../validators"
|
} from "../validators"
|
||||||
import { AdditionalData } from "@medusajs/types"
|
import { AdditionalData, DeleteResponse, HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminGetPromotionParamsType>,
|
req: AuthenticatedMedusaRequest<AdminGetPromotionParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminPromotionResponse>
|
||||||
) => {
|
) => {
|
||||||
const idOrCode = req.params.id
|
const idOrCode = req.params.id
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
@@ -45,7 +45,7 @@ export const GET = async (
|
|||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminUpdatePromotionType & AdditionalData>,
|
req: AuthenticatedMedusaRequest<AdminUpdatePromotionType & AdditionalData>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminPromotionResponse>
|
||||||
) => {
|
) => {
|
||||||
const { additional_data, ...rest } = req.validatedBody
|
const { additional_data, ...rest } = req.validatedBody
|
||||||
const updatePromotions = updatePromotionsWorkflow(req.scope)
|
const updatePromotions = updatePromotionsWorkflow(req.scope)
|
||||||
@@ -71,7 +71,7 @@ export const POST = async (
|
|||||||
|
|
||||||
export const DELETE = async (
|
export const DELETE = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<DeleteResponse<"promotion">>
|
||||||
) => {
|
) => {
|
||||||
const id = req.params.id
|
const id = req.params.id
|
||||||
const deletePromotions = deletePromotionsWorkflow(req.scope)
|
const deletePromotions = deletePromotionsWorkflow(req.scope)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
} from "../../../../../../types/routing"
|
} from "../../../../../../types/routing"
|
||||||
import { BatchMethodRequest } from "@medusajs/types"
|
import { BatchMethodRequest, HttpTypes } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
AdminCreatePromotionRuleType,
|
AdminCreatePromotionRuleType,
|
||||||
AdminUpdatePromotionRuleType,
|
AdminUpdatePromotionRuleType,
|
||||||
@@ -18,7 +18,7 @@ export const POST = async (
|
|||||||
AdminUpdatePromotionRuleType
|
AdminUpdatePromotionRuleType
|
||||||
>
|
>
|
||||||
>,
|
>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse>
|
||||||
) => {
|
) => {
|
||||||
const id = req.params.id
|
const id = req.params.id
|
||||||
const { result } = await batchPromotionRulesWorkflow(req.scope).run({
|
const { result } = await batchPromotionRulesWorkflow(req.scope).run({
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
} from "../../../../../../types/routing"
|
} from "../../../../../../types/routing"
|
||||||
import { BatchMethodRequest } from "@medusajs/types"
|
import { BatchMethodRequest, HttpTypes } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
AdminCreatePromotionRuleType,
|
AdminCreatePromotionRuleType,
|
||||||
AdminUpdatePromotionRuleType,
|
AdminUpdatePromotionRuleType,
|
||||||
@@ -18,7 +18,7 @@ export const POST = async (
|
|||||||
AdminUpdatePromotionRuleType
|
AdminUpdatePromotionRuleType
|
||||||
>
|
>
|
||||||
>,
|
>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminPromotionRuleBatchResponse>
|
||||||
) => {
|
) => {
|
||||||
const id = req.params.id
|
const id = req.params.id
|
||||||
const { result } = await batchPromotionRulesWorkflow(req.scope).run({
|
const { result } = await batchPromotionRulesWorkflow(req.scope).run({
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ import {
|
|||||||
AdminCreatePromotionType,
|
AdminCreatePromotionType,
|
||||||
AdminGetPromotionsParamsType,
|
AdminGetPromotionsParamsType,
|
||||||
} from "./validators"
|
} from "./validators"
|
||||||
import { AdditionalData } from "@medusajs/types"
|
import { AdditionalData, HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminGetPromotionsParamsType>,
|
req: AuthenticatedMedusaRequest<AdminGetPromotionsParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminPromotionListResponse>
|
||||||
) => {
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ export const GET = async (
|
|||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminCreatePromotionType & AdditionalData>,
|
req: AuthenticatedMedusaRequest<AdminCreatePromotionType & AdditionalData>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminPromotionResponse>
|
||||||
) => {
|
) => {
|
||||||
const { additional_data, ...rest } = req.validatedBody
|
const { additional_data, ...rest } = req.validatedBody
|
||||||
const createPromotions = createPromotionsWorkflow(req.scope)
|
const createPromotions = createPromotionsWorkflow(req.scope)
|
||||||
|
|||||||
+2
-1
@@ -1,3 +1,4 @@
|
|||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
@@ -7,7 +8,7 @@ import { AdminGetPromotionRuleParamsType } from "../../validators"
|
|||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminGetPromotionRuleParamsType>,
|
req: AuthenticatedMedusaRequest<AdminGetPromotionRuleParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminRuleAttributeOptionsListResponse>
|
||||||
) => {
|
) => {
|
||||||
const { rule_type: ruleType } = req.params
|
const { rule_type: ruleType } = req.params
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -12,6 +12,7 @@ import {
|
|||||||
validateRuleType,
|
validateRuleType,
|
||||||
} from "../../../utils"
|
} from "../../../utils"
|
||||||
import { AdminGetPromotionRuleParamsType } from "../../../validators"
|
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)
|
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 (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminGetPromotionRuleParamsType>,
|
req: AuthenticatedMedusaRequest<AdminGetPromotionRuleParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminRuleValueOptionsListResponse>
|
||||||
) => {
|
) => {
|
||||||
const {
|
const {
|
||||||
rule_type: ruleType,
|
rule_type: ruleType,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import {
|
|||||||
deleteReturnReasonsWorkflow,
|
deleteReturnReasonsWorkflow,
|
||||||
updateRefundReasonsWorkflow,
|
updateRefundReasonsWorkflow,
|
||||||
} from "@medusajs/core-flows"
|
} from "@medusajs/core-flows"
|
||||||
import { RefundReasonResponse } from "@medusajs/types"
|
import { DeleteResponse, RefundReasonResponse } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
@@ -51,7 +51,7 @@ export const POST = async (
|
|||||||
|
|
||||||
export const DELETE = async (
|
export const DELETE = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<DeleteResponse<"refund_reason">>
|
||||||
) => {
|
) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
const input = { ids: [id] }
|
const input = { ids: [id] }
|
||||||
|
|||||||
Reference in New Issue
Block a user