diff --git a/.changeset/red-mirrors-tap.md b/.changeset/red-mirrors-tap.md new file mode 100644 index 0000000000..a249585ce7 --- /dev/null +++ b/.changeset/red-mirrors-tap.md @@ -0,0 +1,5 @@ +--- +"@medusajs/types": patch +--- + +feat(cart): Add CartService and AddressService diff --git a/packages/cart/integration-tests/__fixtures__/cart/data.ts b/packages/cart/integration-tests/__fixtures__/cart/data.ts new file mode 100644 index 0000000000..ba3eb43849 --- /dev/null +++ b/packages/cart/integration-tests/__fixtures__/cart/data.ts @@ -0,0 +1,23 @@ +export const defaultCartsData = [ + { + id: "cart-id-1", + region_id: "region-id-1", + customer_id: "customer-id-1", + email: "test@email.com", + currency_code: "usd", + }, + { + id: "cart-id-2", + region_id: "region-id-1", + customer_id: "customer-id-1", + shipping_address: { + first_name: "Tony", + last_name: "Stark", + }, + billing_address_id: { + address_1: "Stark Industries", + city: "New York", + }, + currency_code: "usd", + }, +] diff --git a/packages/cart/integration-tests/__fixtures__/cart/index.ts b/packages/cart/integration-tests/__fixtures__/cart/index.ts new file mode 100644 index 0000000000..f355d7fc4c --- /dev/null +++ b/packages/cart/integration-tests/__fixtures__/cart/index.ts @@ -0,0 +1,21 @@ +import { CreateCartDTO } from "@medusajs/types" +import { SqlEntityManager } from "@mikro-orm/postgresql" +import { Cart } from "../../../src/models" +import { defaultCartsData } from "./data" + +export * from "./data" + +export async function createCarts( + manager: SqlEntityManager, + cartsData: CreateCartDTO[] = defaultCartsData +): Promise { + const carts: Cart[] = [] + + for (let cartData of cartsData) { + let cart = manager.create(Cart, cartData) + + await manager.persistAndFlush(cart) + } + + return carts +} diff --git a/packages/cart/integration-tests/__tests__/services/address/index.spec.ts b/packages/cart/integration-tests/__tests__/services/address/index.spec.ts new file mode 100644 index 0000000000..54b1395499 --- /dev/null +++ b/packages/cart/integration-tests/__tests__/services/address/index.spec.ts @@ -0,0 +1,127 @@ +import { SqlEntityManager } from "@mikro-orm/postgresql" +import { AddressRepository } from "../../../../src/repositories" +import { AddressService } from "../../../../src/services" +import { MikroOrmWrapper } from "../../../utils" + +jest.setTimeout(30000) + +describe("Address Service", () => { + let service: AddressService + let testManager: SqlEntityManager + let repositoryManager: SqlEntityManager + + beforeEach(async () => { + await MikroOrmWrapper.setupDatabase() + repositoryManager = await MikroOrmWrapper.forkManager() + testManager = await MikroOrmWrapper.forkManager() + + const addressRepository = new AddressRepository({ + manager: repositoryManager, + }) + + service = new AddressService({ + addressRepository: addressRepository, + }) + }) + + afterEach(async () => { + await MikroOrmWrapper.clearDatabase() + }) + + describe("create", () => { + it("should create an address successfully", async () => { + const [createdAddress] = await service.create([ + { + first_name: "John", + last_name: "Doe", + address_1: "Test street 1", + city: "Test city", + country_code: "US", + postal_code: "12345", + }, + ]) + + const [address] = await service.list({ id: [createdAddress.id] }) + + expect(address).toEqual( + expect.objectContaining({ + id: createdAddress.id, + first_name: "John", + last_name: "Doe", + address_1: "Test street 1", + city: "Test city", + country_code: "US", + postal_code: "12345", + }) + ) + }) + }) + + describe("update", () => { + it("should throw an error if address does not exist", async () => { + const error = await service + .update([ + { + id: "none-existing", + }, + ]) + .catch((e) => e) + + expect(error.message).toContain( + "Address with id \"none-existing\" not found" + ) + }) + + it("should update an address successfully", async () => { + const [createdAddress] = await service.create([ + { + first_name: "Jane", + last_name: "Doe", + address_1: "Test street 1", + city: "Test city", + country_code: "US", + postal_code: "12345", + }, + ]) + + await service.update([ + { + id: createdAddress.id, + address_1: "Test street 2", + city: "Test city 2", + }, + ]) + + const [address] = await service.list({ id: [createdAddress.id] }) + + expect(address).toEqual( + expect.objectContaining({ + id: createdAddress.id, + first_name: "Jane", + last_name: "Doe", + address_1: "Test street 2", + city: "Test city 2", + country_code: "US", + postal_code: "12345", + }) + ) + }) + }) + + describe("delete", () => { + it("should delete a cart successfully", async () => { + const [createdAddress] = await service.create([ + { + first_name: "Jane", + last_name: "Doe", + }, + ]) + + await service.delete([createdAddress.id]) + + const carts = await service.list({ id: [createdAddress.id] }) + + expect(carts.length).toEqual(0) + }) + }) +}) diff --git a/packages/cart/integration-tests/__tests__/services/cart/index.spec.ts b/packages/cart/integration-tests/__tests__/services/cart/index.spec.ts new file mode 100644 index 0000000000..b1dfeb1826 --- /dev/null +++ b/packages/cart/integration-tests/__tests__/services/cart/index.spec.ts @@ -0,0 +1,124 @@ +import { SqlEntityManager } from "@mikro-orm/postgresql" +import { CartRepository } from "../../../../src/repositories" +import { CartService } from "../../../../src/services" +import { createCarts } from "../../../__fixtures__/cart" +import { MikroOrmWrapper } from "../../../utils" + +jest.setTimeout(30000) + +describe("Cart Service", () => { + let service: CartService + let testManager: SqlEntityManager + let repositoryManager: SqlEntityManager + + beforeEach(async () => { + await MikroOrmWrapper.setupDatabase() + repositoryManager = await MikroOrmWrapper.forkManager() + testManager = await MikroOrmWrapper.forkManager() + + const cartRepository = new CartRepository({ + manager: repositoryManager, + }) + + service = new CartService({ + cartRepository: cartRepository, + }) + + await createCarts(testManager) + }) + + 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", + }) + ) + }) + }) + + 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) + }) + }) +}) diff --git a/packages/cart/src/models/cart.ts b/packages/cart/src/models/cart.ts index c44963d6a0..9526e3054e 100644 --- a/packages/cart/src/models/cart.ts +++ b/packages/cart/src/models/cart.ts @@ -67,12 +67,13 @@ export default class Cart { metadata?: Record | null @OneToMany(() => LineItem, (lineItem) => lineItem.cart, { - orphanRemoval: true, + cascade: [Cascade.REMOVE], }) items = new Collection(this) @OneToMany(() => ShippingMethod, (shippingMethod) => shippingMethod.cart, { - orphanRemoval: true, + cascade: [Cascade.REMOVE], + }) shipping_methods = new Collection(this) diff --git a/packages/cart/src/repositories/address.ts b/packages/cart/src/repositories/address.ts new file mode 100644 index 0000000000..994ff44221 --- /dev/null +++ b/packages/cart/src/repositories/address.ts @@ -0,0 +1,27 @@ +import { Context } from "@medusajs/types" +import { DALUtils } from "@medusajs/utils" +import { SqlEntityManager } from "@mikro-orm/postgresql" +import { Address } from "@models" +import { CreateAddressDTO, UpdateAddressDTO } from "../types" + +export class AddressRepository extends DALUtils.mikroOrmBaseRepositoryFactory< + Address, + { + create: CreateAddressDTO + } +>(Address) { + async update( + data: { address: Address; update: UpdateAddressDTO }[], + context: Context = {} + ): Promise { + const manager = this.getActiveManager(context) + + const entities = data.map(({ address, update }) => { + return manager.assign(address, update) + }) + + manager.persist(entities) + + return entities + } +} diff --git a/packages/cart/src/repositories/cart.ts b/packages/cart/src/repositories/cart.ts new file mode 100644 index 0000000000..4aeddee7f3 --- /dev/null +++ b/packages/cart/src/repositories/cart.ts @@ -0,0 +1,27 @@ +import { Context } from "@medusajs/types" +import { DALUtils } from "@medusajs/utils" +import { SqlEntityManager } from "@mikro-orm/postgresql" +import { Cart } from "@models" +import { CreateCartDTO, UpdateCartDTO } from "../types" + +export class CartRepository extends DALUtils.mikroOrmBaseRepositoryFactory< + Cart, + { + create: CreateCartDTO + } +>(Cart) { + async update( + data: { cart: Cart; update: UpdateCartDTO }[], + context: Context = {} + ): Promise { + const manager = this.getActiveManager(context) + + const entities = data.map(({ cart, update }) => { + return manager.assign(cart, update) + }) + + manager.persist(entities) + + return entities + } +} diff --git a/packages/cart/src/repositories/index.ts b/packages/cart/src/repositories/index.ts index 147c9cc259..d527e6f73c 100644 --- a/packages/cart/src/repositories/index.ts +++ b/packages/cart/src/repositories/index.ts @@ -1 +1,4 @@ export { MikroOrmBaseRepository as BaseRepository } from "@medusajs/utils" +export * from "./address" +export * from "./cart" + diff --git a/packages/cart/src/services/address.ts b/packages/cart/src/services/address.ts new file mode 100644 index 0000000000..24484662fe --- /dev/null +++ b/packages/cart/src/services/address.ts @@ -0,0 +1,128 @@ +import { + AddressDTO, + Context, + DAL, + FilterableAddressProps, + FindConfig, +} from "@medusajs/types" +import { + InjectManager, + InjectTransactionManager, + MedusaContext, + MedusaError, + ModulesSdkUtils, + retrieveEntity, +} from "@medusajs/utils" +import { Address } from "@models" +import { AddressRepository } from "../repositories/address" +import { CreateAddressDTO, UpdateAddressDTO } from "../types" + +type InjectedDependencies = { + addressRepository: DAL.RepositoryService +} + +export default class AddressService { + protected readonly addressRepository_: DAL.RepositoryService + + constructor({ addressRepository }: InjectedDependencies) { + this.addressRepository_ = addressRepository + } + + @InjectManager("addressRepository_") + async retrieve( + id: string, + config: FindConfig = {}, + @MedusaContext() sharedContext: Context = {} + ): Promise { + return (await retrieveEntity({ + id: id, + entityName: Address.name, + repository: this.addressRepository_, + config, + sharedContext, + })) as TEntity + } + + @InjectManager("addressRepository_") + async list( + filters: FilterableAddressProps = {}, + config: FindConfig = {}, + @MedusaContext() sharedContext: Context = {} + ): Promise { + const queryOptions = ModulesSdkUtils.buildQuery
(filters, config) + + return (await this.addressRepository_.find( + queryOptions, + sharedContext + )) as TEntity[] + } + + @InjectManager("addressRepository_") + async listAndCount( + filters: FilterableAddressProps = {}, + config: FindConfig = {}, + @MedusaContext() sharedContext: Context = {} + ): Promise<[TEntity[], number]> { + const queryOptions = ModulesSdkUtils.buildQuery
(filters, config) + + return (await this.addressRepository_.findAndCount( + queryOptions, + sharedContext + )) as [TEntity[], number] + } + + @InjectTransactionManager("addressRepository_") + async create( + data: CreateAddressDTO[], + @MedusaContext() sharedContext: Context = {} + ): Promise { + return (await (this.addressRepository_ as AddressRepository).create( + data, + sharedContext + )) as TEntity[] + } + + @InjectTransactionManager("addressRepository_") + async update( + data: UpdateAddressDTO[], + @MedusaContext() sharedContext: Context = {} + ): Promise { + const existingAddresses = await this.list( + { id: data.map(({ id }) => id) }, + {}, + sharedContext + ) + + const existingAddressesMap = new Map( + existingAddresses.map<[string, Address]>((addr) => [addr.id, addr]) + ) + + const updates: { address: Address; update: UpdateAddressDTO }[] = [] + + for (const update of data) { + const address = existingAddressesMap.get(update.id) + + if (!address) { + throw new MedusaError( + MedusaError.Types.NOT_FOUND, + `Address with id "${update.id}" not found` + ) + } + + updates.push({ address, update }) + } + + return (await (this.addressRepository_ as AddressRepository).update( + updates, + sharedContext + )) as TEntity[] + } + + @InjectTransactionManager("addressRepository_") + async delete( + ids: string[], + @MedusaContext() sharedContext: Context = {} + ): Promise { + await this.addressRepository_.delete(ids, sharedContext) + } +} diff --git a/packages/cart/src/services/cart-module.ts b/packages/cart/src/services/cart-module.ts index ab136b060d..b951b660b7 100644 --- a/packages/cart/src/services/cart-module.ts +++ b/packages/cart/src/services/cart-module.ts @@ -1,20 +1,35 @@ import { + CartDTO, + Context, + CreateCartDTO, DAL, + FilterableCartProps, + FindConfig, + ICartModuleService, InternalModuleDeclaration, ModuleJoinerConfig, + UpdateCartDTO, } from "@medusajs/types" -import { Cart } from "@models" - +import { + InjectManager, + InjectTransactionManager, + MedusaContext, +} from "@medusajs/utils" import { joinerConfig } from "../joiner-config" +import AddressService from "./address" +import CartService from "./cart" type InjectedDependencies = { baseRepository: DAL.RepositoryService + cartService: CartService + addressService: AddressService } -// TODO: implement ICartModuleService from @medusajs/types -export default class CartModuleService { +export default class CartModuleService implements ICartModuleService { protected baseRepository_: DAL.RepositoryService + protected cartService_: CartService + protected addressService_: AddressService constructor( { baseRepository }: InjectedDependencies, @@ -26,4 +41,138 @@ export default class CartModuleService { __joinerConfig(): ModuleJoinerConfig { return joinerConfig } + + @InjectManager("baseRepository_") + async retrieve( + id: string, + config: FindConfig = {}, + @MedusaContext() sharedContext: Context = {} + ): Promise { + const cart = await this.cartService_.retrieve(id, config, sharedContext) + + return await this.baseRepository_.serialize(cart, { + populate: true, + }) + } + + @InjectManager("baseRepository_") + async list( + filters: FilterableCartProps = {}, + config: FindConfig = {}, + @MedusaContext() sharedContext: Context = {} + ): Promise { + const carts = await this.cartService_.list(filters, config, sharedContext) + + return await this.baseRepository_.serialize(carts, { + populate: true, + }) + } + + @InjectManager("baseRepository_") + async listAndCount( + filters: FilterableCartProps = {}, + config: FindConfig = {}, + @MedusaContext() sharedContext: Context = {} + ): Promise<[CartDTO[], number]> { + const [carts, count] = await this.cartService_.listAndCount( + filters, + config, + sharedContext + ) + + return [ + await this.baseRepository_.serialize(carts, { + populate: true, + }), + count, + ] + } + + async create( + data: CreateCartDTO[], + sharedContext?: Context + ): Promise + + async create(data: CreateCartDTO, sharedContext?: Context): Promise + + @InjectManager("baseRepository_") + async create( + data: CreateCartDTO[] | CreateCartDTO, + @MedusaContext() sharedContext: Context = {} + ): Promise { + const input = Array.isArray(data) ? data : [data] + + const carts = await this.create_(input, sharedContext) + + const result = await this.list( + { id: carts.map((p) => p!.id) }, + { + relations: ["shipping_address", "billing_address"], + }, + sharedContext + ) + + return (Array.isArray(data) ? result : result[0]) as CartDTO | CartDTO[] + } + + @InjectTransactionManager("baseRepository_") + protected async create_( + data: CreateCartDTO[], + @MedusaContext() sharedContext: Context = {} + ) { + return await this.cartService_.create(data, sharedContext) + } + + async update( + data: UpdateCartDTO[], + sharedContext?: Context + ): Promise + + async update(data: UpdateCartDTO, sharedContext?: Context): Promise + + @InjectManager("baseRepository_") + async update( + data: UpdateCartDTO[] | UpdateCartDTO, + @MedusaContext() sharedContext: Context = {} + ): Promise { + const input = Array.isArray(data) ? data : [data] + const carts = await this.update_(input, sharedContext) + + const result = await this.list( + { id: carts.map((p) => p!.id) }, + { + relations: ["shipping_address", "billing_address"], + }, + sharedContext + ) + + return (Array.isArray(data) ? result : result[0]) as CartDTO | CartDTO[] + } + + @InjectTransactionManager("baseRepository_") + protected async update_( + data: UpdateCartDTO[], + @MedusaContext() sharedContext: Context = {} + ) { + return await this.cartService_.update(data, sharedContext) + } + + async delete( + ids: string[], + sharedContext?: Context + ): Promise + + async delete( + ids: string, + sharedContext?: Context + ): Promise + + @InjectTransactionManager("baseRepository_") + async delete( + ids: string[] | string, + @MedusaContext() sharedContext: Context = {} + ): Promise { + const cartIds = Array.isArray(ids) ? ids : [ids] + await this.cartService_.delete(cartIds, sharedContext) + } } diff --git a/packages/cart/src/services/cart.ts b/packages/cart/src/services/cart.ts new file mode 100644 index 0000000000..0cae7e1dee --- /dev/null +++ b/packages/cart/src/services/cart.ts @@ -0,0 +1,128 @@ +import { + CartDTO, + Context, + DAL, + FilterableCartProps, + FindConfig, +} from "@medusajs/types" +import { + InjectManager, + InjectTransactionManager, + MedusaContext, + MedusaError, + ModulesSdkUtils, + retrieveEntity, +} from "@medusajs/utils" +import { Cart } from "@models" +import { CartRepository } from "@repositories" +import { CreateCartDTO, UpdateCartDTO } from "@types" + +type InjectedDependencies = { + cartRepository: DAL.RepositoryService +} + +export default class CartService { + protected readonly cartRepository_: DAL.RepositoryService + + constructor({ cartRepository }: InjectedDependencies) { + this.cartRepository_ = cartRepository + } + + @InjectManager("cartRepository_") + async retrieve( + id: string, + config: FindConfig = {}, + @MedusaContext() sharedContext: Context = {} + ): Promise { + return (await retrieveEntity({ + id: id, + entityName: Cart.name, + repository: this.cartRepository_, + config, + sharedContext, + })) as TEntity + } + + @InjectManager("cartRepository_") + async list( + filters: FilterableCartProps = {}, + config: FindConfig = {}, + @MedusaContext() sharedContext: Context = {} + ): Promise { + const queryOptions = ModulesSdkUtils.buildQuery(filters, config) + + return (await this.cartRepository_.find( + queryOptions, + sharedContext + )) as TEntity[] + } + + @InjectManager("cartRepository_") + async listAndCount( + filters: FilterableCartProps = {}, + config: FindConfig = {}, + @MedusaContext() sharedContext: Context = {} + ): Promise<[TEntity[], number]> { + const queryOptions = ModulesSdkUtils.buildQuery(filters, config) + + return (await this.cartRepository_.findAndCount( + queryOptions, + sharedContext + )) as [TEntity[], number] + } + + @InjectTransactionManager("cartRepository_") + async create( + data: CreateCartDTO[], + @MedusaContext() sharedContext: Context = {} + ): Promise { + return (await (this.cartRepository_ as CartRepository).create( + data, + sharedContext + )) as TEntity[] + } + + @InjectTransactionManager("cartRepository_") + async update( + data: UpdateCartDTO[], + @MedusaContext() sharedContext: Context = {} + ): Promise { + const existingCarts = await this.list( + { id: data.map(({ id }) => id) }, + {}, + sharedContext + ) + + const existingCartsMap = new Map( + existingCarts.map<[string, Cart]>((cart) => [cart.id, cart]) + ) + + const updates: { cart: Cart; update: UpdateCartDTO }[] = [] + + for (const update of data) { + const cart = existingCartsMap.get(update.id) + + if (!cart) { + throw new MedusaError( + MedusaError.Types.NOT_FOUND, + `Cart with id "${update.id}" not found` + ) + } + + updates.push({ cart, update }) + } + + return (await (this.cartRepository_ as CartRepository).update( + updates, + sharedContext + )) as TEntity[] + } + + @InjectTransactionManager("cartRepository_") + async delete( + ids: string[], + @MedusaContext() sharedContext: Context = {} + ): Promise { + await this.cartRepository_.delete(ids, sharedContext) + } +} diff --git a/packages/cart/src/services/index.ts b/packages/cart/src/services/index.ts index 2191dc84cf..1f70a17a34 100644 --- a/packages/cart/src/services/index.ts +++ b/packages/cart/src/services/index.ts @@ -1,2 +1,4 @@ -export { default as CartModuleService } from "./cart-module"; +export { default as AddressService } from "./address" +export { default as CartService } from "./cart" +export { default as CartModuleService } from "./cart-module" diff --git a/packages/cart/src/types/address.ts b/packages/cart/src/types/address.ts new file mode 100644 index 0000000000..07d8aecd92 --- /dev/null +++ b/packages/cart/src/types/address.ts @@ -0,0 +1,20 @@ +export interface UpsertAddressDTO { + customer_id?: string + company?: string + first_name?: string + last_name?: string + address_1?: string + address_2?: string + city?: string + country_code?: string + province?: string + postal_code?: string + phone?: string + metadata?: Record +} + +export interface UpdateAddressDTO extends UpsertAddressDTO { + id: string +} + +export interface CreateAddressDTO extends UpsertAddressDTO {} diff --git a/packages/cart/src/types/cart.ts b/packages/cart/src/types/cart.ts new file mode 100644 index 0000000000..852159840a --- /dev/null +++ b/packages/cart/src/types/cart.ts @@ -0,0 +1,18 @@ +export interface CreateCartDTO { + region_id?: string + customer_id?: string + sales_channel_id?: string + email?: string + currency_code: string + metadata?: Record +} + +export interface UpdateCartDTO { + id: string + region_id?: string + customer_id?: string + sales_channel_id?: string + email?: string + currency_code?: string + metadata?: Record +} diff --git a/packages/cart/src/types/index.ts b/packages/cart/src/types/index.ts index 0f252977b0..8b97276103 100644 --- a/packages/cart/src/types/index.ts +++ b/packages/cart/src/types/index.ts @@ -1,4 +1,6 @@ import { Logger } from "@medusajs/types" +export * from "./address" +export * from "./cart" export type InitializeModuleInjectableDependencies = { logger?: Logger diff --git a/packages/cart/tsconfig.json b/packages/cart/tsconfig.json index 213e38fc55..6143fb1ef3 100644 --- a/packages/cart/tsconfig.json +++ b/packages/cart/tsconfig.json @@ -22,7 +22,8 @@ "paths": { "@models": ["./src/models"], "@services": ["./src/services"], - "@repositories": ["./src/repositories"] + "@repositories": ["./src/repositories"], + "@types": ["./src/types"], } }, "include": ["src"], diff --git a/packages/types/src/cart/common.ts b/packages/types/src/cart/common.ts index 7a552618c7..1e17abf889 100644 --- a/packages/types/src/cart/common.ts +++ b/packages/types/src/cart/common.ts @@ -465,8 +465,13 @@ export interface FilterableCartProps updated_at?: OperatorMap } +export interface FilterableAddressProps + extends BaseFilterable { + id?: string | string[] +} + /** - * TODO: Remove this in favor of new__CartDTO, when module is released + * TODO: Remove this in favor of CartDTO, when module is released * @deprecated Use CartDTO instead */ diff --git a/packages/types/src/cart/service.ts b/packages/types/src/cart/service.ts index c94bf82f73..800ede55a3 100644 --- a/packages/types/src/cart/service.ts +++ b/packages/types/src/cart/service.ts @@ -2,7 +2,7 @@ import { FindConfig } from "../common" import { IModuleService } from "../modules-sdk" import { Context } from "../shared-context" import { CartDTO, FilterableCartProps } from "./common" -import { AddLineItemsDTO, CreateCartDTO, UpdateCartDTO, UpdateLineItemsDTO } from "./mutations" +import { CreateCartDTO, UpdateCartDTO } from "./mutations" export interface ICartModuleService extends IModuleService { retrieve( @@ -24,25 +24,28 @@ export interface ICartModuleService extends IModuleService { ): Promise<[CartDTO[], number]> create(data: CreateCartDTO[], sharedContext?: Context): Promise + create(data: CreateCartDTO, sharedContext?: Context): Promise update(data: UpdateCartDTO[], sharedContext?: Context): Promise + update(data: UpdateCartDTO, sharedContext?: Context): Promise delete(cartIds: string[], sharedContext?: Context): Promise + delete(cartId: string, sharedContext?: Context): Promise - addLineItems(data: AddLineItemsDTO, sharedContext?: Context): Promise - addLineItems( - data: AddLineItemsDTO[], - sharedContext?: Context - ): Promise + // addLineItems(data: AddLineItemsDTO, sharedContext?: Context): Promise + // addLineItems( + // data: AddLineItemsDTO[], + // sharedContext?: Context + // ): Promise - updateLineItems( - data: UpdateLineItemsDTO, - sharedContext?: Context - ): Promise - updateLineItems( - data: UpdateLineItemsDTO[], - sharedContext?: Context - ): Promise + // updateLineItems( + // data: UpdateLineItemsDTO, + // sharedContext?: Context + // ): Promise + // updateLineItems( + // data: UpdateLineItemsDTO[], + // sharedContext?: Context + // ): Promise - removeLineItems(lineItemIds: string[], sharedContext?: Context): Promise + // removeLineItems(lineItemIds: string[], sharedContext?: Context): Promise } diff --git a/packages/utils/src/dal/mikro-orm/mikro-orm-repository.ts b/packages/utils/src/dal/mikro-orm/mikro-orm-repository.ts index df24e190be..84c8b437f2 100644 --- a/packages/utils/src/dal/mikro-orm/mikro-orm-repository.ts +++ b/packages/utils/src/dal/mikro-orm/mikro-orm-repository.ts @@ -4,14 +4,6 @@ import { FilterQuery as InternalFilerQuery, RepositoryTransformOptions, } from "@medusajs/types" -import { arrayDifference, isString, MedusaError } from "../../common" -import { MedusaContext } from "../../decorators" -import { buildQuery, InjectTransactionManager } from "../../modules-sdk" -import { - getSoftDeletedCascadedEntitiesIdsMappedBy, - transactionWrapper, -} from "../utils" -import { mikroOrmSerializer, mikroOrmUpdateDeletedAtRecursively } from "./utils" import { EntityManager, EntitySchema, @@ -19,12 +11,20 @@ import { LoadStrategy, RequiredEntityData, } from "@mikro-orm/core" +import { FindOptions as MikroOptions } from "@mikro-orm/core/drivers/IDatabaseDriver" import { EntityClass, EntityName, FilterQuery as MikroFilterQuery, } from "@mikro-orm/core/typings" -import { FindOptions as MikroOptions } from "@mikro-orm/core/drivers/IDatabaseDriver" +import { MedusaError, arrayDifference, isString } from "../../common" +import { MedusaContext } from "../../decorators" +import { InjectTransactionManager, buildQuery } from "../../modules-sdk" +import { + getSoftDeletedCascadedEntitiesIdsMappedBy, + transactionWrapper, +} from "../utils" +import { mikroOrmSerializer, mikroOrmUpdateDeletedAtRecursively } from "./utils" export class MikroOrmBase { readonly manager_: any