feat(medusa,types): added buyget support for modules (#6159)

This commit is contained in:
Riqwan Thamir
2024-01-23 21:01:44 +01:00
committed by GitHub
parent 302323916b
commit 68d8daccd2
22 changed files with 1058 additions and 109 deletions
@@ -1,3 +1,4 @@
import { PromotionTypeValues } from "@medusajs/types"
import {
ApplicationMethodAllocation,
ApplicationMethodTargetType,
@@ -15,6 +16,7 @@ import {
IsOptional,
IsString,
Validate,
ValidateIf,
ValidateNested,
} from "class-validator"
import { FindParams, extendedFindParamsMixin } from "../../../types/common"
@@ -43,7 +45,7 @@ export class AdminPostPromotionsReq {
@IsOptional()
@IsEnum(PromotionType)
type?: PromotionType
type?: PromotionTypeValues
@IsOptional()
@IsString()
@@ -56,8 +58,8 @@ export class AdminPostPromotionsReq {
@IsNotEmpty()
@ValidateNested()
@Type(() => ApplicationMethod)
application_method: ApplicationMethod
@Type(() => ApplicationMethodsPostReq)
application_method: ApplicationMethodsPostReq
@IsOptional()
@IsArray()
@@ -83,7 +85,7 @@ export class PromotionRule {
values: string[]
}
export class ApplicationMethod {
export class ApplicationMethodsPostReq {
@IsOptional()
@IsString()
description?: string
@@ -113,6 +115,68 @@ export class ApplicationMethod {
@ValidateNested({ each: true })
@Type(() => PromotionRule)
target_rules?: PromotionRule[]
@ValidateIf((data) => data.type === PromotionType.BUYGET)
@IsArray()
@ValidateNested({ each: true })
@Type(() => PromotionRule)
buy_rules?: PromotionRule[]
@ValidateIf((data) => data.type === PromotionType.BUYGET)
@IsNotEmpty()
@IsNumber()
apply_to_quantity?: number
@ValidateIf((data) => data.type === PromotionType.BUYGET)
@IsNotEmpty()
@IsNumber()
buy_rules_min_quantity?: number
}
export class ApplicationMethodsMethodPostReq {
@IsOptional()
@IsString()
description?: string
@IsOptional()
@IsString()
value?: string
@IsOptional()
@IsNumber()
max_quantity?: number
@IsOptional()
@IsEnum(ApplicationMethodType)
type?: ApplicationMethodType
@IsOptional()
@IsEnum(ApplicationMethodTargetType)
target_type?: ApplicationMethodTargetType
@IsOptional()
@IsEnum(ApplicationMethodAllocation)
allocation?: ApplicationMethodAllocation
@IsOptional()
@IsArray()
@ValidateNested({ each: true })
@Type(() => PromotionRule)
target_rules?: PromotionRule[]
@IsOptional()
@IsArray()
@ValidateNested({ each: true })
@Type(() => PromotionRule)
buy_rules?: PromotionRule[]
@IsOptional()
@IsNumber()
apply_to_quantity?: number
@IsOptional()
@IsNumber()
buy_rules_min_quantity?: number
}
export class AdminPostPromotionsPromotionReq {
@@ -141,8 +205,8 @@ export class AdminPostPromotionsPromotionReq {
@IsOptional()
@ValidateNested()
@Type(() => ApplicationMethod)
application_method?: ApplicationMethod
@Type(() => ApplicationMethodsMethodPostReq)
application_method?: ApplicationMethodsMethodPostReq
@IsOptional()
@IsArray()