Skip to content

Commit

Permalink
update types
Browse files Browse the repository at this point in the history
  • Loading branch information
pKorsholm committed Nov 6, 2023
1 parent cbb483d commit e499a88
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
IsString,
ValidateNested,
} from "class-validator"
import { Workflows, createPriceLists } from "@medusajs/workflows"
import { Workflows } from "@medusajs/workflows"
import {
defaultAdminPriceListFields,
defaultAdminPriceListRelations,
Expand All @@ -26,7 +26,6 @@ import PriceListService from "../../../../services/price-list"
import { Request } from "express"
import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/tax-inclusive-pricing"
import { Type } from "class-transformer"
import { WorkflowTypes } from "@medusajs/types"

/**
* @oas [post] /admin/price-lists
Expand Down Expand Up @@ -120,34 +119,34 @@ export default async (req: Request, res) => {
workflows: Workflows.CreatePriceList,
})

if (isWorkflowEnabled) {
const createPriceListWorkflow = createPriceLists(req.scope)
// if (isWorkflowEnabled) {
// const createPriceListWorkflow = createPriceLists(req.scope)

const input = {
priceLists: [
req.validatedBody,
] as WorkflowTypes.PriceListWorkflow.CreatePriceListDTO[],
}
// const input = {
// priceLists: [
// req.validatedBody,
// ] as WorkflowTypes.PriceListWorkflow.CreatePriceListDTO[],
// }

const { result } = await createPriceListWorkflow.run({
input,
context: {
manager,
},
})
priceList = result[0]
} else {
const createdPl = await manager.transaction(async (transactionManager) => {
return await priceListService
.withTransaction(transactionManager)
.create(req.validatedBody as CreatePriceListInput)
})
// const { result } = await createPriceListWorkflow.run({
// input,
// context: {
// manager,
// },
// })
// priceList = result[0]
// } else {
const createdPl = await manager.transaction(async (transactionManager) => {
return await priceListService
.withTransaction(transactionManager)
.create(req.validatedBody as CreatePriceListInput)
})

priceList = await priceListService.retrieve(createdPl.id, {
select: defaultAdminPriceListFields as (keyof PriceList)[],
relations: defaultAdminPriceListRelations,
})
}
priceList = await priceListService.retrieve(createdPl.id, {
select: defaultAdminPriceListFields as (keyof PriceList)[],
relations: defaultAdminPriceListRelations,
})
// }

res.json({ price_list: priceList })
}
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/pricing/common/price-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface FilterablePriceListProps
status?: PriceListStatus[]
number_rules?: number[]
}

export interface FilterablePriceListRuleProps
extends BaseFilterable<FilterablePriceListRuleProps> {
id?: string[]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { InventoryTypes, WorkflowTypes } from "@medusajs/types"
import { PricingTypes, WorkflowTypes } from "@medusajs/types"
import {
TransactionStepsDefinition,
WorkflowManager,
} from "@medusajs/orchestration"
import { exportWorkflow, pipe } from "../../helper"

import { PriceListHandlers } from "../../handlers"
import { PricingTypes } from "@medusajs/types"
import { Workflows } from "../../definitions"

export enum CreatePriceListActions {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { CreatePriceListDTO, CreatePriceListRuleDTO, IPricingModuleService, PriceListDTO } from "@medusajs/types"

import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import {
CreatePriceListDTO,
CreatePriceListRuleDTO,
PriceListStatus,
} from "@medusajs/types"
import { WorkflowArguments } from "../../helper"

type Result = {
tag: string
priceList: PriceListDTO
tag?: string
priceList: Omit<CreatePriceListDTO, "rules" | "prices">
rules: CreatePriceListRuleDTO[]
prices: CreatePriceListPriceDTO[]
prices: string[] //CreatePriceListPriceDTO
}[]

export async function prepareCreatePriceLists({
container,
data,
}: WorkflowArguments<{
priceLists: (CreatePriceListDTO & { _associationTag?: string })[]
priceLists: (CreatePriceListWorkflowDTO & { _associationTag?: string })[]
}>): Promise<Result | void> {
const pricingService: IPricingModuleService =
// const pricingService: IPricingModuleService =
// container.resolve(ModuleRegistrationName.PRICING)

// if (!pricingService) {
Expand All @@ -30,16 +32,46 @@ export async function prepareCreatePriceLists({
// return await Promise.all(
// data.priceLists.map(async (item) => {
// const [priceList] = await pricingService!.createPriceLists([{

// }])

// return { tag: item._associationTag ?? priceList.id, priceList }
// })
// )

const { priceLists } = data
return priceLists.map((priceListDTO) => {
priceListDTO.title ??= priceListDTO.name
const {
_associationTag,
customer_groups,
rules = [],
type,
includes_tax,
name,
// prices,
...priceList
} = priceListDTO

return { priceList, prices: [], rules, tag: _associationTag }
})
}

prepareCreatePriceLists.aliases = {
payload: "payload",
}

export interface CreatePriceListWorkflowDTO {
name: string
title?: string
description: string
starts_at?: Date
ends_at?: Date
status?: PriceListStatus
number_rules?: number
customer_groups: { id: string }[]
rules?: CreatePriceListRuleDTO[]
type?: string
includes_tax?: boolean
// prices: PriceListPriceDTO[];
}

0 comments on commit e499a88

Please sign in to comment.