Skip to content

Commit

Permalink
feat(cart): Public-facing DTOs + (partial) module interface (#6000)
Browse files Browse the repository at this point in the history
  • Loading branch information
olivermrbl authored Jan 10, 2024
1 parent 6721633 commit ef50249
Show file tree
Hide file tree
Showing 11 changed files with 664 additions and 17 deletions.
3 changes: 3 additions & 0 deletions packages/cart/src/models/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
OnInit,
OneToMany,
OneToOne,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
Expand All @@ -22,6 +23,8 @@ type OptionalCartProps =

@Entity({ tableName: "cart" })
export default class Cart {
[OptionalProps]?: OptionalCartProps

@PrimaryKey({ columnType: "text" })
id: string

Expand Down
3 changes: 0 additions & 3 deletions packages/cart/src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
export { default as Address } from "./address"
export { default as AdjustmentLine } from "./adjustment-line"
export { default as Cart } from "./cart"
export { default as LineItem } from "./line-item"
export { default as LineItemAdjustmentLine } from "./line-item-adjustment-line"
export { default as LineItemTaxLine } from "./line-item-tax-line"
export { default as ShippingMethod } from "./shipping-method"
export { default as ShippingMethodAdjustmentLine } from "./shipping-method-adjustment-line"
export { default as ShippingMethodTaxLine } from "./shipping-method-tax-line"
export { default as TaxLine } from "./tax-line"

2 changes: 1 addition & 1 deletion packages/cart/src/models/line-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
OneToMany,
OptionalProps,
PrimaryKey,
Property
Property,
} from "@mikro-orm/core"
import Cart from "./cart"
import LineItemAdjustmentLine from "./line-item-adjustment-line"
Expand Down
4 changes: 2 additions & 2 deletions packages/cart/src/models/shipping-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class ShippingMethod {
cart: Cart

@Property({ columnType: "text" })
title: string
name: string

@Property({ columnType: "jsonb", nullable: true })
description?: string | null
Expand All @@ -38,7 +38,7 @@ export default class ShippingMethod {
amount: number

@Property({ columnType: "boolean" })
tax_inclusive = false
is_tax_inclusive = false

@Property({ columnType: "text", nullable: true })
shipping_option_id?: string | null
Expand Down
7 changes: 2 additions & 5 deletions packages/cart/src/services/cart-module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
CartTypes,
DAL,
InternalModuleDeclaration,
ModuleJoinerConfig,
Expand All @@ -13,10 +12,8 @@ type InjectedDependencies = {
baseRepository: DAL.RepositoryService
}

export default class CartModuleService<
TCart extends Cart = Cart
> implements CartTypes.ICartModuleService
{
// TODO: implement ICartModuleService from @medusajs/types
export default class CartModuleService<TCart extends Cart = Cart> {
protected baseRepository_: DAL.RepositoryService

constructor(
Expand Down
4 changes: 2 additions & 2 deletions packages/core-flows/src/handlers/cart/create-cart.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AddressDTO, CartDTO, CustomerDTO, RegionDTO } from "@medusajs/types"
import { AddressDTO, CustomerDTO, RegionDTO, legacy__CartDTO } from "@medusajs/types"
import { WorkflowArguments } from "@medusajs/workflows-sdk"

enum Aliases {
Expand Down Expand Up @@ -34,7 +34,7 @@ type HandlerInputData = {
}

type HandlerOutputData = {
cart: CartDTO
cart: legacy__CartDTO
}

export async function createCart({
Expand Down
4 changes: 2 additions & 2 deletions packages/core-flows/src/handlers/cart/retrieve-cart.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CartDTO } from "@medusajs/types"
import { legacy__CartDTO } from "@medusajs/types"
import { WorkflowArguments } from "@medusajs/workflows-sdk"

type HandlerInputData = {
Expand All @@ -22,7 +22,7 @@ export async function retrieveCart({
container,
context,
data,
}: WorkflowArguments<HandlerInputData>): Promise<CartDTO> {
}: WorkflowArguments<HandlerInputData>): Promise<legacy__CartDTO> {
const { manager } = context

const cartService = container.resolve("cartService")
Expand Down
Loading

1 comment on commit ef50249

@vercel
Copy link

@vercel vercel bot commented on ef50249 Jan 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

medusa-dashboard – ./packages/admin-next/dashboard

medusa-dashboard-medusajs.vercel.app
medusa-dashboard-git-develop-medusajs.vercel.app
medusa-dashboard.vercel.app
admin-preview.medusajs.com

Please sign in to comment.