feat(cart): Partial module service implementation (#6012)
Awaiting #6000 #6008 **What** - CRUD for Address in Cart Module service - Tests for CRUD Carts + Address **Not** - Line items, shipping methods, tax lines, adjustment lines
This commit is contained in:
1 parent
8472460f53
commit
192bc336cc
16 files changed
+433
-39
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/inventory": patch
|
||||||
|
"@medusajs/stock-location": patch
|
||||||
|
"@medusajs/types": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat(cart): Partial module service implementation
|
||||||
@@ -14,7 +14,7 @@ export const defaultCartsData = [
|
|||||||
first_name: "Tony",
|
first_name: "Tony",
|
||||||
last_name: "Stark",
|
last_name: "Stark",
|
||||||
},
|
},
|
||||||
billing_address_id: {
|
billing_address: {
|
||||||
address_1: "Stark Industries",
|
address_1: "Stark Industries",
|
||||||
city: "New York",
|
city: "New York",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ describe("Address Service", () => {
|
|||||||
.catch((e) => e)
|
.catch((e) => e)
|
||||||
|
|
||||||
expect(error.message).toContain(
|
expect(error.message).toContain(
|
||||||
"Address with id \"none-existing\" not found"
|
'Address with id "none-existing" not found'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,245 @@
|
|||||||
|
import { ICartModuleService } from "@medusajs/types"
|
||||||
|
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||||
|
import { initialize } from "../../../../src/initialize"
|
||||||
|
import { DB_URL, MikroOrmWrapper } from "../../../utils"
|
||||||
|
|
||||||
|
jest.setTimeout(30000)
|
||||||
|
|
||||||
|
describe("Cart Module Service", () => {
|
||||||
|
let service: ICartModuleService
|
||||||
|
let repositoryManager: SqlEntityManager
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await MikroOrmWrapper.setupDatabase()
|
||||||
|
repositoryManager = await MikroOrmWrapper.forkManager()
|
||||||
|
|
||||||
|
service = await initialize({
|
||||||
|
database: {
|
||||||
|
clientUrl: DB_URL,
|
||||||
|
schema: process.env.MEDUSA_CART_DB_SCHEMA,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await MikroOrmWrapper.clearDatabase()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("create", () => {
|
||||||
|
it("should throw an error when required params are not passed", async () => {
|
||||||
|
const error = await service
|
||||||
|
.create([
|
||||||
|
{
|
||||||
|
email: "test@email.com",
|
||||||
|
} as any,
|
||||||
|
])
|
||||||
|
.catch((e) => e)
|
||||||
|
|
||||||
|
expect(error.message).toContain(
|
||||||
|
"Value for Cart.currency_code is required, 'undefined' found"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should create a cart successfully", async () => {
|
||||||
|
const [createdCart] = await service.create([
|
||||||
|
{
|
||||||
|
currency_code: "eur",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const [cart] = await service.list({ id: [createdCart.id] })
|
||||||
|
|
||||||
|
expect(cart).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: createdCart.id,
|
||||||
|
currency_code: "eur",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should create a cart with billing + shipping address successfully", async () => {
|
||||||
|
const [createdCart] = await service.create([
|
||||||
|
{
|
||||||
|
currency_code: "eur",
|
||||||
|
billing_address: {
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
},
|
||||||
|
shipping_address: {
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const [cart] = await service.list(
|
||||||
|
{ id: [createdCart.id] },
|
||||||
|
{ relations: ["billing_address", "shipping_address"] }
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(cart).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: createdCart.id,
|
||||||
|
currency_code: "eur",
|
||||||
|
billing_address: expect.objectContaining({
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
}),
|
||||||
|
shipping_address: expect.objectContaining({
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should create a cart with billing id + shipping id successfully", async () => {
|
||||||
|
const [createdAddress] = await service.createAddresses([
|
||||||
|
{
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const [createdCart] = await service.create([
|
||||||
|
{
|
||||||
|
currency_code: "eur",
|
||||||
|
billing_address_id: createdAddress.id,
|
||||||
|
shipping_address_id: createdAddress.id,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
expect(createdCart).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: createdCart.id,
|
||||||
|
currency_code: "eur",
|
||||||
|
billing_address: expect.objectContaining({
|
||||||
|
id: createdAddress.id,
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
}),
|
||||||
|
shipping_address: expect.objectContaining({
|
||||||
|
id: createdAddress.id,
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("update", () => {
|
||||||
|
it("should throw an error if cart does not exist", async () => {
|
||||||
|
const error = await service
|
||||||
|
.update([
|
||||||
|
{
|
||||||
|
id: "none-existing",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
.catch((e) => e)
|
||||||
|
|
||||||
|
expect(error.message).toContain('Cart with id "none-existing" not found')
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should update a cart successfully", async () => {
|
||||||
|
const [createdCart] = await service.create([
|
||||||
|
{
|
||||||
|
currency_code: "eur",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const [updatedCart] = await service.update([
|
||||||
|
{
|
||||||
|
id: createdCart.id,
|
||||||
|
email: "test@email.com",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const [cart] = await service.list({ id: [createdCart.id] })
|
||||||
|
|
||||||
|
expect(cart).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: createdCart.id,
|
||||||
|
currency_code: "eur",
|
||||||
|
email: updatedCart.email,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("delete", () => {
|
||||||
|
it("should delete a cart successfully", async () => {
|
||||||
|
const [createdCart] = await service.create([
|
||||||
|
{
|
||||||
|
currency_code: "eur",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
await service.delete([createdCart.id])
|
||||||
|
|
||||||
|
const carts = await service.list({ id: [createdCart.id] })
|
||||||
|
|
||||||
|
expect(carts.length).toEqual(0)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("createAddresses", () => {
|
||||||
|
it("should create an address successfully", async () => {
|
||||||
|
const [createdAddress] = await service.createAddresses([
|
||||||
|
{
|
||||||
|
first_name: "John",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const [address] = await service.listAddresses({
|
||||||
|
id: [createdAddress.id!],
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(address).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: createdAddress.id,
|
||||||
|
first_name: "John",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("updateAddresses", () => {
|
||||||
|
it("should update an address successfully", async () => {
|
||||||
|
const [createdAddress] = await service.createAddresses([
|
||||||
|
{
|
||||||
|
first_name: "John",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const [updatedAddress] = await service.updateAddresses([
|
||||||
|
{ id: createdAddress.id!, first_name: "Jane" },
|
||||||
|
])
|
||||||
|
|
||||||
|
expect(updatedAddress).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: createdAddress.id,
|
||||||
|
first_name: "Jane",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("deleteAddresses", () => {
|
||||||
|
it("should delete an address successfully", async () => {
|
||||||
|
const [createdAddress] = await service.createAddresses([
|
||||||
|
{
|
||||||
|
first_name: "John",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
await service.deleteAddresses([createdAddress.id!])
|
||||||
|
|
||||||
|
const [address] = await service.listAddresses({
|
||||||
|
id: [createdAddress.id!],
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(address).toBe(undefined)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -17,7 +17,7 @@ describe("Cart Service", () => {
|
|||||||
testManager = await MikroOrmWrapper.forkManager()
|
testManager = await MikroOrmWrapper.forkManager()
|
||||||
|
|
||||||
const cartRepository = new CartRepository({
|
const cartRepository = new CartRepository({
|
||||||
manager: repositoryManager,
|
manager: repositoryManager
|
||||||
})
|
})
|
||||||
|
|
||||||
service = new CartService({
|
service = new CartService({
|
||||||
@@ -74,9 +74,7 @@ describe("Cart Service", () => {
|
|||||||
])
|
])
|
||||||
.catch((e) => e)
|
.catch((e) => e)
|
||||||
|
|
||||||
expect(error.message).toContain(
|
expect(error.message).toContain('Cart with id "none-existing" not found')
|
||||||
"Cart with id \"none-existing\" not found"
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should update a cart successfully", async () => {
|
it("should update a cart successfully", async () => {
|
||||||
@@ -87,7 +85,6 @@ describe("Cart Service", () => {
|
|||||||
])
|
])
|
||||||
|
|
||||||
const [updatedCart] = await service.update([
|
const [updatedCart] = await service.update([
|
||||||
|
|
||||||
{
|
{
|
||||||
id: createdCart.id,
|
id: createdCart.id,
|
||||||
email: "test@email.com",
|
email: "test@email.com",
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
|
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@medusajs/types": "workspace:^",
|
||||||
"@mikro-orm/cli": "5.9.7",
|
"@mikro-orm/cli": "5.9.7",
|
||||||
"cross-env": "^5.2.1",
|
"cross-env": "^5.2.1",
|
||||||
"jest": "^29.6.3",
|
"jest": "^29.6.3",
|
||||||
@@ -51,7 +52,6 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@medusajs/modules-sdk": "^1.12.5",
|
"@medusajs/modules-sdk": "^1.12.5",
|
||||||
"@medusajs/types": "^1.11.9",
|
|
||||||
"@medusajs/utils": "^1.11.2",
|
"@medusajs/utils": "^1.11.2",
|
||||||
"@mikro-orm/core": "5.9.7",
|
"@mikro-orm/core": "5.9.7",
|
||||||
"@mikro-orm/migrations": "5.9.7",
|
"@mikro-orm/migrations": "5.9.7",
|
||||||
|
|||||||
@@ -10,7 +10,11 @@ import { moduleDefinition } from "../module-definition"
|
|||||||
import { InitializeModuleInjectableDependencies } from "../types"
|
import { InitializeModuleInjectableDependencies } from "../types"
|
||||||
|
|
||||||
export const initialize = async (
|
export const initialize = async (
|
||||||
options?: ModulesSdkTypes.ModuleBootstrapDeclaration,
|
options?:
|
||||||
|
| ModulesSdkTypes.ModuleServiceInitializeOptions
|
||||||
|
| ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions
|
||||||
|
| ExternalModuleDeclaration
|
||||||
|
| InternalModuleDeclaration,
|
||||||
injectedDependencies?: InitializeModuleInjectableDependencies
|
injectedDependencies?: InitializeModuleInjectableDependencies
|
||||||
): Promise<ICartModuleService> => {
|
): Promise<ICartModuleService> => {
|
||||||
const loaded = await MedusaModule.bootstrap<ICartModuleService>({
|
const loaded = await MedusaModule.bootstrap<ICartModuleService>({
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import * as defaultRepositories from "@repositories"
|
|||||||
import { LoaderOptions } from "@medusajs/modules-sdk"
|
import { LoaderOptions } from "@medusajs/modules-sdk"
|
||||||
import { ModulesSdkTypes } from "@medusajs/types"
|
import { ModulesSdkTypes } from "@medusajs/types"
|
||||||
import { loadCustomRepositories } from "@medusajs/utils"
|
import { loadCustomRepositories } from "@medusajs/utils"
|
||||||
|
import * as defaultServices from "@services"
|
||||||
import { asClass } from "awilix"
|
import { asClass } from "awilix"
|
||||||
|
|
||||||
export default async ({
|
export default async ({
|
||||||
@@ -17,7 +18,8 @@ export default async ({
|
|||||||
)?.repositories
|
)?.repositories
|
||||||
|
|
||||||
container.register({
|
container.register({
|
||||||
// cartService: asClass(defaultServices.CartService).singleton(),
|
cartService: asClass(defaultServices.CartService).singleton(),
|
||||||
|
addressService: asClass(defaultServices.AddressService).singleton(),
|
||||||
})
|
})
|
||||||
|
|
||||||
if (customRepositories) {
|
if (customRepositories) {
|
||||||
@@ -34,5 +36,7 @@ export default async ({
|
|||||||
function loadDefaultRepositories({ container }) {
|
function loadDefaultRepositories({ container }) {
|
||||||
container.register({
|
container.register({
|
||||||
baseRepository: asClass(defaultRepositories.BaseRepository).singleton(),
|
baseRepository: asClass(defaultRepositories.BaseRepository).singleton(),
|
||||||
|
cartRepository: asClass(defaultRepositories.CartRepository).singleton(),
|
||||||
|
addressRepository: asClass(defaultRepositories.AddressRepository).singleton(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -5,9 +5,10 @@ import {
|
|||||||
Cascade,
|
Cascade,
|
||||||
Collection,
|
Collection,
|
||||||
Entity,
|
Entity,
|
||||||
|
Index,
|
||||||
|
ManyToOne,
|
||||||
OnInit,
|
OnInit,
|
||||||
OneToMany,
|
OneToMany,
|
||||||
OneToOne,
|
|
||||||
OptionalProps,
|
OptionalProps,
|
||||||
PrimaryKey,
|
PrimaryKey,
|
||||||
Property,
|
Property,
|
||||||
@@ -19,7 +20,7 @@ import ShippingMethod from "./shipping-method"
|
|||||||
type OptionalCartProps =
|
type OptionalCartProps =
|
||||||
| "shipping_address"
|
| "shipping_address"
|
||||||
| "billing_address"
|
| "billing_address"
|
||||||
| DAL.EntityDateColumns // TODO: To be revisited when more clear
|
| DAL.EntityDateColumns
|
||||||
|
|
||||||
@Entity({ tableName: "cart" })
|
@Entity({ tableName: "cart" })
|
||||||
export default class Cart {
|
export default class Cart {
|
||||||
@@ -47,18 +48,22 @@ export default class Cart {
|
|||||||
@Property({ columnType: "text" })
|
@Property({ columnType: "text" })
|
||||||
currency_code: string
|
currency_code: string
|
||||||
|
|
||||||
@OneToOne({
|
@Index({ name: "IDX_cart_shipping_address_id" })
|
||||||
entity: () => Address,
|
@Property({ columnType: "text", nullable: true })
|
||||||
joinColumn: "shipping_address_id",
|
shipping_address_id?: string | null
|
||||||
cascade: [Cascade.REMOVE],
|
|
||||||
|
@ManyToOne(() => Address, {
|
||||||
|
fieldName: "shipping_address_id",
|
||||||
nullable: true,
|
nullable: true,
|
||||||
})
|
})
|
||||||
shipping_address?: Address | null
|
shipping_address?: Address | null
|
||||||
|
|
||||||
@OneToOne({
|
@Index({ name: "IDX_cart_billing_address_id" })
|
||||||
entity: () => Address,
|
@Property({ columnType: "text", nullable: true })
|
||||||
joinColumn: "billing_address_id",
|
billing_address_id?: string | null
|
||||||
cascade: [Cascade.REMOVE],
|
|
||||||
|
@ManyToOne(() => Address, {
|
||||||
|
fieldName: "billing_address_id",
|
||||||
nullable: true,
|
nullable: true,
|
||||||
})
|
})
|
||||||
billing_address?: Address | null
|
billing_address?: Address | null
|
||||||
@@ -116,7 +121,7 @@ export default class Cart {
|
|||||||
columnType: "timestamptz",
|
columnType: "timestamptz",
|
||||||
defaultRaw: "now()",
|
defaultRaw: "now()",
|
||||||
})
|
})
|
||||||
created_at: Date
|
created_at?: Date
|
||||||
|
|
||||||
@Property({
|
@Property({
|
||||||
onCreate: () => new Date(),
|
onCreate: () => new Date(),
|
||||||
@@ -124,7 +129,10 @@ export default class Cart {
|
|||||||
columnType: "timestamptz",
|
columnType: "timestamptz",
|
||||||
defaultRaw: "now()",
|
defaultRaw: "now()",
|
||||||
})
|
})
|
||||||
updated_at: Date
|
updated_at?: Date
|
||||||
|
|
||||||
|
@Property({ columnType: "timestamptz", nullable: true })
|
||||||
|
deleted_at?: Date
|
||||||
|
|
||||||
@BeforeCreate()
|
@BeforeCreate()
|
||||||
onCreate() {
|
onCreate() {
|
||||||
|
|||||||
@@ -6,3 +6,4 @@ export { default as LineItemTaxLine } from "./line-item-tax-line"
|
|||||||
export { default as ShippingMethod } from "./shipping-method"
|
export { default as ShippingMethod } from "./shipping-method"
|
||||||
export { default as ShippingMethodAdjustmentLine } from "./shipping-method-adjustment-line"
|
export { default as ShippingMethodAdjustmentLine } from "./shipping-method-adjustment-line"
|
||||||
export { default as ShippingMethodTaxLine } from "./shipping-method-tax-line"
|
export { default as ShippingMethodTaxLine } from "./shipping-method-tax-line"
|
||||||
|
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
|
AddressDTO,
|
||||||
|
CartAddressDTO,
|
||||||
CartDTO,
|
CartDTO,
|
||||||
Context,
|
Context,
|
||||||
CreateCartDTO,
|
CreateCartDTO,
|
||||||
@@ -11,11 +13,13 @@ import {
|
|||||||
UpdateCartDTO,
|
UpdateCartDTO,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
|
|
||||||
|
import { FilterableAddressProps } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
InjectManager,
|
InjectManager,
|
||||||
InjectTransactionManager,
|
InjectTransactionManager,
|
||||||
MedusaContext,
|
MedusaContext,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
|
import { CreateAddressDTO, UpdateAddressDTO } from "@types"
|
||||||
import { joinerConfig } from "../joiner-config"
|
import { joinerConfig } from "../joiner-config"
|
||||||
import AddressService from "./address"
|
import AddressService from "./address"
|
||||||
import CartService from "./cart"
|
import CartService from "./cart"
|
||||||
@@ -32,10 +36,12 @@ export default class CartModuleService implements ICartModuleService {
|
|||||||
protected addressService_: AddressService
|
protected addressService_: AddressService
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
{ baseRepository }: InjectedDependencies,
|
{ baseRepository, cartService, addressService }: InjectedDependencies,
|
||||||
protected readonly moduleDeclaration: InternalModuleDeclaration
|
protected readonly moduleDeclaration: InternalModuleDeclaration
|
||||||
) {
|
) {
|
||||||
this.baseRepository_ = baseRepository
|
this.baseRepository_ = baseRepository
|
||||||
|
this.cartService_ = cartService
|
||||||
|
this.addressService_ = addressService
|
||||||
}
|
}
|
||||||
|
|
||||||
__joinerConfig(): ModuleJoinerConfig {
|
__joinerConfig(): ModuleJoinerConfig {
|
||||||
@@ -157,15 +163,9 @@ export default class CartModuleService implements ICartModuleService {
|
|||||||
return await this.cartService_.update(data, sharedContext)
|
return await this.cartService_.update(data, sharedContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(
|
async delete(ids: string[], sharedContext?: Context): Promise<void>
|
||||||
ids: string[],
|
|
||||||
sharedContext?: Context
|
|
||||||
): Promise<void>
|
|
||||||
|
|
||||||
async delete(
|
async delete(ids: string, sharedContext?: Context): Promise<void>
|
||||||
ids: string,
|
|
||||||
sharedContext?: Context
|
|
||||||
): Promise<void>
|
|
||||||
|
|
||||||
@InjectTransactionManager("baseRepository_")
|
@InjectTransactionManager("baseRepository_")
|
||||||
async delete(
|
async delete(
|
||||||
@@ -175,4 +175,93 @@ export default class CartModuleService implements ICartModuleService {
|
|||||||
const cartIds = Array.isArray(ids) ? ids : [ids]
|
const cartIds = Array.isArray(ids) ? ids : [ids]
|
||||||
await this.cartService_.delete(cartIds, sharedContext)
|
await this.cartService_.delete(cartIds, sharedContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@InjectManager("baseRepository_")
|
||||||
|
async listAddresses(
|
||||||
|
filters: FilterableAddressProps = {},
|
||||||
|
config: FindConfig<AddressDTO> = {},
|
||||||
|
@MedusaContext() sharedContext: Context = {}
|
||||||
|
) {
|
||||||
|
const addresses = await this.addressService_.list(
|
||||||
|
filters,
|
||||||
|
config,
|
||||||
|
sharedContext
|
||||||
|
)
|
||||||
|
|
||||||
|
return await this.baseRepository_.serialize<CartAddressDTO[]>(addresses, {
|
||||||
|
populate: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async createAddresses(data: CreateAddressDTO, sharedContext?: Context)
|
||||||
|
async createAddresses(data: CreateAddressDTO[], sharedContext?: Context)
|
||||||
|
|
||||||
|
@InjectManager("baseRepository_")
|
||||||
|
async createAddresses(
|
||||||
|
data: CreateAddressDTO[] | CreateAddressDTO,
|
||||||
|
@MedusaContext() sharedContext: Context = {}
|
||||||
|
) {
|
||||||
|
const input = Array.isArray(data) ? data : [data]
|
||||||
|
const addresses = await this.createAddresses_(input, sharedContext)
|
||||||
|
|
||||||
|
const result = await this.listAddresses(
|
||||||
|
{ id: addresses.map((p) => p.id) },
|
||||||
|
{},
|
||||||
|
sharedContext
|
||||||
|
)
|
||||||
|
|
||||||
|
return (Array.isArray(data) ? result : result[0]) as
|
||||||
|
| AddressDTO
|
||||||
|
| AddressDTO[]
|
||||||
|
}
|
||||||
|
|
||||||
|
@InjectTransactionManager("baseRepository_")
|
||||||
|
protected async createAddresses_(
|
||||||
|
data: CreateAddressDTO[],
|
||||||
|
@MedusaContext() sharedContext: Context = {}
|
||||||
|
) {
|
||||||
|
return await this.addressService_.create(data, sharedContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateAddresses(data: UpdateAddressDTO, sharedContext?: Context)
|
||||||
|
async updateAddresses(data: UpdateAddressDTO[], sharedContext?: Context)
|
||||||
|
|
||||||
|
@InjectManager("baseRepository_")
|
||||||
|
async updateAddresses(
|
||||||
|
data: UpdateAddressDTO[] | UpdateAddressDTO,
|
||||||
|
@MedusaContext() sharedContext: Context = {}
|
||||||
|
) {
|
||||||
|
const input = Array.isArray(data) ? data : [data]
|
||||||
|
const addresses = await this.updateAddresses_(input, sharedContext)
|
||||||
|
|
||||||
|
const result = await this.listAddresses(
|
||||||
|
{ id: addresses.map((p) => p.id) },
|
||||||
|
{},
|
||||||
|
sharedContext
|
||||||
|
)
|
||||||
|
|
||||||
|
return (Array.isArray(data) ? result : result[0]) as
|
||||||
|
| AddressDTO
|
||||||
|
| AddressDTO[]
|
||||||
|
}
|
||||||
|
|
||||||
|
@InjectTransactionManager("baseRepository_")
|
||||||
|
protected async updateAddresses_(
|
||||||
|
data: UpdateAddressDTO[],
|
||||||
|
@MedusaContext() sharedContext: Context = {}
|
||||||
|
) {
|
||||||
|
return await this.addressService_.update(data, sharedContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteAddresses(ids: string[], sharedContext?: Context)
|
||||||
|
async deleteAddresses(ids: string, sharedContext?: Context)
|
||||||
|
|
||||||
|
@InjectTransactionManager("baseRepository_")
|
||||||
|
async deleteAddresses(
|
||||||
|
ids: string[] | string,
|
||||||
|
@MedusaContext() sharedContext: Context = {}
|
||||||
|
) {
|
||||||
|
const addressIds = Array.isArray(ids) ? ids : [ids]
|
||||||
|
await this.addressService_.delete(addressIds, sharedContext)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
"author": "Medusa",
|
"author": "Medusa",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@medusajs/types": "^1.11.8",
|
"@medusajs/types": "^1.11.9",
|
||||||
"cross-env": "^5.2.1",
|
"cross-env": "^5.2.1",
|
||||||
"jest": "^29.6.3",
|
"jest": "^29.6.3",
|
||||||
"rimraf": "^5.0.1",
|
"rimraf": "^5.0.1",
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
"author": "Medusa",
|
"author": "Medusa",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@medusajs/types": "^1.11.8",
|
"@medusajs/types": "^1.11.9",
|
||||||
"cross-env": "^5.2.1",
|
"cross-env": "^5.2.1",
|
||||||
"jest": "^29.6.3",
|
"jest": "^29.6.3",
|
||||||
"rimraf": "^5.0.1",
|
"rimraf": "^5.0.1",
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ export interface CreateCartDTO {
|
|||||||
email?: string
|
email?: string
|
||||||
currency_code: string
|
currency_code: string
|
||||||
|
|
||||||
|
shipping_address_id?: string
|
||||||
|
billing_address_id?: string
|
||||||
|
|
||||||
shipping_address?: CreateAddressDTO | UpdateAddressDTO
|
shipping_address?: CreateAddressDTO | UpdateAddressDTO
|
||||||
billing_address?: CreateAddressDTO | UpdateAddressDTO
|
billing_address?: CreateAddressDTO | UpdateAddressDTO
|
||||||
|
|
||||||
@@ -42,6 +45,9 @@ export interface UpdateCartDTO {
|
|||||||
email?: string
|
email?: string
|
||||||
currency_code?: string
|
currency_code?: string
|
||||||
|
|
||||||
|
shipping_address_id?: string
|
||||||
|
billing_address_id?: string
|
||||||
|
|
||||||
billing_address?: CreateAddressDTO | UpdateAddressDTO
|
billing_address?: CreateAddressDTO | UpdateAddressDTO
|
||||||
shipping_address?: CreateAddressDTO | UpdateAddressDTO
|
shipping_address?: CreateAddressDTO | UpdateAddressDTO
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
|
import { AddressDTO } from "../address"
|
||||||
import { FindConfig } from "../common"
|
import { FindConfig } from "../common"
|
||||||
import { IModuleService } from "../modules-sdk"
|
import { IModuleService } from "../modules-sdk"
|
||||||
import { Context } from "../shared-context"
|
import { Context } from "../shared-context"
|
||||||
import { CartDTO, FilterableCartProps } from "./common"
|
import { CartAddressDTO, CartDTO, FilterableAddressProps, FilterableCartProps } from "./common"
|
||||||
import { CreateCartDTO, UpdateCartDTO } from "./mutations"
|
import {
|
||||||
|
CreateAddressDTO,
|
||||||
|
CreateCartDTO,
|
||||||
|
UpdateAddressDTO,
|
||||||
|
UpdateCartDTO,
|
||||||
|
} from "./mutations"
|
||||||
|
|
||||||
export interface ICartModuleService extends IModuleService {
|
export interface ICartModuleService extends IModuleService {
|
||||||
retrieve(
|
retrieve(
|
||||||
@@ -32,6 +38,33 @@ export interface ICartModuleService extends IModuleService {
|
|||||||
delete(cartIds: string[], sharedContext?: Context): Promise<void>
|
delete(cartIds: string[], sharedContext?: Context): Promise<void>
|
||||||
delete(cartId: string, sharedContext?: Context): Promise<void>
|
delete(cartId: string, sharedContext?: Context): Promise<void>
|
||||||
|
|
||||||
|
listAddresses(
|
||||||
|
filters?: FilterableAddressProps,
|
||||||
|
config?: FindConfig<AddressDTO>,
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<CartAddressDTO[]>
|
||||||
|
|
||||||
|
createAddresses(
|
||||||
|
data: CreateAddressDTO[],
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<CartAddressDTO[]>
|
||||||
|
createAddresses(
|
||||||
|
data: CreateAddressDTO,
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<CartAddressDTO>
|
||||||
|
|
||||||
|
updateAddresses(
|
||||||
|
data: UpdateAddressDTO[],
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<CartAddressDTO[]>
|
||||||
|
updateAddresses(
|
||||||
|
data: UpdateAddressDTO,
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<CartAddressDTO>
|
||||||
|
|
||||||
|
deleteAddresses(ids: string[], sharedContext?: Context): Promise<void>
|
||||||
|
deleteAddresses(ids: string, sharedContext?: Context): Promise<void>
|
||||||
|
|
||||||
// addLineItems(data: AddLineItemsDTO, sharedContext?: Context): Promise<CartDTO>
|
// addLineItems(data: AddLineItemsDTO, sharedContext?: Context): Promise<CartDTO>
|
||||||
// addLineItems(
|
// addLineItems(
|
||||||
// data: AddLineItemsDTO[],
|
// data: AddLineItemsDTO[],
|
||||||
|
|||||||
@@ -7888,7 +7888,7 @@ __metadata:
|
|||||||
resolution: "@medusajs/cart@workspace:packages/cart"
|
resolution: "@medusajs/cart@workspace:packages/cart"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@medusajs/modules-sdk": ^1.12.5
|
"@medusajs/modules-sdk": ^1.12.5
|
||||||
"@medusajs/types": ^1.11.9
|
"@medusajs/types": "workspace:^"
|
||||||
"@medusajs/utils": ^1.11.2
|
"@medusajs/utils": ^1.11.2
|
||||||
"@mikro-orm/cli": 5.9.7
|
"@mikro-orm/cli": 5.9.7
|
||||||
"@mikro-orm/core": 5.9.7
|
"@mikro-orm/core": 5.9.7
|
||||||
@@ -8072,7 +8072,7 @@ __metadata:
|
|||||||
resolution: "@medusajs/inventory@workspace:packages/inventory"
|
resolution: "@medusajs/inventory@workspace:packages/inventory"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@medusajs/modules-sdk": ^1.12.4
|
"@medusajs/modules-sdk": ^1.12.4
|
||||||
"@medusajs/types": ^1.11.8
|
"@medusajs/types": ^1.11.9
|
||||||
"@medusajs/utils": ^1.11.1
|
"@medusajs/utils": ^1.11.1
|
||||||
awilix: ^8.0.0
|
awilix: ^8.0.0
|
||||||
cross-env: ^5.2.1
|
cross-env: ^5.2.1
|
||||||
@@ -8478,7 +8478,7 @@ __metadata:
|
|||||||
resolution: "@medusajs/stock-location@workspace:packages/stock-location"
|
resolution: "@medusajs/stock-location@workspace:packages/stock-location"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@medusajs/modules-sdk": ^1.12.4
|
"@medusajs/modules-sdk": ^1.12.4
|
||||||
"@medusajs/types": ^1.11.8
|
"@medusajs/types": ^1.11.9
|
||||||
"@medusajs/utils": ^1.11.1
|
"@medusajs/utils": ^1.11.1
|
||||||
awilix: ^8.0.0
|
awilix: ^8.0.0
|
||||||
cross-env: ^5.2.1
|
cross-env: ^5.2.1
|
||||||
@@ -8516,7 +8516,7 @@ __metadata:
|
|||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
"@medusajs/types@^1.10.0, @medusajs/types@^1.11.10, @medusajs/types@^1.11.5, @medusajs/types@^1.11.6, @medusajs/types@^1.11.8, @medusajs/types@^1.11.9, @medusajs/types@^1.8.10, @medusajs/types@workspace:packages/types":
|
"@medusajs/types@^1.10.0, @medusajs/types@^1.11.10, @medusajs/types@^1.11.5, @medusajs/types@^1.11.6, @medusajs/types@^1.11.9, @medusajs/types@^1.8.10, @medusajs/types@workspace:^, @medusajs/types@workspace:packages/types":
|
||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "@medusajs/types@workspace:packages/types"
|
resolution: "@medusajs/types@workspace:packages/types"
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|||||||
Reference in new issue
Block a user