chore: Internal medusa service proper typings with DML (#7792)
This commit is contained in:
@@ -30,3 +30,4 @@ export * as TransactionBaseTypes from "./transaction-base"
|
|||||||
export * as UserTypes from "./user"
|
export * as UserTypes from "./user"
|
||||||
export * as WorkflowTypes from "./workflow"
|
export * as WorkflowTypes from "./workflow"
|
||||||
export * as WorkflowsSdkTypes from "./workflows-sdk"
|
export * as WorkflowsSdkTypes from "./workflows-sdk"
|
||||||
|
export * as DmlTypes from "./dml"
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
import { DmlEntity } from "./entity"
|
export const IsDmlEntity = Symbol.for("isDmlEntity")
|
||||||
|
|
||||||
|
export interface IDmlEntity<
|
||||||
|
Schema extends Record<string, PropertyType<any> | RelationshipType<any>>
|
||||||
|
> {
|
||||||
|
[IsDmlEntity]: true
|
||||||
|
schema: Schema
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The supported data types
|
* The supported data types
|
||||||
@@ -92,7 +99,7 @@ export interface EntityConstructor<Props> extends Function {
|
|||||||
/**
|
/**
|
||||||
* Helper to infer the schema type of a DmlEntity
|
* Helper to infer the schema type of a DmlEntity
|
||||||
*/
|
*/
|
||||||
export type Infer<T> = T extends DmlEntity<infer Schema>
|
export type Infer<T> = T extends IDmlEntity<infer Schema>
|
||||||
? EntityConstructor<{
|
? EntityConstructor<{
|
||||||
[K in keyof Schema]: Schema[K]["$dataType"] extends () => infer R
|
[K in keyof Schema]: Schema[K]["$dataType"] extends () => infer R
|
||||||
? Infer<R>
|
? Infer<R>
|
||||||
@@ -123,3 +130,15 @@ export type ExtractEntityRelations<
|
|||||||
export type EntityCascades<Relationships> = {
|
export type EntityCascades<Relationships> = {
|
||||||
delete?: Relationships
|
delete?: Relationships
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to infer the instance type of a DmlEntity once converted as an Entity
|
||||||
|
*/
|
||||||
|
export type InferTypeOf<T extends IDmlEntity<any>> = InstanceType<Infer<T>>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used in the module sdk internal service to infer propert entity typings from DML
|
||||||
|
*/
|
||||||
|
export type ExtractEntityType<T extends any> = T extends IDmlEntity<any>
|
||||||
|
? InferTypeOf<T>
|
||||||
|
: T
|
||||||
@@ -41,3 +41,4 @@ export * from "./user"
|
|||||||
export * from "./workflow"
|
export * from "./workflow"
|
||||||
export * from "./workflows"
|
export * from "./workflows"
|
||||||
export * from "./workflows-sdk"
|
export * from "./workflows-sdk"
|
||||||
|
export * from "./dml"
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
PerformedActions,
|
PerformedActions,
|
||||||
UpsertWithReplaceConfig,
|
UpsertWithReplaceConfig,
|
||||||
} from "../dal"
|
} from "../dal"
|
||||||
|
import { ExtractEntityType } from "../dml"
|
||||||
|
|
||||||
export interface IMedusaInternalService<
|
export interface IMedusaInternalService<
|
||||||
TEntity extends {},
|
TEntity extends {},
|
||||||
@@ -18,44 +19,56 @@ export interface IMedusaInternalService<
|
|||||||
idOrObject: string,
|
idOrObject: string,
|
||||||
config?: FindConfig<any>,
|
config?: FindConfig<any>,
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<TEntity>
|
): Promise<ExtractEntityType<TEntity>>
|
||||||
retrieve(
|
retrieve(
|
||||||
idOrObject: object,
|
idOrObject: object,
|
||||||
config?: FindConfig<any>,
|
config?: FindConfig<any>,
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<TEntity>
|
): Promise<ExtractEntityType<TEntity>>
|
||||||
|
|
||||||
list(
|
list(
|
||||||
filters?: FilterQuery<any> | BaseFilterable<FilterQuery<any>>,
|
filters?: FilterQuery<any> | BaseFilterable<FilterQuery<any>>,
|
||||||
config?: FindConfig<any>,
|
config?: FindConfig<any>,
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<TEntity[]>
|
): Promise<ExtractEntityType<TEntity>[]>
|
||||||
|
|
||||||
listAndCount(
|
listAndCount(
|
||||||
filters?: FilterQuery<any> | BaseFilterable<FilterQuery<any>>,
|
filters?: FilterQuery<any> | BaseFilterable<FilterQuery<any>>,
|
||||||
config?: FindConfig<any>,
|
config?: FindConfig<any>,
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<[TEntity[], number]>
|
): Promise<[ExtractEntityType<TEntity>[], number]>
|
||||||
|
|
||||||
create(data: any[], sharedContext?: Context): Promise<TEntity[]>
|
create(
|
||||||
create(data: any, sharedContext?: Context): Promise<TEntity>
|
data: any[],
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<ExtractEntityType<TEntity>[]>
|
||||||
|
create(
|
||||||
|
data: any,
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<ExtractEntityType<TEntity>>
|
||||||
|
|
||||||
update(data: any[], sharedContext?: Context): Promise<TEntity[]>
|
update(
|
||||||
update(data: any, sharedContext?: Context): Promise<TEntity>
|
data: any[],
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<ExtractEntityType<TEntity>[]>
|
||||||
|
update(
|
||||||
|
data: any,
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<ExtractEntityType<TEntity>>
|
||||||
update(
|
update(
|
||||||
selectorAndData: {
|
selectorAndData: {
|
||||||
selector: FilterQuery<any> | BaseFilterable<FilterQuery<any>>
|
selector: FilterQuery<any> | BaseFilterable<FilterQuery<any>>
|
||||||
data: any
|
data: any
|
||||||
},
|
},
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<TEntity[]>
|
): Promise<ExtractEntityType<TEntity>[]>
|
||||||
update(
|
update(
|
||||||
selectorAndData: {
|
selectorAndData: {
|
||||||
selector: FilterQuery<any> | BaseFilterable<FilterQuery<any>>
|
selector: FilterQuery<any> | BaseFilterable<FilterQuery<any>>
|
||||||
data: any
|
data: any
|
||||||
}[],
|
}[],
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<TEntity[]>
|
): Promise<ExtractEntityType<TEntity>[]>
|
||||||
|
|
||||||
delete(idOrSelector: string, sharedContext?: Context): Promise<void>
|
delete(idOrSelector: string, sharedContext?: Context): Promise<void>
|
||||||
delete(idOrSelector: string[], sharedContext?: Context): Promise<void>
|
delete(idOrSelector: string[], sharedContext?: Context): Promise<void>
|
||||||
@@ -75,19 +88,28 @@ export interface IMedusaInternalService<
|
|||||||
| InternalFilterQuery
|
| InternalFilterQuery
|
||||||
| InternalFilterQuery[],
|
| InternalFilterQuery[],
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<[TEntity[], Record<string, unknown[]>]>
|
): Promise<[ExtractEntityType<TEntity>[], Record<string, unknown[]>]>
|
||||||
|
|
||||||
restore(
|
restore(
|
||||||
idsOrFilter: string[] | InternalFilterQuery,
|
idsOrFilter: string[] | InternalFilterQuery,
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<[TEntity[], Record<string, unknown[]>]>
|
): Promise<[ExtractEntityType<TEntity>[], Record<string, unknown[]>]>
|
||||||
|
|
||||||
upsert(data: any[], sharedContext?: Context): Promise<TEntity[]>
|
upsert(
|
||||||
upsert(data: any, sharedContext?: Context): Promise<TEntity>
|
data: any[],
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<ExtractEntityType<TEntity>[]>
|
||||||
|
upsert(
|
||||||
|
data: any,
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<ExtractEntityType<TEntity>>
|
||||||
|
|
||||||
upsertWithReplace(
|
upsertWithReplace(
|
||||||
data: any[],
|
data: any[],
|
||||||
config?: UpsertWithReplaceConfig<TEntity>,
|
config?: UpsertWithReplaceConfig<ExtractEntityType<TEntity>>,
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<{ entities: TEntity[]; performedActions: PerformedActions }>
|
): Promise<{
|
||||||
|
entities: ExtractEntityType<TEntity>[]
|
||||||
|
performedActions: PerformedActions
|
||||||
|
}>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@
|
|||||||
"author": "Medusa",
|
"author": "Medusa",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@medusajs/types": "^1.11.16",
|
|
||||||
"@types/express": "^4.17.17",
|
"@types/express": "^4.17.17",
|
||||||
"cross-env": "^5.2.1",
|
"cross-env": "^5.2.1",
|
||||||
"expect-type": "^0.19.0",
|
"expect-type": "^0.19.0",
|
||||||
@@ -32,6 +31,7 @@
|
|||||||
"typescript": "^5.1.6"
|
"typescript": "^5.1.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@medusajs/types": "^1.11.16",
|
||||||
"@mikro-orm/core": "5.9.7",
|
"@mikro-orm/core": "5.9.7",
|
||||||
"@mikro-orm/migrations": "5.9.7",
|
"@mikro-orm/migrations": "5.9.7",
|
||||||
"@mikro-orm/postgresql": "5.9.7",
|
"@mikro-orm/postgresql": "5.9.7",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { expectTypeOf } from "expect-type"
|
import { expectTypeOf } from "expect-type"
|
||||||
import { BaseProperty } from "../properties/base"
|
import { BaseProperty } from "../properties/base"
|
||||||
import { PropertyMetadata } from "../types"
|
import { PropertyMetadata } from "@medusajs/types"
|
||||||
|
|
||||||
describe("Base property", () => {
|
describe("Base property", () => {
|
||||||
test("create a property type from base property", () => {
|
test("create a property type from base property", () => {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import type {
|
|||||||
PropertyType,
|
PropertyType,
|
||||||
RelationshipOptions,
|
RelationshipOptions,
|
||||||
RelationshipType,
|
RelationshipType,
|
||||||
} from "./types"
|
} from "@medusajs/types"
|
||||||
import { NullableModifier } from "./properties/nullable"
|
import { NullableModifier } from "./properties/nullable"
|
||||||
import { IdProperty } from "./properties/id"
|
import { IdProperty } from "./properties/id"
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ import { BelongsTo } from "./relations/belongs-to"
|
|||||||
import {
|
import {
|
||||||
EntityCascades,
|
EntityCascades,
|
||||||
ExtractEntityRelations,
|
ExtractEntityRelations,
|
||||||
|
IDmlEntity,
|
||||||
|
IsDmlEntity,
|
||||||
PropertyType,
|
PropertyType,
|
||||||
RelationshipType,
|
RelationshipType,
|
||||||
} from "./types"
|
} from "@medusajs/types"
|
||||||
|
|
||||||
const IsDmlEntity = Symbol("isDmlEntity")
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dml entity is a representation of a DML model with a unique
|
* Dml entity is a representation of a DML model with a unique
|
||||||
@@ -14,8 +14,9 @@ const IsDmlEntity = Symbol("isDmlEntity")
|
|||||||
*/
|
*/
|
||||||
export class DmlEntity<
|
export class DmlEntity<
|
||||||
Schema extends Record<string, PropertyType<any> | RelationshipType<any>>
|
Schema extends Record<string, PropertyType<any> | RelationshipType<any>>
|
||||||
> {
|
> implements IDmlEntity<Schema>
|
||||||
[IsDmlEntity] = true
|
{
|
||||||
|
[IsDmlEntity]: true = true
|
||||||
|
|
||||||
#cascades: EntityCascades<string[]> = {}
|
#cascades: EntityCascades<string[]> = {}
|
||||||
constructor(public name: string, public schema: Schema) {}
|
constructor(public name: string, public schema: Schema) {}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import type {
|
|||||||
PropertyType,
|
PropertyType,
|
||||||
RelationshipMetadata,
|
RelationshipMetadata,
|
||||||
RelationshipType,
|
RelationshipType,
|
||||||
} from "../types"
|
} from "@medusajs/types"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DML entity data types to PostgreSQL data types via
|
* DML entity data types to PostgreSQL data types via
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { PropertyMetadata, PropertyType } from "../types"
|
import { PropertyMetadata, PropertyType } from "@medusajs/types"
|
||||||
import { NullableModifier } from "./nullable"
|
import { NullableModifier } from "./nullable"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { PropertyType } from "../types"
|
import { PropertyType } from "@medusajs/types"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nullable modifier marks a schema node as nullable
|
* Nullable modifier marks a schema node as nullable
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
RelationshipOptions,
|
RelationshipOptions,
|
||||||
RelationshipType,
|
RelationshipType,
|
||||||
RelationshipTypes,
|
RelationshipTypes,
|
||||||
} from "../types"
|
} from "@medusajs/types"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The BaseRelationship encapsulates the repetitive parts of defining
|
* The BaseRelationship encapsulates the repetitive parts of defining
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { BaseRelationship } from "./base"
|
import { BaseRelationship } from "./base"
|
||||||
import { RelationshipTypes } from "../types"
|
|
||||||
import { NullableModifier } from "./nullable"
|
import { NullableModifier } from "./nullable"
|
||||||
|
|
||||||
export class BelongsTo<T> extends BaseRelationship<T> {
|
export class BelongsTo<T> extends BaseRelationship<T> {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { BaseRelationship } from "./base"
|
import { BaseRelationship } from "./base"
|
||||||
import { RelationshipTypes } from "../types"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HasMany relationship defines a relationship between two entities
|
* HasMany relationship defines a relationship between two entities
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { BaseRelationship } from "./base"
|
import { BaseRelationship } from "./base"
|
||||||
import { NullableModifier } from "./nullable"
|
import { NullableModifier } from "./nullable"
|
||||||
import { RelationshipTypes } from "../types"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HasOne relationship defines a relationship between two entities
|
* HasOne relationship defines a relationship between two entities
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { BaseRelationship } from "./base"
|
import { BaseRelationship } from "./base"
|
||||||
import { RelationshipTypes } from "../types"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ManyToMany relationship defines a relationship between two entities
|
* ManyToMany relationship defines a relationship between two entities
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { RelationshipType, PropertyType } from "../types"
|
import { RelationshipType } from "@medusajs/types"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nullable modifier marks a schema node as nullable
|
* Nullable modifier marks a schema node as nullable
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
BaseFilterable,
|
BaseFilterable,
|
||||||
Context,
|
Context,
|
||||||
|
ExtractEntityType,
|
||||||
FilterQuery,
|
FilterQuery,
|
||||||
FilterQuery as InternalFilterQuery,
|
FilterQuery as InternalFilterQuery,
|
||||||
FindConfig,
|
FindConfig,
|
||||||
@@ -100,9 +101,9 @@ export function MedusaInternalService<TContainer extends object = object>(
|
|||||||
@InjectManager(propertyRepositoryName)
|
@InjectManager(propertyRepositoryName)
|
||||||
async retrieve(
|
async retrieve(
|
||||||
idOrObject: string | object,
|
idOrObject: string | object,
|
||||||
config: FindConfig<TEntity> = {},
|
config: FindConfig<ExtractEntityType<TEntity>> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity> {
|
): Promise<ExtractEntityType<TEntity>> {
|
||||||
const primaryKeys = AbstractService_.retrievePrimaryKeys(model)
|
const primaryKeys = AbstractService_.retrievePrimaryKeys(model)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -162,7 +163,7 @@ export function MedusaInternalService<TContainer extends object = object>(
|
|||||||
filters: FilterQuery<any> | BaseFilterable<FilterQuery<any>> = {},
|
filters: FilterQuery<any> | BaseFilterable<FilterQuery<any>> = {},
|
||||||
config: FindConfig<any> = {},
|
config: FindConfig<any> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity[]> {
|
): Promise<ExtractEntityType<TEntity>[]> {
|
||||||
AbstractService_.applyDefaultOrdering(config)
|
AbstractService_.applyDefaultOrdering(config)
|
||||||
AbstractService_.applyFreeTextSearchFilter(filters, config)
|
AbstractService_.applyFreeTextSearchFilter(filters, config)
|
||||||
|
|
||||||
@@ -179,7 +180,7 @@ export function MedusaInternalService<TContainer extends object = object>(
|
|||||||
filters: FilterQuery<any> | BaseFilterable<FilterQuery<any>> = {},
|
filters: FilterQuery<any> | BaseFilterable<FilterQuery<any>> = {},
|
||||||
config: FindConfig<any> = {},
|
config: FindConfig<any> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<[TEntity[], number]> {
|
): Promise<[ExtractEntityType<TEntity>[], number]> {
|
||||||
AbstractService_.applyDefaultOrdering(config)
|
AbstractService_.applyDefaultOrdering(config)
|
||||||
AbstractService_.applyFreeTextSearchFilter(filters, config)
|
AbstractService_.applyFreeTextSearchFilter(filters, config)
|
||||||
|
|
||||||
@@ -191,16 +192,24 @@ export function MedusaInternalService<TContainer extends object = object>(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
create(data: any, sharedContext?: Context): Promise<TEntity>
|
create(
|
||||||
create(data: any[], sharedContext?: Context): Promise<TEntity[]>
|
data: any,
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<ExtractEntityType<TEntity>>
|
||||||
|
create(
|
||||||
|
data: any[],
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<ExtractEntityType<TEntity>[]>
|
||||||
|
|
||||||
@InjectTransactionManager(shouldForceTransaction, propertyRepositoryName)
|
@InjectTransactionManager(shouldForceTransaction, propertyRepositoryName)
|
||||||
async create(
|
async create(
|
||||||
data: any | any[],
|
data: any | any[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity | TEntity[]> {
|
): Promise<ExtractEntityType<TEntity> | ExtractEntityType<TEntity>[]> {
|
||||||
if (!isDefined(data) || (Array.isArray(data) && data.length === 0)) {
|
if (!isDefined(data) || (Array.isArray(data) && data.length === 0)) {
|
||||||
return (Array.isArray(data) ? [] : void 0) as TEntity | TEntity[]
|
return (Array.isArray(data) ? [] : void 0) as
|
||||||
|
| ExtractEntityType<TEntity>
|
||||||
|
| ExtractEntityType<TEntity>[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const data_ = Array.isArray(data) ? data : [data]
|
const data_ = Array.isArray(data) ? data : [data]
|
||||||
@@ -212,24 +221,32 @@ export function MedusaInternalService<TContainer extends object = object>(
|
|||||||
return Array.isArray(data) ? entities : entities[0]
|
return Array.isArray(data) ? entities : entities[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
update(data: any[], sharedContext?: Context): Promise<TEntity[]>
|
update(
|
||||||
update(data: any, sharedContext?: Context): Promise<TEntity>
|
data: any[],
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<ExtractEntityType<TEntity>[]>
|
||||||
|
update(
|
||||||
|
data: any,
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<ExtractEntityType<TEntity>>
|
||||||
update(
|
update(
|
||||||
selectorAndData: SelectorAndData,
|
selectorAndData: SelectorAndData,
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<TEntity[]>
|
): Promise<ExtractEntityType<TEntity>[]>
|
||||||
update(
|
update(
|
||||||
selectorAndData: SelectorAndData[],
|
selectorAndData: SelectorAndData[],
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<TEntity[]>
|
): Promise<ExtractEntityType<TEntity>[]>
|
||||||
|
|
||||||
@InjectTransactionManager(shouldForceTransaction, propertyRepositoryName)
|
@InjectTransactionManager(shouldForceTransaction, propertyRepositoryName)
|
||||||
async update(
|
async update(
|
||||||
input: any | any[] | SelectorAndData | SelectorAndData[],
|
input: any | any[] | SelectorAndData | SelectorAndData[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity | TEntity[]> {
|
): Promise<ExtractEntityType<TEntity> | ExtractEntityType<TEntity>[]> {
|
||||||
if (!isDefined(input) || (Array.isArray(input) && input.length === 0)) {
|
if (!isDefined(input) || (Array.isArray(input) && input.length === 0)) {
|
||||||
return (Array.isArray(input) ? [] : void 0) as TEntity | TEntity[]
|
return (Array.isArray(input) ? [] : void 0) as
|
||||||
|
| ExtractEntityType<TEntity>
|
||||||
|
| ExtractEntityType<TEntity>[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const primaryKeys = AbstractService_.retrievePrimaryKeys(model)
|
const primaryKeys = AbstractService_.retrievePrimaryKeys(model)
|
||||||
@@ -294,7 +311,8 @@ export function MedusaInternalService<TContainer extends object = object>(
|
|||||||
|
|
||||||
// Only throw for missing entities when we dont have selectors involved as selector by design can return 0 entities
|
// Only throw for missing entities when we dont have selectors involved as selector by design can return 0 entities
|
||||||
if (entitiesToUpdate.length !== keySelectorDataMap.size) {
|
if (entitiesToUpdate.length !== keySelectorDataMap.size) {
|
||||||
const entityName = (model as EntityClass<TEntity>).name ?? model
|
const entityName =
|
||||||
|
(model as EntityClass<ExtractEntityType<TEntity>>).name ?? model
|
||||||
|
|
||||||
const compositeKeysValuesForFoundEntities = new Set(
|
const compositeKeysValuesForFoundEntities = new Set(
|
||||||
entitiesToUpdate.map((entity) => {
|
entitiesToUpdate.map((entity) => {
|
||||||
@@ -447,7 +465,7 @@ export function MedusaInternalService<TContainer extends object = object>(
|
|||||||
| InternalFilterQuery
|
| InternalFilterQuery
|
||||||
| InternalFilterQuery[],
|
| InternalFilterQuery[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<[TEntity[], Record<string, unknown[]>]> {
|
): Promise<[ExtractEntityType<TEntity>[], Record<string, unknown[]>]> {
|
||||||
if (
|
if (
|
||||||
(Array.isArray(idsOrFilter) && !idsOrFilter.length) ||
|
(Array.isArray(idsOrFilter) && !idsOrFilter.length) ||
|
||||||
(!Array.isArray(idsOrFilter) && !idsOrFilter)
|
(!Array.isArray(idsOrFilter) && !idsOrFilter)
|
||||||
@@ -465,21 +483,27 @@ export function MedusaInternalService<TContainer extends object = object>(
|
|||||||
async restore(
|
async restore(
|
||||||
idsOrFilter: string[] | InternalFilterQuery,
|
idsOrFilter: string[] | InternalFilterQuery,
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<[TEntity[], Record<string, unknown[]>]> {
|
): Promise<[ExtractEntityType<TEntity>[], Record<string, unknown[]>]> {
|
||||||
return await this[propertyRepositoryName].restore(
|
return await this[propertyRepositoryName].restore(
|
||||||
idsOrFilter,
|
idsOrFilter,
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
upsert(data: any[], sharedContext?: Context): Promise<TEntity[]>
|
upsert(
|
||||||
upsert(data: any, sharedContext?: Context): Promise<TEntity>
|
data: any[],
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<ExtractEntityType<TEntity>[]>
|
||||||
|
upsert(
|
||||||
|
data: any,
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<ExtractEntityType<TEntity>>
|
||||||
|
|
||||||
@InjectTransactionManager(propertyRepositoryName)
|
@InjectTransactionManager(propertyRepositoryName)
|
||||||
async upsert(
|
async upsert(
|
||||||
data: any | any[],
|
data: any | any[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity | TEntity[]> {
|
): Promise<ExtractEntityType<TEntity> | ExtractEntityType<TEntity>[]> {
|
||||||
const data_ = Array.isArray(data) ? data : [data]
|
const data_ = Array.isArray(data) ? data : [data]
|
||||||
const entities = await this[propertyRepositoryName].upsert(
|
const entities = await this[propertyRepositoryName].upsert(
|
||||||
data_,
|
data_,
|
||||||
@@ -490,24 +514,30 @@ export function MedusaInternalService<TContainer extends object = object>(
|
|||||||
|
|
||||||
upsertWithReplace(
|
upsertWithReplace(
|
||||||
data: any[],
|
data: any[],
|
||||||
config?: UpsertWithReplaceConfig<TEntity>,
|
config?: UpsertWithReplaceConfig<ExtractEntityType<TEntity>>,
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<{ entities: TEntity[]; performedActions: PerformedActions }>
|
): Promise<{
|
||||||
|
entities: ExtractEntityType<TEntity>[]
|
||||||
|
performedActions: PerformedActions
|
||||||
|
}>
|
||||||
upsertWithReplace(
|
upsertWithReplace(
|
||||||
data: any,
|
data: any,
|
||||||
config?: UpsertWithReplaceConfig<TEntity>,
|
config?: UpsertWithReplaceConfig<ExtractEntityType<TEntity>>,
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<{ entities: TEntity; performedActions: PerformedActions }>
|
): Promise<{
|
||||||
|
entities: ExtractEntityType<TEntity>
|
||||||
|
performedActions: PerformedActions
|
||||||
|
}>
|
||||||
|
|
||||||
@InjectTransactionManager(propertyRepositoryName)
|
@InjectTransactionManager(propertyRepositoryName)
|
||||||
async upsertWithReplace(
|
async upsertWithReplace(
|
||||||
data: any | any[],
|
data: any | any[],
|
||||||
config: UpsertWithReplaceConfig<TEntity> = {
|
config: UpsertWithReplaceConfig<ExtractEntityType<TEntity>> = {
|
||||||
relations: [],
|
relations: [],
|
||||||
},
|
},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<{
|
): Promise<{
|
||||||
entities: TEntity | TEntity[]
|
entities: ExtractEntityType<TEntity> | TEntity[]
|
||||||
performedActions: PerformedActions
|
performedActions: PerformedActions
|
||||||
}> {
|
}> {
|
||||||
const data_ = Array.isArray(data) ? data : [data]
|
const data_ = Array.isArray(data) ? data : [data]
|
||||||
|
|||||||
@@ -8,11 +8,9 @@ type InjectedDependencies = {
|
|||||||
inventoryLevelRepository: InventoryLevelRepository
|
inventoryLevelRepository: InventoryLevelRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class InventoryLevelService<
|
export default class InventoryLevelService extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||||
TEntity extends InventoryLevel = InventoryLevel
|
|
||||||
> extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
|
||||||
InventoryLevel
|
InventoryLevel
|
||||||
)<TEntity> {
|
)<InventoryLevel> {
|
||||||
protected readonly inventoryLevelRepository: InventoryLevelRepository
|
protected readonly inventoryLevelRepository: InventoryLevelRepository
|
||||||
|
|
||||||
constructor(container: InjectedDependencies) {
|
constructor(container: InjectedDependencies) {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import { IInventoryService } from "@medusajs/types/dist/inventory"
|
|||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
baseRepository: DAL.RepositoryService
|
baseRepository: DAL.RepositoryService
|
||||||
inventoryItemService: ModulesSdkTypes.IMedusaInternalService<any>
|
inventoryItemService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
inventoryLevelService: InventoryLevelService<any>
|
inventoryLevelService: InventoryLevelService
|
||||||
reservationItemService: ModulesSdkTypes.IMedusaInternalService<any>
|
reservationItemService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ export default class InventoryModuleService
|
|||||||
|
|
||||||
protected readonly inventoryItemService_: ModulesSdkTypes.IMedusaInternalService<InventoryItem>
|
protected readonly inventoryItemService_: ModulesSdkTypes.IMedusaInternalService<InventoryItem>
|
||||||
protected readonly reservationItemService_: ModulesSdkTypes.IMedusaInternalService<ReservationItem>
|
protected readonly reservationItemService_: ModulesSdkTypes.IMedusaInternalService<ReservationItem>
|
||||||
protected readonly inventoryLevelService_: InventoryLevelService<InventoryLevel>
|
protected readonly inventoryLevelService_: InventoryLevelService
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,12 +20,10 @@ type InjectedDependencies = {
|
|||||||
orderChangeRepository: DAL.RepositoryService
|
orderChangeRepository: DAL.RepositoryService
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class OrderChangeService<
|
export default class OrderChangeService extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||||
TEntity extends OrderChange = OrderChange
|
|
||||||
> extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
|
||||||
OrderChange
|
OrderChange
|
||||||
)<TEntity> {
|
)<OrderChange> {
|
||||||
protected readonly orderChangeRepository_: RepositoryService<TEntity>
|
protected readonly orderChangeRepository_: RepositoryService<OrderChange>
|
||||||
|
|
||||||
constructor(container: InjectedDependencies) {
|
constructor(container: InjectedDependencies) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -38,7 +36,7 @@ export default class OrderChangeService<
|
|||||||
orderId: string | string[],
|
orderId: string | string[],
|
||||||
config: FindConfig<TEntityMethod> = {},
|
config: FindConfig<TEntityMethod> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity[]> {
|
): Promise<OrderChange[]> {
|
||||||
const allChanges = await super.list(
|
const allChanges = await super.list(
|
||||||
{ order_id: orderId },
|
{ order_id: orderId },
|
||||||
config ?? {
|
config ?? {
|
||||||
@@ -67,7 +65,7 @@ export default class OrderChangeService<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let orderChange!: TEntity
|
let orderChange!: OrderChange
|
||||||
if (allChanges?.length > 0) {
|
if (allChanges?.length > 0) {
|
||||||
if (this.isActive(allChanges[0])) {
|
if (this.isActive(allChanges[0])) {
|
||||||
orderChange = allChanges[0]
|
orderChange = allChanges[0]
|
||||||
@@ -81,7 +79,7 @@ export default class OrderChangeService<
|
|||||||
const relations = deduplicate([...(config.relations ?? []), "actions"])
|
const relations = deduplicate([...(config.relations ?? []), "actions"])
|
||||||
config.relations = relations
|
config.relations = relations
|
||||||
|
|
||||||
const queryConfig = ModulesSdkUtils.buildQuery<TEntity>(
|
const queryConfig = ModulesSdkUtils.buildQuery<OrderChange>(
|
||||||
{
|
{
|
||||||
id: lastChanges,
|
id: lastChanges,
|
||||||
order: {
|
order: {
|
||||||
@@ -104,20 +102,20 @@ export default class OrderChangeService<
|
|||||||
}
|
}
|
||||||
|
|
||||||
async create(
|
async create(
|
||||||
data: Partial<TEntity>[],
|
data: Partial<OrderChange>[],
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<TEntity[]>
|
): Promise<OrderChange[]>
|
||||||
|
|
||||||
async create(
|
async create(
|
||||||
data: Partial<TEntity>,
|
data: Partial<OrderChange>,
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<TEntity>
|
): Promise<OrderChange>
|
||||||
|
|
||||||
@InjectTransactionManager("orderChangeRepository_")
|
@InjectTransactionManager("orderChangeRepository_")
|
||||||
async create(
|
async create(
|
||||||
data: Partial<TEntity>[] | Partial<TEntity>,
|
data: Partial<OrderChange>[] | Partial<OrderChange>,
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity[] | TEntity> {
|
): Promise<OrderChange[] | OrderChange> {
|
||||||
const dataArr = Array.isArray(data) ? data : [data]
|
const dataArr = Array.isArray(data) ? data : [data]
|
||||||
const activeOrderEdit = await this.listCurrentOrderChange(
|
const activeOrderEdit = await this.listCurrentOrderChange(
|
||||||
dataArr.map((d) => d.order_id!),
|
dataArr.map((d) => d.order_id!),
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ import OrderService from "./order-service"
|
|||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
baseRepository: DAL.RepositoryService
|
baseRepository: DAL.RepositoryService
|
||||||
orderService: OrderService<any>
|
orderService: OrderService
|
||||||
addressService: ModulesSdkTypes.IMedusaInternalService<any>
|
addressService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
lineItemService: ModulesSdkTypes.IMedusaInternalService<any>
|
lineItemService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
shippingMethodAdjustmentService: ModulesSdkTypes.IMedusaInternalService<any>
|
shippingMethodAdjustmentService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
@@ -87,7 +87,7 @@ type InjectedDependencies = {
|
|||||||
lineItemTaxLineService: ModulesSdkTypes.IMedusaInternalService<any>
|
lineItemTaxLineService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
shippingMethodTaxLineService: ModulesSdkTypes.IMedusaInternalService<any>
|
shippingMethodTaxLineService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
transactionService: ModulesSdkTypes.IMedusaInternalService<any>
|
transactionService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
orderChangeService: OrderChangeService<any>
|
orderChangeService: OrderChangeService
|
||||||
orderChangeActionService: ModulesSdkTypes.IMedusaInternalService<any>
|
orderChangeActionService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
orderItemService: ModulesSdkTypes.IMedusaInternalService<any>
|
orderItemService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
orderSummaryService: ModulesSdkTypes.IMedusaInternalService<any>
|
orderSummaryService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
@@ -169,7 +169,7 @@ export default class OrderModuleService<
|
|||||||
implements IOrderModuleService
|
implements IOrderModuleService
|
||||||
{
|
{
|
||||||
protected baseRepository_: DAL.RepositoryService
|
protected baseRepository_: DAL.RepositoryService
|
||||||
protected orderService_: OrderService<TOrder>
|
protected orderService_: OrderService
|
||||||
protected addressService_: ModulesSdkTypes.IMedusaInternalService<TAddress>
|
protected addressService_: ModulesSdkTypes.IMedusaInternalService<TAddress>
|
||||||
protected lineItemService_: ModulesSdkTypes.IMedusaInternalService<TLineItem>
|
protected lineItemService_: ModulesSdkTypes.IMedusaInternalService<TLineItem>
|
||||||
protected shippingMethodAdjustmentService_: ModulesSdkTypes.IMedusaInternalService<TShippingMethodAdjustment>
|
protected shippingMethodAdjustmentService_: ModulesSdkTypes.IMedusaInternalService<TShippingMethodAdjustment>
|
||||||
@@ -178,7 +178,7 @@ export default class OrderModuleService<
|
|||||||
protected lineItemTaxLineService_: ModulesSdkTypes.IMedusaInternalService<TLineItemTaxLine>
|
protected lineItemTaxLineService_: ModulesSdkTypes.IMedusaInternalService<TLineItemTaxLine>
|
||||||
protected shippingMethodTaxLineService_: ModulesSdkTypes.IMedusaInternalService<TShippingMethodTaxLine>
|
protected shippingMethodTaxLineService_: ModulesSdkTypes.IMedusaInternalService<TShippingMethodTaxLine>
|
||||||
protected transactionService_: ModulesSdkTypes.IMedusaInternalService<TTransaction>
|
protected transactionService_: ModulesSdkTypes.IMedusaInternalService<TTransaction>
|
||||||
protected orderChangeService_: OrderChangeService<TOrderChange>
|
protected orderChangeService_: OrderChangeService
|
||||||
protected orderChangeActionService_: ModulesSdkTypes.IMedusaInternalService<TOrderChangeAction>
|
protected orderChangeActionService_: ModulesSdkTypes.IMedusaInternalService<TOrderChangeAction>
|
||||||
protected orderItemService_: ModulesSdkTypes.IMedusaInternalService<TOrderItem>
|
protected orderItemService_: ModulesSdkTypes.IMedusaInternalService<TOrderItem>
|
||||||
protected orderSummaryService_: ModulesSdkTypes.IMedusaInternalService<TOrderSummary>
|
protected orderSummaryService_: ModulesSdkTypes.IMedusaInternalService<TOrderSummary>
|
||||||
|
|||||||
@@ -17,12 +17,10 @@ type InjectedDependencies = {
|
|||||||
orderRepository: DAL.RepositoryService
|
orderRepository: DAL.RepositoryService
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class OrderService<
|
export default class OrderService extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||||
TEntity extends Order = Order
|
|
||||||
> extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
|
||||||
Order
|
Order
|
||||||
)<TEntity> {
|
)<Order> {
|
||||||
protected readonly orderRepository_: RepositoryService<TEntity>
|
protected readonly orderRepository_: RepositoryService<Order>
|
||||||
|
|
||||||
constructor(container: InjectedDependencies) {
|
constructor(container: InjectedDependencies) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -36,8 +34,8 @@ export default class OrderService<
|
|||||||
version: number,
|
version: number,
|
||||||
config: FindConfig<TEntityMethod> = {},
|
config: FindConfig<TEntityMethod> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity> {
|
): Promise<Order> {
|
||||||
const queryConfig = ModulesSdkUtils.buildQuery<TEntity>(
|
const queryConfig = ModulesSdkUtils.buildQuery<Order>(
|
||||||
{ id, items: { version } },
|
{ id, items: { version } },
|
||||||
{ ...config, take: 1 }
|
{ ...config, take: 1 }
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,11 +7,9 @@ type InjectedDependencies = {
|
|||||||
priceListRepository: DAL.RepositoryService
|
priceListRepository: DAL.RepositoryService
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class PriceListService<
|
export default class PriceListService extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||||
TEntity extends PriceList = PriceList
|
|
||||||
> extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
|
||||||
PriceList
|
PriceList
|
||||||
)<TEntity> {
|
)<PriceList> {
|
||||||
constructor(container: InjectedDependencies) {
|
constructor(container: InjectedDependencies) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
super(...arguments)
|
super(...arguments)
|
||||||
@@ -20,32 +18,32 @@ export default class PriceListService<
|
|||||||
create(
|
create(
|
||||||
data: ServiceTypes.CreatePriceListDTO[],
|
data: ServiceTypes.CreatePriceListDTO[],
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<TEntity[]>
|
): Promise<PriceList[]>
|
||||||
create(
|
create(
|
||||||
data: ServiceTypes.CreatePriceListDTO,
|
data: ServiceTypes.CreatePriceListDTO,
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<TEntity>
|
): Promise<PriceList>
|
||||||
|
|
||||||
async create(
|
async create(
|
||||||
data: ServiceTypes.CreatePriceListDTO | ServiceTypes.CreatePriceListDTO[],
|
data: ServiceTypes.CreatePriceListDTO | ServiceTypes.CreatePriceListDTO[],
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<TEntity | TEntity[]> {
|
): Promise<PriceList | PriceList[]> {
|
||||||
const data_ = Array.isArray(data) ? data : [data]
|
const data_ = Array.isArray(data) ? data : [data]
|
||||||
const priceLists = this.normalizePriceListDate(data_)
|
const priceLists = this.normalizePriceListDate(data_)
|
||||||
return await super.create(priceLists, sharedContext)
|
return await super.create(priceLists, sharedContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
update(data: any[], sharedContext?: Context): Promise<TEntity[]>
|
update(data: any[], sharedContext?: Context): Promise<PriceList[]>
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
update(data: any, sharedContext?: Context): Promise<TEntity>
|
update(data: any, sharedContext?: Context): Promise<PriceList>
|
||||||
|
|
||||||
// TODO: Add support for selector? and then rm ts ignore
|
// TODO: Add support for selector? and then rm ts ignore
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
async update(
|
async update(
|
||||||
data: ServiceTypes.UpdatePriceListDTO | ServiceTypes.UpdatePriceListDTO[],
|
data: ServiceTypes.UpdatePriceListDTO | ServiceTypes.UpdatePriceListDTO[],
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<TEntity | TEntity[]> {
|
): Promise<PriceList | PriceList[]> {
|
||||||
const data_ = Array.isArray(data) ? data : [data]
|
const data_ = Array.isArray(data) ? data : [data]
|
||||||
const priceLists = this.normalizePriceListDate(data_)
|
const priceLists = this.normalizePriceListDate(data_)
|
||||||
return await super.update(priceLists, sharedContext)
|
return await super.update(priceLists, sharedContext)
|
||||||
|
|||||||
@@ -58,11 +58,11 @@ type InjectedDependencies = {
|
|||||||
baseRepository: DAL.RepositoryService
|
baseRepository: DAL.RepositoryService
|
||||||
pricingRepository: PricingRepositoryService
|
pricingRepository: PricingRepositoryService
|
||||||
priceSetService: ModulesSdkTypes.IMedusaInternalService<any>
|
priceSetService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
ruleTypeService: RuleTypeService<any>
|
ruleTypeService: RuleTypeService
|
||||||
priceRuleService: ModulesSdkTypes.IMedusaInternalService<any>
|
priceRuleService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
priceSetRuleTypeService: ModulesSdkTypes.IMedusaInternalService<any>
|
priceSetRuleTypeService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
priceService: ModulesSdkTypes.IMedusaInternalService<any>
|
priceService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
priceListService: PriceListService<any>
|
priceListService: PriceListService
|
||||||
priceListRuleService: ModulesSdkTypes.IMedusaInternalService<any>
|
priceListRuleService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
priceListRuleValueService: ModulesSdkTypes.IMedusaInternalService<any>
|
priceListRuleValueService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
}
|
}
|
||||||
@@ -99,12 +99,12 @@ export default class PricingModuleService
|
|||||||
{
|
{
|
||||||
protected baseRepository_: DAL.RepositoryService
|
protected baseRepository_: DAL.RepositoryService
|
||||||
protected readonly pricingRepository_: PricingRepositoryService
|
protected readonly pricingRepository_: PricingRepositoryService
|
||||||
protected readonly ruleTypeService_: RuleTypeService<RuleType>
|
protected readonly ruleTypeService_: RuleTypeService
|
||||||
protected readonly priceSetService_: ModulesSdkTypes.IMedusaInternalService<PriceSet>
|
protected readonly priceSetService_: ModulesSdkTypes.IMedusaInternalService<PriceSet>
|
||||||
protected readonly priceRuleService_: ModulesSdkTypes.IMedusaInternalService<PriceRule>
|
protected readonly priceRuleService_: ModulesSdkTypes.IMedusaInternalService<PriceRule>
|
||||||
protected readonly priceSetRuleTypeService_: ModulesSdkTypes.IMedusaInternalService<PriceSetRuleType>
|
protected readonly priceSetRuleTypeService_: ModulesSdkTypes.IMedusaInternalService<PriceSetRuleType>
|
||||||
protected readonly priceService_: ModulesSdkTypes.IMedusaInternalService<Price>
|
protected readonly priceService_: ModulesSdkTypes.IMedusaInternalService<Price>
|
||||||
protected readonly priceListService_: PriceListService<PriceList>
|
protected readonly priceListService_: PriceListService
|
||||||
protected readonly priceListRuleService_: ModulesSdkTypes.IMedusaInternalService<PriceListRule>
|
protected readonly priceListRuleService_: ModulesSdkTypes.IMedusaInternalService<PriceListRule>
|
||||||
protected readonly priceListRuleValueService_: ModulesSdkTypes.IMedusaInternalService<PriceListRuleValue>
|
protected readonly priceListRuleValueService_: ModulesSdkTypes.IMedusaInternalService<PriceListRuleValue>
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,10 @@ type InjectedDependencies = {
|
|||||||
ruleTypeRepository: DAL.RepositoryService
|
ruleTypeRepository: DAL.RepositoryService
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class RuleTypeService<
|
export default class RuleTypeService extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||||
TEntity extends RuleType = RuleType
|
|
||||||
> extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
|
||||||
RuleType
|
RuleType
|
||||||
)<TEntity> {
|
)<RuleType> {
|
||||||
protected readonly ruleTypeRepository_: DAL.RepositoryService<TEntity>
|
protected readonly ruleTypeRepository_: DAL.RepositoryService<RuleType>
|
||||||
|
|
||||||
constructor({ ruleTypeRepository }: InjectedDependencies) {
|
constructor({ ruleTypeRepository }: InjectedDependencies) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -27,17 +25,17 @@ export default class RuleTypeService<
|
|||||||
create(
|
create(
|
||||||
data: PricingTypes.CreateRuleTypeDTO,
|
data: PricingTypes.CreateRuleTypeDTO,
|
||||||
sharedContext: Context
|
sharedContext: Context
|
||||||
): Promise<TEntity>
|
): Promise<RuleType>
|
||||||
create(
|
create(
|
||||||
data: PricingTypes.CreateRuleTypeDTO[],
|
data: PricingTypes.CreateRuleTypeDTO[],
|
||||||
sharedContext: Context
|
sharedContext: Context
|
||||||
): Promise<TEntity[]>
|
): Promise<RuleType[]>
|
||||||
|
|
||||||
@InjectTransactionManager("ruleTypeRepository_")
|
@InjectTransactionManager("ruleTypeRepository_")
|
||||||
async create(
|
async create(
|
||||||
data: PricingTypes.CreateRuleTypeDTO | PricingTypes.CreateRuleTypeDTO[],
|
data: PricingTypes.CreateRuleTypeDTO | PricingTypes.CreateRuleTypeDTO[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity | TEntity[]> {
|
): Promise<RuleType | RuleType[]> {
|
||||||
const data_ = Array.isArray(data) ? data : [data]
|
const data_ = Array.isArray(data) ? data : [data]
|
||||||
validateRuleAttributes(data_.map((d) => d.rule_attribute))
|
validateRuleAttributes(data_.map((d) => d.rule_attribute))
|
||||||
return await super.create(data, sharedContext)
|
return await super.create(data, sharedContext)
|
||||||
@@ -47,12 +45,12 @@ export default class RuleTypeService<
|
|||||||
update(
|
update(
|
||||||
data: PricingTypes.UpdateRuleTypeDTO[],
|
data: PricingTypes.UpdateRuleTypeDTO[],
|
||||||
sharedContext: Context
|
sharedContext: Context
|
||||||
): Promise<TEntity[]>
|
): Promise<RuleType[]>
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
update(
|
update(
|
||||||
data: PricingTypes.UpdateRuleTypeDTO,
|
data: PricingTypes.UpdateRuleTypeDTO,
|
||||||
sharedContext: Context
|
sharedContext: Context
|
||||||
): Promise<TEntity>
|
): Promise<RuleType>
|
||||||
|
|
||||||
@InjectTransactionManager("ruleTypeRepository_")
|
@InjectTransactionManager("ruleTypeRepository_")
|
||||||
// TODO: add support for selector? and then rm ts ignore
|
// TODO: add support for selector? and then rm ts ignore
|
||||||
@@ -60,7 +58,7 @@ export default class RuleTypeService<
|
|||||||
async update(
|
async update(
|
||||||
data: PricingTypes.UpdateRuleTypeDTO | PricingTypes.UpdateRuleTypeDTO[],
|
data: PricingTypes.UpdateRuleTypeDTO | PricingTypes.UpdateRuleTypeDTO[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity | TEntity[]> {
|
): Promise<RuleType | RuleType[]> {
|
||||||
const data_ = Array.isArray(data) ? data : [data]
|
const data_ = Array.isArray(data) ? data : [data]
|
||||||
validateRuleAttributes(data_.map((d) => d.rule_attribute))
|
validateRuleAttributes(data_.map((d) => d.rule_attribute))
|
||||||
return await super.update(data, sharedContext)
|
return await super.update(data, sharedContext)
|
||||||
|
|||||||
@@ -15,9 +15,7 @@ import { UpdateCategoryInput } from "@types"
|
|||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
productCategoryRepository: DAL.TreeRepositoryService
|
productCategoryRepository: DAL.TreeRepositoryService
|
||||||
}
|
}
|
||||||
export default class ProductCategoryService<
|
export default class ProductCategoryService {
|
||||||
TEntity extends ProductCategory = ProductCategory
|
|
||||||
> {
|
|
||||||
protected readonly productCategoryRepository_: DAL.TreeRepositoryService
|
protected readonly productCategoryRepository_: DAL.TreeRepositoryService
|
||||||
|
|
||||||
constructor({ productCategoryRepository }: InjectedDependencies) {
|
constructor({ productCategoryRepository }: InjectedDependencies) {
|
||||||
@@ -30,7 +28,7 @@ export default class ProductCategoryService<
|
|||||||
productCategoryId: string,
|
productCategoryId: string,
|
||||||
config: FindConfig<ProductTypes.ProductCategoryDTO> = {},
|
config: FindConfig<ProductTypes.ProductCategoryDTO> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity> {
|
): Promise<ProductCategory> {
|
||||||
if (!isDefined(productCategoryId)) {
|
if (!isDefined(productCategoryId)) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
@@ -64,7 +62,7 @@ export default class ProductCategoryService<
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return productCategories[0] as TEntity
|
return productCategories[0] as ProductCategory
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectManager("productCategoryRepository_")
|
@InjectManager("productCategoryRepository_")
|
||||||
@@ -72,7 +70,7 @@ export default class ProductCategoryService<
|
|||||||
filters: ProductTypes.FilterableProductCategoryProps = {},
|
filters: ProductTypes.FilterableProductCategoryProps = {},
|
||||||
config: FindConfig<ProductTypes.ProductCategoryDTO> = {},
|
config: FindConfig<ProductTypes.ProductCategoryDTO> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity[]> {
|
): Promise<ProductCategory[]> {
|
||||||
const transformOptions = {
|
const transformOptions = {
|
||||||
includeDescendantsTree: filters?.include_descendants_tree || false,
|
includeDescendantsTree: filters?.include_descendants_tree || false,
|
||||||
includeAncestorsTree: filters?.include_ancestors_tree || false,
|
includeAncestorsTree: filters?.include_ancestors_tree || false,
|
||||||
@@ -101,7 +99,7 @@ export default class ProductCategoryService<
|
|||||||
queryOptions,
|
queryOptions,
|
||||||
transformOptions,
|
transformOptions,
|
||||||
sharedContext
|
sharedContext
|
||||||
)) as TEntity[]
|
)) as ProductCategory[]
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectManager("productCategoryRepository_")
|
@InjectManager("productCategoryRepository_")
|
||||||
@@ -109,7 +107,7 @@ export default class ProductCategoryService<
|
|||||||
filters: ProductTypes.FilterableProductCategoryProps = {},
|
filters: ProductTypes.FilterableProductCategoryProps = {},
|
||||||
config: FindConfig<ProductTypes.ProductCategoryDTO> = {},
|
config: FindConfig<ProductTypes.ProductCategoryDTO> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<[TEntity[], number]> {
|
): Promise<[ProductCategory[], number]> {
|
||||||
const transformOptions = {
|
const transformOptions = {
|
||||||
includeDescendantsTree: filters?.include_descendants_tree || false,
|
includeDescendantsTree: filters?.include_descendants_tree || false,
|
||||||
includeAncestorsTree: filters?.include_ancestors_tree || false,
|
includeAncestorsTree: filters?.include_ancestors_tree || false,
|
||||||
@@ -138,27 +136,27 @@ export default class ProductCategoryService<
|
|||||||
queryOptions,
|
queryOptions,
|
||||||
transformOptions,
|
transformOptions,
|
||||||
sharedContext
|
sharedContext
|
||||||
)) as [TEntity[], number]
|
)) as [ProductCategory[], number]
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectTransactionManager("productCategoryRepository_")
|
@InjectTransactionManager("productCategoryRepository_")
|
||||||
async create(
|
async create(
|
||||||
data: ProductTypes.CreateProductCategoryDTO[],
|
data: ProductTypes.CreateProductCategoryDTO[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity[]> {
|
): Promise<ProductCategory[]> {
|
||||||
return (await (
|
return (await (
|
||||||
this.productCategoryRepository_ as unknown as ProductCategoryRepository
|
this.productCategoryRepository_ as unknown as ProductCategoryRepository
|
||||||
).create(data, sharedContext)) as TEntity[]
|
).create(data, sharedContext)) as ProductCategory[]
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectTransactionManager("productCategoryRepository_")
|
@InjectTransactionManager("productCategoryRepository_")
|
||||||
async update(
|
async update(
|
||||||
data: UpdateCategoryInput[],
|
data: UpdateCategoryInput[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity[]> {
|
): Promise<ProductCategory[]> {
|
||||||
return (await (
|
return (await (
|
||||||
this.productCategoryRepository_ as unknown as ProductCategoryRepository
|
this.productCategoryRepository_ as unknown as ProductCategoryRepository
|
||||||
).update(data, sharedContext)) as TEntity[]
|
).update(data, sharedContext)) as ProductCategory[]
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectTransactionManager("productCategoryRepository_")
|
@InjectTransactionManager("productCategoryRepository_")
|
||||||
|
|||||||
@@ -55,10 +55,10 @@ import { entityNameToLinkableKeysMap, joinerConfig } from "./../joiner-config"
|
|||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
baseRepository: DAL.RepositoryService
|
baseRepository: DAL.RepositoryService
|
||||||
productService: ProductService<any>
|
productService: ProductService
|
||||||
productVariantService: ModulesSdkTypes.IMedusaInternalService<any, any>
|
productVariantService: ModulesSdkTypes.IMedusaInternalService<any, any>
|
||||||
productTagService: ModulesSdkTypes.IMedusaInternalService<any>
|
productTagService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
productCategoryService: ProductCategoryService<any>
|
productCategoryService: ProductCategoryService
|
||||||
productCollectionService: ModulesSdkTypes.IMedusaInternalService<any>
|
productCollectionService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
productImageService: ModulesSdkTypes.IMedusaInternalService<any>
|
productImageService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
productTypeService: ModulesSdkTypes.IMedusaInternalService<any>
|
productTypeService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||||
@@ -105,9 +105,9 @@ export default class ProductModuleService
|
|||||||
implements ProductTypes.IProductModuleService
|
implements ProductTypes.IProductModuleService
|
||||||
{
|
{
|
||||||
protected baseRepository_: DAL.RepositoryService
|
protected baseRepository_: DAL.RepositoryService
|
||||||
protected readonly productService_: ProductService<Product>
|
protected readonly productService_: ProductService
|
||||||
protected readonly productVariantService_: ModulesSdkTypes.IMedusaInternalService<ProductVariant>
|
protected readonly productVariantService_: ModulesSdkTypes.IMedusaInternalService<ProductVariant>
|
||||||
protected readonly productCategoryService_: ProductCategoryService<ProductCategory>
|
protected readonly productCategoryService_: ProductCategoryService
|
||||||
protected readonly productTagService_: ModulesSdkTypes.IMedusaInternalService<ProductTag>
|
protected readonly productTagService_: ModulesSdkTypes.IMedusaInternalService<ProductTag>
|
||||||
protected readonly productCollectionService_: ModulesSdkTypes.IMedusaInternalService<ProductCollection>
|
protected readonly productCollectionService_: ModulesSdkTypes.IMedusaInternalService<ProductCollection>
|
||||||
protected readonly productImageService_: ModulesSdkTypes.IMedusaInternalService<ProductImage>
|
protected readonly productImageService_: ModulesSdkTypes.IMedusaInternalService<ProductImage>
|
||||||
|
|||||||
@@ -18,12 +18,10 @@ type NormalizedFilterableProductProps = ProductTypes.FilterableProductProps & {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class ProductService<
|
export default class ProductService extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||||
TEntity extends Product = Product
|
|
||||||
> extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
|
||||||
Product
|
Product
|
||||||
)<TEntity> {
|
)<Product> {
|
||||||
protected readonly productRepository_: DAL.RepositoryService<TEntity>
|
protected readonly productRepository_: DAL.RepositoryService<Product>
|
||||||
|
|
||||||
constructor({ productRepository }: InjectedDependencies) {
|
constructor({ productRepository }: InjectedDependencies) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -36,9 +34,9 @@ export default class ProductService<
|
|||||||
@InjectManager("productRepository_")
|
@InjectManager("productRepository_")
|
||||||
async list(
|
async list(
|
||||||
filters: ProductTypes.FilterableProductProps = {},
|
filters: ProductTypes.FilterableProductProps = {},
|
||||||
config: FindConfig<TEntity> = {},
|
config: FindConfig<Product> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TEntity[]> {
|
): Promise<Product[]> {
|
||||||
return await super.list(
|
return await super.list(
|
||||||
ProductService.normalizeFilters(filters),
|
ProductService.normalizeFilters(filters),
|
||||||
config,
|
config,
|
||||||
@@ -51,7 +49,7 @@ export default class ProductService<
|
|||||||
filters: ProductTypes.FilterableProductProps = {},
|
filters: ProductTypes.FilterableProductProps = {},
|
||||||
config: FindConfig<any> = {},
|
config: FindConfig<any> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<[TEntity[], number]> {
|
): Promise<[Product[], number]> {
|
||||||
return await super.listAndCount(
|
return await super.listAndCount(
|
||||||
ProductService.normalizeFilters(filters),
|
ProductService.normalizeFilters(filters),
|
||||||
config,
|
config,
|
||||||
|
|||||||
Reference in New Issue
Block a user