Duplicate of #6008, but I messed up my git history big time :'( **What** - CartService and CartRepository + tests - AddressService and AddressRepository + tests - CartModuleService skeleton. Full implementation + tests will be added in a separate PR
28 lines
744 B
TypeScript
28 lines
744 B
TypeScript
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<Address[]> {
|
|
const manager = this.getActiveManager<SqlEntityManager>(context)
|
|
|
|
const entities = data.map(({ address, update }) => {
|
|
return manager.assign(address, update)
|
|
})
|
|
|
|
manager.persist(entities)
|
|
|
|
return entities
|
|
}
|
|
}
|