chore: Abstract module services (#6087)
**What** Create a service abstraction for the modules internal service layer. The objective is to reduce the effort of building new modules when the logic is the same or otherwise allow to override the default behavior. Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
1 parent
80feb972cb
commit
130c641e5c
46 files changed
+855
-2834
No files matched your search
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/pricing": patch
|
||||||
|
"@medusajs/product": patch
|
||||||
|
"@medusajs/utils": patch
|
||||||
|
"@medusajs/types": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
chore: Abstract module services
|
||||||
@@ -2,32 +2,16 @@ import { DALUtils } from "@medusajs/utils"
|
|||||||
|
|
||||||
import { AuthProvider } from "@models"
|
import { AuthProvider } from "@models"
|
||||||
import { RepositoryTypes } from "@types"
|
import { RepositoryTypes } from "@types"
|
||||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
|
||||||
import { Context } from "@medusajs/types"
|
|
||||||
|
|
||||||
export class AuthProviderRepository extends DALUtils.mikroOrmBaseRepositoryFactory<
|
export class AuthProviderRepository extends DALUtils.mikroOrmBaseRepositoryFactory<
|
||||||
AuthProvider,
|
AuthProvider,
|
||||||
{
|
{
|
||||||
create: RepositoryTypes.CreateAuthProviderDTO
|
create: RepositoryTypes.CreateAuthProviderDTO
|
||||||
|
update: RepositoryTypes.UpdateAuthProviderDTO
|
||||||
}
|
}
|
||||||
>(AuthProvider) {
|
>(AuthProvider) {
|
||||||
constructor(...args: any[]) {
|
constructor(...args: any[]) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
super(...arguments)
|
super(...arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(
|
|
||||||
data: RepositoryTypes.UpdateAuthProviderDTO[],
|
|
||||||
context: Context = {}
|
|
||||||
): Promise<AuthProvider[]> {
|
|
||||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
|
||||||
|
|
||||||
const authProviders = data.map(({ provider, update }) => {
|
|
||||||
return manager.assign(provider, update)
|
|
||||||
})
|
|
||||||
|
|
||||||
manager.persist(authProviders)
|
|
||||||
|
|
||||||
return authProviders
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,45 +1,17 @@
|
|||||||
import { Context } from "@medusajs/types"
|
|
||||||
import { DALUtils } from "@medusajs/utils"
|
import { DALUtils } from "@medusajs/utils"
|
||||||
|
|
||||||
import { AuthUser } from "@models"
|
import { AuthUser } from "@models"
|
||||||
import { RepositoryTypes } from "@types"
|
import { RepositoryTypes } from "@types"
|
||||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
|
||||||
|
|
||||||
export class AuthUserRepository extends DALUtils.mikroOrmBaseRepositoryFactory(
|
export class AuthUserRepository extends DALUtils.mikroOrmBaseRepositoryFactory<
|
||||||
AuthUser
|
AuthUser,
|
||||||
) {
|
{
|
||||||
|
create: RepositoryTypes.CreateAuthUserDTO
|
||||||
|
update: RepositoryTypes.UpdateAuthUserDTO
|
||||||
|
}
|
||||||
|
>(AuthUser) {
|
||||||
constructor(...args: any[]) {
|
constructor(...args: any[]) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
super(...arguments)
|
super(...arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(
|
|
||||||
data: RepositoryTypes.CreateAuthUserDTO[],
|
|
||||||
context: Context = {}
|
|
||||||
): Promise<AuthUser[]> {
|
|
||||||
const toCreate = data.map((authUser) => {
|
|
||||||
const authUserClone = { ...authUser } as any
|
|
||||||
|
|
||||||
authUserClone.provider ??= authUser.provider_id
|
|
||||||
|
|
||||||
return authUserClone
|
|
||||||
})
|
|
||||||
|
|
||||||
return await super.create(toCreate, context)
|
|
||||||
}
|
|
||||||
|
|
||||||
async update(
|
|
||||||
data: RepositoryTypes.UpdateAuthUserDTO[],
|
|
||||||
context: Context = {}
|
|
||||||
): Promise<AuthUser[]> {
|
|
||||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
|
||||||
|
|
||||||
const authUsers = data.map(({ user, update }) => {
|
|
||||||
return manager.assign(user, update)
|
|
||||||
})
|
|
||||||
|
|
||||||
manager.persist(authUsers)
|
|
||||||
|
|
||||||
return authUsers
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,8 @@
|
|||||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
import { DAL } from "@medusajs/types"
|
||||||
import {
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
MedusaError,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { AuthProvider } from "@models"
|
import { AuthProvider } from "@models"
|
||||||
import { AuthProviderRepository } from "@repositories"
|
|
||||||
|
|
||||||
import { RepositoryTypes, ServiceTypes } from "@types"
|
import { ServiceTypes } from "@types"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
authProviderRepository: DAL.RepositoryService
|
authProviderRepository: DAL.RepositoryService
|
||||||
@@ -18,122 +10,15 @@ type InjectedDependencies = {
|
|||||||
|
|
||||||
export default class AuthProviderService<
|
export default class AuthProviderService<
|
||||||
TEntity extends AuthProvider = AuthProvider
|
TEntity extends AuthProvider = AuthProvider
|
||||||
> {
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
protected readonly authProviderRepository_: DAL.RepositoryService
|
InjectedDependencies,
|
||||||
|
{
|
||||||
constructor({ authProviderRepository }: InjectedDependencies) {
|
create: ServiceTypes.CreateAuthProviderDTO
|
||||||
this.authProviderRepository_ = authProviderRepository
|
update: ServiceTypes.UpdateAuthProviderDTO
|
||||||
}
|
}
|
||||||
|
>(AuthProvider)<TEntity> {
|
||||||
@InjectManager("authProviderRepository_")
|
constructor(container: InjectedDependencies) {
|
||||||
async retrieve(
|
// @ts-ignore
|
||||||
provider: string,
|
super(...arguments)
|
||||||
config: FindConfig<ServiceTypes.AuthProviderDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<AuthProvider, ServiceTypes.AuthProviderDTO>({
|
|
||||||
id: provider,
|
|
||||||
identifierColumn: "provider",
|
|
||||||
entityName: AuthProvider.name,
|
|
||||||
repository: this.authProviderRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("authProviderRepository_")
|
|
||||||
async list(
|
|
||||||
filters: ServiceTypes.FilterableAuthProviderProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.AuthProviderDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const queryConfig = ModulesSdkUtils.buildQuery<AuthProvider>(
|
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
return (await this.authProviderRepository_.find(
|
|
||||||
queryConfig,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("authProviderRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: ServiceTypes.FilterableAuthProviderProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.AuthProviderDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
const queryConfig = ModulesSdkUtils.buildQuery<AuthProvider>(
|
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
return (await this.authProviderRepository_.findAndCount(
|
|
||||||
queryConfig,
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("authProviderRepository_")
|
|
||||||
async create(
|
|
||||||
data: ServiceTypes.CreateAuthProviderDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this.authProviderRepository_ as AuthProviderRepository
|
|
||||||
).create(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("authProviderRepository_")
|
|
||||||
async update(
|
|
||||||
data: ServiceTypes.UpdateAuthProviderDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const authProviderIds = data.map(
|
|
||||||
(authProviderData) => authProviderData.provider
|
|
||||||
)
|
|
||||||
|
|
||||||
const existingAuthProviders = await this.list(
|
|
||||||
{
|
|
||||||
provider: authProviderIds,
|
|
||||||
},
|
|
||||||
{},
|
|
||||||
sharedContext
|
|
||||||
)
|
|
||||||
|
|
||||||
const updates: RepositoryTypes.UpdateAuthProviderDTO[] = []
|
|
||||||
|
|
||||||
const existingAuthProvidersMap = new Map(
|
|
||||||
existingAuthProviders.map<[string, AuthProvider]>((authProvider) => [
|
|
||||||
authProvider.provider,
|
|
||||||
authProvider,
|
|
||||||
])
|
|
||||||
)
|
|
||||||
|
|
||||||
for (const update of data) {
|
|
||||||
const provider = existingAuthProvidersMap.get(update.provider)
|
|
||||||
|
|
||||||
if (!provider) {
|
|
||||||
throw new MedusaError(
|
|
||||||
MedusaError.Types.NOT_FOUND,
|
|
||||||
`AuthProvider with provider "${update.provider}" not found`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
updates.push({ update, provider })
|
|
||||||
}
|
|
||||||
|
|
||||||
return (await (
|
|
||||||
this.authProviderRepository_ as AuthProviderRepository
|
|
||||||
).update(updates, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("authProviderRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.authProviderRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,126 +1,23 @@
|
|||||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
import { DAL } from "@medusajs/types"
|
||||||
import {
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
MedusaError,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { AuthUser } from "@models"
|
import { AuthUser } from "@models"
|
||||||
import { AuthUserRepository } from "@repositories"
|
|
||||||
|
|
||||||
import { RepositoryTypes, ServiceTypes } from "@types"
|
import { ServiceTypes } from "@types"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
authUserRepository: DAL.RepositoryService
|
authUserRepository: DAL.RepositoryService
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class AuthUserService<TEntity extends AuthUser = AuthUser> {
|
export default class AuthUserService<
|
||||||
protected readonly authUserRepository_: DAL.RepositoryService
|
TEntity extends AuthUser = AuthUser
|
||||||
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
|
InjectedDependencies,
|
||||||
|
{
|
||||||
|
create: ServiceTypes.CreateAuthUserDTO
|
||||||
|
}
|
||||||
|
>(AuthUser)<TEntity> {
|
||||||
constructor({ authUserRepository }: InjectedDependencies) {
|
constructor({ authUserRepository }: InjectedDependencies) {
|
||||||
this.authUserRepository_ = authUserRepository
|
// @ts-ignore
|
||||||
}
|
super(...arguments)
|
||||||
|
|
||||||
@InjectManager("authUserRepository_")
|
|
||||||
async retrieve(
|
|
||||||
provider: string,
|
|
||||||
config: FindConfig<ServiceTypes.AuthUserDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<AuthUser, ServiceTypes.AuthUserDTO>({
|
|
||||||
id: provider,
|
|
||||||
entityName: AuthUser.name,
|
|
||||||
repository: this.authUserRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("authUserRepository_")
|
|
||||||
async list(
|
|
||||||
filters: ServiceTypes.FilterableAuthProviderProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.AuthUserDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const queryConfig = ModulesSdkUtils.buildQuery<AuthUser>(filters, config)
|
|
||||||
|
|
||||||
return (await this.authUserRepository_.find(
|
|
||||||
queryConfig,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("authUserRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: ServiceTypes.FilterableAuthUserProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.AuthUserDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
const queryConfig = ModulesSdkUtils.buildQuery<AuthUser>(filters, config)
|
|
||||||
|
|
||||||
return (await this.authUserRepository_.findAndCount(
|
|
||||||
queryConfig,
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("authUserRepository_")
|
|
||||||
async create(
|
|
||||||
data: ServiceTypes.CreateAuthUserDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.authUserRepository_ as AuthUserRepository).create(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("authUserRepository_")
|
|
||||||
async update(
|
|
||||||
data: ServiceTypes.UpdateAuthUserDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const existingUsers = await this.list(
|
|
||||||
{ id: data.map(({ id }) => id) },
|
|
||||||
{},
|
|
||||||
sharedContext
|
|
||||||
)
|
|
||||||
|
|
||||||
const existingUsersMap = new Map(
|
|
||||||
existingUsers.map<[string, AuthUser]>((authUser) => [
|
|
||||||
authUser.id,
|
|
||||||
authUser,
|
|
||||||
])
|
|
||||||
)
|
|
||||||
|
|
||||||
const updates: RepositoryTypes.UpdateAuthUserDTO[] = []
|
|
||||||
|
|
||||||
for (const update of data) {
|
|
||||||
const user = existingUsersMap.get(update.id)
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
throw new MedusaError(
|
|
||||||
MedusaError.Types.NOT_FOUND,
|
|
||||||
`AuthUser with id "${update.id}" not found`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
updates.push({ update, user })
|
|
||||||
}
|
|
||||||
|
|
||||||
return (await (this.authUserRepository_ as AuthUserRepository).update(
|
|
||||||
updates,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("authUserRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.authUserRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,32 +1,16 @@
|
|||||||
import { Context } from "@medusajs/types"
|
|
||||||
import { DALUtils } from "@medusajs/utils"
|
import { DALUtils } from "@medusajs/utils"
|
||||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
|
||||||
import { Cart } from "@models"
|
import { Cart } from "@models"
|
||||||
import { CreateCartDTO, UpdateCartDTO } from "../types"
|
import { CreateCartDTO, UpdateCartDTO } from "@types"
|
||||||
|
|
||||||
export class CartRepository extends DALUtils.mikroOrmBaseRepositoryFactory<
|
export class CartRepository extends DALUtils.mikroOrmBaseRepositoryFactory<
|
||||||
Cart,
|
Cart,
|
||||||
{
|
{
|
||||||
create: CreateCartDTO
|
create: CreateCartDTO
|
||||||
|
update: UpdateCartDTO
|
||||||
}
|
}
|
||||||
>(Cart) {
|
>(Cart) {
|
||||||
constructor(...args: any[]) {
|
constructor(...args: any[]) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
super(...arguments)
|
super(...arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(
|
|
||||||
data: { cart: Cart; update: UpdateCartDTO }[],
|
|
||||||
context: Context = {}
|
|
||||||
): Promise<Cart[]> {
|
|
||||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
|
||||||
|
|
||||||
const entities = data.map(({ cart, update }) => {
|
|
||||||
return manager.assign(cart, update)
|
|
||||||
})
|
|
||||||
|
|
||||||
manager.persist(entities)
|
|
||||||
|
|
||||||
return entities
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,129 +1,23 @@
|
|||||||
import {
|
import { DAL } from "@medusajs/types"
|
||||||
AddressDTO,
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
CartAddressDTO,
|
|
||||||
Context,
|
|
||||||
DAL,
|
|
||||||
FilterableAddressProps,
|
|
||||||
FindConfig,
|
|
||||||
} from "@medusajs/types"
|
|
||||||
import {
|
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
MedusaError,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { Address } from "@models"
|
import { Address } from "@models"
|
||||||
import { AddressRepository } from "../repositories/address"
|
import { CreateAddressDTO, UpdateAddressDTO } from "@types"
|
||||||
import { CreateAddressDTO, UpdateAddressDTO } from "../types"
|
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
addressRepository: DAL.RepositoryService
|
addressRepository: DAL.RepositoryService
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class AddressService<TEntity extends Address = Address> {
|
export default class AddressService<
|
||||||
protected readonly addressRepository_: DAL.RepositoryService
|
TEntity extends Address = Address
|
||||||
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
constructor({ addressRepository }: InjectedDependencies) {
|
InjectedDependencies,
|
||||||
this.addressRepository_ = addressRepository
|
{
|
||||||
|
create: CreateAddressDTO
|
||||||
|
update: UpdateAddressDTO
|
||||||
}
|
}
|
||||||
|
>(Address)<TEntity> {
|
||||||
@InjectManager("addressRepository_")
|
constructor(container: InjectedDependencies) {
|
||||||
async retrieve(
|
// @ts-ignore
|
||||||
id: string,
|
super(...arguments)
|
||||||
config: FindConfig<AddressDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<Address, AddressDTO>({
|
|
||||||
id: id,
|
|
||||||
entityName: Address.name,
|
|
||||||
repository: this.addressRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("addressRepository_")
|
|
||||||
async list(
|
|
||||||
filters: FilterableAddressProps = {},
|
|
||||||
config: FindConfig<CartAddressDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<Address>(filters, config)
|
|
||||||
|
|
||||||
return (await this.addressRepository_.find(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("addressRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: FilterableAddressProps = {},
|
|
||||||
config: FindConfig<AddressDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<Address>(filters, config)
|
|
||||||
|
|
||||||
return (await this.addressRepository_.findAndCount(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("addressRepository_")
|
|
||||||
async create(
|
|
||||||
data: CreateAddressDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.addressRepository_ as AddressRepository).create(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("addressRepository_")
|
|
||||||
async update(
|
|
||||||
data: UpdateAddressDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
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: 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({ ...update, id: address.id })
|
|
||||||
}
|
|
||||||
|
|
||||||
return (await (this.addressRepository_ as AddressRepository).update(
|
|
||||||
updates,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("addressRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.addressRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,128 +1,23 @@
|
|||||||
import {
|
import { DAL } from "@medusajs/types"
|
||||||
CartDTO,
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
Context,
|
|
||||||
DAL,
|
|
||||||
FilterableCartProps,
|
|
||||||
FindConfig,
|
|
||||||
} from "@medusajs/types"
|
|
||||||
import {
|
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
MedusaError,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { Cart } from "@models"
|
import { Cart } from "@models"
|
||||||
import { CartRepository } from "@repositories"
|
|
||||||
import { CreateCartDTO, UpdateCartDTO } from "@types"
|
import { CreateCartDTO, UpdateCartDTO } from "@types"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
cartRepository: DAL.RepositoryService
|
cartRepository: DAL.RepositoryService
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class CartService<TEntity extends Cart = Cart> {
|
export default class CartService<
|
||||||
protected readonly cartRepository_: DAL.RepositoryService
|
TEntity extends Cart = Cart
|
||||||
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
|
InjectedDependencies,
|
||||||
|
{
|
||||||
|
create: CreateCartDTO
|
||||||
|
update: UpdateCartDTO
|
||||||
|
}
|
||||||
|
>(Cart)<TEntity> {
|
||||||
constructor({ cartRepository }: InjectedDependencies) {
|
constructor({ cartRepository }: InjectedDependencies) {
|
||||||
this.cartRepository_ = cartRepository
|
// @ts-ignore
|
||||||
}
|
super(...arguments)
|
||||||
|
|
||||||
@InjectManager("cartRepository_")
|
|
||||||
async retrieve(
|
|
||||||
id: string,
|
|
||||||
config: FindConfig<CartDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<Cart, CartDTO>({
|
|
||||||
id: id,
|
|
||||||
entityName: Cart.name,
|
|
||||||
repository: this.cartRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("cartRepository_")
|
|
||||||
async list(
|
|
||||||
filters: FilterableCartProps = {},
|
|
||||||
config: FindConfig<CartDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<Cart>(filters, config)
|
|
||||||
|
|
||||||
return (await this.cartRepository_.find(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("cartRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: FilterableCartProps = {},
|
|
||||||
config: FindConfig<CartDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<Cart>(filters, config)
|
|
||||||
|
|
||||||
return (await this.cartRepository_.findAndCount(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("cartRepository_")
|
|
||||||
async create(
|
|
||||||
data: CreateCartDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.cartRepository_ as CartRepository).create(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("cartRepository_")
|
|
||||||
async update(
|
|
||||||
data: UpdateCartDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
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<void> {
|
|
||||||
await this.cartRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,128 +1,18 @@
|
|||||||
import {
|
import { DAL } from "@medusajs/types"
|
||||||
CartLineItemDTO,
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
Context,
|
|
||||||
DAL,
|
|
||||||
FilterableLineItemProps,
|
|
||||||
FindConfig,
|
|
||||||
} from "@medusajs/types"
|
|
||||||
import {
|
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
MedusaError,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { LineItem } from "@models"
|
import { LineItem } from "@models"
|
||||||
import { LineItemRepository } from "@repositories"
|
|
||||||
import { CreateLineItemDTO, UpdateLineItemDTO } from "../types"
|
import { CreateLineItemDTO, UpdateLineItemDTO } from "../types"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
lineItemRepository: DAL.RepositoryService
|
lineItemRepository: DAL.RepositoryService
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class LineItemService<TEntity extends LineItem = LineItem> {
|
export default class LineItemService<
|
||||||
protected readonly lineItemRepository_: DAL.RepositoryService<LineItem>
|
TEntity extends LineItem = LineItem
|
||||||
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
constructor({ lineItemRepository }: InjectedDependencies) {
|
InjectedDependencies,
|
||||||
this.lineItemRepository_ = lineItemRepository
|
{
|
||||||
|
create: CreateLineItemDTO
|
||||||
|
update: UpdateLineItemDTO
|
||||||
}
|
}
|
||||||
|
>(LineItem)<TEntity> {}
|
||||||
@InjectManager("lineItemRepository_")
|
|
||||||
async retrieve(
|
|
||||||
id: string,
|
|
||||||
config: FindConfig<CartLineItemDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<LineItem, CartLineItemDTO>({
|
|
||||||
id: id,
|
|
||||||
entityName: LineItem.name,
|
|
||||||
repository: this.lineItemRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("lineItemRepository_")
|
|
||||||
async list(
|
|
||||||
filters: FilterableLineItemProps = {},
|
|
||||||
config: FindConfig<CartLineItemDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<LineItem>(filters, config)
|
|
||||||
|
|
||||||
return (await this.lineItemRepository_.find(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("lineItemRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: FilterableLineItemProps = {},
|
|
||||||
config: FindConfig<CartLineItemDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<LineItem>(filters, config)
|
|
||||||
|
|
||||||
return (await this.lineItemRepository_.findAndCount(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("lineItemRepository_")
|
|
||||||
async create(
|
|
||||||
data: CreateLineItemDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.lineItemRepository_ as LineItemRepository).create(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("lineItemRepository_")
|
|
||||||
async update(
|
|
||||||
data: UpdateLineItemDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const existingLines = await this.list(
|
|
||||||
{ id: [...data.map((d) => d.id)] },
|
|
||||||
{},
|
|
||||||
sharedContext
|
|
||||||
)
|
|
||||||
|
|
||||||
const existingLinesMap = new Map(
|
|
||||||
existingLines.map<[string, LineItem]>((li) => [li.id, li])
|
|
||||||
)
|
|
||||||
|
|
||||||
const updates: UpdateLineItemDTO[] = []
|
|
||||||
|
|
||||||
for (const update of data) {
|
|
||||||
const lineItem = existingLinesMap.get(update.id)
|
|
||||||
|
|
||||||
if (!lineItem) {
|
|
||||||
throw new MedusaError(
|
|
||||||
MedusaError.Types.NOT_FOUND,
|
|
||||||
`Line item with id "${update.id}" not found`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
updates.push({ ...update, id: lineItem.id })
|
|
||||||
}
|
|
||||||
|
|
||||||
return (await (this.lineItemRepository_ as LineItemRepository).update(
|
|
||||||
updates,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("lineItemRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.lineItemRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
|
import { Currency } from "@models"
|
||||||
import { CurrencyService } from "@services"
|
import { CurrencyService } from "@services"
|
||||||
import { asClass, asValue, createContainer } from "awilix"
|
import { asClass, asValue, createContainer } from "awilix"
|
||||||
|
|
||||||
|
;(Currency as any).meta = {
|
||||||
|
/**
|
||||||
|
* Need to mock the Currency model as well to expose the primary keys when it is different than `id`
|
||||||
|
*/
|
||||||
|
primaryKeys: ["code"],
|
||||||
|
}
|
||||||
|
|
||||||
export const nonExistingCurrencyCode = "non-existing-code"
|
export const nonExistingCurrencyCode = "non-existing-code"
|
||||||
export const mockContainer = createContainer()
|
export const mockContainer = createContainer()
|
||||||
|
|
||||||
|
|||||||
@@ -1,106 +1,23 @@
|
|||||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
import { DAL } from "@medusajs/types"
|
||||||
import {
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { Currency } from "@models"
|
import { Currency } from "@models"
|
||||||
import { CurrencyRepository } from "@repositories"
|
|
||||||
import { ServiceTypes } from "@types"
|
import { ServiceTypes } from "@types"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
currencyRepository: DAL.RepositoryService
|
currencyRepository: DAL.RepositoryService
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class CurrencyService<TEntity extends Currency = Currency> {
|
export default class CurrencyService<
|
||||||
protected readonly currencyRepository_: DAL.RepositoryService
|
TEntity extends Currency = Currency
|
||||||
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
|
InjectedDependencies,
|
||||||
|
{
|
||||||
|
create: ServiceTypes.CreateCurrencyDTO
|
||||||
|
update: ServiceTypes.UpdateCurrencyDTO
|
||||||
|
}
|
||||||
|
>(Currency)<TEntity> {
|
||||||
constructor({ currencyRepository }: InjectedDependencies) {
|
constructor({ currencyRepository }: InjectedDependencies) {
|
||||||
this.currencyRepository_ = currencyRepository
|
// @ts-ignore
|
||||||
}
|
super(...arguments)
|
||||||
|
|
||||||
@InjectManager("currencyRepository_")
|
|
||||||
async retrieve(
|
|
||||||
currencyCode: string,
|
|
||||||
config: FindConfig<ServiceTypes.CurrencyDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<Currency, ServiceTypes.CurrencyDTO>({
|
|
||||||
id: currencyCode,
|
|
||||||
identifierColumn: "code",
|
|
||||||
entityName: Currency.name,
|
|
||||||
repository: this.currencyRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("currencyRepository_")
|
|
||||||
async list(
|
|
||||||
filters: ServiceTypes.FilterableCurrencyProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.CurrencyDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await this.currencyRepository_.find(
|
|
||||||
this.buildQueryForList(filters, config),
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("currencyRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: ServiceTypes.FilterableCurrencyProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.CurrencyDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
return (await this.currencyRepository_.findAndCount(
|
|
||||||
this.buildQueryForList(filters, config),
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
private buildQueryForList(
|
|
||||||
filters: ServiceTypes.FilterableCurrencyProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.CurrencyDTO> = {}
|
|
||||||
) {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<Currency>(filters, config)
|
|
||||||
|
|
||||||
if (filters.code) {
|
|
||||||
queryOptions.where["code"] = { $in: filters.code }
|
|
||||||
}
|
|
||||||
|
|
||||||
return queryOptions
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("currencyRepository_")
|
|
||||||
async create(
|
|
||||||
data: ServiceTypes.CreateCurrencyDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.currencyRepository_ as CurrencyRepository).create(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("currencyRepository_")
|
|
||||||
async update(
|
|
||||||
data: ServiceTypes.UpdateCurrencyDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.currencyRepository_ as CurrencyRepository).update(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("currencyRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.currencyRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,6 @@
|
|||||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
import { DAL } from "@medusajs/types"
|
||||||
import {
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { MoneyAmount } from "@models"
|
import { MoneyAmount } from "@models"
|
||||||
import { MoneyAmountRepository } from "@repositories"
|
|
||||||
import { ServiceTypes } from "@types"
|
import { ServiceTypes } from "@types"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
@@ -16,105 +9,19 @@ type InjectedDependencies = {
|
|||||||
|
|
||||||
export default class MoneyAmountService<
|
export default class MoneyAmountService<
|
||||||
TEntity extends MoneyAmount = MoneyAmount
|
TEntity extends MoneyAmount = MoneyAmount
|
||||||
> {
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
protected readonly moneyAmountRepository_: DAL.RepositoryService
|
InjectedDependencies,
|
||||||
|
{
|
||||||
constructor({ moneyAmountRepository }: InjectedDependencies) {
|
create: ServiceTypes.CreateMoneyAmountDTO
|
||||||
this.moneyAmountRepository_ = moneyAmountRepository
|
update: ServiceTypes.UpdateMoneyAmountDTO
|
||||||
|
},
|
||||||
|
{
|
||||||
|
list: ServiceTypes.FilterableMoneyAmountProps
|
||||||
|
listAndCount: ServiceTypes.FilterableMoneyAmountProps
|
||||||
}
|
}
|
||||||
|
>(MoneyAmount)<TEntity> {
|
||||||
@InjectManager("moneyAmountRepository_")
|
constructor(container: InjectedDependencies) {
|
||||||
async retrieve(
|
// @ts-ignore
|
||||||
moneyAmountId: string,
|
super(...arguments)
|
||||||
config: FindConfig<ServiceTypes.MoneyAmountDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<MoneyAmount, ServiceTypes.MoneyAmountDTO>({
|
|
||||||
id: moneyAmountId,
|
|
||||||
entityName: MoneyAmount.name,
|
|
||||||
repository: this.moneyAmountRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("moneyAmountRepository_")
|
|
||||||
async list(
|
|
||||||
filters: ServiceTypes.FilterableMoneyAmountProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.MoneyAmountDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<MoneyAmount>(
|
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
return (await this.moneyAmountRepository_.find(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("moneyAmountRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: ServiceTypes.FilterableMoneyAmountProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.MoneyAmountDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<MoneyAmount>(
|
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
return (await this.moneyAmountRepository_.findAndCount(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("moneyAmountRepository_")
|
|
||||||
async create(
|
|
||||||
data: ServiceTypes.CreateMoneyAmountDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.moneyAmountRepository_ as MoneyAmountRepository).create(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("moneyAmountRepository_")
|
|
||||||
async update(
|
|
||||||
data: ServiceTypes.UpdateMoneyAmountDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.moneyAmountRepository_ as MoneyAmountRepository).update(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("moneyAmountRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.moneyAmountRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("moneyAmountRepository_")
|
|
||||||
async softDelete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.moneyAmountRepository_.softDelete(ids, sharedContext)
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("moneyAmountRepository_")
|
|
||||||
async restore(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], Record<string, unknown[]>]> {
|
|
||||||
return await this.moneyAmountRepository_.restore(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,6 @@
|
|||||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
import { DAL } from "@medusajs/types"
|
||||||
import {
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
doNotForceTransaction,
|
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
shouldForceTransaction,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { PriceListRuleValue } from "@models"
|
import { PriceListRuleValue } from "@models"
|
||||||
import { PriceListRuleValueRepository } from "@repositories"
|
|
||||||
import { ServiceTypes } from "@types"
|
import { ServiceTypes } from "@types"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
@@ -18,99 +9,19 @@ type InjectedDependencies = {
|
|||||||
|
|
||||||
export default class PriceListRuleValueService<
|
export default class PriceListRuleValueService<
|
||||||
TEntity extends PriceListRuleValue = PriceListRuleValue
|
TEntity extends PriceListRuleValue = PriceListRuleValue
|
||||||
> {
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
protected readonly priceListRuleValueRepository_: DAL.RepositoryService
|
InjectedDependencies,
|
||||||
|
{
|
||||||
constructor({ priceListRuleValueRepository }: InjectedDependencies) {
|
create: ServiceTypes.CreatePriceListRuleValueDTO
|
||||||
this.priceListRuleValueRepository_ = priceListRuleValueRepository
|
update: ServiceTypes.UpdatePriceListRuleValueDTO
|
||||||
|
},
|
||||||
|
{
|
||||||
|
list: ServiceTypes.FilterablePriceListRuleValueProps
|
||||||
|
listAndCount: ServiceTypes.FilterablePriceListRuleValueProps
|
||||||
}
|
}
|
||||||
|
>(PriceListRuleValue)<TEntity> {
|
||||||
@InjectManager("priceListRuleValueRepository_")
|
constructor(container: InjectedDependencies) {
|
||||||
async retrieve(
|
// @ts-ignore
|
||||||
priceSetId: string,
|
super(...arguments)
|
||||||
config: FindConfig<ServiceTypes.PriceListRuleValueDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<
|
|
||||||
PriceListRuleValue,
|
|
||||||
ServiceTypes.PriceListRuleValueDTO
|
|
||||||
>({
|
|
||||||
id: priceSetId,
|
|
||||||
entityName: PriceListRuleValue.name,
|
|
||||||
repository: this.priceListRuleValueRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("priceListRuleValueRepository_")
|
|
||||||
async list(
|
|
||||||
filters: ServiceTypes.FilterablePriceListRuleValueProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.PriceListRuleValueDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceListRuleValue>(
|
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
return (await this.priceListRuleValueRepository_.find(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("priceListRuleValueRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: ServiceTypes.FilterablePriceListRuleValueProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.PriceListRuleValueDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceListRuleValue>(
|
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
return (await this.priceListRuleValueRepository_.findAndCount(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager(
|
|
||||||
shouldForceTransaction,
|
|
||||||
"priceListRuleValueRepository_"
|
|
||||||
)
|
|
||||||
async create(
|
|
||||||
data: ServiceTypes.CreatePriceListRuleValueDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this.priceListRuleValueRepository_ as PriceListRuleValueRepository
|
|
||||||
).create(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager(
|
|
||||||
shouldForceTransaction,
|
|
||||||
"priceListRuleValueRepository_"
|
|
||||||
)
|
|
||||||
async update(
|
|
||||||
data: ServiceTypes.UpdatePriceListRuleValueDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this.priceListRuleValueRepository_ as PriceListRuleValueRepository
|
|
||||||
).update(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager(
|
|
||||||
doNotForceTransaction,
|
|
||||||
"priceListRuleValueRepository_"
|
|
||||||
)
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.priceListRuleValueRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,6 @@
|
|||||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
import { DAL } from "@medusajs/types"
|
||||||
import {
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
doNotForceTransaction,
|
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
shouldForceTransaction,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { PriceListRule } from "@models"
|
import { PriceListRule } from "@models"
|
||||||
import { PriceListRuleRepository } from "@repositories"
|
|
||||||
import { ServiceTypes } from "@types"
|
import { ServiceTypes } from "@types"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
@@ -18,87 +9,19 @@ type InjectedDependencies = {
|
|||||||
|
|
||||||
export default class PriceListRuleService<
|
export default class PriceListRuleService<
|
||||||
TEntity extends PriceListRule = PriceListRule
|
TEntity extends PriceListRule = PriceListRule
|
||||||
> {
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
protected readonly priceListRuleRepository_: DAL.RepositoryService
|
InjectedDependencies,
|
||||||
|
{
|
||||||
constructor({ priceListRuleRepository }: InjectedDependencies) {
|
create: ServiceTypes.CreatePriceListRuleDTO
|
||||||
this.priceListRuleRepository_ = priceListRuleRepository
|
update: ServiceTypes.UpdatePriceListRuleDTO
|
||||||
|
},
|
||||||
|
{
|
||||||
|
list: ServiceTypes.FilterablePriceListRuleProps
|
||||||
|
listAndCount: ServiceTypes.FilterablePriceListRuleProps
|
||||||
}
|
}
|
||||||
|
>(PriceListRule)<TEntity> {
|
||||||
@InjectManager("priceListRuleRepository_")
|
constructor(container: InjectedDependencies) {
|
||||||
async retrieve(
|
// @ts-ignore
|
||||||
priceSetId: string,
|
super(...arguments)
|
||||||
config: FindConfig<ServiceTypes.PriceListRuleDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<PriceListRule, ServiceTypes.PriceListRuleDTO>({
|
|
||||||
id: priceSetId,
|
|
||||||
entityName: PriceListRule.name,
|
|
||||||
repository: this.priceListRuleRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("priceListRuleRepository_")
|
|
||||||
async list(
|
|
||||||
filters: ServiceTypes.FilterablePriceListRuleProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.PriceListRuleDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceListRule>(
|
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
return (await this.priceListRuleRepository_.find(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("priceListRuleRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: ServiceTypes.FilterablePriceListRuleProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.PriceListRuleDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceListRule>(
|
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
return (await this.priceListRuleRepository_.findAndCount(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager(shouldForceTransaction, "priceListRuleRepository_")
|
|
||||||
async create(
|
|
||||||
data: ServiceTypes.CreatePriceListRuleDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this.priceListRuleRepository_ as PriceListRuleRepository
|
|
||||||
).create(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager(shouldForceTransaction, "priceListRuleRepository_")
|
|
||||||
async update(
|
|
||||||
data: ServiceTypes.UpdatePriceListRuleDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this.priceListRuleRepository_ as PriceListRuleRepository
|
|
||||||
).update(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager(doNotForceTransaction, "priceListRuleRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.priceListRuleRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,98 +1,27 @@
|
|||||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
import { DAL } from "@medusajs/types"
|
||||||
import {
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
doNotForceTransaction,
|
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
shouldForceTransaction,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { PriceList } from "@models"
|
import { PriceList } from "@models"
|
||||||
import { PriceListRepository } from "@repositories"
|
|
||||||
import { ServiceTypes } from "@types"
|
import { ServiceTypes } from "@types"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
priceListRepository: DAL.RepositoryService
|
priceListRepository: DAL.RepositoryService
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class PriceListService<TEntity extends PriceList = PriceList> {
|
export default class PriceListService<
|
||||||
protected readonly priceListRepository_: DAL.RepositoryService
|
TEntity extends PriceList = PriceList
|
||||||
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
constructor({ priceListRepository }: InjectedDependencies) {
|
InjectedDependencies,
|
||||||
this.priceListRepository_ = priceListRepository
|
{
|
||||||
|
create: ServiceTypes.CreatePriceListDTO
|
||||||
|
update: ServiceTypes.UpdatePriceListDTO
|
||||||
|
},
|
||||||
|
{
|
||||||
|
list: ServiceTypes.FilterablePriceListProps
|
||||||
|
listAndCount: ServiceTypes.FilterablePriceListProps
|
||||||
}
|
}
|
||||||
|
>(PriceList)<TEntity> {
|
||||||
@InjectManager("priceListRepository_")
|
constructor(container: InjectedDependencies) {
|
||||||
async retrieve(
|
// @ts-ignore
|
||||||
priceListId: string,
|
super(...arguments)
|
||||||
config: FindConfig<ServiceTypes.PriceListDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<PriceList, ServiceTypes.PriceListDTO>({
|
|
||||||
id: priceListId,
|
|
||||||
entityName: PriceList.name,
|
|
||||||
repository: this.priceListRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("priceListRepository_")
|
|
||||||
async list(
|
|
||||||
filters: ServiceTypes.FilterablePriceListProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.PriceListDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceList>(filters, config)
|
|
||||||
|
|
||||||
return (await this.priceListRepository_.find(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("priceListRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: ServiceTypes.FilterablePriceListProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.PriceListDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceList>(filters, config)
|
|
||||||
|
|
||||||
return (await this.priceListRepository_.findAndCount(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager(shouldForceTransaction, "priceListRepository_")
|
|
||||||
async create(
|
|
||||||
data: ServiceTypes.CreatePriceListDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.priceListRepository_ as PriceListRepository).create(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager(shouldForceTransaction, "priceListRepository_")
|
|
||||||
async update(
|
|
||||||
data: Omit<ServiceTypes.UpdatePriceListDTO, "rules">[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.priceListRepository_ as PriceListRepository).update(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager(doNotForceTransaction, "priceListRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.priceListRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,6 @@
|
|||||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
import { DAL } from "@medusajs/types"
|
||||||
import {
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { PriceRule } from "@models"
|
import { PriceRule } from "@models"
|
||||||
import { PriceRuleRepository } from "@repositories"
|
|
||||||
|
|
||||||
import { ServiceTypes } from "@types"
|
import { ServiceTypes } from "@types"
|
||||||
|
|
||||||
@@ -15,83 +8,21 @@ type InjectedDependencies = {
|
|||||||
priceRuleRepository: DAL.RepositoryService
|
priceRuleRepository: DAL.RepositoryService
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class PriceRuleService<TEntity extends PriceRule = PriceRule> {
|
export default class PriceRuleService<
|
||||||
protected readonly priceRuleRepository_: DAL.RepositoryService
|
TEntity extends PriceRule = PriceRule
|
||||||
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
constructor({ priceRuleRepository }: InjectedDependencies) {
|
InjectedDependencies,
|
||||||
this.priceRuleRepository_ = priceRuleRepository
|
{
|
||||||
|
create: ServiceTypes.CreatePriceRuleDTO
|
||||||
|
update: ServiceTypes.UpdatePriceRuleDTO
|
||||||
|
},
|
||||||
|
{
|
||||||
|
list: ServiceTypes.FilterablePriceRuleProps
|
||||||
|
listAndCount: ServiceTypes.FilterablePriceRuleProps
|
||||||
}
|
}
|
||||||
|
>(PriceRule)<TEntity> {
|
||||||
@InjectManager("priceRuleRepository_")
|
constructor(container: InjectedDependencies) {
|
||||||
async retrieve(
|
// @ts-ignore
|
||||||
priceRuleId: string,
|
super(...arguments)
|
||||||
config: FindConfig<ServiceTypes.PriceRuleDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<PriceRule, ServiceTypes.PriceRuleDTO>({
|
|
||||||
id: priceRuleId,
|
|
||||||
entityName: PriceRule.name,
|
|
||||||
repository: this.priceRuleRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("priceRuleRepository_")
|
|
||||||
async list(
|
|
||||||
filters: ServiceTypes.FilterablePriceRuleProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.PriceRuleDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const queryConfig = ModulesSdkUtils.buildQuery<PriceRule>(filters, config)
|
|
||||||
|
|
||||||
return (await this.priceRuleRepository_.find(
|
|
||||||
queryConfig,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("priceRuleRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: ServiceTypes.FilterablePriceRuleProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.PriceRuleDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
const queryConfig = ModulesSdkUtils.buildQuery<PriceRule>(filters, config)
|
|
||||||
|
|
||||||
return (await this.priceRuleRepository_.findAndCount(
|
|
||||||
queryConfig,
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("priceRuleRepository_")
|
|
||||||
async create(
|
|
||||||
data: ServiceTypes.CreatePriceRuleDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.priceRuleRepository_ as PriceRuleRepository).create(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("priceRuleRepository_")
|
|
||||||
async update(
|
|
||||||
data: ServiceTypes.UpdatePriceRuleDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.priceRuleRepository_ as PriceRuleRepository).update(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("priceRuleRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.priceRuleRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,5 @@
|
|||||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
import { DAL } from "@medusajs/types"
|
||||||
import {
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { PriceSetMoneyAmountRules } from "@models"
|
import { PriceSetMoneyAmountRules } from "@models"
|
||||||
import { ServiceTypes } from "@types"
|
import { ServiceTypes } from "@types"
|
||||||
|
|
||||||
@@ -15,96 +9,15 @@ type InjectedDependencies = {
|
|||||||
|
|
||||||
export default class PriceSetMoneyAmountRulesService<
|
export default class PriceSetMoneyAmountRulesService<
|
||||||
TEntity extends PriceSetMoneyAmountRules = PriceSetMoneyAmountRules
|
TEntity extends PriceSetMoneyAmountRules = PriceSetMoneyAmountRules
|
||||||
> {
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
protected readonly priceSetMoneyAmountRulesRepository_: DAL.RepositoryService
|
InjectedDependencies,
|
||||||
|
{
|
||||||
|
create: ServiceTypes.CreatePriceSetMoneyAmountRulesDTO
|
||||||
|
update: ServiceTypes.UpdatePriceSetMoneyAmountRulesDTO
|
||||||
|
}
|
||||||
|
>(PriceSetMoneyAmountRules)<TEntity> {
|
||||||
constructor({ priceSetMoneyAmountRulesRepository }: InjectedDependencies) {
|
constructor({ priceSetMoneyAmountRulesRepository }: InjectedDependencies) {
|
||||||
this.priceSetMoneyAmountRulesRepository_ =
|
// @ts-ignore
|
||||||
priceSetMoneyAmountRulesRepository
|
super(...arguments)
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("priceSetMoneyAmountRulesRepository_")
|
|
||||||
async retrieve(
|
|
||||||
priceSetMoneyAmountRulesId: string,
|
|
||||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountRulesDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<
|
|
||||||
PriceSetMoneyAmountRules,
|
|
||||||
ServiceTypes.PriceSetMoneyAmountRulesDTO
|
|
||||||
>({
|
|
||||||
id: priceSetMoneyAmountRulesId,
|
|
||||||
identifierColumn: "id",
|
|
||||||
entityName: PriceSetMoneyAmountRules.name,
|
|
||||||
repository: this.priceSetMoneyAmountRulesRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("priceSetMoneyAmountRulesRepository_")
|
|
||||||
async list(
|
|
||||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountRulesProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountRulesDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await this.priceSetMoneyAmountRulesRepository_.find(
|
|
||||||
this.buildQueryForList(filters, config),
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("priceSetMoneyAmountRulesRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountRulesProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountRulesDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
return (await this.priceSetMoneyAmountRulesRepository_.findAndCount(
|
|
||||||
this.buildQueryForList(filters, config),
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
private buildQueryForList(
|
|
||||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountRulesProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountRulesDTO> = {}
|
|
||||||
) {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceSetMoneyAmountRules>(
|
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
return queryOptions
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("priceSetMoneyAmountRulesRepository_")
|
|
||||||
async create(
|
|
||||||
data: ServiceTypes.CreatePriceSetMoneyAmountRulesDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await this.priceSetMoneyAmountRulesRepository_.create(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("priceSetMoneyAmountRulesRepository_")
|
|
||||||
async update(
|
|
||||||
data: ServiceTypes.UpdatePriceSetMoneyAmountRulesDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await this.priceSetMoneyAmountRulesRepository_.update(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("priceSetMoneyAmountRulesRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.priceSetMoneyAmountRulesRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,6 @@
|
|||||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||||
import {
|
import { InjectManager, MedusaContext, ModulesSdkUtils } from "@medusajs/utils"
|
||||||
InjectManager,
|
import { PriceSetMoneyAmount } from "@models"
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { PriceSet, PriceSetMoneyAmount } from "@models"
|
|
||||||
import { PriceSetMoneyAmountRepository } from "@repositories"
|
|
||||||
import { ServiceTypes } from "@types"
|
import { ServiceTypes } from "@types"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
@@ -16,95 +9,51 @@ type InjectedDependencies = {
|
|||||||
|
|
||||||
export default class PriceSetMoneyAmountService<
|
export default class PriceSetMoneyAmountService<
|
||||||
TEntity extends PriceSetMoneyAmount = PriceSetMoneyAmount
|
TEntity extends PriceSetMoneyAmount = PriceSetMoneyAmount
|
||||||
> {
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
protected readonly priceSetMoneyAmountRepository_: DAL.RepositoryService
|
InjectedDependencies,
|
||||||
|
{
|
||||||
|
create: ServiceTypes.CreatePriceSetMoneyAmountDTO
|
||||||
|
update: ServiceTypes.UpdatePriceSetMoneyAmountDTO
|
||||||
|
}
|
||||||
|
>(PriceSetMoneyAmount)<TEntity> {
|
||||||
|
protected readonly priceSetMoneyAmountRepository_: DAL.RepositoryService<TEntity>
|
||||||
|
|
||||||
constructor({ priceSetMoneyAmountRepository }: InjectedDependencies) {
|
constructor({ priceSetMoneyAmountRepository }: InjectedDependencies) {
|
||||||
|
// @ts-ignore
|
||||||
|
super(...arguments)
|
||||||
this.priceSetMoneyAmountRepository_ = priceSetMoneyAmountRepository
|
this.priceSetMoneyAmountRepository_ = priceSetMoneyAmountRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectManager("priceSetMoneyAmountRepository_")
|
@InjectManager("priceSetMoneyAmountRepository_")
|
||||||
async retrieve(
|
async list<TEntityMethod = ServiceTypes.PriceSetMoneyAmountDTO>(
|
||||||
priceSetId: string,
|
|
||||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<
|
|
||||||
PriceSetMoneyAmount,
|
|
||||||
ServiceTypes.PriceSetMoneyAmountDTO
|
|
||||||
>({
|
|
||||||
id: priceSetId,
|
|
||||||
entityName: PriceSet.name,
|
|
||||||
repository: this.priceSetMoneyAmountRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("priceSetMoneyAmountRepository_")
|
|
||||||
async list(
|
|
||||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountProps = {},
|
filters: ServiceTypes.FilterablePriceSetMoneyAmountProps = {},
|
||||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountDTO> = {},
|
config: FindConfig<TEntityMethod> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity[]> {
|
): Promise<TEntity[]> {
|
||||||
return (await this.priceSetMoneyAmountRepository_.find(
|
return await this.priceSetMoneyAmountRepository_.find(
|
||||||
this.buildQueryForList(filters, config),
|
this.buildQueryForList(filters, config),
|
||||||
sharedContext
|
sharedContext
|
||||||
)) as TEntity[]
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectManager("priceSetMoneyAmountRepository_")
|
@InjectManager("priceSetMoneyAmountRepository_")
|
||||||
async listAndCount(
|
async listAndCount<TEntityMethod = ServiceTypes.PriceSetMoneyAmountDTO>(
|
||||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountProps = {},
|
filters: ServiceTypes.FilterablePriceSetMoneyAmountProps = {},
|
||||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountDTO> = {},
|
config: FindConfig<TEntityMethod> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<[TEntity[], number]> {
|
): Promise<[TEntity[], number]> {
|
||||||
return (await this.priceSetMoneyAmountRepository_.findAndCount(
|
return await this.priceSetMoneyAmountRepository_.findAndCount(
|
||||||
this.buildQueryForList(filters, config),
|
this.buildQueryForList(filters, config),
|
||||||
sharedContext
|
sharedContext
|
||||||
)) as [TEntity[], number]
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildQueryForList(
|
private buildQueryForList<
|
||||||
|
TEntityMethod = ServiceTypes.PriceSetMoneyAmountDTO
|
||||||
|
>(
|
||||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountProps = {},
|
filters: ServiceTypes.FilterablePriceSetMoneyAmountProps = {},
|
||||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountDTO> = {}
|
config: FindConfig<TEntityMethod> = {}
|
||||||
) {
|
) {
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceSet>(filters, config)
|
return ModulesSdkUtils.buildQuery<TEntity>(filters, config)
|
||||||
|
|
||||||
if (filters.id) {
|
|
||||||
queryOptions.where.id = { $in: filters.id }
|
|
||||||
}
|
|
||||||
|
|
||||||
return queryOptions
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("priceSetMoneyAmountRepository_")
|
|
||||||
async create(
|
|
||||||
data: ServiceTypes.CreatePriceSetMoneyAmountDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this
|
|
||||||
.priceSetMoneyAmountRepository_ as unknown as PriceSetMoneyAmountRepository
|
|
||||||
).create(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("priceSetMoneyAmountRepository_")
|
|
||||||
async update(
|
|
||||||
data: ServiceTypes.UpdatePriceSetMoneyAmountDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this
|
|
||||||
.priceSetMoneyAmountRepository_ as unknown as PriceSetMoneyAmountRepository
|
|
||||||
).update(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("priceSetMoneyAmountRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.priceSetMoneyAmountRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,6 @@
|
|||||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||||
import {
|
import { InjectManager, MedusaContext, ModulesSdkUtils } from "@medusajs/utils"
|
||||||
InjectManager,
|
import { PriceSetRuleType } from "@models"
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { PriceSet, PriceSetRuleType } from "@models"
|
|
||||||
import { PriceSetRuleTypeRepository } from "src/repositories/price-set-rule-type"
|
|
||||||
import { ServiceTypes } from "@types"
|
import { ServiceTypes } from "@types"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
@@ -16,93 +9,51 @@ type InjectedDependencies = {
|
|||||||
|
|
||||||
export default class PriceSetRuleTypeService<
|
export default class PriceSetRuleTypeService<
|
||||||
TEntity extends PriceSetRuleType = PriceSetRuleType
|
TEntity extends PriceSetRuleType = PriceSetRuleType
|
||||||
> {
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
protected readonly priceSetRuleTypeRepository_: DAL.RepositoryService
|
InjectedDependencies,
|
||||||
|
{
|
||||||
|
create: ServiceTypes.CreatePriceSetRuleTypeDTO
|
||||||
|
update: ServiceTypes.UpdatePriceSetRuleTypeDTO
|
||||||
|
}
|
||||||
|
>(PriceSetRuleType)<TEntity> {
|
||||||
|
protected readonly priceSetRuleTypeRepository_: DAL.RepositoryService<TEntity>
|
||||||
|
|
||||||
constructor({ priceSetRuleTypeRepository }: InjectedDependencies) {
|
constructor({ priceSetRuleTypeRepository }: InjectedDependencies) {
|
||||||
|
// @ts-ignore
|
||||||
|
super(...arguments)
|
||||||
this.priceSetRuleTypeRepository_ = priceSetRuleTypeRepository
|
this.priceSetRuleTypeRepository_ = priceSetRuleTypeRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectManager("priceSetRuleTypeRepository_")
|
@InjectManager("priceSetRuleTypeRepository_")
|
||||||
async retrieve(
|
async list<TEntityMethod = ServiceTypes.PriceSetMoneyAmountDTO>(
|
||||||
priceSetId: string,
|
|
||||||
config: FindConfig<ServiceTypes.PriceSetRuleTypeDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<
|
|
||||||
PriceSetRuleType,
|
|
||||||
ServiceTypes.PriceSetRuleTypeDTO
|
|
||||||
>({
|
|
||||||
id: priceSetId,
|
|
||||||
entityName: PriceSet.name,
|
|
||||||
repository: this.priceSetRuleTypeRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("priceSetRuleTypeRepository_")
|
|
||||||
async list(
|
|
||||||
filters: ServiceTypes.FilterablePriceSetRuleTypeProps = {},
|
filters: ServiceTypes.FilterablePriceSetRuleTypeProps = {},
|
||||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
config: FindConfig<TEntityMethod> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity[]> {
|
): Promise<TEntity[]> {
|
||||||
return (await this.priceSetRuleTypeRepository_.find(
|
return await this.priceSetRuleTypeRepository_.find(
|
||||||
this.buildQueryForList(filters, config),
|
this.buildQueryForList(filters, config),
|
||||||
sharedContext
|
sharedContext
|
||||||
)) as TEntity[]
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectManager("priceSetRuleTypeRepository_")
|
@InjectManager("priceSetRuleTypeRepository_")
|
||||||
async listAndCount(
|
async listAndCount<TEntityMethod = ServiceTypes.PriceSetMoneyAmountDTO>(
|
||||||
filters: ServiceTypes.FilterablePriceSetRuleTypeProps = {},
|
filters: ServiceTypes.FilterablePriceSetRuleTypeProps = {},
|
||||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
config: FindConfig<TEntityMethod> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<[TEntity[], number]> {
|
): Promise<[TEntity[], number]> {
|
||||||
return (await this.priceSetRuleTypeRepository_.findAndCount(
|
return await this.priceSetRuleTypeRepository_.findAndCount(
|
||||||
this.buildQueryForList(filters, config),
|
this.buildQueryForList(filters, config),
|
||||||
sharedContext
|
sharedContext
|
||||||
)) as [TEntity[], number]
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildQueryForList(
|
private buildQueryForList<
|
||||||
|
TEntityMethod = ServiceTypes.PriceSetMoneyAmountDTO
|
||||||
|
>(
|
||||||
filters: ServiceTypes.FilterablePriceSetRuleTypeProps = {},
|
filters: ServiceTypes.FilterablePriceSetRuleTypeProps = {},
|
||||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {}
|
config: FindConfig<TEntityMethod> = {}
|
||||||
) {
|
) {
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceSet>(filters, config)
|
return ModulesSdkUtils.buildQuery<TEntity>(filters, config)
|
||||||
|
|
||||||
if (filters.id) {
|
|
||||||
queryOptions.where.id = { $in: filters.id }
|
|
||||||
}
|
|
||||||
|
|
||||||
return queryOptions
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("priceSetRuleTypeRepository_")
|
|
||||||
async create(
|
|
||||||
data: ServiceTypes.CreatePriceSetRuleTypeDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this.priceSetRuleTypeRepository_ as PriceSetRuleTypeRepository
|
|
||||||
).create(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("priceSetRuleTypeRepository_")
|
|
||||||
async update(
|
|
||||||
data: ServiceTypes.UpdatePriceSetRuleTypeDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this.priceSetRuleTypeRepository_ as PriceSetRuleTypeRepository
|
|
||||||
).update(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("priceSetRuleTypeRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.priceSetRuleTypeRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,6 @@
|
|||||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
import { DAL } from "@medusajs/types"
|
||||||
import {
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { PriceSet } from "@models"
|
import { PriceSet } from "@models"
|
||||||
import { PriceSetRepository } from "@repositories"
|
|
||||||
|
|
||||||
import { ServiceTypes } from "@types"
|
import { ServiceTypes } from "@types"
|
||||||
|
|
||||||
@@ -15,83 +8,21 @@ type InjectedDependencies = {
|
|||||||
priceSetRepository: DAL.RepositoryService
|
priceSetRepository: DAL.RepositoryService
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class PriceSetService<TEntity extends PriceSet = PriceSet> {
|
export default class PriceSetService<
|
||||||
protected readonly priceSetRepository_: DAL.RepositoryService
|
TEntity extends PriceSet = PriceSet
|
||||||
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
constructor({ priceSetRepository }: InjectedDependencies) {
|
InjectedDependencies,
|
||||||
this.priceSetRepository_ = priceSetRepository
|
{
|
||||||
|
create: Omit<ServiceTypes.CreatePriceSetDTO, "rules">
|
||||||
|
update: Omit<ServiceTypes.UpdatePriceSetDTO, "rules">
|
||||||
|
},
|
||||||
|
{
|
||||||
|
list: ServiceTypes.FilterablePriceSetProps
|
||||||
|
listAndCount: ServiceTypes.FilterablePriceSetProps
|
||||||
}
|
}
|
||||||
|
>(PriceSet)<TEntity> {
|
||||||
@InjectManager("priceSetRepository_")
|
constructor(container: InjectedDependencies) {
|
||||||
async retrieve(
|
// @ts-ignore
|
||||||
priceSetId: string,
|
super(...arguments)
|
||||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<PriceSet, ServiceTypes.PriceSetDTO>({
|
|
||||||
id: priceSetId,
|
|
||||||
entityName: PriceSet.name,
|
|
||||||
repository: this.priceSetRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("priceSetRepository_")
|
|
||||||
async list(
|
|
||||||
filters: ServiceTypes.FilterablePriceSetProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceSet>(filters, config)
|
|
||||||
|
|
||||||
return (await this.priceSetRepository_.find(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("priceSetRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: ServiceTypes.FilterablePriceSetProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceSet>(filters, config)
|
|
||||||
|
|
||||||
return (await this.priceSetRepository_.findAndCount(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("priceSetRepository_")
|
|
||||||
async create(
|
|
||||||
data: Omit<ServiceTypes.CreatePriceSetDTO, "rules">[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.priceSetRepository_ as PriceSetRepository).create(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("priceSetRepository_")
|
|
||||||
async update(
|
|
||||||
data: Omit<ServiceTypes.UpdatePriceSetDTO, "rules">[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.priceSetRepository_ as PriceSetRepository).update(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("priceSetRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.priceSetRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
import { Context, DAL } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
InjectTransactionManager,
|
||||||
MedusaContext,
|
MedusaContext,
|
||||||
ModulesSdkUtils,
|
ModulesSdkUtils,
|
||||||
retrieveEntity,
|
|
||||||
validateRuleAttributes,
|
validateRuleAttributes,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { RuleType } from "@models"
|
import { RuleType } from "@models"
|
||||||
@@ -14,67 +12,34 @@ type InjectedDependencies = {
|
|||||||
ruleTypeRepository: DAL.RepositoryService
|
ruleTypeRepository: DAL.RepositoryService
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class RuleTypeService<TEntity extends RuleType = RuleType> {
|
export default class RuleTypeService<
|
||||||
protected readonly ruleTypeRepository_: DAL.RepositoryService
|
TEntity extends RuleType = RuleType
|
||||||
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
|
InjectedDependencies,
|
||||||
|
{
|
||||||
|
create: ServiceTypes.CreateRuleTypeDTO
|
||||||
|
update: ServiceTypes.UpdateRuleTypeDTO
|
||||||
|
},
|
||||||
|
{
|
||||||
|
list: ServiceTypes.FilterableRuleTypeProps
|
||||||
|
listAndCount: ServiceTypes.FilterableRuleTypeProps
|
||||||
|
}
|
||||||
|
>(RuleType)<TEntity> {
|
||||||
|
protected readonly ruleTypeRepository_: DAL.RepositoryService<TEntity>
|
||||||
|
|
||||||
constructor({ ruleTypeRepository }: InjectedDependencies) {
|
constructor({ ruleTypeRepository }: InjectedDependencies) {
|
||||||
|
// @ts-ignore
|
||||||
|
super(...arguments)
|
||||||
this.ruleTypeRepository_ = ruleTypeRepository
|
this.ruleTypeRepository_ = ruleTypeRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectManager("ruleTypeRepository_")
|
|
||||||
async retrieve(
|
|
||||||
ruleTypeId: string,
|
|
||||||
config: FindConfig<ServiceTypes.RuleTypeDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<RuleType, ServiceTypes.RuleTypeDTO>({
|
|
||||||
id: ruleTypeId,
|
|
||||||
identifierColumn: "id",
|
|
||||||
entityName: RuleType.name,
|
|
||||||
repository: this.ruleTypeRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("ruleTypeRepository_")
|
|
||||||
async list(
|
|
||||||
filters: ServiceTypes.FilterableRuleTypeProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.RuleTypeDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<RuleType>(filters, config)
|
|
||||||
|
|
||||||
return (await this.ruleTypeRepository_.find(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("ruleTypeRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: ServiceTypes.FilterableRuleTypeProps = {},
|
|
||||||
config: FindConfig<ServiceTypes.RuleTypeDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<RuleType>(filters, config)
|
|
||||||
|
|
||||||
return (await this.ruleTypeRepository_.findAndCount(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("ruleTypeRepository_")
|
@InjectTransactionManager("ruleTypeRepository_")
|
||||||
async create(
|
async create(
|
||||||
data: ServiceTypes.CreateRuleTypeDTO[],
|
data: ServiceTypes.CreateRuleTypeDTO[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity[]> {
|
): Promise<TEntity[]> {
|
||||||
validateRuleAttributes(data.map((d) => d.rule_attribute))
|
validateRuleAttributes(data.map((d) => d.rule_attribute))
|
||||||
return (await this.ruleTypeRepository_.create(
|
return await this.ruleTypeRepository_.create(data, sharedContext)
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectTransactionManager("ruleTypeRepository_")
|
@InjectTransactionManager("ruleTypeRepository_")
|
||||||
@@ -83,17 +48,6 @@ export default class RuleTypeService<TEntity extends RuleType = RuleType> {
|
|||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity[]> {
|
): Promise<TEntity[]> {
|
||||||
validateRuleAttributes(data.map((d) => d.rule_attribute))
|
validateRuleAttributes(data.map((d) => d.rule_attribute))
|
||||||
return (await this.ruleTypeRepository_.update(
|
return await this.ruleTypeRepository_.update(data, sharedContext)
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("ruleTypeRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.ruleTypeRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ module.exports = {
|
|||||||
"^@models": "<rootDir>/src/models",
|
"^@models": "<rootDir>/src/models",
|
||||||
"^@services": "<rootDir>/src/services",
|
"^@services": "<rootDir>/src/services",
|
||||||
"^@repositories": "<rootDir>/src/repositories",
|
"^@repositories": "<rootDir>/src/repositories",
|
||||||
|
"^@types": "<rootDir>/src/types",
|
||||||
},
|
},
|
||||||
transform: {
|
transform: {
|
||||||
"^.+\\.[jt]s?$": [
|
"^.+\\.[jt]s?$": [
|
||||||
|
|||||||
@@ -13,17 +13,20 @@ import {
|
|||||||
WithRequiredProperty,
|
WithRequiredProperty,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||||
import { DALUtils, isDefined, MedusaError, promiseAll } from "@medusajs/utils"
|
import {
|
||||||
|
DALUtils,
|
||||||
|
isDefined,
|
||||||
|
MedusaError,
|
||||||
|
promiseAll,
|
||||||
|
ProductUtils,
|
||||||
|
} from "@medusajs/utils"
|
||||||
|
|
||||||
import { ProductServiceTypes } from "../types/services"
|
import { ProductServiceTypes } from "../types/services"
|
||||||
|
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
export class ProductRepository extends DALUtils.mikroOrmBaseRepositoryFactory<
|
export class ProductRepository extends DALUtils.mikroOrmBaseRepositoryFactory<Product>(
|
||||||
Product,
|
Product
|
||||||
{
|
) {
|
||||||
create: WithRequiredProperty<ProductTypes.CreateProductOnlyDTO, "status">
|
|
||||||
}
|
|
||||||
>(Product) {
|
|
||||||
constructor(...args: any[]) {
|
constructor(...args: any[]) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
super(...arguments)
|
super(...arguments)
|
||||||
@@ -103,6 +106,17 @@ export class ProductRepository extends DALUtils.mikroOrmBaseRepositoryFactory<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async create(
|
||||||
|
data: WithRequiredProperty<ProductTypes.CreateProductOnlyDTO, "status">[],
|
||||||
|
context: Context = {}
|
||||||
|
): Promise<Product[]> {
|
||||||
|
data.forEach((productData) => {
|
||||||
|
productData.status ??= ProductUtils.ProductStatus.DRAFT
|
||||||
|
})
|
||||||
|
|
||||||
|
return await super.create(data, context)
|
||||||
|
}
|
||||||
|
|
||||||
async update(
|
async update(
|
||||||
data: WithRequiredProperty<ProductServiceTypes.UpdateProductDTO, "id">[],
|
data: WithRequiredProperty<ProductServiceTypes.UpdateProductDTO, "id">[],
|
||||||
context: Context = {}
|
context: Context = {}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
MedusaError,
|
MedusaError,
|
||||||
ModulesSdkUtils,
|
ModulesSdkUtils,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { ProductCategoryServiceTypes } from "../types"
|
import { ProductCategoryServiceTypes } from "@types"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
productCategoryRepository: DAL.TreeRepositoryService
|
productCategoryRepository: DAL.TreeRepositoryService
|
||||||
|
|||||||
@@ -1,12 +1,5 @@
|
|||||||
import { Context, DAL, FindConfig, ProductTypes } from "@medusajs/types"
|
import { Context, DAL, FindConfig, ProductTypes } from "@medusajs/types"
|
||||||
import {
|
import { InjectManager, MedusaContext, ModulesSdkUtils } from "@medusajs/utils"
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { ProductCollectionRepository } from "../repositories"
|
|
||||||
|
|
||||||
import { ProductCollection } from "@models"
|
import { ProductCollection } from "@models"
|
||||||
|
|
||||||
@@ -16,98 +9,61 @@ type InjectedDependencies = {
|
|||||||
|
|
||||||
export default class ProductCollectionService<
|
export default class ProductCollectionService<
|
||||||
TEntity extends ProductCollection = ProductCollection
|
TEntity extends ProductCollection = ProductCollection
|
||||||
> {
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
protected readonly productCollectionRepository_: DAL.RepositoryService
|
InjectedDependencies,
|
||||||
|
{
|
||||||
|
create: ProductTypes.CreateProductCollectionDTO
|
||||||
|
update: ProductTypes.UpdateProductCollectionDTO
|
||||||
|
}
|
||||||
|
>(ProductCollection)<TEntity> {
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
|
protected readonly productCollectionRepository_: DAL.RepositoryService<TEntity>
|
||||||
|
|
||||||
constructor({ productCollectionRepository }: InjectedDependencies) {
|
constructor(container: InjectedDependencies) {
|
||||||
this.productCollectionRepository_ = productCollectionRepository
|
super(container)
|
||||||
|
this.productCollectionRepository_ = container.productCollectionRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectManager("productCollectionRepository_")
|
@InjectManager("productCollectionRepository_")
|
||||||
async retrieve(
|
async list<TEntityMethod = ProductTypes.ProductCollectionDTO>(
|
||||||
productCollectionId: string,
|
|
||||||
config: FindConfig<ProductTypes.ProductCollectionDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<
|
|
||||||
ProductCollection,
|
|
||||||
ProductTypes.ProductCollectionDTO
|
|
||||||
>({
|
|
||||||
id: productCollectionId,
|
|
||||||
entityName: ProductCollection.name,
|
|
||||||
repository: this.productCollectionRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("productCollectionRepository_")
|
|
||||||
async list(
|
|
||||||
filters: ProductTypes.FilterableProductCollectionProps = {},
|
filters: ProductTypes.FilterableProductCollectionProps = {},
|
||||||
config: FindConfig<ProductTypes.ProductCollectionDTO> = {},
|
config: FindConfig<TEntityMethod> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity[]> {
|
): Promise<TEntity[]> {
|
||||||
return (await this.productCollectionRepository_.find(
|
return await this.productCollectionRepository_.find(
|
||||||
this.buildListQueryOptions(filters, config),
|
this.buildListQueryOptions(filters, config),
|
||||||
sharedContext
|
sharedContext
|
||||||
)) as TEntity[]
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectManager("productCollectionRepository_")
|
@InjectManager("productCollectionRepository_")
|
||||||
async listAndCount(
|
async listAndCount<TEntityMethod = ProductTypes.ProductCollectionDTO>(
|
||||||
filters: ProductTypes.FilterableProductCollectionProps = {},
|
filters: ProductTypes.FilterableProductCollectionProps = {},
|
||||||
config: FindConfig<ProductTypes.ProductCollectionDTO> = {},
|
config: FindConfig<TEntityMethod> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<[TEntity[], number]> {
|
): Promise<[TEntity[], number]> {
|
||||||
return (await this.productCollectionRepository_.findAndCount(
|
return await this.productCollectionRepository_.findAndCount(
|
||||||
this.buildListQueryOptions(filters, config),
|
this.buildListQueryOptions(filters, config),
|
||||||
sharedContext
|
sharedContext
|
||||||
)) as [TEntity[], number]
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected buildListQueryOptions(
|
protected buildListQueryOptions<
|
||||||
|
TEntityMethod = ProductTypes.ProductCollectionDTO
|
||||||
|
>(
|
||||||
filters: ProductTypes.FilterableProductCollectionProps = {},
|
filters: ProductTypes.FilterableProductCollectionProps = {},
|
||||||
config: FindConfig<ProductTypes.ProductCollectionDTO> = {}
|
config: FindConfig<TEntityMethod> = {}
|
||||||
) {
|
): DAL.FindOptions<TEntity> {
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<ProductCollection>(
|
const queryOptions = ModulesSdkUtils.buildQuery<TEntity>(filters, config)
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
queryOptions.where ??= {}
|
queryOptions.where ??= {}
|
||||||
|
|
||||||
if (filters.title) {
|
if (filters.title) {
|
||||||
queryOptions.where["title"] = { $like: filters.title }
|
queryOptions.where.title = {
|
||||||
|
$like: `%${filters.title}%`,
|
||||||
|
} as DAL.FindOptions<TEntity>["where"]["title"]
|
||||||
}
|
}
|
||||||
|
|
||||||
return queryOptions
|
return queryOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectTransactionManager("productCollectionRepository_")
|
|
||||||
async create(
|
|
||||||
data: ProductTypes.CreateProductCollectionDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this.productCollectionRepository_ as ProductCollectionRepository
|
|
||||||
).create(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("productCollectionRepository_")
|
|
||||||
async update(
|
|
||||||
data: ProductTypes.UpdateProductCollectionDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this.productCollectionRepository_ as ProductCollectionRepository
|
|
||||||
).update(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("productCollectionRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.productCollectionRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import { Image } from "@models"
|
import { Image } from "@models"
|
||||||
import { Context, DAL } from "@medusajs/types"
|
import { Context, DAL } from "@medusajs/types"
|
||||||
import { InjectTransactionManager, MedusaContext } from "@medusajs/utils"
|
import { InjectTransactionManager, MedusaContext } from "@medusajs/utils"
|
||||||
import { ProductImageRepository } from "@repositories"
|
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
productImageRepository: DAL.RepositoryService
|
productImageRepository: DAL.RepositoryService
|
||||||
@@ -19,7 +18,6 @@ export default class ProductImageService<TEntity extends Image = Image> {
|
|||||||
urls: string[],
|
urls: string[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity[]> {
|
): Promise<TEntity[]> {
|
||||||
return (await (this.productImageRepository_ as ProductImageRepository)
|
return await this.productImageRepository_.upsert!(urls, sharedContext)
|
||||||
.upsert!(urls, sharedContext)) as TEntity[]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,24 +35,11 @@ import {
|
|||||||
import ProductImageService from "./product-image"
|
import ProductImageService from "./product-image"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CreateProductCategoryDTO,
|
ProductCategoryServiceTypes,
|
||||||
ProductCategoryEventData,
|
ProductCollectionServiceTypes,
|
||||||
ProductCategoryEvents,
|
ProductServiceTypes,
|
||||||
UpdateProductCategoryDTO,
|
ProductVariantServiceTypes,
|
||||||
} from "../types/services/product-category"
|
} from "@types"
|
||||||
|
|
||||||
import { UpdateProductVariantDTO } from "../types/services/product-variant"
|
|
||||||
|
|
||||||
import {
|
|
||||||
ProductCollectionEventData,
|
|
||||||
ProductCollectionEvents,
|
|
||||||
} from "../types/services/product-collection"
|
|
||||||
|
|
||||||
import {
|
|
||||||
ProductEventData,
|
|
||||||
ProductEvents,
|
|
||||||
UpdateProductDTO,
|
|
||||||
} from "../types/services/product"
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
arrayDifference,
|
arrayDifference,
|
||||||
@@ -76,6 +63,11 @@ import {
|
|||||||
joinerConfig,
|
joinerConfig,
|
||||||
LinkableKeys,
|
LinkableKeys,
|
||||||
} from "./../joiner-config"
|
} from "./../joiner-config"
|
||||||
|
import {
|
||||||
|
ProductCategoryEventData,
|
||||||
|
ProductCategoryEvents,
|
||||||
|
} from "../types/services/product-category"
|
||||||
|
import { ProductEventData, ProductEvents } from "../types/services/product"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
baseRepository: DAL.RepositoryService
|
baseRepository: DAL.RepositoryService
|
||||||
@@ -373,7 +365,7 @@ export default class ProductModuleService<
|
|||||||
const toUpdate = data.map(({ id, options, ...rest }) => {
|
const toUpdate = data.map(({ id, options, ...rest }) => {
|
||||||
const variant = variantsMap.get(id)!
|
const variant = variantsMap.get(id)!
|
||||||
|
|
||||||
const toUpdate: UpdateProductVariantDTO = {
|
const toUpdate: ProductVariantServiceTypes.UpdateProductVariantDTO = {
|
||||||
id,
|
id,
|
||||||
product_id: variant.product_id,
|
product_id: variant.product_id,
|
||||||
}
|
}
|
||||||
@@ -749,9 +741,12 @@ export default class ProductModuleService<
|
|||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
await this.eventBusModuleService_?.emit<ProductCollectionEventData>(
|
// eslint-disable-next-line max-len
|
||||||
|
await this.eventBusModuleService_?.emit<ProductCollectionServiceTypes.ProductCollectionEventData>(
|
||||||
productCollections.map(({ id }) => ({
|
productCollections.map(({ id }) => ({
|
||||||
eventName: ProductCollectionEvents.COLLECTION_CREATED,
|
eventName:
|
||||||
|
ProductCollectionServiceTypes.ProductCollectionEvents
|
||||||
|
.COLLECTION_CREATED,
|
||||||
data: { id },
|
data: { id },
|
||||||
}))
|
}))
|
||||||
)
|
)
|
||||||
@@ -769,9 +764,12 @@ export default class ProductModuleService<
|
|||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
await this.eventBusModuleService_?.emit<ProductCollectionEventData>(
|
// eslint-disable-next-line max-len
|
||||||
|
await this.eventBusModuleService_?.emit<ProductCollectionServiceTypes.ProductCollectionEventData>(
|
||||||
productCollections.map(({ id }) => ({
|
productCollections.map(({ id }) => ({
|
||||||
eventName: ProductCollectionEvents.COLLECTION_UPDATED,
|
eventName:
|
||||||
|
ProductCollectionServiceTypes.ProductCollectionEvents
|
||||||
|
.COLLECTION_UPDATED,
|
||||||
data: { id },
|
data: { id },
|
||||||
}))
|
}))
|
||||||
)
|
)
|
||||||
@@ -789,9 +787,12 @@ export default class ProductModuleService<
|
|||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
await this.eventBusModuleService_?.emit<ProductCollectionEventData>(
|
// eslint-disable-next-line max-len
|
||||||
|
await this.eventBusModuleService_?.emit<ProductCollectionServiceTypes.ProductCollectionEventData>(
|
||||||
productCollectionIds.map((id) => ({
|
productCollectionIds.map((id) => ({
|
||||||
eventName: ProductCollectionEvents.COLLECTION_DELETED,
|
eventName:
|
||||||
|
ProductCollectionServiceTypes.ProductCollectionEvents
|
||||||
|
.COLLECTION_DELETED,
|
||||||
data: { id },
|
data: { id },
|
||||||
}))
|
}))
|
||||||
)
|
)
|
||||||
@@ -829,7 +830,7 @@ export default class ProductModuleService<
|
|||||||
|
|
||||||
@InjectTransactionManager("baseRepository_")
|
@InjectTransactionManager("baseRepository_")
|
||||||
async createCategory(
|
async createCategory(
|
||||||
data: CreateProductCategoryDTO,
|
data: ProductCategoryServiceTypes.CreateProductCategoryDTO,
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
) {
|
) {
|
||||||
const productCategory = await this.productCategoryService_.create(
|
const productCategory = await this.productCategoryService_.create(
|
||||||
@@ -848,7 +849,7 @@ export default class ProductModuleService<
|
|||||||
@InjectTransactionManager("baseRepository_")
|
@InjectTransactionManager("baseRepository_")
|
||||||
async updateCategory(
|
async updateCategory(
|
||||||
categoryId: string,
|
categoryId: string,
|
||||||
data: UpdateProductCategoryDTO,
|
data: ProductCategoryServiceTypes.UpdateProductCategoryDTO,
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
) {
|
) {
|
||||||
const productCategory = await this.productCategoryService_.update(
|
const productCategory = await this.productCategoryService_.update(
|
||||||
@@ -1124,7 +1125,7 @@ export default class ProductModuleService<
|
|||||||
(productData.options ?? []) as TProductOption[]
|
(productData.options ?? []) as TProductOption[]
|
||||||
)
|
)
|
||||||
|
|
||||||
return productData as UpdateProductDTO
|
return productData as ProductServiceTypes.UpdateProductDTO
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1203,10 +1204,13 @@ export default class ProductModuleService<
|
|||||||
})
|
})
|
||||||
|
|
||||||
productVariantsToUpdateMap.forEach((variants, productId) => {
|
productVariantsToUpdateMap.forEach((variants, productId) => {
|
||||||
|
const variants_ =
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
|
variants as unknown as ProductVariantServiceTypes.UpdateProductVariantDTO[]
|
||||||
promises.push(
|
promises.push(
|
||||||
this.productVariantService_.update(
|
this.productVariantService_.update(
|
||||||
productByIdMap.get(productId)!,
|
productByIdMap.get(productId)!,
|
||||||
variants as unknown as UpdateProductVariantDTO[],
|
variants_,
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,14 +1,7 @@
|
|||||||
import { ProductOptionValue } from "@models"
|
import { ProductOptionValue } from "@models"
|
||||||
import { Context, DAL } from "@medusajs/types"
|
import { Context, DAL } from "@medusajs/types"
|
||||||
import {
|
|
||||||
ProductOptionRepository,
|
|
||||||
ProductOptionValueRepository,
|
|
||||||
} from "@repositories"
|
|
||||||
import { InjectTransactionManager, MedusaContext } from "@medusajs/utils"
|
import { InjectTransactionManager, MedusaContext } from "@medusajs/utils"
|
||||||
import {
|
import { ProductOptionValueServiceTypes } from "@types"
|
||||||
CreateProductOptionValueDTO,
|
|
||||||
UpdateProductOptionValueDTO,
|
|
||||||
} from "../types/services/product-option-value"
|
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
productOptionValueRepository: DAL.RepositoryService
|
productOptionValueRepository: DAL.RepositoryService
|
||||||
@@ -17,11 +10,11 @@ type InjectedDependencies = {
|
|||||||
export default class ProductOptionValueService<
|
export default class ProductOptionValueService<
|
||||||
TEntity extends ProductOptionValue = ProductOptionValue
|
TEntity extends ProductOptionValue = ProductOptionValue
|
||||||
> {
|
> {
|
||||||
protected readonly productOptionValueRepository_: DAL.RepositoryService
|
// eslint-disable-next-line max-len
|
||||||
|
protected readonly productOptionValueRepository_: DAL.RepositoryService<TEntity>
|
||||||
|
|
||||||
constructor({ productOptionValueRepository }: InjectedDependencies) {
|
constructor({ productOptionValueRepository }: InjectedDependencies) {
|
||||||
this.productOptionValueRepository_ =
|
this.productOptionValueRepository_ = productOptionValueRepository
|
||||||
productOptionValueRepository as ProductOptionRepository
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectTransactionManager("productOptionValueRepository_")
|
@InjectTransactionManager("productOptionValueRepository_")
|
||||||
@@ -34,11 +27,12 @@ export default class ProductOptionValueService<
|
|||||||
|
|
||||||
@InjectTransactionManager("productOptionValueRepository_")
|
@InjectTransactionManager("productOptionValueRepository_")
|
||||||
async upsert(
|
async upsert(
|
||||||
data: (UpdateProductOptionValueDTO | CreateProductOptionValueDTO)[],
|
data: (
|
||||||
|
| ProductOptionValueServiceTypes.UpdateProductOptionValueDTO
|
||||||
|
| ProductOptionValueServiceTypes.CreateProductOptionValueDTO
|
||||||
|
)[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity[]> {
|
): Promise<TEntity[]> {
|
||||||
return (await (
|
return await this.productOptionValueRepository_.upsert!(data, sharedContext)
|
||||||
this.productOptionValueRepository_ as ProductOptionValueRepository
|
|
||||||
).upsert!(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
import { ProductOption } from "@models"
|
import { ProductOption } from "@models"
|
||||||
import { Context, DAL, FindConfig, ProductTypes } from "@medusajs/types"
|
import { Context, DAL, FindConfig, ProductTypes } from "@medusajs/types"
|
||||||
import { ProductOptionRepository } from "@repositories"
|
|
||||||
import {
|
import {
|
||||||
InjectManager,
|
InjectManager,
|
||||||
InjectTransactionManager,
|
InjectTransactionManager,
|
||||||
MedusaContext,
|
MedusaContext,
|
||||||
ModulesSdkUtils,
|
ModulesSdkUtils,
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
@@ -15,99 +13,59 @@ type InjectedDependencies = {
|
|||||||
|
|
||||||
export default class ProductOptionService<
|
export default class ProductOptionService<
|
||||||
TEntity extends ProductOption = ProductOption
|
TEntity extends ProductOption = ProductOption
|
||||||
> {
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
protected readonly productOptionRepository_: DAL.RepositoryService
|
InjectedDependencies,
|
||||||
|
{
|
||||||
|
create: ProductTypes.CreateProductOptionDTO
|
||||||
|
update: ProductTypes.UpdateProductOptionDTO
|
||||||
|
}
|
||||||
|
>(ProductOption)<TEntity> {
|
||||||
|
protected readonly productOptionRepository_: DAL.RepositoryService<TEntity>
|
||||||
|
|
||||||
constructor({ productOptionRepository }: InjectedDependencies) {
|
constructor(container: InjectedDependencies) {
|
||||||
this.productOptionRepository_ =
|
super(container)
|
||||||
productOptionRepository as ProductOptionRepository
|
this.productOptionRepository_ = container.productOptionRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectManager("productOptionRepository_")
|
@InjectManager("productOptionRepository_")
|
||||||
async retrieve(
|
async list<TEntityMethod = ProductTypes.ProductOptionDTO>(
|
||||||
productOptionId: string,
|
|
||||||
config: FindConfig<ProductTypes.ProductOptionDTO> = {},
|
|
||||||
@MedusaContext() sharedContext?: Context
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<ProductOption, ProductTypes.ProductOptionDTO>({
|
|
||||||
id: productOptionId,
|
|
||||||
entityName: ProductOption.name,
|
|
||||||
repository: this.productOptionRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("productOptionRepository_")
|
|
||||||
async list(
|
|
||||||
filters: ProductTypes.FilterableProductOptionProps = {},
|
filters: ProductTypes.FilterableProductOptionProps = {},
|
||||||
config: FindConfig<ProductTypes.ProductOptionDTO> = {},
|
config: FindConfig<TEntityMethod> = {},
|
||||||
@MedusaContext() sharedContext?: Context
|
@MedusaContext() sharedContext?: Context
|
||||||
): Promise<TEntity[]> {
|
): Promise<TEntity[]> {
|
||||||
return (await this.productOptionRepository_.find(
|
return await this.productOptionRepository_.find(
|
||||||
this.buildQueryForList(filters, config),
|
this.buildQueryForList(filters, config),
|
||||||
sharedContext
|
sharedContext
|
||||||
)) as TEntity[]
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectManager("productOptionRepository_")
|
@InjectManager("productOptionRepository_")
|
||||||
async listAndCount(
|
async listAndCount<TEntityMethod = ProductTypes.ProductOptionDTO>(
|
||||||
filters: ProductTypes.FilterableProductOptionProps = {},
|
filters: ProductTypes.FilterableProductOptionProps = {},
|
||||||
config: FindConfig<ProductTypes.ProductOptionDTO> = {},
|
config: FindConfig<TEntityMethod> = {},
|
||||||
@MedusaContext() sharedContext?: Context
|
@MedusaContext() sharedContext?: Context
|
||||||
): Promise<[TEntity[], number]> {
|
): Promise<[TEntity[], number]> {
|
||||||
return (await this.productOptionRepository_.findAndCount(
|
return await this.productOptionRepository_.findAndCount(
|
||||||
this.buildQueryForList(filters, config),
|
this.buildQueryForList(filters, config),
|
||||||
sharedContext
|
sharedContext
|
||||||
)) as [TEntity[], number]
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildQueryForList(
|
private buildQueryForList<TEntityMethod = ProductTypes.ProductOptionDTO>(
|
||||||
filters: ProductTypes.FilterableProductOptionProps = {},
|
filters: ProductTypes.FilterableProductOptionProps = {},
|
||||||
config: FindConfig<ProductTypes.ProductOptionDTO> = {}
|
config: FindConfig<TEntityMethod> = {}
|
||||||
) {
|
): DAL.FindOptions<TEntity> {
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<ProductOption>(
|
const queryOptions = ModulesSdkUtils.buildQuery<TEntity>(filters, config)
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
if (filters.title) {
|
if (filters.title) {
|
||||||
queryOptions.where["title"] = { $ilike: filters.title }
|
queryOptions.where.title = {
|
||||||
|
$ilike: filters.title,
|
||||||
|
} as DAL.FindOptions<TEntity>["where"]["title"]
|
||||||
}
|
}
|
||||||
|
|
||||||
return queryOptions
|
return queryOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectTransactionManager("productOptionRepository_")
|
|
||||||
async create(
|
|
||||||
data: ProductTypes.CreateProductOptionOnlyDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this.productOptionRepository_ as ProductOptionRepository
|
|
||||||
).create(data, {
|
|
||||||
transactionManager: sharedContext.transactionManager,
|
|
||||||
})) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("productOptionRepository_")
|
|
||||||
async update(
|
|
||||||
data: ProductTypes.UpdateProductOptionDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this.productOptionRepository_ as ProductOptionRepository
|
|
||||||
).update(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("productOptionRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
return await this.productOptionRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("productOptionRepository_")
|
@InjectTransactionManager("productOptionRepository_")
|
||||||
async upsert(
|
async upsert(
|
||||||
data:
|
data:
|
||||||
@@ -115,7 +73,6 @@ export default class ProductOptionService<
|
|||||||
| ProductTypes.UpdateProductOptionDTO[],
|
| ProductTypes.UpdateProductOptionDTO[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity[]> {
|
): Promise<TEntity[]> {
|
||||||
return (await (this.productOptionRepository_ as ProductOptionRepository)
|
return await this.productOptionRepository_.upsert!(data, sharedContext)
|
||||||
.upsert!(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
import { ProductTag } from "@models"
|
import { ProductTag } from "@models"
|
||||||
import {
|
import {
|
||||||
Context,
|
Context,
|
||||||
CreateProductTagDTO,
|
|
||||||
DAL,
|
DAL,
|
||||||
FindConfig,
|
FindConfig,
|
||||||
ProductTypes,
|
ProductTypes,
|
||||||
UpdateProductTagDTO,
|
|
||||||
UpsertProductTagDTO,
|
UpsertProductTagDTO,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
@@ -13,11 +11,7 @@ import {
|
|||||||
InjectTransactionManager,
|
InjectTransactionManager,
|
||||||
MedusaContext,
|
MedusaContext,
|
||||||
ModulesSdkUtils,
|
ModulesSdkUtils,
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { ProductTagRepository } from "@repositories"
|
|
||||||
|
|
||||||
import { shouldForceTransaction } from "../utils"
|
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
productTagRepository: DAL.RepositoryService
|
productTagRepository: DAL.RepositoryService
|
||||||
@@ -25,103 +19,63 @@ type InjectedDependencies = {
|
|||||||
|
|
||||||
export default class ProductTagService<
|
export default class ProductTagService<
|
||||||
TEntity extends ProductTag = ProductTag
|
TEntity extends ProductTag = ProductTag
|
||||||
> {
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
protected readonly productTagRepository_: DAL.RepositoryService
|
InjectedDependencies,
|
||||||
|
{
|
||||||
constructor({ productTagRepository }: InjectedDependencies) {
|
create: ProductTypes.CreateProductTagDTO
|
||||||
this.productTagRepository_ = productTagRepository
|
update: ProductTypes.UpdateProductTagDTO
|
||||||
}
|
}
|
||||||
|
>(ProductTag)<TEntity> {
|
||||||
|
protected readonly productTagRepository_: DAL.RepositoryService<TEntity>
|
||||||
|
|
||||||
@InjectManager("productTagRepository_")
|
constructor(container: InjectedDependencies) {
|
||||||
async retrieve(
|
super(container)
|
||||||
productTagId: string,
|
this.productTagRepository_ = container.productTagRepository
|
||||||
config: FindConfig<ProductTypes.ProductTagDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<ProductTag, ProductTypes.ProductTagDTO>({
|
|
||||||
id: productTagId,
|
|
||||||
entityName: ProductTag.name,
|
|
||||||
repository: this.productTagRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectManager("productTagRepository_")
|
@InjectManager("productTagRepository_")
|
||||||
async list(
|
async list<TEntityMethod = ProductTypes.ProductTagDTO>(
|
||||||
filters: ProductTypes.FilterableProductTagProps = {},
|
filters: ProductTypes.FilterableProductTagProps = {},
|
||||||
config: FindConfig<ProductTypes.ProductTagDTO> = {},
|
config: FindConfig<TEntityMethod> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity[]> {
|
): Promise<TEntity[]> {
|
||||||
return (await this.productTagRepository_.find(
|
return await this.productTagRepository_.find(
|
||||||
this.buildQueryForList(filters, config),
|
this.buildQueryForList(filters, config),
|
||||||
sharedContext
|
sharedContext
|
||||||
)) as TEntity[]
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectManager("productTagRepository_")
|
@InjectManager("productTagRepository_")
|
||||||
async listAndCount(
|
async listAndCount<TEntityMethod = ProductTypes.ProductTagDTO>(
|
||||||
filters: ProductTypes.FilterableProductTagProps = {},
|
filters: ProductTypes.FilterableProductTagProps = {},
|
||||||
config: FindConfig<ProductTypes.ProductTagDTO> = {},
|
config: FindConfig<TEntityMethod> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<[TEntity[], number]> {
|
): Promise<[TEntity[], number]> {
|
||||||
return (await this.productTagRepository_.findAndCount(
|
return await this.productTagRepository_.findAndCount(
|
||||||
this.buildQueryForList(filters, config),
|
this.buildQueryForList(filters, config),
|
||||||
sharedContext
|
sharedContext
|
||||||
)) as [TEntity[], number]
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildQueryForList(
|
private buildQueryForList<TEntityMethod = ProductTypes.ProductTagDTO>(
|
||||||
filters: ProductTypes.FilterableProductTagProps = {},
|
filters: ProductTypes.FilterableProductTagProps = {},
|
||||||
config: FindConfig<ProductTypes.ProductTagDTO> = {}
|
config: FindConfig<TEntityMethod> = {}
|
||||||
) {
|
): DAL.FindOptions<TEntity> {
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<ProductTag>(filters, config)
|
const queryOptions = ModulesSdkUtils.buildQuery<TEntity>(filters, config)
|
||||||
|
|
||||||
if (filters.value) {
|
if (filters.value) {
|
||||||
queryOptions.where["value"] = { $ilike: filters.value }
|
queryOptions.where.value = {
|
||||||
|
$ilike: filters.value,
|
||||||
|
} as DAL.FindOptions<TEntity>["where"]["value"]
|
||||||
}
|
}
|
||||||
|
|
||||||
return queryOptions
|
return queryOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectTransactionManager("productTagRepository_")
|
|
||||||
async create(
|
|
||||||
data: CreateProductTagDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.productTagRepository_ as ProductTagRepository).create(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("productTagRepository_")
|
|
||||||
async update(
|
|
||||||
data: UpdateProductTagDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.productTagRepository_ as ProductTagRepository).update(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("productTagRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.productTagRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("productTagRepository_")
|
@InjectTransactionManager("productTagRepository_")
|
||||||
async upsert(
|
async upsert(
|
||||||
data: UpsertProductTagDTO[],
|
data: UpsertProductTagDTO[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity[]> {
|
): Promise<TEntity[]> {
|
||||||
return (await (this.productTagRepository_ as ProductTagRepository).upsert!(
|
return await this.productTagRepository_.upsert!(data, sharedContext)
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,87 +1,72 @@
|
|||||||
import { ProductType } from "@models"
|
import { ProductType } from "@models"
|
||||||
import {
|
import {
|
||||||
Context,
|
Context,
|
||||||
CreateProductTypeDTO,
|
|
||||||
DAL,
|
DAL,
|
||||||
FindConfig,
|
FindConfig,
|
||||||
ProductTypes,
|
ProductTypes,
|
||||||
UpdateProductTypeDTO,
|
|
||||||
UpsertProductTypeDTO,
|
UpsertProductTypeDTO,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import { ProductTypeRepository } from "@repositories"
|
|
||||||
import {
|
import {
|
||||||
InjectManager,
|
InjectManager,
|
||||||
InjectTransactionManager,
|
InjectTransactionManager,
|
||||||
MedusaContext,
|
MedusaContext,
|
||||||
ModulesSdkUtils,
|
ModulesSdkUtils,
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
|
|
||||||
import { shouldForceTransaction } from "../utils"
|
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
productTypeRepository: DAL.RepositoryService
|
productTypeRepository: DAL.RepositoryService
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class ProductTypeService<
|
export default class ProductTypeService<
|
||||||
TEntity extends ProductType = ProductType
|
TEntity extends ProductType = ProductType
|
||||||
> {
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
protected readonly productTypeRepository_: DAL.RepositoryService
|
InjectedDependencies,
|
||||||
|
{
|
||||||
|
create: ProductTypes.CreateProductTypeDTO
|
||||||
|
update: ProductTypes.UpdateProductTypeDTO
|
||||||
|
}
|
||||||
|
>(ProductType)<TEntity> {
|
||||||
|
protected readonly productTypeRepository_: DAL.RepositoryService<TEntity>
|
||||||
|
|
||||||
constructor({ productTypeRepository }: InjectedDependencies) {
|
constructor(container: InjectedDependencies) {
|
||||||
this.productTypeRepository_ = productTypeRepository
|
super(container)
|
||||||
|
this.productTypeRepository_ = container.productTypeRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectManager("productTypeRepository_")
|
@InjectManager("productTypeRepository_")
|
||||||
async retrieve(
|
async list<TEntityMethod = ProductTypes.ProductTypeDTO>(
|
||||||
productTypeId: string,
|
|
||||||
config: FindConfig<ProductTypes.ProductTypeDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<ProductType, ProductTypes.ProductTypeDTO>({
|
|
||||||
id: productTypeId,
|
|
||||||
entityName: ProductType.name,
|
|
||||||
repository: this.productTypeRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("productTypeRepository_")
|
|
||||||
async list(
|
|
||||||
filters: ProductTypes.FilterableProductTypeProps = {},
|
filters: ProductTypes.FilterableProductTypeProps = {},
|
||||||
config: FindConfig<ProductTypes.ProductTypeDTO> = {},
|
config: FindConfig<TEntityMethod> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity[]> {
|
): Promise<TEntity[]> {
|
||||||
return (await this.productTypeRepository_.find(
|
return await this.productTypeRepository_.find(
|
||||||
this.buildQueryForList(filters, config),
|
this.buildQueryForList(filters, config),
|
||||||
sharedContext
|
sharedContext
|
||||||
)) as TEntity[]
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectManager("productTypeRepository_")
|
@InjectManager("productTypeRepository_")
|
||||||
async listAndCount(
|
async listAndCount<TEntityMethod = ProductTypes.ProductOptionDTO>(
|
||||||
filters: ProductTypes.FilterableProductTypeProps = {},
|
filters: ProductTypes.FilterableProductTypeProps = {},
|
||||||
config: FindConfig<ProductTypes.ProductTypeDTO> = {},
|
config: FindConfig<TEntityMethod> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<[TEntity[], number]> {
|
): Promise<[TEntity[], number]> {
|
||||||
return (await this.productTypeRepository_.findAndCount(
|
return await this.productTypeRepository_.findAndCount(
|
||||||
this.buildQueryForList(filters, config),
|
this.buildQueryForList(filters, config),
|
||||||
sharedContext
|
sharedContext
|
||||||
)) as [TEntity[], number]
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildQueryForList(
|
private buildQueryForList<TEntityMethod = ProductTypes.ProductTypeDTO>(
|
||||||
filters: ProductTypes.FilterableProductTypeProps = {},
|
filters: ProductTypes.FilterableProductTypeProps = {},
|
||||||
config: FindConfig<ProductTypes.ProductTypeDTO> = {}
|
config: FindConfig<TEntityMethod> = {}
|
||||||
) {
|
): DAL.FindOptions<TEntity> {
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<ProductType>(
|
const queryOptions = ModulesSdkUtils.buildQuery<TEntity>(filters, config)
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
if (filters.value) {
|
if (filters.value) {
|
||||||
queryOptions.where["value"] = { $ilike: filters.value }
|
queryOptions.where.value = {
|
||||||
|
$ilike: filters.value,
|
||||||
|
} as DAL.FindOptions<TEntity>["where"]["value"]
|
||||||
}
|
}
|
||||||
|
|
||||||
return queryOptions
|
return queryOptions
|
||||||
@@ -92,37 +77,6 @@ export default class ProductTypeService<
|
|||||||
types: UpsertProductTypeDTO[],
|
types: UpsertProductTypeDTO[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity[]> {
|
): Promise<TEntity[]> {
|
||||||
return (await (this.productTypeRepository_ as ProductTypeRepository)
|
return await this.productTypeRepository_.upsert!(types, sharedContext)
|
||||||
.upsert!(types, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("productTypeRepository_")
|
|
||||||
async create(
|
|
||||||
data: CreateProductTypeDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.productTypeRepository_ as ProductTypeRepository).create(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("productTypeRepository_")
|
|
||||||
async update(
|
|
||||||
data: UpdateProductTypeDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.productTypeRepository_ as ProductTypeRepository).update(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("productTypeRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.productTypeRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,13 @@
|
|||||||
import { Context, DAL, FindConfig, ProductTypes } from "@medusajs/types"
|
import { Context, DAL, ProductTypes } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
InjectTransactionManager,
|
||||||
|
isString,
|
||||||
MedusaContext,
|
MedusaContext,
|
||||||
ModulesSdkUtils,
|
ModulesSdkUtils,
|
||||||
isString,
|
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { Product, ProductVariant } from "@models"
|
import { Product, ProductVariant } from "@models"
|
||||||
import { ProductVariantRepository } from "@repositories"
|
|
||||||
|
|
||||||
import { ProductVariantServiceTypes } from "../types/services"
|
import { ProductVariantServiceTypes } from "@types"
|
||||||
import ProductService from "./product"
|
import ProductService from "./product"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
@@ -21,72 +18,29 @@ type InjectedDependencies = {
|
|||||||
export default class ProductVariantService<
|
export default class ProductVariantService<
|
||||||
TEntity extends ProductVariant = ProductVariant,
|
TEntity extends ProductVariant = ProductVariant,
|
||||||
TProduct extends Product = Product
|
TProduct extends Product = Product
|
||||||
> {
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
protected readonly productVariantRepository_: DAL.RepositoryService
|
InjectedDependencies,
|
||||||
|
{
|
||||||
|
create: ProductTypes.CreateProductVariantOnlyDTO
|
||||||
|
update: ProductVariantServiceTypes.UpdateProductVariantDTO
|
||||||
|
}
|
||||||
|
>(ProductVariant)<TEntity> {
|
||||||
|
protected readonly productVariantRepository_: DAL.RepositoryService<TEntity>
|
||||||
protected readonly productService_: ProductService<TProduct>
|
protected readonly productService_: ProductService<TProduct>
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
productVariantRepository,
|
productVariantRepository,
|
||||||
productService,
|
productService,
|
||||||
}: InjectedDependencies) {
|
}: InjectedDependencies) {
|
||||||
|
// @ts-ignore
|
||||||
|
super(...arguments)
|
||||||
this.productVariantRepository_ = productVariantRepository
|
this.productVariantRepository_ = productVariantRepository
|
||||||
this.productService_ = productService
|
this.productService_ = productService
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectManager("productVariantRepository_")
|
|
||||||
async retrieve(
|
|
||||||
productVariantId: string,
|
|
||||||
config: FindConfig<ProductTypes.ProductVariantDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<
|
|
||||||
ProductVariant,
|
|
||||||
ProductTypes.ProductVariantDTO
|
|
||||||
>({
|
|
||||||
id: productVariantId,
|
|
||||||
entityName: ProductVariant.name,
|
|
||||||
repository: this.productVariantRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("productVariantRepository_")
|
|
||||||
async list(
|
|
||||||
filters: ProductTypes.FilterableProductVariantProps = {},
|
|
||||||
config: FindConfig<ProductTypes.ProductVariantDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<ProductVariant>(
|
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
return (await this.productVariantRepository_.find(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("productVariantRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: ProductTypes.FilterableProductVariantProps = {},
|
|
||||||
config: FindConfig<ProductTypes.ProductVariantDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<ProductVariant>(
|
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
return (await this.productVariantRepository_.findAndCount(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("productVariantRepository_")
|
@InjectTransactionManager("productVariantRepository_")
|
||||||
async create(
|
// @ts-ignore
|
||||||
|
override async create(
|
||||||
productOrId: TProduct | string,
|
productOrId: TProduct | string,
|
||||||
data: ProductTypes.CreateProductVariantOnlyDTO[],
|
data: ProductTypes.CreateProductVariantOnlyDTO[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
@@ -113,15 +67,14 @@ export default class ProductVariantService<
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return (await (
|
return await this.productVariantRepository_.create(data_, {
|
||||||
this.productVariantRepository_ as ProductVariantRepository
|
|
||||||
).create(data_, {
|
|
||||||
transactionManager: sharedContext.transactionManager,
|
transactionManager: sharedContext.transactionManager,
|
||||||
})) as TEntity[]
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectTransactionManager("productVariantRepository_")
|
@InjectTransactionManager("productVariantRepository_")
|
||||||
async update(
|
// @ts-ignore
|
||||||
|
override async update(
|
||||||
productOrId: TProduct | string,
|
productOrId: TProduct | string,
|
||||||
data: ProductVariantServiceTypes.UpdateProductVariantDTO[],
|
data: ProductVariantServiceTypes.UpdateProductVariantDTO[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
@@ -139,39 +92,7 @@ export default class ProductVariantService<
|
|||||||
const variantsData = [...data]
|
const variantsData = [...data]
|
||||||
variantsData.forEach((variant) => Object.assign(variant, { product }))
|
variantsData.forEach((variant) => Object.assign(variant, { product }))
|
||||||
|
|
||||||
return (await (
|
return await this.productVariantRepository_.update(variantsData, {
|
||||||
this.productVariantRepository_ as ProductVariantRepository
|
|
||||||
).update(variantsData, {
|
|
||||||
transactionManager: sharedContext.transactionManager,
|
|
||||||
})) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("productVariantRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
return await this.productVariantRepository_.delete(ids, {
|
|
||||||
transactionManager: sharedContext.transactionManager,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("productVariantRepository_")
|
|
||||||
async softDelete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.productVariantRepository_.softDelete(ids, {
|
|
||||||
transactionManager: sharedContext.transactionManager,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("productVariantRepository_")
|
|
||||||
async restore(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], Record<string, unknown[]>]> {
|
|
||||||
return await this.productVariantRepository_.restore(ids, {
|
|
||||||
transactionManager: sharedContext.transactionManager,
|
transactionManager: sharedContext.transactionManager,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,74 +1,35 @@
|
|||||||
import {
|
import { Context, DAL, FindConfig, ProductTypes } from "@medusajs/types"
|
||||||
Context,
|
import { InjectManager, MedusaContext, ModulesSdkUtils } from "@medusajs/utils"
|
||||||
DAL,
|
|
||||||
FindConfig,
|
|
||||||
ProductTypes,
|
|
||||||
WithRequiredProperty,
|
|
||||||
} from "@medusajs/types"
|
|
||||||
import {
|
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
isDefined,
|
|
||||||
MedusaContext,
|
|
||||||
MedusaError,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
ProductUtils,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { Product } from "@models"
|
import { Product } from "@models"
|
||||||
import { ProductRepository } from "@repositories"
|
import { ProductServiceTypes } from "@types"
|
||||||
|
|
||||||
import { ProductServiceTypes } from "../types/services"
|
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
productRepository: DAL.RepositoryService
|
productRepository: DAL.RepositoryService
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class ProductService<TEntity extends Product = Product> {
|
export default class ProductService<
|
||||||
protected readonly productRepository_: DAL.RepositoryService
|
TEntity extends Product = Product
|
||||||
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
|
InjectedDependencies,
|
||||||
|
{
|
||||||
|
create: ProductTypes.CreateProductOnlyDTO
|
||||||
|
update: ProductServiceTypes.UpdateProductDTO
|
||||||
|
}
|
||||||
|
>(Product)<TEntity> {
|
||||||
|
protected readonly productRepository_: DAL.RepositoryService<TEntity>
|
||||||
|
|
||||||
constructor({ productRepository }: InjectedDependencies) {
|
constructor({ productRepository }: InjectedDependencies) {
|
||||||
|
// @ts-ignore
|
||||||
|
// eslint-disable-next-line prefer-rest-params
|
||||||
|
super(...arguments)
|
||||||
|
|
||||||
this.productRepository_ = productRepository
|
this.productRepository_ = productRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectManager("productRepository_")
|
@InjectManager("productRepository_")
|
||||||
async retrieve(
|
async list<TEntityMethod = ProductTypes.ProductDTO>(
|
||||||
productId: string,
|
|
||||||
config: FindConfig<ProductTypes.ProductDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
if (!isDefined(productId)) {
|
|
||||||
throw new MedusaError(
|
|
||||||
MedusaError.Types.NOT_FOUND,
|
|
||||||
`"productId" must be defined`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<Product>(
|
|
||||||
{
|
|
||||||
id: productId,
|
|
||||||
},
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
const product = await this.productRepository_.find(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!product?.length) {
|
|
||||||
throw new MedusaError(
|
|
||||||
MedusaError.Types.NOT_FOUND,
|
|
||||||
`Product with id: ${productId} was not found`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return product[0] as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("productRepository_")
|
|
||||||
async list(
|
|
||||||
filters: ProductTypes.FilterableProductProps = {},
|
filters: ProductTypes.FilterableProductProps = {},
|
||||||
config: FindConfig<ProductTypes.ProductDTO> = {},
|
config: FindConfig<TEntityMethod> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity[]> {
|
): Promise<TEntity[]> {
|
||||||
if (filters.category_id) {
|
if (filters.category_id) {
|
||||||
@@ -84,17 +45,13 @@ export default class ProductService<TEntity extends Product = Product> {
|
|||||||
delete filters.category_id
|
delete filters.category_id
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<Product>(filters, config)
|
return await super.list<TEntityMethod>(filters, config, sharedContext)
|
||||||
return (await this.productRepository_.find(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectManager("productRepository_")
|
@InjectManager("productRepository_")
|
||||||
async listAndCount(
|
async listAndCount<TEntityMethod = ProductTypes.ProductDTO>(
|
||||||
filters: ProductTypes.FilterableProductProps = {},
|
filters: ProductTypes.FilterableProductProps = {},
|
||||||
config: FindConfig<ProductTypes.ProductDTO> = {},
|
config: FindConfig<TEntityMethod> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<[TEntity[], number]> {
|
): Promise<[TEntity[], number]> {
|
||||||
if (filters.category_id) {
|
if (filters.category_id) {
|
||||||
@@ -110,76 +67,10 @@ export default class ProductService<TEntity extends Product = Product> {
|
|||||||
delete filters.category_id
|
delete filters.category_id
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<Product>(filters, config)
|
return await super.listAndCount<TEntityMethod>(
|
||||||
return (await this.productRepository_.findAndCount(
|
filters,
|
||||||
queryOptions,
|
config,
|
||||||
sharedContext
|
sharedContext
|
||||||
)) as [TEntity[], number]
|
)
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("productRepository_")
|
|
||||||
async create(
|
|
||||||
data: ProductTypes.CreateProductOnlyDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
data.forEach((product) => {
|
|
||||||
product.status ??= ProductUtils.ProductStatus.DRAFT
|
|
||||||
})
|
|
||||||
|
|
||||||
return (await (this.productRepository_ as ProductRepository).create(
|
|
||||||
data as WithRequiredProperty<
|
|
||||||
ProductTypes.CreateProductOnlyDTO,
|
|
||||||
"status"
|
|
||||||
>[],
|
|
||||||
{
|
|
||||||
transactionManager: sharedContext.transactionManager,
|
|
||||||
}
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("productRepository_")
|
|
||||||
async update(
|
|
||||||
data: ProductServiceTypes.UpdateProductDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.productRepository_ as ProductRepository).update(
|
|
||||||
data as WithRequiredProperty<
|
|
||||||
ProductServiceTypes.UpdateProductDTO,
|
|
||||||
"id"
|
|
||||||
>[],
|
|
||||||
{
|
|
||||||
transactionManager: sharedContext.transactionManager,
|
|
||||||
}
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("productRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.productRepository_.delete(ids, {
|
|
||||||
transactionManager: sharedContext.transactionManager,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("productRepository_")
|
|
||||||
async softDelete(
|
|
||||||
productIds: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], Record<string, unknown[]>]> {
|
|
||||||
return await this.productRepository_.softDelete(productIds, {
|
|
||||||
transactionManager: sharedContext.transactionManager,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("productRepository_")
|
|
||||||
async restore(
|
|
||||||
productIds: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], Record<string, unknown[]>]> {
|
|
||||||
return await this.productRepository_.restore(productIds, {
|
|
||||||
transactionManager: sharedContext.transactionManager,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,3 +2,4 @@ export * as ProductCategoryServiceTypes from "./product-category"
|
|||||||
export * as ProductServiceTypes from "./product"
|
export * as ProductServiceTypes from "./product"
|
||||||
export * as ProductVariantServiceTypes from "./product-variant"
|
export * as ProductVariantServiceTypes from "./product-variant"
|
||||||
export * as ProductCollectionServiceTypes from "./product-collection"
|
export * as ProductCollectionServiceTypes from "./product-collection"
|
||||||
|
export * as ProductOptionValueServiceTypes from "./product-option-value"
|
||||||
@@ -22,7 +22,8 @@
|
|||||||
"paths": {
|
"paths": {
|
||||||
"@models": ["./src/models"],
|
"@models": ["./src/models"],
|
||||||
"@services": ["./src/services"],
|
"@services": ["./src/services"],
|
||||||
"@repositories": ["./src/repositories"]
|
"@repositories": ["./src/repositories"],
|
||||||
|
"@types": ["./src/types"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": ["src"],
|
"include": ["src"],
|
||||||
|
|||||||
@@ -1,17 +1,7 @@
|
|||||||
import { Context, DAL, FindConfig, PromotionTypes } from "@medusajs/types"
|
import { DAL, PromotionTypes } from "@medusajs/types"
|
||||||
import {
|
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { ApplicationMethod } from "@models"
|
import { ApplicationMethod } from "@models"
|
||||||
import { ApplicationMethodRepository } from "@repositories"
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
import {
|
import { CreateApplicationMethodDTO, UpdateApplicationMethodDTO } from "@types"
|
||||||
CreateApplicationMethodDTO,
|
|
||||||
UpdateApplicationMethodDTO,
|
|
||||||
} from "../types"
|
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
applicationMethodRepository: DAL.RepositoryService
|
applicationMethodRepository: DAL.RepositoryService
|
||||||
@@ -19,90 +9,19 @@ type InjectedDependencies = {
|
|||||||
|
|
||||||
export default class ApplicationMethodService<
|
export default class ApplicationMethodService<
|
||||||
TEntity extends ApplicationMethod = ApplicationMethod
|
TEntity extends ApplicationMethod = ApplicationMethod
|
||||||
> {
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
protected readonly applicationMethodRepository_: DAL.RepositoryService
|
InjectedDependencies,
|
||||||
|
{
|
||||||
constructor({ applicationMethodRepository }: InjectedDependencies) {
|
create: CreateApplicationMethodDTO
|
||||||
this.applicationMethodRepository_ = applicationMethodRepository
|
update: UpdateApplicationMethodDTO
|
||||||
|
},
|
||||||
|
{
|
||||||
|
list: PromotionTypes.FilterableApplicationMethodProps
|
||||||
|
listAndCount: PromotionTypes.FilterableApplicationMethodProps
|
||||||
}
|
}
|
||||||
|
>(ApplicationMethod)<TEntity> {
|
||||||
@InjectManager("applicationMethodRepository_")
|
constructor(...args: any[]) {
|
||||||
async retrieve(
|
// @ts-ignore
|
||||||
applicationMethodId: string,
|
super(...arguments)
|
||||||
config: FindConfig<PromotionTypes.ApplicationMethodDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<
|
|
||||||
ApplicationMethod,
|
|
||||||
PromotionTypes.ApplicationMethodDTO
|
|
||||||
>({
|
|
||||||
id: applicationMethodId,
|
|
||||||
entityName: ApplicationMethod.name,
|
|
||||||
repository: this.applicationMethodRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("applicationMethodRepository_")
|
|
||||||
async list(
|
|
||||||
filters: PromotionTypes.FilterableApplicationMethodProps = {},
|
|
||||||
config: FindConfig<PromotionTypes.ApplicationMethodDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<ApplicationMethod>(
|
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
return (await this.applicationMethodRepository_.find(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("applicationMethodRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: PromotionTypes.FilterableApplicationMethodProps = {},
|
|
||||||
config: FindConfig<PromotionTypes.ApplicationMethodDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<ApplicationMethod>(
|
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
return (await this.applicationMethodRepository_.findAndCount(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("applicationMethodRepository_")
|
|
||||||
async create(
|
|
||||||
data: CreateApplicationMethodDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this.applicationMethodRepository_ as ApplicationMethodRepository
|
|
||||||
).create(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("applicationMethodRepository_")
|
|
||||||
async update(
|
|
||||||
data: UpdateApplicationMethodDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this.applicationMethodRepository_ as ApplicationMethodRepository
|
|
||||||
).update(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("applicationMethodRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.applicationMethodRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,6 @@
|
|||||||
import { Context, DAL, FindConfig, PromotionTypes } from "@medusajs/types"
|
import { DAL, PromotionTypes } from "@medusajs/types"
|
||||||
import {
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { CampaignBudget } from "@models"
|
import { CampaignBudget } from "@models"
|
||||||
import { CampaignBudgetRepository } from "@repositories"
|
|
||||||
import { CreateCampaignBudgetDTO, UpdateCampaignBudgetDTO } from "../types"
|
import { CreateCampaignBudgetDTO, UpdateCampaignBudgetDTO } from "../types"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
@@ -16,90 +9,19 @@ type InjectedDependencies = {
|
|||||||
|
|
||||||
export default class CampaignBudgetService<
|
export default class CampaignBudgetService<
|
||||||
TEntity extends CampaignBudget = CampaignBudget
|
TEntity extends CampaignBudget = CampaignBudget
|
||||||
> {
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
protected readonly campaignBudgetRepository_: DAL.RepositoryService
|
InjectedDependencies,
|
||||||
|
{
|
||||||
constructor({ campaignBudgetRepository }: InjectedDependencies) {
|
create: CreateCampaignBudgetDTO
|
||||||
this.campaignBudgetRepository_ = campaignBudgetRepository
|
update: UpdateCampaignBudgetDTO
|
||||||
|
},
|
||||||
|
{
|
||||||
|
list: PromotionTypes.FilterableCampaignBudgetProps
|
||||||
|
listAndCount: PromotionTypes.FilterableCampaignBudgetProps
|
||||||
}
|
}
|
||||||
|
>(CampaignBudget)<TEntity> {
|
||||||
@InjectManager("campaignBudgetRepository_")
|
constructor(...args: any[]) {
|
||||||
async retrieve(
|
// @ts-ignore
|
||||||
campaignBudgetId: string,
|
super(...arguments)
|
||||||
config: FindConfig<PromotionTypes.CampaignBudgetDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<
|
|
||||||
CampaignBudget,
|
|
||||||
PromotionTypes.CampaignBudgetDTO
|
|
||||||
>({
|
|
||||||
id: campaignBudgetId,
|
|
||||||
entityName: CampaignBudget.name,
|
|
||||||
repository: this.campaignBudgetRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("campaignBudgetRepository_")
|
|
||||||
async list(
|
|
||||||
filters: PromotionTypes.FilterableCampaignBudgetProps = {},
|
|
||||||
config: FindConfig<PromotionTypes.CampaignBudgetDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<CampaignBudget>(
|
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
return (await this.campaignBudgetRepository_.find(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("campaignBudgetRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: PromotionTypes.FilterableCampaignBudgetProps = {},
|
|
||||||
config: FindConfig<PromotionTypes.CampaignBudgetDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<CampaignBudget>(
|
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
return (await this.campaignBudgetRepository_.findAndCount(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("campaignBudgetRepository_")
|
|
||||||
async create(
|
|
||||||
data: CreateCampaignBudgetDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this.campaignBudgetRepository_ as CampaignBudgetRepository
|
|
||||||
).create(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("campaignBudgetRepository_")
|
|
||||||
async update(
|
|
||||||
data: UpdateCampaignBudgetDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this.campaignBudgetRepository_ as CampaignBudgetRepository
|
|
||||||
).update(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("campaignBudgetRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.campaignBudgetRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,96 +1,27 @@
|
|||||||
import { Context, DAL, FindConfig, PromotionTypes } from "@medusajs/types"
|
import { DAL, PromotionTypes } from "@medusajs/types"
|
||||||
import {
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { Campaign } from "@models"
|
import { Campaign } from "@models"
|
||||||
import { CampaignRepository } from "@repositories"
|
|
||||||
import { CreateCampaignDTO, UpdateCampaignDTO } from "../types"
|
import { CreateCampaignDTO, UpdateCampaignDTO } from "../types"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
campaignRepository: DAL.RepositoryService
|
campaignRepository: DAL.RepositoryService
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class CampaignService<TEntity extends Campaign = Campaign> {
|
export default class CampaignService<
|
||||||
protected readonly campaignRepository_: DAL.RepositoryService
|
TEntity extends Campaign = Campaign
|
||||||
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
constructor({ campaignRepository }: InjectedDependencies) {
|
InjectedDependencies,
|
||||||
this.campaignRepository_ = campaignRepository
|
{
|
||||||
|
create: CreateCampaignDTO
|
||||||
|
update: UpdateCampaignDTO
|
||||||
|
},
|
||||||
|
{
|
||||||
|
list: PromotionTypes.FilterableCampaignProps
|
||||||
|
listAndCount: PromotionTypes.FilterableCampaignProps
|
||||||
}
|
}
|
||||||
|
>(Campaign)<TEntity> {
|
||||||
@InjectManager("campaignRepository_")
|
constructor(...args: any[]) {
|
||||||
async retrieve(
|
// @ts-ignore
|
||||||
campaignId: string,
|
super(...arguments)
|
||||||
config: FindConfig<PromotionTypes.CampaignDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<Campaign, PromotionTypes.CampaignDTO>({
|
|
||||||
id: campaignId,
|
|
||||||
entityName: Campaign.name,
|
|
||||||
repository: this.campaignRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("campaignRepository_")
|
|
||||||
async list(
|
|
||||||
filters: PromotionTypes.FilterableCampaignProps = {},
|
|
||||||
config: FindConfig<PromotionTypes.CampaignDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<Campaign>(filters, config)
|
|
||||||
|
|
||||||
return (await this.campaignRepository_.find(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("campaignRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: PromotionTypes.FilterableCampaignProps = {},
|
|
||||||
config: FindConfig<PromotionTypes.CampaignDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<Campaign>(filters, config)
|
|
||||||
|
|
||||||
return (await this.campaignRepository_.findAndCount(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("campaignRepository_")
|
|
||||||
async create(
|
|
||||||
data: CreateCampaignDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.campaignRepository_ as CampaignRepository).create(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("campaignRepository_")
|
|
||||||
async update(
|
|
||||||
data: UpdateCampaignDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.campaignRepository_ as CampaignRepository).update(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("campaignRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.campaignRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,6 @@
|
|||||||
import { Context, DAL, FindConfig, PromotionTypes } from "@medusajs/types"
|
import { DAL, PromotionTypes } from "@medusajs/types"
|
||||||
import {
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { PromotionRuleValue } from "@models"
|
import { PromotionRuleValue } from "@models"
|
||||||
import { PromotionRuleValueRepository } from "@repositories"
|
|
||||||
import {
|
import {
|
||||||
CreatePromotionRuleValueDTO,
|
CreatePromotionRuleValueDTO,
|
||||||
UpdatePromotionRuleValueDTO,
|
UpdatePromotionRuleValueDTO,
|
||||||
@@ -19,90 +12,19 @@ type InjectedDependencies = {
|
|||||||
|
|
||||||
export default class PromotionRuleValueService<
|
export default class PromotionRuleValueService<
|
||||||
TEntity extends PromotionRuleValue = PromotionRuleValue
|
TEntity extends PromotionRuleValue = PromotionRuleValue
|
||||||
> {
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
protected readonly promotionRuleValueRepository_: DAL.RepositoryService
|
InjectedDependencies,
|
||||||
|
{
|
||||||
constructor({ promotionRuleValueRepository }: InjectedDependencies) {
|
create: CreatePromotionRuleValueDTO
|
||||||
this.promotionRuleValueRepository_ = promotionRuleValueRepository
|
update: UpdatePromotionRuleValueDTO
|
||||||
|
},
|
||||||
|
{
|
||||||
|
list: PromotionTypes.FilterablePromotionRuleValueProps
|
||||||
|
listAndCount: PromotionTypes.FilterablePromotionRuleValueProps
|
||||||
}
|
}
|
||||||
|
>(PromotionRuleValue)<TEntity> {
|
||||||
@InjectManager("promotionRuleValueRepository_")
|
constructor(...args: any[]) {
|
||||||
async retrieve(
|
// @ts-ignore
|
||||||
promotionRuleValueId: string,
|
super(...arguments)
|
||||||
config: FindConfig<PromotionTypes.PromotionRuleValueDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<
|
|
||||||
PromotionRuleValue,
|
|
||||||
PromotionTypes.PromotionRuleValueDTO
|
|
||||||
>({
|
|
||||||
id: promotionRuleValueId,
|
|
||||||
entityName: PromotionRuleValue.name,
|
|
||||||
repository: this.promotionRuleValueRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("promotionRuleValueRepository_")
|
|
||||||
async list(
|
|
||||||
filters: PromotionTypes.FilterablePromotionRuleValueProps = {},
|
|
||||||
config: FindConfig<PromotionTypes.PromotionRuleValueDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<PromotionRuleValue>(
|
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
return (await this.promotionRuleValueRepository_.find(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("promotionRuleValueRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: PromotionTypes.FilterablePromotionRuleValueProps = {},
|
|
||||||
config: FindConfig<PromotionTypes.PromotionRuleValueDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<PromotionRuleValue>(
|
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
return (await this.promotionRuleValueRepository_.findAndCount(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("promotionRuleValueRepository_")
|
|
||||||
async create(
|
|
||||||
data: CreatePromotionRuleValueDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this.promotionRuleValueRepository_ as PromotionRuleValueRepository
|
|
||||||
).create(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("promotionRuleValueRepository_")
|
|
||||||
async update(
|
|
||||||
data: UpdatePromotionRuleValueDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this.promotionRuleValueRepository_ as PromotionRuleValueRepository
|
|
||||||
).update(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("promotionRuleValueRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.promotionRuleValueRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,6 @@
|
|||||||
import { Context, DAL, FindConfig, PromotionTypes } from "@medusajs/types"
|
import { DAL, PromotionTypes } from "@medusajs/types"
|
||||||
import {
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { PromotionRule } from "@models"
|
import { PromotionRule } from "@models"
|
||||||
import { PromotionRuleRepository } from "@repositories"
|
|
||||||
import { CreatePromotionRuleDTO, UpdatePromotionRuleDTO } from "../types"
|
import { CreatePromotionRuleDTO, UpdatePromotionRuleDTO } from "../types"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
@@ -16,90 +9,19 @@ type InjectedDependencies = {
|
|||||||
|
|
||||||
export default class PromotionRuleService<
|
export default class PromotionRuleService<
|
||||||
TEntity extends PromotionRule = PromotionRule
|
TEntity extends PromotionRule = PromotionRule
|
||||||
> {
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
protected readonly promotionRuleRepository_: DAL.RepositoryService
|
InjectedDependencies,
|
||||||
|
{
|
||||||
constructor({ promotionRuleRepository }: InjectedDependencies) {
|
create: CreatePromotionRuleDTO
|
||||||
this.promotionRuleRepository_ = promotionRuleRepository
|
update: UpdatePromotionRuleDTO
|
||||||
|
},
|
||||||
|
{
|
||||||
|
list: PromotionTypes.FilterablePromotionRuleProps
|
||||||
|
listAndCount: PromotionTypes.FilterablePromotionRuleProps
|
||||||
}
|
}
|
||||||
|
>(PromotionRule)<TEntity> {
|
||||||
@InjectManager("promotionRuleRepository_")
|
constructor(...args: any[]) {
|
||||||
async retrieve(
|
// @ts-ignore
|
||||||
promotionRuleId: string,
|
super(...arguments)
|
||||||
config: FindConfig<PromotionTypes.PromotionRuleDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<
|
|
||||||
PromotionRule,
|
|
||||||
PromotionTypes.PromotionRuleDTO
|
|
||||||
>({
|
|
||||||
id: promotionRuleId,
|
|
||||||
entityName: PromotionRule.name,
|
|
||||||
repository: this.promotionRuleRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("promotionRuleRepository_")
|
|
||||||
async list(
|
|
||||||
filters: PromotionTypes.FilterablePromotionRuleProps = {},
|
|
||||||
config: FindConfig<PromotionTypes.PromotionRuleDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<PromotionRule>(
|
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
return (await this.promotionRuleRepository_.find(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("promotionRuleRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: PromotionTypes.FilterablePromotionRuleProps = {},
|
|
||||||
config: FindConfig<PromotionTypes.PromotionRuleDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<PromotionRule>(
|
|
||||||
filters,
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
return (await this.promotionRuleRepository_.findAndCount(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("promotionRuleRepository_")
|
|
||||||
async create(
|
|
||||||
data: CreatePromotionRuleDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this.promotionRuleRepository_ as PromotionRuleRepository
|
|
||||||
).create(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("promotionRuleRepository_")
|
|
||||||
async update(
|
|
||||||
data: UpdatePromotionRuleDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (
|
|
||||||
this.promotionRuleRepository_ as PromotionRuleRepository
|
|
||||||
).update(data, sharedContext)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("promotionRuleRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.promotionRuleRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,96 +1,27 @@
|
|||||||
import { Context, DAL, FindConfig, PromotionTypes } from "@medusajs/types"
|
import { DAL, PromotionTypes } from "@medusajs/types"
|
||||||
import {
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
InjectManager,
|
|
||||||
InjectTransactionManager,
|
|
||||||
MedusaContext,
|
|
||||||
ModulesSdkUtils,
|
|
||||||
retrieveEntity,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { Promotion } from "@models"
|
import { Promotion } from "@models"
|
||||||
import { PromotionRepository } from "@repositories"
|
|
||||||
import { CreatePromotionDTO, UpdatePromotionDTO } from "../types"
|
import { CreatePromotionDTO, UpdatePromotionDTO } from "../types"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
promotionRepository: DAL.RepositoryService
|
promotionRepository: DAL.RepositoryService
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class PromotionService<TEntity extends Promotion = Promotion> {
|
export default class PromotionService<
|
||||||
protected readonly promotionRepository_: DAL.RepositoryService
|
TEntity extends Promotion = Promotion
|
||||||
|
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||||
constructor({ promotionRepository }: InjectedDependencies) {
|
InjectedDependencies,
|
||||||
this.promotionRepository_ = promotionRepository
|
{
|
||||||
|
create: CreatePromotionDTO
|
||||||
|
update: UpdatePromotionDTO
|
||||||
|
},
|
||||||
|
{
|
||||||
|
list: PromotionTypes.FilterablePromotionProps
|
||||||
|
listAndCount: PromotionTypes.FilterablePromotionProps
|
||||||
}
|
}
|
||||||
|
>(Promotion)<TEntity> {
|
||||||
@InjectManager("promotionRepository_")
|
constructor(...args: any[]) {
|
||||||
async retrieve(
|
// @ts-ignore
|
||||||
promotionId: string,
|
super(...arguments)
|
||||||
config: FindConfig<PromotionTypes.PromotionDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity> {
|
|
||||||
return (await retrieveEntity<Promotion, PromotionTypes.PromotionDTO>({
|
|
||||||
id: promotionId,
|
|
||||||
entityName: Promotion.name,
|
|
||||||
repository: this.promotionRepository_,
|
|
||||||
config,
|
|
||||||
sharedContext,
|
|
||||||
})) as TEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("promotionRepository_")
|
|
||||||
async list(
|
|
||||||
filters: PromotionTypes.FilterablePromotionProps = {},
|
|
||||||
config: FindConfig<PromotionTypes.PromotionDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<Promotion>(filters, config)
|
|
||||||
|
|
||||||
return (await this.promotionRepository_.find(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectManager("promotionRepository_")
|
|
||||||
async listAndCount(
|
|
||||||
filters: PromotionTypes.FilterablePromotionProps = {},
|
|
||||||
config: FindConfig<PromotionTypes.PromotionDTO> = {},
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<[TEntity[], number]> {
|
|
||||||
const queryOptions = ModulesSdkUtils.buildQuery<Promotion>(filters, config)
|
|
||||||
|
|
||||||
return (await this.promotionRepository_.findAndCount(
|
|
||||||
queryOptions,
|
|
||||||
sharedContext
|
|
||||||
)) as [TEntity[], number]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("promotionRepository_")
|
|
||||||
async create(
|
|
||||||
data: CreatePromotionDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.promotionRepository_ as PromotionRepository).create(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("promotionRepository_")
|
|
||||||
async update(
|
|
||||||
data: UpdatePromotionDTO[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<TEntity[]> {
|
|
||||||
return (await (this.promotionRepository_ as PromotionRepository).update(
|
|
||||||
data,
|
|
||||||
sharedContext
|
|
||||||
)) as TEntity[]
|
|
||||||
}
|
|
||||||
|
|
||||||
@InjectTransactionManager("promotionRepository_")
|
|
||||||
async delete(
|
|
||||||
ids: string[],
|
|
||||||
@MedusaContext() sharedContext: Context = {}
|
|
||||||
): Promise<void> {
|
|
||||||
await this.promotionRepository_.delete(ids, sharedContext)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,6 +58,8 @@ export interface RepositoryService<T = any> extends BaseRepositoryService<T> {
|
|||||||
ids: string[],
|
ids: string[],
|
||||||
context?: Context
|
context?: Context
|
||||||
): Promise<[T[], Record<string, unknown[]>]>
|
): Promise<[T[], Record<string, unknown[]>]>
|
||||||
|
|
||||||
|
upsert?(data: unknown[], context?: Context): Promise<T[]>
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TreeRepositoryService<T = any>
|
export interface TreeRepositoryService<T = any>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
Context,
|
Context,
|
||||||
DAL,
|
DAL,
|
||||||
FilterQuery as InternalFilerQuery,
|
FilterQuery as InternalFilterQuery,
|
||||||
RepositoryTransformOptions,
|
RepositoryTransformOptions,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
@@ -16,9 +16,9 @@ import {
|
|||||||
EntityName,
|
EntityName,
|
||||||
FilterQuery as MikroFilterQuery,
|
FilterQuery as MikroFilterQuery,
|
||||||
} from "@mikro-orm/core/typings"
|
} from "@mikro-orm/core/typings"
|
||||||
import { isString, MedusaError } from "../../common"
|
import { MedusaError, isString } from "../../common"
|
||||||
import { MedusaContext } from "../../decorators"
|
import { MedusaContext } from "../../decorators"
|
||||||
import { buildQuery, InjectTransactionManager } from "../../modules-sdk"
|
import { InjectTransactionManager, buildQuery } from "../../modules-sdk"
|
||||||
import {
|
import {
|
||||||
getSoftDeletedCascadedEntitiesIdsMappedBy,
|
getSoftDeletedCascadedEntitiesIdsMappedBy,
|
||||||
transactionWrapper,
|
transactionWrapper,
|
||||||
@@ -106,7 +106,7 @@ export class MikroOrmBaseRepository<
|
|||||||
|
|
||||||
@InjectTransactionManager()
|
@InjectTransactionManager()
|
||||||
async softDelete(
|
async softDelete(
|
||||||
idsOrFilter: string[] | InternalFilerQuery,
|
idsOrFilter: string[] | InternalFilterQuery,
|
||||||
@MedusaContext()
|
@MedusaContext()
|
||||||
{ transactionManager: manager }: Context = {}
|
{ transactionManager: manager }: Context = {}
|
||||||
): Promise<[T[], Record<string, unknown[]>]> {
|
): Promise<[T[], Record<string, unknown[]>]> {
|
||||||
@@ -138,7 +138,7 @@ export class MikroOrmBaseRepository<
|
|||||||
|
|
||||||
@InjectTransactionManager()
|
@InjectTransactionManager()
|
||||||
async restore(
|
async restore(
|
||||||
idsOrFilter: string[] | InternalFilerQuery,
|
idsOrFilter: string[] | InternalFilterQuery,
|
||||||
@MedusaContext()
|
@MedusaContext()
|
||||||
{ transactionManager: manager }: Context = {}
|
{ transactionManager: manager }: Context = {}
|
||||||
): Promise<[T[], Record<string, unknown[]>]> {
|
): Promise<[T[], Record<string, unknown[]>]> {
|
||||||
@@ -224,7 +224,7 @@ type DtoBasedMutationMethods = "create" | "update"
|
|||||||
|
|
||||||
export function mikroOrmBaseRepositoryFactory<
|
export function mikroOrmBaseRepositoryFactory<
|
||||||
T extends object = object,
|
T extends object = object,
|
||||||
TDTos extends { [K in DtoBasedMutationMethods]?: any } = {
|
TDTOs extends { [K in DtoBasedMutationMethods]?: any } = {
|
||||||
[K in DtoBasedMutationMethods]?: any
|
[K in DtoBasedMutationMethods]?: any
|
||||||
}
|
}
|
||||||
>(entity: EntityClass<T> | EntitySchema<T>) {
|
>(entity: EntityClass<T> | EntitySchema<T>) {
|
||||||
@@ -242,11 +242,11 @@ export function mikroOrmBaseRepositoryFactory<
|
|||||||
static retrievePrimaryKeys(entity: EntityClass<T> | EntitySchema<T>) {
|
static retrievePrimaryKeys(entity: EntityClass<T> | EntitySchema<T>) {
|
||||||
return (
|
return (
|
||||||
(entity as EntitySchema<T>).meta?.primaryKeys ??
|
(entity as EntitySchema<T>).meta?.primaryKeys ??
|
||||||
(entity as EntityClass<T>).prototype.__meta.primaryKeys
|
(entity as EntityClass<T>).prototype.__meta.primaryKeys ?? ["id"]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(data: TDTos["create"][], context?: Context): Promise<T[]> {
|
async create(data: TDTOs["create"][], context?: Context): Promise<T[]> {
|
||||||
const manager = this.getActiveManager<EntityManager>(context)
|
const manager = this.getActiveManager<EntityManager>(context)
|
||||||
|
|
||||||
const entities = data.map((data_) => {
|
const entities = data.map((data_) => {
|
||||||
@@ -261,7 +261,8 @@ export function mikroOrmBaseRepositoryFactory<
|
|||||||
return entities
|
return entities
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(data: TDTos["update"][], context?: Context): Promise<T[]> {
|
async update(data: TDTOs["update"][], context?: Context): Promise<T[]> {
|
||||||
|
// TODO: Move this logic to the service packages/utils/src/modules-sdk/abstract-service-factory.ts
|
||||||
const manager = this.getActiveManager<EntityManager>(context)
|
const manager = this.getActiveManager<EntityManager>(context)
|
||||||
|
|
||||||
const primaryKeys =
|
const primaryKeys =
|
||||||
|
|||||||
@@ -0,0 +1,245 @@
|
|||||||
|
import {
|
||||||
|
Context,
|
||||||
|
FilterQuery as InternalFilterQuery,
|
||||||
|
FindConfig,
|
||||||
|
} from "@medusajs/types"
|
||||||
|
import { EntitySchema } from "@mikro-orm/core"
|
||||||
|
import { EntityClass } from "@mikro-orm/core/typings"
|
||||||
|
import {
|
||||||
|
doNotForceTransaction,
|
||||||
|
isDefined,
|
||||||
|
isString,
|
||||||
|
lowerCaseFirst,
|
||||||
|
MedusaError,
|
||||||
|
shouldForceTransaction,
|
||||||
|
upperCaseFirst,
|
||||||
|
} from "../common"
|
||||||
|
import { MedusaContext } from "../decorators"
|
||||||
|
import { buildQuery } from "./build-query"
|
||||||
|
import { InjectManager, InjectTransactionManager } from "./decorators"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility factory and interfaces for internal module services
|
||||||
|
*/
|
||||||
|
|
||||||
|
type FilterableMethods = "list" | "listAndCount"
|
||||||
|
type Methods = "create" | "update"
|
||||||
|
|
||||||
|
export interface AbstractService<
|
||||||
|
TEntity extends {},
|
||||||
|
TContainer extends object = object,
|
||||||
|
TDTOs extends { [K in Methods]?: any } = { [K in Methods]?: any },
|
||||||
|
TFilters extends { [K in FilterableMethods]?: any } = {
|
||||||
|
[K in FilterableMethods]?: any
|
||||||
|
}
|
||||||
|
> {
|
||||||
|
get __container__(): TContainer
|
||||||
|
|
||||||
|
retrieve<TEntityMethod = TEntity>(
|
||||||
|
id: string,
|
||||||
|
config?: FindConfig<TEntityMethod>,
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<TEntity>
|
||||||
|
list<TEntityMethod = TEntity>(
|
||||||
|
filters?: TFilters["list"],
|
||||||
|
config?: FindConfig<TEntityMethod>,
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<TEntity[]>
|
||||||
|
listAndCount<TEntityMethod = TEntity>(
|
||||||
|
filters?: TFilters["listAndCount"],
|
||||||
|
config?: FindConfig<TEntityMethod>,
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<[TEntity[], number]>
|
||||||
|
create(data: TDTOs["create"][], sharedContext?: Context): Promise<TEntity[]>
|
||||||
|
update(data: TDTOs["update"][], sharedContext?: Context): Promise<TEntity[]>
|
||||||
|
delete(
|
||||||
|
primaryKeyValues: string[] | object[],
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<void>
|
||||||
|
softDelete(
|
||||||
|
idsOrFilter: string[] | InternalFilterQuery,
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<[TEntity[], Record<string, unknown[]>]>
|
||||||
|
restore(
|
||||||
|
idsOrFilter: string[] | InternalFilterQuery,
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<[TEntity[], Record<string, unknown[]>]>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function abstractServiceFactory<
|
||||||
|
TContainer extends object = object,
|
||||||
|
TDTOs extends { [K in Methods]?: any } = { [K in Methods]?: any },
|
||||||
|
TFilters extends { [K in FilterableMethods]?: any } = {
|
||||||
|
[K in FilterableMethods]?: any
|
||||||
|
}
|
||||||
|
>(
|
||||||
|
model: new (...args: any[]) => any
|
||||||
|
): {
|
||||||
|
new <TEntity extends {}>(container: TContainer): AbstractService<
|
||||||
|
TEntity,
|
||||||
|
TContainer,
|
||||||
|
TDTOs,
|
||||||
|
TFilters
|
||||||
|
>
|
||||||
|
} {
|
||||||
|
const injectedRepositoryName = `${lowerCaseFirst(model.name)}Repository`
|
||||||
|
const propertyRepositoryName = `__${injectedRepositoryName}__`
|
||||||
|
|
||||||
|
class AbstractService_<TEntity extends {}>
|
||||||
|
implements AbstractService<TEntity, TContainer, TDTOs, TFilters>
|
||||||
|
{
|
||||||
|
readonly __container__: TContainer;
|
||||||
|
[key: string]: any
|
||||||
|
|
||||||
|
constructor(container: TContainer) {
|
||||||
|
this.__container__ = container
|
||||||
|
this[propertyRepositoryName] = container[injectedRepositoryName]
|
||||||
|
}
|
||||||
|
|
||||||
|
static retrievePrimaryKeys(entity: EntityClass<any> | EntitySchema<any>) {
|
||||||
|
return (
|
||||||
|
(entity as EntitySchema<any>).meta?.primaryKeys ??
|
||||||
|
(entity as EntityClass<any>).prototype.__meta?.primaryKeys ?? ["id"]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@InjectManager(propertyRepositoryName)
|
||||||
|
async retrieve<TEntityMethod = TEntity>(
|
||||||
|
primaryKeyValues: string | string[] | object[],
|
||||||
|
config: FindConfig<TEntityMethod> = {},
|
||||||
|
@MedusaContext() sharedContext: Context = {}
|
||||||
|
): Promise<TEntity> {
|
||||||
|
const primaryKeys = AbstractService_.retrievePrimaryKeys(model)
|
||||||
|
|
||||||
|
if (!isDefined(primaryKeyValues)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`${
|
||||||
|
primaryKeys.length === 1
|
||||||
|
? `"${
|
||||||
|
lowerCaseFirst(model.name) + upperCaseFirst(primaryKeys[0])
|
||||||
|
}"`
|
||||||
|
: `${lowerCaseFirst(model.name)} ${primaryKeys.join(", ")}`
|
||||||
|
} must be defined`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let primaryKeysCriteria = {}
|
||||||
|
if (primaryKeys.length === 1) {
|
||||||
|
primaryKeysCriteria[primaryKeys[0]] = primaryKeyValues
|
||||||
|
} else {
|
||||||
|
primaryKeysCriteria = (primaryKeyValues as string[] | object[]).map(
|
||||||
|
(primaryKeyValue) => ({
|
||||||
|
$and: primaryKeys.map((key) => ({ [key]: primaryKeyValue[key] })),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const queryOptions = buildQuery<TEntity>(primaryKeysCriteria, config)
|
||||||
|
|
||||||
|
const entities = await this[propertyRepositoryName].find(
|
||||||
|
queryOptions,
|
||||||
|
sharedContext
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!entities?.length) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
`${model.name} with ${primaryKeys.join(", ")}: ${
|
||||||
|
Array.isArray(primaryKeyValues)
|
||||||
|
? primaryKeyValues.map((v) =>
|
||||||
|
[isString(v) ? v : Object.values(v)].join(", ")
|
||||||
|
)
|
||||||
|
: primaryKeyValues
|
||||||
|
} was not found`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return entities[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
@InjectManager(propertyRepositoryName)
|
||||||
|
async list<TEntityMethod = TEntity>(
|
||||||
|
filters: TFilters["list"] = {},
|
||||||
|
config: FindConfig<TEntityMethod> = {},
|
||||||
|
@MedusaContext() sharedContext: Context = {}
|
||||||
|
): Promise<TEntity[]> {
|
||||||
|
const queryOptions = buildQuery<TEntity>(filters, config)
|
||||||
|
|
||||||
|
return (await this[propertyRepositoryName].find(
|
||||||
|
queryOptions,
|
||||||
|
sharedContext
|
||||||
|
)) as TEntity[]
|
||||||
|
}
|
||||||
|
|
||||||
|
@InjectManager(propertyRepositoryName)
|
||||||
|
async listAndCount<TEntityMethod = TEntity>(
|
||||||
|
filters: TFilters["listAndCount"] = {},
|
||||||
|
config: FindConfig<TEntityMethod> = {},
|
||||||
|
@MedusaContext() sharedContext: Context = {}
|
||||||
|
): Promise<[TEntity[], number]> {
|
||||||
|
const queryOptions = buildQuery<TEntity>(filters, config)
|
||||||
|
|
||||||
|
return (await this[propertyRepositoryName].findAndCount(
|
||||||
|
queryOptions,
|
||||||
|
sharedContext
|
||||||
|
)) as [TEntity[], number]
|
||||||
|
}
|
||||||
|
|
||||||
|
@InjectTransactionManager(shouldForceTransaction, propertyRepositoryName)
|
||||||
|
async create(
|
||||||
|
data: TDTOs["create"][],
|
||||||
|
@MedusaContext() sharedContext: Context = {}
|
||||||
|
): Promise<TEntity[]> {
|
||||||
|
return (await this[propertyRepositoryName].create(
|
||||||
|
data,
|
||||||
|
sharedContext
|
||||||
|
)) as TEntity[]
|
||||||
|
}
|
||||||
|
|
||||||
|
@InjectTransactionManager(shouldForceTransaction, propertyRepositoryName)
|
||||||
|
async update(
|
||||||
|
data: TDTOs["update"][],
|
||||||
|
@MedusaContext() sharedContext: Context = {}
|
||||||
|
): Promise<TEntity[]> {
|
||||||
|
return (await this[propertyRepositoryName].update(
|
||||||
|
data,
|
||||||
|
sharedContext
|
||||||
|
)) as TEntity[]
|
||||||
|
}
|
||||||
|
|
||||||
|
@InjectTransactionManager(doNotForceTransaction, propertyRepositoryName)
|
||||||
|
async delete(
|
||||||
|
primaryKeyValues: string[] | object[],
|
||||||
|
@MedusaContext() sharedContext: Context = {}
|
||||||
|
): Promise<void> {
|
||||||
|
await this[propertyRepositoryName].delete(primaryKeyValues, sharedContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
@InjectTransactionManager(propertyRepositoryName)
|
||||||
|
async softDelete(
|
||||||
|
idsOrFilter: string[] | InternalFilterQuery,
|
||||||
|
@MedusaContext() sharedContext: Context = {}
|
||||||
|
): Promise<[TEntity[], Record<string, unknown[]>]> {
|
||||||
|
return await this[propertyRepositoryName].softDelete(
|
||||||
|
idsOrFilter,
|
||||||
|
sharedContext
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@InjectTransactionManager(propertyRepositoryName)
|
||||||
|
async restore(
|
||||||
|
idsOrFilter: string[] | InternalFilterQuery,
|
||||||
|
@MedusaContext() sharedContext: Context = {}
|
||||||
|
): Promise<[TEntity[], Record<string, unknown[]>]> {
|
||||||
|
return await this[propertyRepositoryName].restore(
|
||||||
|
idsOrFilter,
|
||||||
|
sharedContext
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return AbstractService_ as unknown as new <TEntity extends {}>(
|
||||||
|
container: TContainer
|
||||||
|
) => AbstractService<TEntity, TContainer, TDTOs, TFilters>
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
export * from "./load-module-database-config"
|
export * from "./load-module-database-config"
|
||||||
export * from "./decorators"
|
export * from "./decorators"
|
||||||
export * from "./build-query"
|
export * from "./build-query"
|
||||||
export * from "./retrieve-entity"
|
|
||||||
export * from "./loaders/mikro-orm-connection-loader"
|
export * from "./loaders/mikro-orm-connection-loader"
|
||||||
export * from "./create-pg-connection"
|
export * from "./create-pg-connection"
|
||||||
export * from "./migration-scripts"
|
export * from "./migration-scripts"
|
||||||
|
export * from "./abstract-service-factory"
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
|
||||||
import {
|
|
||||||
MedusaError,
|
|
||||||
isDefined,
|
|
||||||
lowerCaseFirst,
|
|
||||||
upperCaseFirst,
|
|
||||||
} from "../common"
|
|
||||||
import { buildQuery } from "./build-query"
|
|
||||||
|
|
||||||
type RetrieveEntityParams<TDTO> = {
|
|
||||||
id: string
|
|
||||||
identifierColumn?: string
|
|
||||||
entityName: string
|
|
||||||
repository: DAL.TreeRepositoryService | DAL.RepositoryService
|
|
||||||
config: FindConfig<TDTO>
|
|
||||||
sharedContext?: Context
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function retrieveEntity<TEntity, TDTO>({
|
|
||||||
id,
|
|
||||||
identifierColumn = "id",
|
|
||||||
entityName,
|
|
||||||
repository,
|
|
||||||
config = {},
|
|
||||||
sharedContext,
|
|
||||||
}: RetrieveEntityParams<TDTO>): Promise<TEntity> {
|
|
||||||
if (!isDefined(id)) {
|
|
||||||
throw new MedusaError(
|
|
||||||
MedusaError.Types.NOT_FOUND,
|
|
||||||
`"${lowerCaseFirst(entityName)}${upperCaseFirst(
|
|
||||||
identifierColumn
|
|
||||||
)}" must be defined`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const queryOptions = buildQuery<TEntity>(
|
|
||||||
{
|
|
||||||
[identifierColumn]: id,
|
|
||||||
},
|
|
||||||
config
|
|
||||||
)
|
|
||||||
|
|
||||||
const entities = await repository.find(queryOptions, sharedContext)
|
|
||||||
|
|
||||||
if (!entities?.length) {
|
|
||||||
throw new MedusaError(
|
|
||||||
MedusaError.Types.NOT_FOUND,
|
|
||||||
`${entityName} with ${identifierColumn}: ${id} was not found`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return entities[0]
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user