diff --git a/.changeset/green-insects-invite.md b/.changeset/green-insects-invite.md new file mode 100644 index 0000000000..d4e96eddf3 --- /dev/null +++ b/.changeset/green-insects-invite.md @@ -0,0 +1,23 @@ +--- +"@medusajs/api-key": patch +"@medusajs/auth": patch +"@medusajs/cart": patch +"@medusajs/customer": patch +"@medusajs/fulfillment": patch +"@medusajs/inventory": patch +"@medusajs/notification": patch +"@medusajs/order": patch +"@medusajs/payment": patch +"@medusajs/pricing": patch +"@medusajs/product": patch +"@medusajs/promotion": patch +"@medusajs/region": patch +"@medusajs/sales-channel": patch +"@medusajs/stock-location": patch +"@medusajs/store": patch +"@medusajs/tax": patch +"@medusajs/user": patch +"@medusajs/utils": patch +--- + +feat: make AbstractModuleService create method type-safe diff --git a/packages/core/utils/src/modules-sdk/__tests__/medusa-service-typings.spec.ts b/packages/core/utils/src/modules-sdk/__tests__/medusa-service-typings.spec.ts new file mode 100644 index 0000000000..47dc55e549 --- /dev/null +++ b/packages/core/utils/src/modules-sdk/__tests__/medusa-service-typings.spec.ts @@ -0,0 +1,275 @@ +import { expectTypeOf } from "expect-type" +import { model } from "../../dml" +import { MedusaService } from "../medusa-service" +import { InferTypeOf } from "@medusajs/types" + +const Blog = model.define("Blog", { + id: model.text(), + title: model.text(), + description: model.text().nullable(), +}) + +type BlogDTO = { + id: number + title: string +} + +type CreateBlogDTO = { + title: string | null +} + +const baseRepoMock = { + serialize: jest.fn().mockImplementation((item) => item), + transaction: (task) => task("transactionManager"), + getFreshManager: jest.fn().mockReturnThis(), +} + +const containerMock = { + baseRepository: baseRepoMock, + mainModelMockRepository: baseRepoMock, + otherModelMock1Repository: baseRepoMock, + otherModelMock2Repository: baseRepoMock, + mainModelMockService: { + retrieve: jest.fn().mockResolvedValue({ id: "1", name: "Item" }), + list: jest.fn().mockResolvedValue([{ id: "1", name: "Item" }]), + delete: jest.fn().mockResolvedValue(undefined), + softDelete: jest.fn().mockResolvedValue([[], {}]), + restore: jest.fn().mockResolvedValue([[], {}]), + }, + otherModelMock1Service: { + retrieve: jest.fn().mockResolvedValue({ id: "1", name: "Item" }), + list: jest.fn().mockResolvedValue([{ id: "1", name: "Item" }]), + delete: jest.fn().mockResolvedValue(undefined), + softDelete: jest.fn().mockResolvedValue([[], {}]), + restore: jest.fn().mockResolvedValue([[], {}]), + }, + otherModelMock2Service: { + retrieve: jest.fn().mockResolvedValue({ id: "1", name: "Item" }), + list: jest.fn().mockResolvedValue([{ id: "1", name: "Item" }]), + delete: jest.fn().mockResolvedValue(undefined), + softDelete: jest.fn().mockResolvedValue([[], {}]), + restore: jest.fn().mockResolvedValue([[], {}]), + }, +} + +describe("Medusa Service typings", () => { + describe("create", () => { + test("type-hint model properties", () => { + class BlogService extends MedusaService({ Blog }) {} + const blogService = new BlogService(containerMock) + + expectTypeOf(blogService.createBlogs).parameters.toEqualTypeOf< + | [ + Partial<{ + id: string | undefined + title: string | undefined + description: string | null | undefined + }>, + ...rest: any[] + ] + | [ + Partial<{ + id: string | undefined + title: string | undefined + description: string | null | undefined + }>[], + ...rest: any[] + ] + >() + expectTypeOf(blogService.createBlogs).returns.toEqualTypeOf< + Promise> | Promise[]> + >() + }) + + test("type-hint DTO properties", () => { + class BlogService extends MedusaService<{ Blog: { dto: BlogDTO } }>({ + Blog, + }) {} + const blogService = new BlogService(containerMock) + + expectTypeOf(blogService.createBlogs).parameters.toEqualTypeOf< + | [Partial, ...rest: any[]] + | [Partial[], ...rest: any[]] + >() + expectTypeOf(blogService.createBlogs).returns.toEqualTypeOf< + Promise | Promise + >() + }) + + test("type-hint force overridden properties", () => { + class BlogService extends MedusaService<{ Blog: { dto: BlogDTO } }>({ + Blog, + }) { + // @ts-expect-error + async createBlogs(_: CreateBlogDTO): Promise { + return {} as BlogDTO + } + } + const blogService = new BlogService(containerMock) + + expectTypeOf(blogService.createBlogs).parameters.toEqualTypeOf< + [CreateBlogDTO] + >() + expectTypeOf(blogService.createBlogs).returns.toEqualTypeOf< + Promise + >() + }) + + test("define custom DTO for inputs", () => { + class BlogService extends MedusaService<{ + Blog: { dto: BlogDTO; inputDto: Omit } + }>({ + Blog, + }) {} + const blogService = new BlogService(containerMock) + + expectTypeOf(blogService.createBlogs).parameters.toEqualTypeOf< + | [Partial<{ title: string | undefined }>, ...rest: any[]] + | [Partial<{ title: string | undefined }>[], ...rest: any[]] + >() + expectTypeOf(blogService.createBlogs).returns.toEqualTypeOf< + Promise | Promise + >() + }) + }) + + describe("update", () => { + test("type-hint model properties", () => { + class BlogService extends MedusaService({ Blog }) {} + const blogService = new BlogService(containerMock) + + expectTypeOf(blogService.updateBlogs).parameters.toEqualTypeOf< + | [ + Partial<{ + id: string | undefined + title: string | undefined + description: string | null | undefined + }>, + ...rest: any[] + ] + | [ + ( + | Partial<{ + id: string | undefined + title: string | undefined + description: string | null | undefined + }>[] + | { + selector: Record + data: + | Partial<{ + id: string | undefined + title: string | undefined + description: string | null | undefined + }> + | Partial<{ + id: string | undefined + title: string | undefined + description: string | null | undefined + }>[] + } + | { + selector: Record + data: + | Partial<{ + id: string | undefined + title: string | undefined + description: string | null | undefined + }> + | Partial<{ + id: string | undefined + title: string | undefined + description: string | null | undefined + }>[] + }[] + ), + ...rest: any[] + ] + >() + expectTypeOf(blogService.updateBlogs).returns.toEqualTypeOf< + Promise> | Promise[]> + >() + }) + + test("type-hint DTO properties", () => { + class BlogService extends MedusaService<{ Blog: { dto: BlogDTO } }>({ + Blog, + }) {} + const blogService = new BlogService(containerMock) + + expectTypeOf(blogService.updateBlogs).parameters.toEqualTypeOf< + | [Partial, ...rest: any[]] + | [ + ( + | Partial[] + | { + selector: Record + data: Partial | Partial[] + } + | { + selector: Record + data: Partial | Partial[] + }[] + ), + ...rest: any[] + ] + >() + expectTypeOf(blogService.updateBlogs).returns.toEqualTypeOf< + Promise | Promise + >() + }) + + test("type-hint force overridden properties", () => { + class BlogService extends MedusaService<{ Blog: { dto: BlogDTO } }>({ + Blog, + }) { + // @ts-expect-error + async updateBlogs(_: string, __: CreateBlogDTO): Promise { + return {} as BlogDTO + } + } + const blogService = new BlogService(containerMock) + + expectTypeOf(blogService.updateBlogs).parameters.toEqualTypeOf< + [id: string, data: CreateBlogDTO] + >() + expectTypeOf(blogService.updateBlogs).returns.toEqualTypeOf< + Promise + >() + }) + + test("define custom DTO for inputs", () => { + class BlogService extends MedusaService<{ + Blog: { dto: BlogDTO; inputDto: Omit } + }>({ + Blog, + }) {} + const blogService = new BlogService(containerMock) + + expectTypeOf(blogService.updateBlogs).parameters.toEqualTypeOf< + | [Partial<{ title: string | undefined }>, ...rest: any[]] + | [ + ( + | Partial<{ title: string | undefined }>[] + | { + selector: Record + data: + | Partial<{ title: string | undefined }> + | Partial<{ title: string | undefined }>[] + } + | { + selector: Record + data: + | Partial<{ title: string | undefined }> + | Partial<{ title: string | undefined }>[] + }[] + ), + ...rest: any[] + ] + >() + expectTypeOf(blogService.createBlogs).returns.toEqualTypeOf< + Promise | Promise + >() + }) + }) +}) diff --git a/packages/core/utils/src/modules-sdk/types/medusa-service.ts b/packages/core/utils/src/modules-sdk/types/medusa-service.ts index 82a6eb04ab..635cb623a7 100644 --- a/packages/core/utils/src/modules-sdk/types/medusa-service.ts +++ b/packages/core/utils/src/modules-sdk/types/medusa-service.ts @@ -5,6 +5,7 @@ import { IDmlEntity, InferEntityType, Pluralize, + Prettify, RestoreReturn, SoftDeleteReturn, } from "@medusajs/types" @@ -29,6 +30,13 @@ export type ModelDTOConfig = { export type ModelsConfigTemplate = { [key: string]: ModelDTOConfig } +/** + * We do not want the DML DTO to accept auto-managed timestamps + * as part of the input for the "create" and the "update" + * methods + */ +type DMLDTOExcludeProperties = "created_at" | "updated_at" | "deleted_at" + export type ModelConfigurationsToConfigTemplate = { [Key in keyof T]: { dto: T[Key] extends DmlEntity @@ -36,6 +44,11 @@ export type ModelConfigurationsToConfigTemplate = { : T[Key] extends Constructor ? InstanceType : any + inputDto: T[Key] extends DmlEntity + ? Omit, DMLDTOExcludeProperties> + : T[Key] extends Constructor + ? InstanceType + : any model: T[Key] extends { model: infer MODEL } ? MODEL : T[Key] extends IDmlEntity @@ -83,6 +96,16 @@ export type ModelEntries = Record< | { name?: string; singular?: string; plural?: string } > +/** + * Returns the input DTO for the servide + */ +type GetServiceInput = + Partial< + [undefined] extends ModelConfig["inputDto"] + ? ModelConfig["dto"] + : ModelConfig["inputDto"] + > + export type ExtractKeysFromConfig = ModelsConfig extends { __empty: any } @@ -90,7 +113,7 @@ export type ExtractKeysFromConfig = ModelsConfig extends { : keyof ModelsConfig export type AbstractModuleService< - TModelsDtoConfig extends Record + TModelsDtoConfig extends Record > = { [TModelName in keyof TModelsDtoConfig as `retrieve${ExtractSingularName< TModelsDtoConfig, @@ -155,14 +178,41 @@ export type AbstractModuleService< TModelsDtoConfig, TModelName >}`]: { - (...args: any[]): Promise + ( + data: Prettify>, + ...rest: any[] + ): Promise + ( + data: Prettify>[], + ...rest: any[] + ): Promise } } & { [TModelName in keyof TModelsDtoConfig as `update${ExtractPluralName< TModelsDtoConfig, TModelName >}`]: { - (...args: any[]): Promise + ( + data: Prettify>, + ...rest: any[] + ): Promise + ( + dataOrOptions: + | Prettify>[] + | { + selector: Record + data: + | Prettify> + | Prettify>[] + } + | { + selector: Record + data: + | Prettify> + | Prettify>[] + }[], + ...rest: any[] + ): Promise } } diff --git a/packages/core/utils/src/product/events.ts b/packages/core/utils/src/product/events.ts index 379ca42e3a..9921a2ff65 100644 --- a/packages/core/utils/src/product/events.ts +++ b/packages/core/utils/src/product/events.ts @@ -5,6 +5,7 @@ const eventBaseNames: [ "product", "productVariant", "productOption", + "productOptionValue", "productType", "productTag", "productCategory", @@ -13,10 +14,11 @@ const eventBaseNames: [ "product", "productVariant", "productOption", + "productOptionValue", "productType", "productTag", "productCategory", - "productCollection" + "productCollection", ] export const ProductEvents = buildEventNamesFromEntityName( diff --git a/packages/modules/api-key/src/services/api-key-module-service.ts b/packages/modules/api-key/src/services/api-key-module-service.ts index baba804e31..e2819af497 100644 --- a/packages/modules/api-key/src/services/api-key-module-service.ts +++ b/packages/modules/api-key/src/services/api-key-module-service.ts @@ -104,12 +104,14 @@ export class ApiKeyModuleService data: ApiKeyTypes.CreateApiKeyDTO[], sharedContext?: Context ): Promise + //@ts-expect-error createApiKeys( data: ApiKeyTypes.CreateApiKeyDTO, sharedContext?: Context ): Promise @InjectManager() + //@ts-expect-error async createApiKeys( data: ApiKeyTypes.CreateApiKeyDTO | ApiKeyTypes.CreateApiKeyDTO[], @MedusaContext() sharedContext: Context = {} @@ -243,6 +245,7 @@ export class ApiKeyModuleService data: ApiKeyTypes.UpdateApiKeyDTO, sharedContext?: Context ): Promise + //@ts-expect-error async updateApiKeys( selector: FilterableApiKeyProps, data: ApiKeyTypes.UpdateApiKeyDTO, @@ -250,6 +253,7 @@ export class ApiKeyModuleService ): Promise @InjectManager() + //@ts-expect-error async updateApiKeys( idOrSelector: string | FilterableApiKeyProps, data: ApiKeyTypes.UpdateApiKeyDTO, diff --git a/packages/modules/auth/src/services/auth-module.ts b/packages/modules/auth/src/services/auth-module.ts index 95545d7eaa..d0af5f5a14 100644 --- a/packages/modules/auth/src/services/auth-module.ts +++ b/packages/modules/auth/src/services/auth-module.ts @@ -106,12 +106,14 @@ export default class AuthModuleService sharedContext?: Context ): Promise + // @ts-expect-error updateAuthIdentities( data: AuthTypes.UpdateAuthIdentityDTO, sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async updateAuthIdentities( data: AuthTypes.UpdateAuthIdentityDTO | AuthTypes.UpdateAuthIdentityDTO[], @MedusaContext() sharedContext: Context = {} @@ -151,12 +153,14 @@ export default class AuthModuleService sharedContext?: Context ): Promise + // @ts-expect-error createProviderIdentities( data: AuthTypes.CreateProviderIdentityDTO, sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async createProviderIdentities( data: | AuthTypes.CreateProviderIdentityDTO[] @@ -179,12 +183,14 @@ export default class AuthModuleService sharedContext?: Context ): Promise + // @ts-expect-error updateProviderIdentities( data: AuthTypes.UpdateProviderIdentityDTO, sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async updateProviderIdentities( data: | AuthTypes.UpdateProviderIdentityDTO diff --git a/packages/modules/cart/src/services/cart-module.ts b/packages/modules/cart/src/services/cart-module.ts index 25f155e0e8..46fbee69f1 100644 --- a/packages/modules/cart/src/services/cart-module.ts +++ b/packages/modules/cart/src/services/cart-module.ts @@ -258,12 +258,14 @@ export default class CartModuleService sharedContext?: Context ): Promise + // @ts-expect-error async createCarts( data: CartTypes.CreateCartDTO, sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async createCarts( data: CartTypes.CreateCartDTO[] | CartTypes.CreateCartDTO, @MedusaContext() sharedContext: Context = {} @@ -320,11 +322,13 @@ export default class CartModuleService async updateCarts( data: CartTypes.UpdateCartDTO[] ): Promise + // @ts-expect-error async updateCarts( cartId: string, data: CartTypes.UpdateCartDataDTO, sharedContext?: Context ): Promise + // @ts-expect-error async updateCarts( selector: Partial, data: CartTypes.UpdateCartDataDTO, @@ -332,6 +336,7 @@ export default class CartModuleService ): Promise @InjectManager() + // @ts-expect-error async updateCarts( dataOrIdOrSelector: | CartTypes.UpdateCartDTO[] @@ -393,6 +398,18 @@ export default class CartModuleService return result } + @InjectManager() + // @ts-expect-error + async updateShippingMethods( + data: CartTypes.UpdateShippingMethodDTO[], + sharedContext?: Context + ): Promise { + return super.updateShippingMethods( + data as unknown as CartTypes.CartShippingMethodDTO[], + sharedContext + ) as unknown as Promise + } + addLineItems( data: CartTypes.CreateLineItemForCartDTO ): Promise @@ -468,11 +485,13 @@ export default class CartModuleService updateLineItems( data: CartTypes.UpdateLineItemWithSelectorDTO[] ): Promise + // @ts-expect-error updateLineItems( selector: Partial, data: CartTypes.UpdateLineItemDTO, sharedContext?: Context ): Promise + // @ts-expect-error updateLineItems( lineItemId: string, data: Partial, @@ -480,6 +499,7 @@ export default class CartModuleService ): Promise @InjectManager() + // @ts-expect-error async updateLineItems( lineItemIdOrDataOrSelector: | string @@ -562,12 +582,14 @@ export default class CartModuleService data: CartTypes.CreateAddressDTO, sharedContext?: Context ): Promise + // @ts-expect-error async createAddresses( data: CartTypes.CreateAddressDTO[], sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async createAddresses( data: CartTypes.CreateAddressDTO[] | CartTypes.CreateAddressDTO, @MedusaContext() sharedContext: Context = {} @@ -599,12 +621,14 @@ export default class CartModuleService data: CartTypes.UpdateAddressDTO, sharedContext?: Context ): Promise + // @ts-expect-error async updateAddresses( data: CartTypes.UpdateAddressDTO[], sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async updateAddresses( data: CartTypes.UpdateAddressDTO[] | CartTypes.UpdateAddressDTO, @MedusaContext() sharedContext: Context = {} diff --git a/packages/modules/customer/src/services/customer-module.ts b/packages/modules/customer/src/services/customer-module.ts index 8e5f82c66d..000f393aec 100644 --- a/packages/modules/customer/src/services/customer-module.ts +++ b/packages/modules/customer/src/services/customer-module.ts @@ -162,11 +162,13 @@ export default class CustomerModuleService data: CustomerTypes.CustomerUpdatableFields, sharedContext?: Context ): Promise + // @ts-expect-error updateCustomers( customerIds: string[], data: CustomerTypes.CustomerUpdatableFields, sharedContext?: Context ): Promise + // @ts-expect-error updateCustomers( selector: CustomerTypes.FilterableCustomerProps, data: CustomerTypes.CustomerUpdatableFields, @@ -174,6 +176,7 @@ export default class CustomerModuleService ): Promise @InjectTransactionManager() + // @ts-expect-error async updateCustomers( idsOrSelector: string | string[] | CustomerTypes.FilterableCustomerProps, data: CustomerTypes.CustomerUpdatableFields, @@ -224,12 +227,14 @@ export default class CustomerModuleService sharedContext?: Context ): Promise + // @ts-expect-error async createCustomerGroups( dataOrArrayOfData: CustomerTypes.CreateCustomerGroupDTO[], sharedContext?: Context ): Promise @InjectTransactionManager() + // @ts-expect-error async createCustomerGroups( dataOrArrayOfData: | CustomerTypes.CreateCustomerGroupDTO @@ -254,11 +259,13 @@ export default class CustomerModuleService data: CustomerTypes.CustomerGroupUpdatableFields, sharedContext?: Context ): Promise + // @ts-expect-error async updateCustomerGroups( groupIds: string[], data: CustomerTypes.CustomerGroupUpdatableFields, sharedContext?: Context ): Promise + // @ts-expect-error async updateCustomerGroups( selector: CustomerTypes.FilterableCustomerGroupProps, data: CustomerTypes.CustomerGroupUpdatableFields, @@ -266,6 +273,7 @@ export default class CustomerModuleService ): Promise @InjectTransactionManager() + // @ts-expect-error async updateCustomerGroups( groupIdOrSelector: | string @@ -350,12 +358,14 @@ export default class CustomerModuleService addresses: CustomerTypes.CreateCustomerAddressDTO[], sharedContext?: Context ): Promise + // @ts-expect-error async createCustomerAddresses( address: CustomerTypes.CreateCustomerAddressDTO, sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async createCustomerAddresses( data: | CustomerTypes.CreateCustomerAddressDTO @@ -396,11 +406,13 @@ export default class CustomerModuleService data: CustomerTypes.UpdateCustomerAddressDTO, sharedContext?: Context ): Promise + // @ts-expect-error async updateCustomerAddresses( addressIds: string[], data: CustomerTypes.UpdateCustomerAddressDTO, sharedContext?: Context ): Promise + // @ts-expect-error async updateCustomerAddresses( selector: CustomerTypes.FilterableCustomerAddressProps, data: CustomerTypes.UpdateCustomerAddressDTO, @@ -408,6 +420,7 @@ export default class CustomerModuleService ): Promise @InjectTransactionManager() + // @ts-expect-error async updateCustomerAddresses( addressIdOrSelector: | string diff --git a/packages/modules/fulfillment/src/services/fulfillment-module-service.ts b/packages/modules/fulfillment/src/services/fulfillment-module-service.ts index 936aa337cf..6ef34ea304 100644 --- a/packages/modules/fulfillment/src/services/fulfillment-module-service.ts +++ b/packages/modules/fulfillment/src/services/fulfillment-module-service.ts @@ -279,6 +279,7 @@ export default class FulfillmentModuleService data: FulfillmentTypes.CreateFulfillmentSetDTO[], sharedContext?: Context ): Promise + // @ts-expect-error createFulfillmentSets( data: FulfillmentTypes.CreateFulfillmentSetDTO, sharedContext?: Context @@ -286,6 +287,7 @@ export default class FulfillmentModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async createFulfillmentSets( data: | FulfillmentTypes.CreateFulfillmentSetDTO @@ -349,6 +351,7 @@ export default class FulfillmentModuleService data: FulfillmentTypes.CreateServiceZoneDTO[], sharedContext?: Context ): Promise + // @ts-expect-error createServiceZones( data: FulfillmentTypes.CreateServiceZoneDTO, sharedContext?: Context @@ -356,6 +359,7 @@ export default class FulfillmentModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async createServiceZones( data: | FulfillmentTypes.CreateServiceZoneDTO[] @@ -413,6 +417,7 @@ export default class FulfillmentModuleService data: FulfillmentTypes.CreateShippingOptionDTO[], sharedContext?: Context ): Promise + // @ts-expect-error createShippingOptions( data: FulfillmentTypes.CreateShippingOptionDTO, sharedContext?: Context @@ -420,6 +425,7 @@ export default class FulfillmentModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async createShippingOptions( data: | FulfillmentTypes.CreateShippingOptionDTO[] @@ -474,6 +480,7 @@ export default class FulfillmentModuleService data: FulfillmentTypes.CreateShippingProfileDTO[], sharedContext?: Context ): Promise + // @ts-expect-error createShippingProfiles( data: FulfillmentTypes.CreateShippingProfileDTO, sharedContext?: Context @@ -481,6 +488,7 @@ export default class FulfillmentModuleService @InjectTransactionManager() @EmitEvents() + // @ts-expect-error async createShippingProfiles( data: | FulfillmentTypes.CreateShippingProfileDTO[] @@ -523,11 +531,12 @@ export default class FulfillmentModuleService return await this.shippingProfileService_.create(data_, sharedContext) } - // @ts-ignore + // @ts-expect-error createGeoZones( data: FulfillmentTypes.CreateGeoZoneDTO[], sharedContext?: Context ): Promise + // @ts-expect-error createGeoZones( data: FulfillmentTypes.CreateGeoZoneDTO, sharedContext?: Context @@ -535,6 +544,7 @@ export default class FulfillmentModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async createGeoZones( data: | FulfillmentTypes.CreateGeoZoneDTO @@ -560,11 +570,12 @@ export default class FulfillmentModuleService ) } - // @ts-ignore + // @ts-expect-error async createShippingOptionRules( data: FulfillmentTypes.CreateShippingOptionRuleDTO[], sharedContext?: Context ): Promise + // @ts-expect-error async createShippingOptionRules( data: FulfillmentTypes.CreateShippingOptionRuleDTO, sharedContext?: Context @@ -572,6 +583,7 @@ export default class FulfillmentModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async createShippingOptionRules( data: | FulfillmentTypes.CreateShippingOptionRuleDTO[] @@ -756,6 +768,7 @@ export default class FulfillmentModuleService data: FulfillmentTypes.UpdateFulfillmentSetDTO[], sharedContext?: Context ): Promise + // @ts-expect-error updateFulfillmentSets( data: FulfillmentTypes.UpdateFulfillmentSetDTO, sharedContext?: Context @@ -763,6 +776,7 @@ export default class FulfillmentModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async updateFulfillmentSets( data: UpdateFulfillmentSetDTO[] | UpdateFulfillmentSetDTO, @MedusaContext() sharedContext: Context = {} @@ -995,6 +1009,7 @@ export default class FulfillmentModuleService data: FulfillmentTypes.UpdateServiceZoneDTO, sharedContext?: Context ): Promise + // @ts-expect-error updateServiceZones( selector: FulfillmentTypes.FilterableServiceZoneProps, data: FulfillmentTypes.UpdateServiceZoneDTO, @@ -1003,6 +1018,7 @@ export default class FulfillmentModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async updateServiceZones( idOrSelector: string | FulfillmentTypes.FilterableServiceZoneProps, data: FulfillmentTypes.UpdateServiceZoneDTO, @@ -1299,6 +1315,7 @@ export default class FulfillmentModuleService data: FulfillmentTypes.UpdateShippingOptionDTO, sharedContext?: Context ): Promise + // @ts-expect-error updateShippingOptions( selector: FulfillmentTypes.FilterableShippingOptionProps, data: FulfillmentTypes.UpdateShippingOptionDTO, @@ -1307,6 +1324,7 @@ export default class FulfillmentModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async updateShippingOptions( idOrSelector: string | FulfillmentTypes.FilterableShippingOptionProps, data: FulfillmentTypes.UpdateShippingOptionDTO, @@ -1624,12 +1642,13 @@ export default class FulfillmentModuleService return [...created, ...updated] } - // @ts-ignore + // @ts-expect-error updateShippingProfiles( selector: FulfillmentTypes.FilterableShippingProfileProps, data: FulfillmentTypes.UpdateShippingProfileDTO, sharedContext?: Context ): Promise + // @ts-expect-error updateShippingProfiles( id: string, data: FulfillmentTypes.UpdateShippingProfileDTO, @@ -1637,6 +1656,7 @@ export default class FulfillmentModuleService ): Promise @InjectTransactionManager() + // @ts-expect-error async updateShippingProfiles( idOrSelector: string | FulfillmentTypes.FilterableShippingProfileProps, data: FulfillmentTypes.UpdateShippingProfileDTO, @@ -1728,11 +1748,12 @@ export default class FulfillmentModuleService return Array.isArray(data) ? allProfiles : allProfiles[0] } - // @ts-ignore + // @ts-expect-error updateGeoZones( data: FulfillmentTypes.UpdateGeoZoneDTO[], sharedContext?: Context ): Promise + // @ts-expect-error updateGeoZones( data: FulfillmentTypes.UpdateGeoZoneDTO, sharedContext?: Context @@ -1740,6 +1761,7 @@ export default class FulfillmentModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async updateGeoZones( data: | FulfillmentTypes.UpdateGeoZoneDTO @@ -1771,11 +1793,12 @@ export default class FulfillmentModuleService return Array.isArray(data) ? serialized : serialized[0] } - // @ts-ignore + // @ts-expect-error updateShippingOptionRules( data: FulfillmentTypes.UpdateShippingOptionRuleDTO[], sharedContext?: Context ): Promise + // @ts-expect-error updateShippingOptionRules( data: FulfillmentTypes.UpdateShippingOptionRuleDTO, sharedContext?: Context @@ -1783,6 +1806,7 @@ export default class FulfillmentModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async updateShippingOptionRules( data: | FulfillmentTypes.UpdateShippingOptionRuleDTO[] diff --git a/packages/modules/inventory/src/services/inventory-module.ts b/packages/modules/inventory/src/services/inventory-module.ts index 3fbac62d12..3d01ac3264 100644 --- a/packages/modules/inventory/src/services/inventory-module.ts +++ b/packages/modules/inventory/src/services/inventory-module.ts @@ -222,11 +222,12 @@ export default class InventoryModuleService }) } - // @ts-ignore + // @ts-expect-error async createReservationItems( input: InventoryTypes.CreateReservationItemInput[], context?: Context ): Promise + // @ts-expect-error async createReservationItems( input: InventoryTypes.CreateReservationItemInput, context?: Context @@ -234,6 +235,7 @@ export default class InventoryModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async createReservationItems( input: | InventoryTypes.CreateReservationItemInput[] @@ -380,6 +382,7 @@ export default class InventoryModuleService input: InventoryTypes.CreateInventoryLevelInput, context?: Context ): Promise + // @ts-expect-error createInventoryLevels( input: InventoryTypes.CreateInventoryLevelInput[], context?: Context @@ -387,6 +390,7 @@ export default class InventoryModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async createInventoryLevels( input: | InventoryTypes.CreateInventoryLevelInput[] @@ -434,6 +438,7 @@ export default class InventoryModuleService input: InventoryTypes.UpdateInventoryItemInput[], context?: Context ): Promise + // @ts-expect-error updateInventoryItems( input: InventoryTypes.UpdateInventoryItemInput, context?: Context @@ -441,6 +446,7 @@ export default class InventoryModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async updateInventoryItems( input: | InventoryTypes.UpdateInventoryItemInput @@ -549,6 +555,7 @@ export default class InventoryModuleService updates: InventoryTypes.UpdateInventoryLevelInput[], context?: Context ): Promise + // @ts-expect-error async updateInventoryLevels( updates: InventoryTypes.UpdateInventoryLevelInput, context?: Context @@ -556,6 +563,7 @@ export default class InventoryModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async updateInventoryLevels( updates: | InventoryTypes.UpdateInventoryLevelInput[] @@ -628,11 +636,12 @@ export default class InventoryModuleService * @param context * @return The updated inventory level */ - // @ts-ignore + // @ts-expect-error async updateReservationItems( input: InventoryTypes.UpdateReservationItemInput[], context?: Context ): Promise + // @ts-expect-error async updateReservationItems( input: InventoryTypes.UpdateReservationItemInput, context?: Context @@ -640,6 +649,7 @@ export default class InventoryModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async updateReservationItems( input: | InventoryTypes.UpdateReservationItemInput diff --git a/packages/modules/notification/src/services/notification-module-service.ts b/packages/modules/notification/src/services/notification-module-service.ts index 75ee656da7..ff1b2e91ac 100644 --- a/packages/modules/notification/src/services/notification-module-service.ts +++ b/packages/modules/notification/src/services/notification-module-service.ts @@ -63,6 +63,7 @@ export default class NotificationModuleService data: NotificationTypes.CreateNotificationDTO[], sharedContext?: Context ): Promise + // @ts-expect-error createNotifications( data: NotificationTypes.CreateNotificationDTO, sharedContext?: Context @@ -70,6 +71,7 @@ export default class NotificationModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async createNotifications( data: | NotificationTypes.CreateNotificationDTO diff --git a/packages/modules/order/src/services/order-module-service.ts b/packages/modules/order/src/services/order-module-service.ts index b1b084d465..6dcd7e61e6 100644 --- a/packages/modules/order/src/services/order-module-service.ts +++ b/packages/modules/order/src/services/order-module-service.ts @@ -663,13 +663,14 @@ export default class OrderModuleService data: OrderTypes.CreateOrderDTO[], sharedContext?: Context ): Promise - + // @ts-expect-error async createOrders( data: OrderTypes.CreateOrderDTO, sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async createOrders( data: OrderTypes.CreateOrderDTO[] | OrderTypes.CreateOrderDTO, @MedusaContext() sharedContext: Context = {} @@ -814,11 +815,13 @@ export default class OrderModuleService async updateOrders( data: OrderTypes.UpdateOrderDTO[] ): Promise + // @ts-expect-error async updateOrders( orderId: string, data: OrderTypes.UpdateOrderDTO, sharedContext?: Context ): Promise + // @ts-expect-error async updateOrders( selector: Partial, data: OrderTypes.UpdateOrderDTO, @@ -826,6 +829,7 @@ export default class OrderModuleService ): Promise @InjectManager() + // @ts-expect-error async updateOrders( dataOrIdOrSelector: | OrderTypes.UpdateOrderDTO[] @@ -891,9 +895,11 @@ export default class OrderModuleService createOrderLineItems( data: OrderTypes.CreateOrderLineItemForOrderDTO ): Promise + // @ts-expect-error createOrderLineItems( data: OrderTypes.CreateOrderLineItemForOrderDTO[] ): Promise + // @ts-expect-error createOrderLineItems( orderId: string, items: OrderTypes.CreateOrderLineItemDTO[], @@ -901,6 +907,7 @@ export default class OrderModuleService ): Promise @InjectManager() + // @ts-expect-error async createOrderLineItems( orderIdOrData: | string @@ -1012,11 +1019,13 @@ export default class OrderModuleService updateOrderLineItems( data: OrderTypes.UpdateOrderLineItemWithSelectorDTO[] ): Promise + // @ts-expect-error updateOrderLineItems( selector: Partial, data: OrderTypes.UpdateOrderLineItemDTO, sharedContext?: Context ): Promise + // @ts-expect-error updateOrderLineItems( lineItemId: string, data: Partial, @@ -1024,6 +1033,7 @@ export default class OrderModuleService ): Promise @InjectManager() + // @ts-expect-error async updateOrderLineItems( lineItemIdOrDataOrSelector: | string @@ -1229,13 +1239,15 @@ export default class OrderModuleService return await this.orderItemService_.update(toUpdate, sharedContext) } - // @ts-ignore + // @ts-expect-error async createOrderShippingMethods( data: OrderTypes.CreateOrderShippingMethodDTO ): Promise + // @ts-expect-error async createOrderShippingMethods( data: OrderTypes.CreateOrderShippingMethodDTO[] ): Promise + // @ts-expect-error async createOrderShippingMethods( orderId: string, methods: OrderTypes.CreateOrderShippingMethodDTO[], @@ -1243,6 +1255,7 @@ export default class OrderModuleService ): Promise @InjectManager() + // @ts-expect-error async createOrderShippingMethods( orderIdOrData: | string @@ -1394,9 +1407,11 @@ export default class OrderModuleService async createOrderLineItemAdjustments( adjustments: OrderTypes.CreateOrderLineItemAdjustmentDTO[] ): Promise + // @ts-expect-error async createOrderLineItemAdjustments( adjustment: OrderTypes.CreateOrderLineItemAdjustmentDTO ): Promise + // @ts-expect-error async createOrderLineItemAdjustments( orderId: string, adjustments: OrderTypes.CreateOrderLineItemAdjustmentDTO[], @@ -1404,6 +1419,7 @@ export default class OrderModuleService ): Promise @InjectTransactionManager() + // @ts-expect-error async createOrderLineItemAdjustments( orderIdOrData: | string @@ -1564,9 +1580,11 @@ export default class OrderModuleService async createOrderShippingMethodAdjustments( adjustments: OrderTypes.CreateOrderShippingMethodAdjustmentDTO[] ): Promise + // @ts-expect-error async createOrderShippingMethodAdjustments( adjustment: OrderTypes.CreateOrderShippingMethodAdjustmentDTO ): Promise + // @ts-expect-error async createOrderShippingMethodAdjustments( orderId: string, adjustments: OrderTypes.CreateOrderShippingMethodAdjustmentDTO[], @@ -1574,6 +1592,7 @@ export default class OrderModuleService ): Promise @InjectTransactionManager() + // @ts-expect-error async createOrderShippingMethodAdjustments( orderIdOrData: | string @@ -1643,9 +1662,11 @@ export default class OrderModuleService createOrderLineItemTaxLines( taxLines: OrderTypes.CreateOrderLineItemTaxLineDTO[] ): Promise + // @ts-expect-error createOrderLineItemTaxLines( taxLine: OrderTypes.CreateOrderLineItemTaxLineDTO ): Promise + // @ts-expect-error createOrderLineItemTaxLines( orderId: string, taxLines: @@ -1655,6 +1676,7 @@ export default class OrderModuleService ): Promise @InjectTransactionManager() + // @ts-expect-error async createOrderLineItemTaxLines( orderIdOrData: | string @@ -1754,9 +1776,11 @@ export default class OrderModuleService createOrderShippingMethodTaxLines( taxLines: OrderTypes.CreateOrderShippingMethodTaxLineDTO[] ): Promise + // @ts-expect-error createOrderShippingMethodTaxLines( taxLine: OrderTypes.CreateOrderShippingMethodTaxLineDTO ): Promise + // @ts-expect-error createOrderShippingMethodTaxLines( orderId: string, taxLines: @@ -1766,6 +1790,7 @@ export default class OrderModuleService ): Promise @InjectTransactionManager() + // @ts-expect-error async createOrderShippingMethodTaxLines( orderIdOrData: | string @@ -1870,12 +1895,14 @@ export default class OrderModuleService sharedContext?: Context ): Promise + // @ts-expect-error async createReturns( data: OrderTypes.CreateOrderReturnDTO[], sharedContext?: Context ): Promise @InjectTransactionManager() + // @ts-expect-error async createReturns( data: OrderTypes.CreateOrderReturnDTO | OrderTypes.CreateOrderReturnDTO[], @MedusaContext() sharedContext?: Context @@ -1900,12 +1927,14 @@ export default class OrderModuleService sharedContext?: Context ): Promise + // @ts-expect-error async createOrderClaims( data: OrderTypes.CreateOrderClaimDTO[], sharedContext?: Context ): Promise @InjectTransactionManager() + // @ts-expect-error async createOrderClaims( data: OrderTypes.CreateOrderClaimDTO | OrderTypes.CreateOrderClaimDTO[], @MedusaContext() sharedContext?: Context @@ -1930,12 +1959,14 @@ export default class OrderModuleService sharedContext?: Context ): Promise + // @ts-expect-error async createOrderExchanges( data: OrderTypes.CreateOrderExchangeDTO[], sharedContext?: Context ): Promise @InjectTransactionManager() + // @ts-expect-error async createOrderExchanges( data: | OrderTypes.CreateOrderExchangeDTO @@ -3537,12 +3568,13 @@ export default class OrderModuleService ) } - // @ts-ignore + // @ts-expect-error updateReturnReasons( id: string, data: UpdateOrderReturnReasonDTO, sharedContext?: Context ): Promise + // @ts-expect-error updateReturnReasons( selector: FilterableOrderReturnReasonProps, data: Partial, @@ -3550,6 +3582,7 @@ export default class OrderModuleService ): Promise @InjectManager() + // @ts-expect-error async updateReturnReasons( idOrSelector: string | FilterableOrderReturnReasonProps, data: UpdateOrderReturnReasonDTO, @@ -3652,4 +3685,16 @@ export default class OrderModuleService ): Promise { return await BundledActions.registerDelivery.bind(this)(data, sharedContext) } + + @InjectManager() + // @ts-expect-error + async createReturnItems( + data: OrderTypes.CreateOrderReturnItemDTO, + sharedContext?: Context + ): Promise { + return super.createReturnItems( + data as unknown as OrderTypes.OrderReturnItemDTO, + sharedContext + ) + } } diff --git a/packages/modules/payment/src/services/payment-module.ts b/packages/modules/payment/src/services/payment-module.ts index 4063883402..1056f03df7 100644 --- a/packages/modules/payment/src/services/payment-module.ts +++ b/packages/modules/payment/src/services/payment-module.ts @@ -151,17 +151,20 @@ export default class PaymentModuleService return joinerConfig } - // @ts-ignore + // @ts-expect-error createPaymentCollections( data: CreatePaymentCollectionDTO, sharedContext?: Context ): Promise + // @ts-expect-error createPaymentCollections( data: CreatePaymentCollectionDTO[], sharedContext?: Context ): Promise @InjectManager() + + // @ts-expect-error async createPaymentCollections( data: CreatePaymentCollectionDTO | CreatePaymentCollectionDTO[], @MedusaContext() sharedContext?: Context @@ -189,12 +192,13 @@ export default class PaymentModuleService return await this.paymentCollectionService_.create(data, sharedContext) } - // @ts-ignore + // @ts-expect-error updatePaymentCollections( paymentCollectionId: string, data: PaymentCollectionUpdatableFields, sharedContext?: Context ): Promise + // @ts-expect-error updatePaymentCollections( selector: FilterablePaymentCollectionProps, data: PaymentCollectionUpdatableFields, @@ -202,6 +206,7 @@ export default class PaymentModuleService ): Promise @InjectManager() + // @ts-expect-error async updatePaymentCollections( idOrSelector: string | FilterablePaymentCollectionProps, data: PaymentCollectionUpdatableFields, diff --git a/packages/modules/pricing/src/services/pricing-module.ts b/packages/modules/pricing/src/services/pricing-module.ts index 0b5d7ef3c6..2905da23d9 100644 --- a/packages/modules/pricing/src/services/pricing-module.ts +++ b/packages/modules/pricing/src/services/pricing-module.ts @@ -427,6 +427,7 @@ export default class PricingModuleService sharedContext?: Context ): Promise + // @ts-expect-error async createPriceSets( data: PricingTypes.CreatePriceSetDTO[], sharedContext?: Context @@ -434,6 +435,7 @@ export default class PricingModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async createPriceSets( data: PricingTypes.CreatePriceSetDTO | PricingTypes.CreatePriceSetDTO[], @MedusaContext() sharedContext: Context = {} @@ -503,6 +505,7 @@ export default class PricingModuleService data: PricingTypes.UpdatePriceSetDTO, sharedContext?: Context ): Promise + // @ts-expect-error async updatePriceSets( selector: PricingTypes.FilterablePriceSetProps, data: PricingTypes.UpdatePriceSetDTO, @@ -510,6 +513,7 @@ export default class PricingModuleService ): Promise @InjectManager() + // @ts-expect-error async updatePriceSets( idOrSelector: string | PricingTypes.FilterablePriceSetProps, data: PricingTypes.UpdatePriceSetDTO, @@ -885,6 +889,7 @@ export default class PricingModuleService data: PricingTypes.UpdatePricePreferenceDTO, sharedContext?: Context ): Promise + // @ts-expect-error async updatePricePreferences( selector: PricingTypes.FilterablePricePreferenceProps, data: PricingTypes.UpdatePricePreferenceDTO, @@ -892,6 +897,7 @@ export default class PricingModuleService ): Promise @InjectManager() + // @ts-expect-error async updatePricePreferences( idOrSelector: string | PricingTypes.FilterablePricePreferenceProps, data: PricingTypes.UpdatePricePreferenceDTO, diff --git a/packages/modules/product/src/services/product-module-service.ts b/packages/modules/product/src/services/product-module-service.ts index 4c8b0a7dad..71849e9885 100644 --- a/packages/modules/product/src/services/product-module-service.ts +++ b/packages/modules/product/src/services/product-module-service.ts @@ -1,6 +1,7 @@ import { Context, DAL, + FilterableProductOptionValueProps, FindConfig, IEventBusModuleService, InferEntityType, @@ -242,11 +243,12 @@ export default class ProductModuleService } } - // @ts-ignore + // @ts-expect-error createProductVariants( data: ProductTypes.CreateProductVariantDTO[], sharedContext?: Context ): Promise + // @ts-expect-error createProductVariants( data: ProductTypes.CreateProductVariantDTO, sharedContext?: Context @@ -254,6 +256,7 @@ export default class ProductModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async createProductVariants( data: | ProductTypes.CreateProductVariantDTO[] @@ -371,12 +374,13 @@ export default class ProductModuleService return Array.isArray(data) ? allVariants : allVariants[0] } - // @ts-ignore + // @ts-expect-error updateProductVariants( id: string, data: ProductTypes.UpdateProductVariantDTO, sharedContext?: Context ): Promise + // @ts-expect-error updateProductVariants( selector: ProductTypes.FilterableProductVariantProps, data: ProductTypes.UpdateProductVariantDTO, @@ -385,6 +389,7 @@ export default class ProductModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async updateProductVariants( idOrSelector: string | ProductTypes.FilterableProductVariantProps, data: ProductTypes.UpdateProductVariantDTO, @@ -503,11 +508,12 @@ export default class ProductModuleService return productVariants } - // @ts-ignore + // @ts-expect-error createProductTags( data: ProductTypes.CreateProductTagDTO[], sharedContext?: Context ): Promise + // @ts-expect-error createProductTags( data: ProductTypes.CreateProductTagDTO, sharedContext?: Context @@ -515,6 +521,7 @@ export default class ProductModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async createProductTags( data: ProductTypes.CreateProductTagDTO[] | ProductTypes.CreateProductTagDTO, @MedusaContext() sharedContext: Context = {} @@ -582,12 +589,13 @@ export default class ProductModuleService return Array.isArray(data) ? allTags : allTags[0] } - // @ts-ignore + // @ts-expect-error updateProductTags( id: string, data: ProductTypes.UpdateProductTagDTO, sharedContext?: Context ): Promise + // @ts-expect-error updateProductTags( selector: ProductTypes.FilterableProductTagProps, data: ProductTypes.UpdateProductTagDTO, @@ -596,6 +604,7 @@ export default class ProductModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async updateProductTags( idOrSelector: string | ProductTypes.FilterableProductTagProps, data: ProductTypes.UpdateProductTagDTO, @@ -636,17 +645,19 @@ export default class ProductModuleService return isString(idOrSelector) ? updatedTags[0] : updatedTags } - // @ts-ignore + // @ts-expect-error createProductTypes( data: ProductTypes.CreateProductTypeDTO[], sharedContext?: Context ): Promise + // @ts-expect-error createProductTypes( data: ProductTypes.CreateProductTypeDTO, sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async createProductTypes( data: | ProductTypes.CreateProductTypeDTO[] @@ -704,12 +715,13 @@ export default class ProductModuleService return Array.isArray(data) ? allTypes : allTypes[0] } - // @ts-ignore + // @ts-expect-error updateProductTypes( id: string, data: ProductTypes.UpdateProductTypeDTO, sharedContext?: Context ): Promise + // @ts-expect-error updateProductTypes( selector: ProductTypes.FilterableProductTypeProps, data: ProductTypes.UpdateProductTypeDTO, @@ -717,6 +729,7 @@ export default class ProductModuleService ): Promise @InjectManager() + // @ts-expect-error async updateProductTypes( idOrSelector: string | ProductTypes.FilterableProductTypeProps, data: ProductTypes.UpdateProductTypeDTO, @@ -752,17 +765,19 @@ export default class ProductModuleService return isString(idOrSelector) ? updatedTypes[0] : updatedTypes } - // @ts-ignore + // @ts-expect-error createProductOptions( data: ProductTypes.CreateProductOptionDTO[], sharedContext?: Context ): Promise + // @ts-expect-error createProductOptions( data: ProductTypes.CreateProductOptionDTO, sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async createProductOptions( data: | ProductTypes.CreateProductOptionDTO[] @@ -849,12 +864,13 @@ export default class ProductModuleService return Array.isArray(data) ? allOptions : allOptions[0] } - // @ts-ignore + // @ts-expect-error updateProductOptions( id: string, data: ProductTypes.UpdateProductOptionDTO, sharedContext?: Context ): Promise + // @ts-expect-error updateProductOptions( selector: ProductTypes.FilterableProductOptionProps, data: ProductTypes.UpdateProductOptionDTO, @@ -862,6 +878,7 @@ export default class ProductModuleService ): Promise @InjectManager() + // @ts-expect-error async updateProductOptions( idOrSelector: string | ProductTypes.FilterableProductOptionProps, data: ProductTypes.UpdateProductOptionDTO, @@ -966,11 +983,12 @@ export default class ProductModuleService return productOptions } - // @ts-ignore + // @ts-expect-error createProductCollections( data: ProductTypes.CreateProductCollectionDTO[], sharedContext?: Context ): Promise + // @ts-expect-error createProductCollections( data: ProductTypes.CreateProductCollectionDTO, sharedContext?: Context @@ -978,6 +996,7 @@ export default class ProductModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async createProductCollections( data: | ProductTypes.CreateProductCollectionDTO[] @@ -1084,12 +1103,13 @@ export default class ProductModuleService return Array.isArray(data) ? allCollections : allCollections[0] } - // @ts-ignore + // @ts-expect-error updateProductCollections( id: string, data: ProductTypes.UpdateProductCollectionDTO, sharedContext?: Context ): Promise + // @ts-expect-error updateProductCollections( selector: ProductTypes.FilterableProductCollectionProps, data: ProductTypes.UpdateProductCollectionDTO, @@ -1098,6 +1118,7 @@ export default class ProductModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async updateProductCollections( idOrSelector: string | ProductTypes.FilterableProductCollectionProps, data: ProductTypes.UpdateProductCollectionDTO, @@ -1216,11 +1237,12 @@ export default class ProductModuleService return collections } - // @ts-ignore + // @ts-expect-error createProductCategories( data: ProductTypes.CreateProductCategoryDTO[], sharedContext?: Context ): Promise + // @ts-expect-error createProductCategories( data: ProductTypes.CreateProductCategoryDTO, sharedContext?: Context @@ -1228,6 +1250,7 @@ export default class ProductModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async createProductCategories( data: | ProductTypes.CreateProductCategoryDTO[] @@ -1325,12 +1348,13 @@ export default class ProductModuleService return Array.isArray(data) ? result : result[0] } - // @ts-ignore + // @ts-expect-error updateProductCategories( id: string, data: ProductTypes.UpdateProductCategoryDTO, sharedContext?: Context ): Promise + // @ts-expect-error updateProductCategories( selector: ProductTypes.FilterableProductTypeProps, data: ProductTypes.UpdateProductCategoryDTO, @@ -1339,6 +1363,7 @@ export default class ProductModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async updateProductCategories( idOrSelector: string | ProductTypes.FilterableProductTypeProps, data: ProductTypes.UpdateProductCategoryDTO, @@ -1390,6 +1415,7 @@ export default class ProductModuleService data: ProductTypes.CreateProductDTO[], sharedContext?: Context ): Promise + // @ts-expect-error createProducts( data: ProductTypes.CreateProductDTO, sharedContext?: Context @@ -1397,6 +1423,7 @@ export default class ProductModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async createProducts( data: ProductTypes.CreateProductDTO[] | ProductTypes.CreateProductDTO, @MedusaContext() sharedContext: Context = {} @@ -1477,6 +1504,7 @@ export default class ProductModuleService data: ProductTypes.UpdateProductDTO, sharedContext?: Context ): Promise + // @ts-expect-error updateProducts( selector: ProductTypes.FilterableProductProps, data: ProductTypes.UpdateProductDTO, @@ -1485,6 +1513,7 @@ export default class ProductModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async updateProducts( idOrSelector: string | ProductTypes.FilterableProductProps, data: ProductTypes.UpdateProductDTO, @@ -1746,6 +1775,70 @@ export default class ProductModuleService return productData } + // @ts-expect-error + updateProductOptionValues( + idOrSelector: string, + data: ProductTypes.UpdateProductOptionValueDTO, + sharedContext?: Context + ): Promise + // @ts-expect-error + updateProductOptionValues( + selector: FilterableProductOptionValueProps, + data: ProductTypes.UpdateProductOptionValueDTO, + sharedContext?: Context + ): Promise + // @ts-expect-error + async updateProductOptionValues( + idOrSelector: string | FilterableProductOptionValueProps, + data: ProductTypes.UpdateProductOptionValueDTO, + sharedContext: Context = {} + ): Promise< + ProductTypes.ProductOptionValueDTO | ProductTypes.ProductOptionValueDTO[] + > { + let normalizedInput: ({ + id: string + } & ProductTypes.UpdateProductOptionValueDTO)[] = [] + if (isString(idOrSelector)) { + // This will throw if the product option value does not exist + await this.productOptionValueService_.retrieve( + idOrSelector, + {}, + sharedContext + ) + + normalizedInput = [{ id: idOrSelector, ...data }] + } else { + const productOptionValues = await this.productOptionValueService_.list( + idOrSelector, + {}, + sharedContext + ) + + normalizedInput = productOptionValues.map((product) => ({ + id: product.id, + ...data, + })) + } + + const productOptionValues = await super.updateProductOptionValues( + normalizedInput, + sharedContext + ) + + const updatedProductOptionValues = await this.baseRepository_.serialize< + ProductTypes.ProductOptionValueDTO[] + >(productOptionValues) + + eventBuilders.updatedProductOptionValue({ + data: updatedProductOptionValues, + sharedContext: sharedContext, + }) + + return isString(idOrSelector) + ? updatedProductOptionValues[0] + : updatedProductOptionValues + } + /** * Validates the manually provided handle value of the product * to be URL-safe diff --git a/packages/modules/product/src/utils/events.ts b/packages/modules/product/src/utils/events.ts index 0c3a445b58..dc91d7c417 100644 --- a/packages/modules/product/src/utils/events.ts +++ b/packages/modules/product/src/utils/events.ts @@ -132,4 +132,22 @@ export const eventBuilders = { object: "product_collection", eventName: ProductEvents.PRODUCT_COLLECTION_DELETED, }), + createdProductOptionValue: moduleEventBuilderFactory({ + source: Modules.PRODUCT, + action: CommonEvents.CREATED, + object: "product_option_value", + eventName: ProductEvents.PRODUCT_OPTION_VALUE_CREATED, + }), + updatedProductOptionValue: moduleEventBuilderFactory({ + source: Modules.PRODUCT, + action: CommonEvents.UPDATED, + object: "product_option_value", + eventName: ProductEvents.PRODUCT_OPTION_VALUE_UPDATED, + }), + deletedProductOptionValue: moduleEventBuilderFactory({ + source: Modules.PRODUCT, + action: CommonEvents.DELETED, + object: "product_option_value", + eventName: ProductEvents.PRODUCT_OPTION_VALUE_DELETED, + }), } diff --git a/packages/modules/promotion/src/services/promotion-module.ts b/packages/modules/promotion/src/services/promotion-module.ts index 3ff1b79250..3f65bab659 100644 --- a/packages/modules/promotion/src/services/promotion-module.ts +++ b/packages/modules/promotion/src/services/promotion-module.ts @@ -574,12 +574,14 @@ export default class PromotionModuleService sharedContext?: Context ): Promise + // @ts-expect-error async createPromotions( data: PromotionTypes.CreatePromotionDTO[], sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async createPromotions( data: | PromotionTypes.CreatePromotionDTO @@ -841,12 +843,14 @@ export default class PromotionModuleService sharedContext?: Context ): Promise + // @ts-expect-error async updatePromotions( data: PromotionTypes.UpdatePromotionDTO[], sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async updatePromotions( data: | PromotionTypes.UpdatePromotionDTO @@ -1295,18 +1299,20 @@ export default class PromotionModuleService ) } - // @ts-ignore + // @ts-expect-error async createCampaigns( data: PromotionTypes.CreateCampaignDTO, sharedContext?: Context ): Promise + // @ts-expect-error async createCampaigns( data: PromotionTypes.CreateCampaignDTO[], sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async createCampaigns( data: PromotionTypes.CreateCampaignDTO | PromotionTypes.CreateCampaignDTO[], @MedusaContext() sharedContext: Context = {} @@ -1404,18 +1410,20 @@ export default class PromotionModuleService } } - // @ts-ignore + // @ts-expect-error async updateCampaigns( data: PromotionTypes.UpdateCampaignDTO, sharedContext?: Context ): Promise + // @ts-expect-error async updateCampaigns( data: PromotionTypes.UpdateCampaignDTO[], sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async updateCampaigns( data: PromotionTypes.UpdateCampaignDTO | PromotionTypes.UpdateCampaignDTO[], @MedusaContext() sharedContext: Context = {} diff --git a/packages/modules/region/src/services/region-module.ts b/packages/modules/region/src/services/region-module.ts index 09f684dea2..2ec4a5eb3f 100644 --- a/packages/modules/region/src/services/region-module.ts +++ b/packages/modules/region/src/services/region-module.ts @@ -71,12 +71,14 @@ export default class RegionModuleService data: CreateRegionDTO[], sharedContext?: Context ): Promise + // @ts-expect-error async createRegions( data: CreateRegionDTO, sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async createRegions( data: CreateRegionDTO | CreateRegionDTO[], @MedusaContext() sharedContext: Context = {} @@ -130,7 +132,7 @@ export default class RegionModuleService } @InjectManager() - // @ts-ignore + // @ts-expect-error async softDeleteRegions( ids: string | object | string[] | object[], config?: SoftDeleteReturn, @@ -141,7 +143,7 @@ export default class RegionModuleService await super.updateCountries( { selector: { region_id: ids }, - data: { region_id: null }, + data: { region_id: null } as any, }, sharedContext ) @@ -192,6 +194,7 @@ export default class RegionModuleService data: UpdateRegionDTO, sharedContext?: Context ): Promise + // @ts-expect-error async updateRegions( selector: FilterableRegionProps, data: UpdateRegionDTO, @@ -199,6 +202,7 @@ export default class RegionModuleService ): Promise @InjectManager() + // @ts-expect-error async updateRegions( idOrSelector: string | FilterableRegionProps, data: UpdateRegionDTO, diff --git a/packages/modules/sales-channel/src/services/sales-channel-module.ts b/packages/modules/sales-channel/src/services/sales-channel-module.ts index 3e8bddba4c..6d60d1b88e 100644 --- a/packages/modules/sales-channel/src/services/sales-channel-module.ts +++ b/packages/modules/sales-channel/src/services/sales-channel-module.ts @@ -60,12 +60,14 @@ export default class SalesChannelModuleService data: CreateSalesChannelDTO[], sharedContext?: Context ): Promise + // @ts-expect-error async createSalesChannels( data: CreateSalesChannelDTO, sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async createSalesChannels( data: CreateSalesChannelDTO | CreateSalesChannelDTO[], @MedusaContext() sharedContext: Context = {} @@ -96,6 +98,7 @@ export default class SalesChannelModuleService data: UpdateSalesChannelDTO, sharedContext?: Context ): Promise + // @ts-expect-error async updateSalesChannels( selector: FilterableSalesChannelProps, data: UpdateSalesChannelDTO, @@ -103,6 +106,7 @@ export default class SalesChannelModuleService ): Promise @InjectManager() + // @ts-expect-error async updateSalesChannels( idOrSelector: string | FilterableSalesChannelProps, data: UpdateSalesChannelDTO | UpdateSalesChannelDTO[], diff --git a/packages/modules/stock-location/src/services/stock-location-module.ts b/packages/modules/stock-location/src/services/stock-location-module.ts index 0762f5993c..8e9487ad9e 100644 --- a/packages/modules/stock-location/src/services/stock-location-module.ts +++ b/packages/modules/stock-location/src/services/stock-location-module.ts @@ -81,12 +81,13 @@ export default class StockLocationModuleService data: CreateStockLocationInput, context: Context ): Promise + // @ts-expect-error createStockLocations( data: CreateStockLocationInput[], context: Context ): Promise - @InjectManager() + // @ts-expect-error async createStockLocations( data: CreateStockLocationInput | CreateStockLocationInput[], @MedusaContext() context: Context = {} @@ -172,6 +173,7 @@ export default class StockLocationModuleService input: UpdateStockLocationInput, context?: Context ): Promise + // @ts-expect-error updateStockLocations( selector: FilterableStockLocationProps, input: UpdateStockLocationInput, @@ -185,6 +187,7 @@ export default class StockLocationModuleService * @returns The updated stock location. */ @InjectManager() + // @ts-expect-error async updateStockLocations( idOrSelector: string | FilterableStockLocationProps, data: UpdateStockLocationInput | UpdateStockLocationInput[], @@ -229,12 +232,14 @@ export default class StockLocationModuleService data: StockLocationAddressInput & { id: string }, context?: Context ): Promise + // @ts-expect-error updateStockLocationAddresses( data: (StockLocationAddressInput & { id: string })[], context?: Context ): Promise @InjectManager() + // @ts-expect-error async updateStockLocationAddresses( data: | (StockLocationAddressInput & { id: string }) diff --git a/packages/modules/store/src/services/store-module-service.ts b/packages/modules/store/src/services/store-module-service.ts index c4654465bf..5a6221a0d3 100644 --- a/packages/modules/store/src/services/store-module-service.ts +++ b/packages/modules/store/src/services/store-module-service.ts @@ -54,11 +54,13 @@ export default class StoreModuleService data: StoreTypes.CreateStoreDTO[], sharedContext?: Context ): Promise + // @ts-expect-error async createStores( data: StoreTypes.CreateStoreDTO, sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async createStores( data: StoreTypes.CreateStoreDTO | StoreTypes.CreateStoreDTO[], @MedusaContext() sharedContext: Context = {} @@ -131,12 +133,14 @@ export default class StoreModuleService data: StoreTypes.UpdateStoreDTO, sharedContext?: Context ): Promise + // @ts-expect-error async updateStores( selector: StoreTypes.FilterableStoreProps, data: StoreTypes.UpdateStoreDTO, sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async updateStores( idOrSelector: string | StoreTypes.FilterableStoreProps, data: StoreTypes.UpdateStoreDTO, diff --git a/packages/modules/tax/src/services/tax-module-service.ts b/packages/modules/tax/src/services/tax-module-service.ts index 8412a28e7c..48a3c018b7 100644 --- a/packages/modules/tax/src/services/tax-module-service.ts +++ b/packages/modules/tax/src/services/tax-module-service.ts @@ -88,12 +88,14 @@ export default class TaxModuleService sharedContext?: Context ): Promise + // @ts-expect-error async createTaxRates( data: TaxTypes.CreateTaxRateDTO, sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async createTaxRates( data: TaxTypes.CreateTaxRateDTO[] | TaxTypes.CreateTaxRateDTO, @MedusaContext() sharedContext: Context = {} @@ -155,11 +157,13 @@ export default class TaxModuleService data: TaxTypes.UpdateTaxRateDTO, sharedContext?: Context ): Promise + // @ts-expect-error async updateTaxRates( ids: string[], data: TaxTypes.UpdateTaxRateDTO, sharedContext?: Context ): Promise + // @ts-expect-error async updateTaxRates( selector: TaxTypes.FilterableTaxRateProps, data: TaxTypes.UpdateTaxRateDTO, @@ -167,6 +171,7 @@ export default class TaxModuleService ): Promise @InjectManager() + // @ts-expect-error async updateTaxRates( selector: string | string[] | TaxTypes.FilterableTaxRateProps, data: TaxTypes.UpdateTaxRateDTO, @@ -296,12 +301,14 @@ export default class TaxModuleService sharedContext?: Context ): Promise + // @ts-expect-error createTaxRegions( data: TaxTypes.CreateTaxRegionDTO[], sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async createTaxRegions( data: TaxTypes.CreateTaxRegionDTO | TaxTypes.CreateTaxRegionDTO[], @MedusaContext() sharedContext: Context = {} @@ -347,17 +354,19 @@ export default class TaxModuleService ) } - // @ts-ignore + // @ts-expect-error createTaxRateRules( data: TaxTypes.CreateTaxRateRuleDTO, sharedContext?: Context ): Promise + // @ts-expect-error createTaxRateRules( data: TaxTypes.CreateTaxRateRuleDTO[], sharedContext?: Context ): Promise @InjectManager() + // @ts-expect-error async createTaxRateRules( data: TaxTypes.CreateTaxRateRuleDTO | TaxTypes.CreateTaxRateRuleDTO[], @MedusaContext() sharedContext: Context = {} diff --git a/packages/modules/user/src/services/user-module.ts b/packages/modules/user/src/services/user-module.ts index 2174748d41..31e880e549 100644 --- a/packages/modules/user/src/services/user-module.ts +++ b/packages/modules/user/src/services/user-module.ts @@ -170,6 +170,7 @@ export default class UserModuleService data: UserTypes.CreateUserDTO[], sharedContext?: Context ): Promise + // @ts-expect-error createUsers( data: UserTypes.CreateUserDTO, sharedContext?: Context @@ -177,6 +178,7 @@ export default class UserModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async createUsers( data: UserTypes.CreateUserDTO[] | UserTypes.CreateUserDTO, @MedusaContext() sharedContext: Context = {} @@ -210,6 +212,7 @@ export default class UserModuleService data: UserTypes.UpdateUserDTO[], sharedContext?: Context ): Promise + // @ts-expect-error updateUsers( data: UserTypes.UpdateUserDTO, sharedContext?: Context @@ -217,6 +220,7 @@ export default class UserModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async updateUsers( data: UserTypes.UpdateUserDTO | UserTypes.UpdateUserDTO[], @MedusaContext() sharedContext: Context = {} @@ -245,11 +249,12 @@ export default class UserModuleService return Array.isArray(data) ? serializedUsers : serializedUsers[0] } - // @ts-ignore + // @ts-expect-error createInvites( data: UserTypes.CreateInviteDTO[], sharedContext?: Context ): Promise + // @ts-expect-error createInvites( data: UserTypes.CreateInviteDTO, sharedContext?: Context @@ -257,6 +262,7 @@ export default class UserModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async createInvites( data: UserTypes.CreateInviteDTO[] | UserTypes.CreateInviteDTO, @MedusaContext() sharedContext: Context = {} @@ -332,6 +338,7 @@ export default class UserModuleService data: UserTypes.UpdateInviteDTO[], sharedContext?: Context ): Promise + // @ts-expect-error updateInvites( data: UserTypes.UpdateInviteDTO, sharedContext?: Context @@ -339,6 +346,7 @@ export default class UserModuleService @InjectManager() @EmitEvents() + // @ts-expect-error async updateInvites( data: UserTypes.UpdateInviteDTO | UserTypes.UpdateInviteDTO[], @MedusaContext() sharedContext: Context = {}