chore: rename rule endpoints validators (#6955)
This commit is contained in:
@@ -10,10 +10,10 @@ import {
|
||||
defaultAdminPromotionFields,
|
||||
defaultAdminPromotionRelations,
|
||||
} from "../../../../query-config"
|
||||
import { AdminPostPromotionsPromotionRulesBatchAddReq } from "../../../../validators"
|
||||
import { AdminPostBatchAddRules } from "../../../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostPromotionsPromotionRulesBatchAddReq>,
|
||||
req: AuthenticatedMedusaRequest<AdminPostBatchAddRules>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const id = req.params.id
|
||||
|
||||
@@ -4,10 +4,10 @@ import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../../../types/routing"
|
||||
import { AdminPostPromotionsPromotionRulesBatchRemoveReq } from "../../../../validators"
|
||||
import { AdminPostBatchRemoveRules } from "../../../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostPromotionsPromotionRulesBatchRemoveReq>,
|
||||
req: AuthenticatedMedusaRequest<AdminPostBatchRemoveRules>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const id = req.params.id
|
||||
|
||||
@@ -10,10 +10,10 @@ import {
|
||||
defaultAdminPromotionFields,
|
||||
defaultAdminPromotionRelations,
|
||||
} from "../../../../query-config"
|
||||
import { AdminPostPromotionsPromotionRulesBatchAddReq } from "../../../../validators"
|
||||
import { AdminPostBatchAddRules } from "../../../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostPromotionsPromotionRulesBatchAddReq>,
|
||||
req: AuthenticatedMedusaRequest<AdminPostBatchAddRules>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const id = req.params.id
|
||||
|
||||
@@ -3,12 +3,12 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../../../types/routing"
|
||||
|
||||
import { AdminPostPromotionsPromotionRulesBatchRemoveReq } from "../../../../validators"
|
||||
import { RuleType } from "@medusajs/utils"
|
||||
import { removeRulesFromPromotionsWorkflow } from "@medusajs/core-flows"
|
||||
import { RuleType } from "@medusajs/utils"
|
||||
import { AdminPostBatchRemoveRules } from "../../../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostPromotionsPromotionRulesBatchRemoveReq>,
|
||||
req: AuthenticatedMedusaRequest<AdminPostBatchRemoveRules>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const id = req.params.id
|
||||
|
||||
@@ -9,10 +9,10 @@ import {
|
||||
defaultAdminPromotionFields,
|
||||
defaultAdminPromotionRelations,
|
||||
} from "../../../../query-config"
|
||||
import { AdminPostPromotionsPromotionRulesBatchUpdateReq } from "../../../../validators"
|
||||
import { AdminPostBatchUpdateRules } from "../../../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostPromotionsPromotionRulesBatchUpdateReq>,
|
||||
req: AuthenticatedMedusaRequest<AdminPostBatchUpdateRules>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const id = req.params.id
|
||||
|
||||
@@ -10,10 +10,10 @@ import {
|
||||
defaultAdminPromotionFields,
|
||||
defaultAdminPromotionRelations,
|
||||
} from "../../../../query-config"
|
||||
import { AdminPostPromotionsPromotionRulesBatchAddReq } from "../../../../validators"
|
||||
import { AdminPostBatchAddRules } from "../../../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostPromotionsPromotionRulesBatchAddReq>,
|
||||
req: AuthenticatedMedusaRequest<AdminPostBatchAddRules>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const id = req.params.id
|
||||
|
||||
@@ -4,10 +4,10 @@ import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../../../types/routing"
|
||||
import { AdminPostPromotionsPromotionRulesBatchRemoveReq } from "../../../../validators"
|
||||
import { AdminPostBatchRemoveRules } from "../../../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostPromotionsPromotionRulesBatchRemoveReq>,
|
||||
req: AuthenticatedMedusaRequest<AdminPostBatchRemoveRules>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const id = req.params.id
|
||||
|
||||
@@ -5,10 +5,10 @@ import {
|
||||
AdminGetPromotionsParams,
|
||||
AdminGetPromotionsPromotionParams,
|
||||
AdminGetPromotionsRuleValueParams,
|
||||
AdminPostBatchAddRules,
|
||||
AdminPostBatchRemoveRules,
|
||||
AdminPostBatchUpdateRules,
|
||||
AdminPostPromotionsPromotionReq,
|
||||
AdminPostPromotionsPromotionRulesBatchAddReq,
|
||||
AdminPostPromotionsPromotionRulesBatchRemoveReq,
|
||||
AdminPostPromotionsPromotionRulesBatchUpdateReq,
|
||||
AdminPostPromotionsReq,
|
||||
} from "./validators"
|
||||
|
||||
@@ -53,45 +53,37 @@ export const adminPromotionRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/promotions/:id/rules/batch/add",
|
||||
middlewares: [transformBody(AdminPostPromotionsPromotionRulesBatchAddReq)],
|
||||
middlewares: [transformBody(AdminPostBatchAddRules)],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/promotions/:id/target-rules/batch/add",
|
||||
middlewares: [transformBody(AdminPostPromotionsPromotionRulesBatchAddReq)],
|
||||
middlewares: [transformBody(AdminPostBatchAddRules)],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/promotions/:id/buy-rules/batch/add",
|
||||
middlewares: [transformBody(AdminPostPromotionsPromotionRulesBatchAddReq)],
|
||||
middlewares: [transformBody(AdminPostBatchAddRules)],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/promotions/:id/rules/batch/update",
|
||||
middlewares: [
|
||||
transformBody(AdminPostPromotionsPromotionRulesBatchUpdateReq),
|
||||
],
|
||||
middlewares: [transformBody(AdminPostBatchUpdateRules)],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/promotions/:id/rules/batch/remove",
|
||||
middlewares: [
|
||||
transformBody(AdminPostPromotionsPromotionRulesBatchRemoveReq),
|
||||
],
|
||||
middlewares: [transformBody(AdminPostBatchRemoveRules)],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/promotions/:id/target-rules/batch/remove",
|
||||
middlewares: [
|
||||
transformBody(AdminPostPromotionsPromotionRulesBatchRemoveReq),
|
||||
],
|
||||
middlewares: [transformBody(AdminPostBatchRemoveRules)],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/promotions/:id/buy-rules/batch/remove",
|
||||
middlewares: [
|
||||
transformBody(AdminPostPromotionsPromotionRulesBatchRemoveReq),
|
||||
],
|
||||
middlewares: [transformBody(AdminPostBatchRemoveRules)],
|
||||
},
|
||||
{
|
||||
method: ["GET"],
|
||||
|
||||
@@ -74,6 +74,23 @@ export class AdminGetPromotionsParams extends extendedFindParamsMixin({
|
||||
updated_at?: DateComparisonOperator
|
||||
}
|
||||
|
||||
export class AdminPostCreatePromotionRule {
|
||||
@IsEnum(PromotionRuleOperator)
|
||||
operator: PromotionRuleOperator
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string | null
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
attribute: string
|
||||
|
||||
@IsArray()
|
||||
@Type(() => String)
|
||||
values: string[]
|
||||
}
|
||||
|
||||
export class AdminPostPromotionsReq {
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@@ -103,25 +120,8 @@ export class AdminPostPromotionsReq {
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => PromotionRule)
|
||||
rules?: PromotionRule[]
|
||||
}
|
||||
|
||||
export class PromotionRule {
|
||||
@IsEnum(PromotionRuleOperator)
|
||||
operator: PromotionRuleOperator
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string | null
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
attribute: string
|
||||
|
||||
@IsArray()
|
||||
@Type(() => String)
|
||||
values: string[]
|
||||
@Type(() => AdminPostCreatePromotionRule)
|
||||
rules?: AdminPostCreatePromotionRule[]
|
||||
}
|
||||
|
||||
export class AdminPostApplicationMethodsReq {
|
||||
@@ -151,14 +151,14 @@ export class AdminPostApplicationMethodsReq {
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => PromotionRule)
|
||||
target_rules?: PromotionRule[]
|
||||
@Type(() => AdminPostCreatePromotionRule)
|
||||
target_rules?: AdminPostCreatePromotionRule[]
|
||||
|
||||
@ValidateIf((data) => data.type === PromotionType.BUYGET)
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => PromotionRule)
|
||||
buy_rules?: PromotionRule[]
|
||||
@Type(() => AdminPostCreatePromotionRule)
|
||||
buy_rules?: AdminPostCreatePromotionRule[]
|
||||
|
||||
@ValidateIf((data) => data.type === PromotionType.BUYGET)
|
||||
@IsNotEmpty()
|
||||
@@ -199,14 +199,14 @@ export class AdminPostApplicationMethodsMethodReq {
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => PromotionRule)
|
||||
target_rules?: PromotionRule[]
|
||||
@Type(() => AdminPostCreatePromotionRule)
|
||||
target_rules?: AdminPostCreatePromotionRule[]
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => PromotionRule)
|
||||
buy_rules?: PromotionRule[]
|
||||
@Type(() => AdminPostCreatePromotionRule)
|
||||
buy_rules?: AdminPostCreatePromotionRule[]
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@@ -249,31 +249,31 @@ export class AdminPostPromotionsPromotionReq {
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => PromotionRule)
|
||||
rules?: PromotionRule[]
|
||||
@Type(() => AdminPostCreatePromotionRule)
|
||||
rules?: AdminPostCreatePromotionRule[]
|
||||
}
|
||||
|
||||
export class AdminPostPromotionsPromotionRulesBatchAddReq {
|
||||
export class AdminPostBatchAddRules {
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => PromotionRule)
|
||||
rules: PromotionRule[]
|
||||
@Type(() => AdminPostCreatePromotionRule)
|
||||
rules: AdminPostCreatePromotionRule[]
|
||||
}
|
||||
|
||||
export class AdminPostPromotionsPromotionRulesBatchRemoveReq {
|
||||
export class AdminPostBatchRemoveRules {
|
||||
@ArrayNotEmpty()
|
||||
@IsString({ each: true })
|
||||
rule_ids: string[]
|
||||
}
|
||||
|
||||
export class AdminPostPromotionsPromotionRulesBatchUpdateReq {
|
||||
export class AdminPostBatchUpdateRules {
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => UpdatePromotionRule)
|
||||
rules: UpdatePromotionRule[]
|
||||
@Type(() => AdminPostUpdatePromotionRule)
|
||||
rules: AdminPostUpdatePromotionRule[]
|
||||
}
|
||||
|
||||
export class UpdatePromotionRule {
|
||||
export class AdminPostUpdatePromotionRule {
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
id: string
|
||||
@@ -289,10 +289,10 @@ export class UpdatePromotionRule {
|
||||
@IsOptional()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
attribute: string
|
||||
attribute?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@Type(() => String)
|
||||
values: string[]
|
||||
values?: string[]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user