diff --git a/.changeset/angry-planets-wave.md b/.changeset/angry-planets-wave.md new file mode 100644 index 0000000000..4462f2d1b0 --- /dev/null +++ b/.changeset/angry-planets-wave.md @@ -0,0 +1,6 @@ +--- +"@medusajs/types": patch +--- + +feat(fulfillment): Init dtos work and module service interface + diff --git a/packages/fulfillment/src/models/fulfillment-label.ts b/packages/fulfillment/src/models/fulfillment-label.ts index 585e92b8ae..f770b5cf5c 100644 --- a/packages/fulfillment/src/models/fulfillment-label.ts +++ b/packages/fulfillment/src/models/fulfillment-label.ts @@ -28,14 +28,6 @@ const fulfillmentIdIndexStatement = createPsqlIndexStatementHelper({ where: "deleted_at IS NULL", }) -const providerIdIndexName = "IDX_fulfillment_label_provider_id" -const providerIdIndexStatement = createPsqlIndexStatementHelper({ - name: providerIdIndexName, - tableName: "fulfillment_label", - columns: "provider_id", - where: "deleted_at IS NULL", -}) - const deletedAtIndexName = "IDX_fulfillment_label_deleted_at" const deletedAtIndexStatement = createPsqlIndexStatementHelper({ name: deletedAtIndexName, @@ -66,13 +58,6 @@ export default class FulfillmentLabel { name: fulfillmentIdIndexName, expression: fulfillmentIdIndexStatement, }) - provider_id: string - - @Property({ columnType: "text" }) - @Index({ - name: providerIdIndexName, - expression: providerIdIndexStatement, - }) fulfillment_id: string @ManyToOne(() => Fulfillment) diff --git a/packages/fulfillment/src/models/shipping-option-type.ts b/packages/fulfillment/src/models/shipping-option-type.ts index be1b4438ed..bed46b6ffe 100644 --- a/packages/fulfillment/src/models/shipping-option-type.ts +++ b/packages/fulfillment/src/models/shipping-option-type.ts @@ -28,6 +28,14 @@ const deletedAtIndexStatement = createPsqlIndexStatementHelper({ where: "deleted_at IS NOT NULL", }) +const shippingOptionIdIndexName = "IDX_shipping_option_type_shipping_option_id" +const shippingOptionIdIndexStatement = createPsqlIndexStatementHelper({ + name: shippingOptionIdIndexName, + tableName: "shipping_option_type", + columns: "shipping_option_id", + where: "deleted_at IS NULL", +}) + @Entity() @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) export default class ShippingOptionType { @@ -42,6 +50,16 @@ export default class ShippingOptionType { @Property({ columnType: "text", nullable: true }) description: string | null = null + @Property({ columnType: "text" }) + code: string + + @Property({ columnType: "text" }) + @Index({ + name: shippingOptionIdIndexName, + expression: shippingOptionIdIndexStatement, + }) + shipping_option_id: string + @OneToOne(() => ShippingOption, (so) => so.shipping_option_type) shipping_option: ShippingOption diff --git a/packages/fulfillment/src/services/fulfillment-module-service.ts b/packages/fulfillment/src/services/fulfillment-module-service.ts index 0236198985..908de3fd3e 100644 --- a/packages/fulfillment/src/services/fulfillment-module-service.ts +++ b/packages/fulfillment/src/services/fulfillment-module-service.ts @@ -6,11 +6,14 @@ import { InternalModuleDeclaration, ModuleJoinerConfig, ModulesSdkTypes, + UpdateFulfillmentSetDTO, } from "@medusajs/types" import { InjectTransactionManager, ModulesSdkUtils } from "@medusajs/utils" import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config" -import { FulfillmentSet } from "@models" +import { FulfillmentSet, ServiceZone, ShippingOption } from "@models" + +const generateMethodForModels = [ServiceZone, ShippingOption] type InjectedDependencies = { baseRepository: DAL.RepositoryService @@ -22,9 +25,13 @@ export default class FulfillmentModuleService< > extends ModulesSdkUtils.abstractModuleServiceFactory< InjectedDependencies, - any, // TODO Create appropriate DTO - {} - >(FulfillmentSet, [], entityNameToLinkableKeysMap) + FulfillmentTypes.FulfillmentSetDTO, + { + FulfillmentSet: { dto: FulfillmentTypes.FulfillmentSetDTO } + ServiceZone: { dto: FulfillmentTypes.ServiceZoneDTO } + ShippingOption: { dto: FulfillmentTypes.ShippingOptionDTO } + } + >(FulfillmentSet, generateMethodForModels, entityNameToLinkableKeysMap) implements IFulfillmentModuleService { protected baseRepository_: DAL.RepositoryService @@ -45,47 +52,126 @@ export default class FulfillmentModuleService< } create( - data: any[], + data: FulfillmentTypes.CreateFulfillmentSetDTO[], sharedContext?: Context - ): Promise - + ): Promise create( - data: any, + data: FulfillmentTypes.CreateFulfillmentSetDTO, sharedContext?: Context - ): Promise + ): Promise - // TODO Implement the methods from the interface and change type @InjectTransactionManager("baseRepository_") async create( - data: any[] | any, + data: + | FulfillmentTypes.CreateFulfillmentSetDTO + | FulfillmentTypes.CreateFulfillmentSetDTO[], sharedContext?: Context ): Promise< - FulfillmentTypes.FulfillmentDTO | FulfillmentTypes.FulfillmentDTO[] + FulfillmentTypes.FulfillmentSetDTO | FulfillmentTypes.FulfillmentSetDTO[] > { - return await Promise.resolve( - [] as FulfillmentTypes.FulfillmentDTO[] | FulfillmentTypes.FulfillmentDTO - ) + return [] } - // TODO Implement the methods from the interface and change type - update( - data: any[], + createServiceZones( + data: FulfillmentTypes.CreateServiceZoneDTO[], sharedContext?: Context - ): Promise - update( - data: any, + ): Promise + createServiceZones( + data: FulfillmentTypes.CreateServiceZoneDTO, sharedContext?: Context - ): Promise + ): Promise + + @InjectTransactionManager("baseRepository_") + async createServiceZones( + data: + | FulfillmentTypes.CreateServiceZoneDTO[] + | FulfillmentTypes.CreateServiceZoneDTO, + sharedContext?: Context + ): Promise< + FulfillmentTypes.ServiceZoneDTO | FulfillmentTypes.ServiceZoneDTO[] + > { + return [] + } + + createShippingOptions( + data: FulfillmentTypes.CreateShippingOptionDTO[], + sharedContext?: Context + ): Promise + createShippingOptions( + data: FulfillmentTypes.CreateShippingOptionDTO, + sharedContext?: Context + ): Promise + + @InjectTransactionManager("baseRepository_") + async createShippingOptions( + data: + | FulfillmentTypes.CreateShippingOptionDTO[] + | FulfillmentTypes.CreateShippingOptionDTO, + sharedContext?: Context + ): Promise< + FulfillmentTypes.ShippingOptionDTO | FulfillmentTypes.ShippingOptionDTO[] + > { + return [] + } + + update( + data: FulfillmentTypes.UpdateFulfillmentSetDTO[], + sharedContext?: Context + ): Promise + update( + data: FulfillmentTypes.UpdateFulfillmentSetDTO, + sharedContext?: Context + ): Promise @InjectTransactionManager("baseRepository_") async update( - data: any, + data: UpdateFulfillmentSetDTO[] | UpdateFulfillmentSetDTO, sharedContext?: Context ): Promise< - FulfillmentTypes.FulfillmentDTO | FulfillmentTypes.FulfillmentDTO[] + FulfillmentTypes.FulfillmentSetDTO[] | FulfillmentTypes.FulfillmentSetDTO > { - return await Promise.resolve( - [] as FulfillmentTypes.FulfillmentDTO[] | FulfillmentTypes.FulfillmentDTO - ) + return [] + } + + updateServiceZones( + data: FulfillmentTypes.UpdateServiceZoneDTO[], + sharedContext?: Context + ): Promise + updateServiceZones( + data: FulfillmentTypes.UpdateServiceZoneDTO, + sharedContext?: Context + ): Promise + + @InjectTransactionManager("baseRepository_") + async updateServiceZones( + data: + | FulfillmentTypes.UpdateServiceZoneDTO[] + | FulfillmentTypes.UpdateServiceZoneDTO, + sharedContext?: Context + ): Promise< + FulfillmentTypes.ServiceZoneDTO[] | FulfillmentTypes.ServiceZoneDTO + > { + return [] + } + + updateShippingOptions( + data: FulfillmentTypes.UpdateShippingOptionDTO[], + sharedContext?: Context + ): Promise + updateShippingOptions( + data: FulfillmentTypes.UpdateShippingOptionDTO, + sharedContext?: Context + ): Promise + + @InjectTransactionManager("baseRepository_") + async updateShippingOptions( + data: + | FulfillmentTypes.UpdateShippingOptionDTO[] + | FulfillmentTypes.UpdateShippingOptionDTO, + sharedContext?: Context + ): Promise< + FulfillmentTypes.ShippingOptionDTO[] | FulfillmentTypes.ShippingOptionDTO + > { + return [] } } diff --git a/packages/types/src/fulfillment/common.ts b/packages/types/src/fulfillment/common.ts deleted file mode 100644 index 04b1cf5fbf..0000000000 --- a/packages/types/src/fulfillment/common.ts +++ /dev/null @@ -1,6 +0,0 @@ -export type GeoZoneType = "country" | "province" | "city" | "zip" - -export interface FulfillmentDTO { - id: string - name: string -} diff --git a/packages/types/src/fulfillment/common/address.ts b/packages/types/src/fulfillment/common/address.ts new file mode 100644 index 0000000000..9ca639e5c2 --- /dev/null +++ b/packages/types/src/fulfillment/common/address.ts @@ -0,0 +1,18 @@ +export interface FulfillmentAddressDTO { + id: string + fulfillment_id: string | null + company: string | null + first_name: string | null + last_name: string | null + address_1: string | null + address_2: string | null + city: string | null + country_code: string | null + province: string | null + postal_code: string | null + phone: string | null + metadata: Record | null + created_at: Date + updated_at: Date + deleted_at: Date | null +} diff --git a/packages/types/src/fulfillment/common/fulfillment-item.ts b/packages/types/src/fulfillment/common/fulfillment-item.ts new file mode 100644 index 0000000000..1c0d5a5114 --- /dev/null +++ b/packages/types/src/fulfillment/common/fulfillment-item.ts @@ -0,0 +1,16 @@ +import { FulfillmentDTO } from "./fulfillment" + +export interface FulfillmentItemDTO { + id: string + title: string + quantity: number + sku: string + barcode: string + line_item_id: string | null + inventory_item_id: string | null + fulfillment_id: string + fulfillment: FulfillmentDTO + created_at: Date + updated_at: Date + deleted_at: Date | null +} diff --git a/packages/types/src/fulfillment/common/fulfillment-label.ts b/packages/types/src/fulfillment/common/fulfillment-label.ts new file mode 100644 index 0000000000..914f7be2e6 --- /dev/null +++ b/packages/types/src/fulfillment/common/fulfillment-label.ts @@ -0,0 +1,13 @@ +import { FulfillmentDTO } from "./fulfillment" + +export interface FulfillmentLabelDTO { + id: string + tracking_number: string + tracking_url: string + label_url: string + fulfillment_id: string + fulfillment: FulfillmentDTO + created_at: Date + updated_at: Date + deleted_at: Date | null +} diff --git a/packages/types/src/fulfillment/common/fulfillment-set.ts b/packages/types/src/fulfillment/common/fulfillment-set.ts new file mode 100644 index 0000000000..0858768f55 --- /dev/null +++ b/packages/types/src/fulfillment/common/fulfillment-set.ts @@ -0,0 +1,21 @@ +import { FilterableServiceZoneProps, ServiceZoneDTO } from "./service-zone" +import { BaseFilterable } from "../../dal" + +export interface FulfillmentSetDTO { + id: string + name: string + type: string + metadata: Record | null + service_zones: ServiceZoneDTO[] + created_at: Date + updated_at: Date + deleted_at: Date | null +} + +export interface FilterableFulfillmentSetProps + extends BaseFilterable { + id?: string | string[] + name?: string | string[] + type?: string | string[] + service_zones?: FilterableServiceZoneProps +} diff --git a/packages/types/src/fulfillment/common/fulfillment.ts b/packages/types/src/fulfillment/common/fulfillment.ts new file mode 100644 index 0000000000..7e8966b899 --- /dev/null +++ b/packages/types/src/fulfillment/common/fulfillment.ts @@ -0,0 +1,26 @@ +import { ShippingOptionDTO } from "./shipping-option" +import { ServiceProviderDTO } from "./service-provider" +import { FulfillmentAddressDTO } from "./address" +import { FulfillmentItemDTO } from "./fulfillment-item" +import { FulfillmentLabelDTO } from "./fulfillment-label" + +export interface FulfillmentDTO { + id: string + location_id: string + packed_at: Date | null + shipped_at: Date | null + delivered_at: Date | null + canceled_at: Date | null + data: Record | null + provider_id: string + shipping_option_id: string | null + metadata: Record | null + shipping_option: ShippingOptionDTO | null + provider: ServiceProviderDTO + delivery_address: FulfillmentAddressDTO + items: FulfillmentItemDTO[] + labels: FulfillmentLabelDTO[] + created_at: Date + updated_at: Date + deleted_at: Date | null +} diff --git a/packages/types/src/fulfillment/common/geo-zone.ts b/packages/types/src/fulfillment/common/geo-zone.ts new file mode 100644 index 0000000000..4ee450e520 --- /dev/null +++ b/packages/types/src/fulfillment/common/geo-zone.ts @@ -0,0 +1,26 @@ +import { BaseFilterable } from "../../dal" + +export type GeoZoneType = "country" | "province" | "city" | "zip" + +export interface GeoZoneDTO { + id: string + type: GeoZoneType + country_code: string + province_code: string | null + city: string | null + postal_expression: Record | null + metadata: Record | null + created_at: Date + updated_at: Date + deleted_at: Date | null +} + +export interface FilterableGeoZoneProps + extends BaseFilterable { + id?: string | string[] + type?: GeoZoneType | GeoZoneType[] + country_code?: string | string[] + province_code?: string | string[] + city?: string | string[] + // postal_expression?: Record | Record[] // TODO: Add support for postal_expression filtering +} diff --git a/packages/types/src/fulfillment/common/index.ts b/packages/types/src/fulfillment/common/index.ts new file mode 100644 index 0000000000..dff878e31f --- /dev/null +++ b/packages/types/src/fulfillment/common/index.ts @@ -0,0 +1,12 @@ +export * from "./address" +export * from "./fulfillment-set" +export * from "./shipping-profile" +export * from "./shipping-option-rule" +export * from "./shipping-option" +export * from "./shipping-option-type" +export * from "./service-zone" +export * from "./geo-zone" +export * from "./service-provider" +export * from "./fulfillment" +export * from "./fulfillment-item" +export * from "./fulfillment-label" diff --git a/packages/types/src/fulfillment/common/service-provider.ts b/packages/types/src/fulfillment/common/service-provider.ts new file mode 100644 index 0000000000..2a9e7522a8 --- /dev/null +++ b/packages/types/src/fulfillment/common/service-provider.ts @@ -0,0 +1,11 @@ +import { ShippingOptionDTO } from "./shipping-option" + +export interface ServiceProviderDTO { + id: string + name: string + metadata: Record | null + shipping_options: ShippingOptionDTO[] + created_at: Date + updated_at: Date + deleted_at: Date | null +} diff --git a/packages/types/src/fulfillment/common/service-zone.ts b/packages/types/src/fulfillment/common/service-zone.ts new file mode 100644 index 0000000000..8dcb3076f0 --- /dev/null +++ b/packages/types/src/fulfillment/common/service-zone.ts @@ -0,0 +1,24 @@ +import { FulfillmentSetDTO } from "./fulfillment-set" +import { FilterableGeoZoneProps, GeoZoneDTO } from "./geo-zone" +import { ShippingOptionDTO } from "./shipping-option" +import { BaseFilterable } from "../../dal" + +export interface ServiceZoneDTO { + id: string + name: string + metadata: Record | null + fulfillment_sets: FulfillmentSetDTO[] + geo_zones: GeoZoneDTO[] + shipping_options: ShippingOptionDTO[] + created_at: Date + updated_at: Date + deleted_at: Date | null +} + +export interface FilterableServiceZoneProps + extends BaseFilterable { + id?: string | string[] + name?: string | string[] + geo_zones?: FilterableGeoZoneProps + shipping_options?: any // TODO +} diff --git a/packages/types/src/fulfillment/common/shipping-option-rule.ts b/packages/types/src/fulfillment/common/shipping-option-rule.ts new file mode 100644 index 0000000000..dff66b4ca1 --- /dev/null +++ b/packages/types/src/fulfillment/common/shipping-option-rule.ts @@ -0,0 +1,22 @@ +import { ShippingOptionDTO } from "./shipping-option" +import { BaseFilterable } from "../../dal" + +export interface ShippingOptionRuleDTO { + id: string + attribute: string + operator: string + value: { value: string | string[] } | null + shipping_option_id: string + shipping_option: ShippingOptionDTO + created_at: Date + updated_at: Date + deleted_at: Date | null +} + +export interface FilterableShippingOptionRuleProps + extends BaseFilterable { + id?: string | string[] + attribute?: string | string[] + operator?: string | string[] + value?: string | string[] +} diff --git a/packages/types/src/fulfillment/common/shipping-option-type.ts b/packages/types/src/fulfillment/common/shipping-option-type.ts new file mode 100644 index 0000000000..a2f86741c5 --- /dev/null +++ b/packages/types/src/fulfillment/common/shipping-option-type.ts @@ -0,0 +1,22 @@ +import { ShippingOptionDTO } from "./shipping-option" +import { BaseFilterable } from "../../dal" + +export interface ShippingOptionTypeDTO { + id: string + label: string + description: string + code: string + shipping_option_id: string + shipping_option: ShippingOptionDTO + created_at: Date + updated_at: Date + deleted_at: Date | null +} + +export interface FilterableShippingOptionTypeProps + extends BaseFilterable { + id?: string | string[] + label?: string | string[] + description?: string | string[] + code?: string | string[] +} diff --git a/packages/types/src/fulfillment/common/shipping-option.ts b/packages/types/src/fulfillment/common/shipping-option.ts new file mode 100644 index 0000000000..9243adfcae --- /dev/null +++ b/packages/types/src/fulfillment/common/shipping-option.ts @@ -0,0 +1,44 @@ +import { FilterableServiceZoneProps, ServiceZoneDTO } from "./service-zone" +import { ShippingProfileDTO } from "./shipping-profile" +import { ServiceProviderDTO } from "./service-provider" +import { + FilterableShippingOptionTypeProps, + ShippingOptionTypeDTO, +} from "./shipping-option-type" +import { + FilterableShippingOptionRuleProps, + ShippingOptionRuleDTO, +} from "./shipping-option-rule" +import { BaseFilterable } from "../../dal" + +export type ShippingOptionPriceType = "calculated" | "flat" + +export interface ShippingOptionDTO { + id: string + name: string + price_type: ShippingOptionPriceType + service_zone_id: string + shipping_profile_id: string + service_provider_id: string + shipping_option_type_id: string | null + data: Record | null + metadata: Record | null + service_zone: ServiceZoneDTO + shipping_profile: ShippingProfileDTO + service_provider: ServiceProviderDTO + shipping_option_type: ShippingOptionTypeDTO + rules: ShippingOptionRuleDTO[] + created_at: Date + updated_at: Date + deleted_at: Date | null +} + +export interface FilterableShippingOptionProps + extends BaseFilterable { + id?: string | string[] + name?: string | string[] + price_type?: ShippingOptionPriceType | ShippingOptionPriceType[] + service_zone?: FilterableServiceZoneProps + shipping_option_type?: FilterableShippingOptionTypeProps + rules?: FilterableShippingOptionRuleProps +} diff --git a/packages/types/src/fulfillment/common/shipping-profile.ts b/packages/types/src/fulfillment/common/shipping-profile.ts new file mode 100644 index 0000000000..3a2830e254 --- /dev/null +++ b/packages/types/src/fulfillment/common/shipping-profile.ts @@ -0,0 +1,11 @@ +import { ShippingOptionDTO } from "./shipping-option" + +export interface ShippingProfileDTO { + id: string + name: string + metadata: Record | null + shipping_options: ShippingOptionDTO[] + created_at: Date + updated_at: Date + deleted_at: Date | null +} diff --git a/packages/types/src/fulfillment/mutations.ts b/packages/types/src/fulfillment/mutations.ts deleted file mode 100644 index 336ce12bb9..0000000000 --- a/packages/types/src/fulfillment/mutations.ts +++ /dev/null @@ -1 +0,0 @@ -export {} diff --git a/packages/types/src/fulfillment/mutations/fulfillment-set.ts b/packages/types/src/fulfillment/mutations/fulfillment-set.ts new file mode 100644 index 0000000000..4c74f55481 --- /dev/null +++ b/packages/types/src/fulfillment/mutations/fulfillment-set.ts @@ -0,0 +1,12 @@ +import { CreateServiceZoneDTO } from "./service-zone" + +export interface CreateFulfillmentSetDTO { + name: string + type: string + service_zones: Omit[] +} + +export interface UpdateFulfillmentSetDTO + extends Partial { + id: string +} diff --git a/packages/types/src/fulfillment/mutations/geo-zone.ts b/packages/types/src/fulfillment/mutations/geo-zone.ts new file mode 100644 index 0000000000..9ffe572068 --- /dev/null +++ b/packages/types/src/fulfillment/mutations/geo-zone.ts @@ -0,0 +1,70 @@ +import { GeoZoneType } from "../common" + +interface CreateGeoZoneBaseDTO { + type: GeoZoneType + service_zone_id: string + country_code: string + metadata?: Record | null +} + +interface CreateCountryGeoZoneDTO extends CreateGeoZoneBaseDTO { + type: "country" + country_code: string +} + +interface CreateProvinceGeoZoneDTO extends CreateGeoZoneBaseDTO { + type: "province" + country_code: string + province_code: string +} + +interface CreateCityGeoZoneDTO extends CreateGeoZoneBaseDTO { + type: "city" + country_code: string + city: string +} + +interface CreateZipGeoZoneDTO extends CreateGeoZoneBaseDTO { + type: "zip" + country_code: string + postal_expression: Record +} + +export type CreateGeoZoneDTO = + | CreateCountryGeoZoneDTO + | CreateProvinceGeoZoneDTO + | CreateCityGeoZoneDTO + | CreateZipGeoZoneDTO + +interface UpdateGeoZoneBaseDTO extends Partial { + id: string +} + +interface UpdateCountryGeoZoneDTO extends UpdateGeoZoneBaseDTO { + type: "country" + country_code: string +} + +interface UpdateProvinceGeoZoneDTO extends UpdateGeoZoneBaseDTO { + type: "province" + country_code: string + province_code: string +} + +interface UpdateCityGeoZoneDTO extends UpdateGeoZoneBaseDTO { + type: "city" + country_code: string + city: string +} + +interface UpdateZipGeoZoneDTO extends UpdateGeoZoneBaseDTO { + type: "zip" + country_code: string + postal_expression: Record +} + +export type UpdateGeoZoneDTO = + | UpdateCountryGeoZoneDTO + | UpdateProvinceGeoZoneDTO + | UpdateCityGeoZoneDTO + | UpdateZipGeoZoneDTO diff --git a/packages/types/src/fulfillment/mutations/index.ts b/packages/types/src/fulfillment/mutations/index.ts new file mode 100644 index 0000000000..6f14b920ca --- /dev/null +++ b/packages/types/src/fulfillment/mutations/index.ts @@ -0,0 +1,6 @@ +export * from "./shipping-option-type" +export * from "./shipping-option-rule" +export * from "./geo-zone" +export * from "./service-zone" +export * from "./shipping-option" +export * from "./fulfillment-set" diff --git a/packages/types/src/fulfillment/mutations/service-zone.ts b/packages/types/src/fulfillment/mutations/service-zone.ts new file mode 100644 index 0000000000..0c436e6cfd --- /dev/null +++ b/packages/types/src/fulfillment/mutations/service-zone.ts @@ -0,0 +1,14 @@ +import { CreateGeoZoneDTO, UpdateGeoZoneDTO } from "./geo-zone" + +export interface CreateServiceZoneDTO { + fulfillment_set_id: string + name: string + geo_zones: ( + | Omit + | Omit + )[] +} + +export interface UpdateServiceZoneDTO extends Partial { + id: string +} diff --git a/packages/types/src/fulfillment/mutations/shipping-option-rule.ts b/packages/types/src/fulfillment/mutations/shipping-option-rule.ts new file mode 100644 index 0000000000..7fa40eacc9 --- /dev/null +++ b/packages/types/src/fulfillment/mutations/shipping-option-rule.ts @@ -0,0 +1,11 @@ +export interface CreateShippingOptionRuleDTO { + attribute: string + operator: string + value: string | string[] + shipping_option_id: string +} + +export interface UpdateShippingOptionRuleDTO + extends Partial { + id: string +} diff --git a/packages/types/src/fulfillment/mutations/shipping-option-type.ts b/packages/types/src/fulfillment/mutations/shipping-option-type.ts new file mode 100644 index 0000000000..ed882a31da --- /dev/null +++ b/packages/types/src/fulfillment/mutations/shipping-option-type.ts @@ -0,0 +1,11 @@ +export interface CreateShippingOptionTypeDTO { + label: string + description: string + code: string + shipping_option_id: string +} + +export interface UpdateShippingOptionTypeDTO + extends Partial { + id: string +} diff --git a/packages/types/src/fulfillment/mutations/shipping-option.ts b/packages/types/src/fulfillment/mutations/shipping-option.ts new file mode 100644 index 0000000000..d0967fb89b --- /dev/null +++ b/packages/types/src/fulfillment/mutations/shipping-option.ts @@ -0,0 +1,37 @@ +import { + CreateShippingOptionTypeDTO, + UpdateShippingOptionTypeDTO, +} from "./shipping-option-type" +import { ShippingOptionPriceType } from "../common" +import { + CreateShippingOptionRuleDTO, + UpdateShippingOptionRuleDTO, +} from "./shipping-option-rule" + +export interface CreateShippingOptionDTO { + name: string + price_type: ShippingOptionPriceType + service_zone_id: string + shipping_profile_id: string + service_provider_id: string + type: Omit + data?: Record | null + rules?: Omit[] +} + +export interface UpdateShippingOptionDTO { + id: string + name?: string + price_type?: ShippingOptionPriceType + service_zone_id?: string + shipping_profile_id?: string + service_provider_id?: string + type: + | Omit + | Omit + data?: Record | null + rules?: ( + | Omit + | Omit + )[] +} diff --git a/packages/types/src/fulfillment/service.ts b/packages/types/src/fulfillment/service.ts index da5cbfca6c..034f65b9cc 100644 --- a/packages/types/src/fulfillment/service.ts +++ b/packages/types/src/fulfillment/service.ts @@ -1,55 +1,277 @@ import { IModuleService } from "../modules-sdk" -import { FulfillmentDTO } from "./common" +import { + FilterableFulfillmentSetProps, + FilterableServiceZoneProps, + FilterableShippingOptionProps, + FulfillmentSetDTO, + ServiceZoneDTO, + ShippingOptionDTO, +} from "./common" import { FindConfig } from "../common" import { Context } from "../shared-context" import { RestoreReturn, SoftDeleteReturn } from "../dal" +import { + CreateFulfillmentSetDTO, + CreateServiceZoneDTO, + CreateShippingOptionDTO, + UpdateFulfillmentSetDTO, + UpdateServiceZoneDTO, + UpdateShippingOptionDTO, +} from "./mutations" export interface IFulfillmentModuleService extends IModuleService { + /** + * Create a new fulfillment set + * @param data + * @param sharedContext + */ create( - data: any[], // TODO Create appropriate DTO + data: CreateFulfillmentSetDTO[], sharedContext?: Context - ): Promise + ): Promise create( - data: any, // TODO Create appropriate DTO + data: CreateFulfillmentSetDTO, sharedContext?: Context - ): Promise + ): Promise - update( - data: any[], // TODO Create appropriate DTO + /** + * Create a new service zone + * @param data + * @param sharedContext + */ + createServiceZones( + data: CreateServiceZoneDTO[], sharedContext?: Context - ): Promise - update( - data: any, // TODO Create appropriate DTO + ): Promise + createServiceZones( + data: CreateServiceZoneDTO, sharedContext?: Context - ): Promise + ): Promise + /** + * Create a new shipping option + * @param data + * @param sharedContext + */ + createShippingOptions( + data: CreateShippingOptionDTO[], + sharedContext?: Context + ): Promise + createShippingOptions( + data: CreateShippingOptionDTO, + sharedContext?: Context + ): Promise + + /** + * Update a fulfillment set + * @param data + * @param sharedContext + */ + update( + data: UpdateFulfillmentSetDTO[], + sharedContext?: Context + ): Promise + update( + data: UpdateFulfillmentSetDTO, + sharedContext?: Context + ): Promise + + /** + * Update a service zone + * @param data + * @param sharedContext + */ + updateServiceZones( + data: UpdateServiceZoneDTO[], + sharedContext?: Context + ): Promise + updateServiceZones( + data: UpdateServiceZoneDTO, + sharedContext?: Context + ): Promise + + /** + * Update a shipping option + * @param data + * @param sharedContext + */ + updateShippingOptions( + data: UpdateShippingOptionDTO[], + sharedContext?: Context + ): Promise + updateShippingOptions( + data: UpdateShippingOptionDTO, + sharedContext?: Context + ): Promise + + /** + * Delete a fulfillment set + * @param ids + * @param sharedContext + */ delete(ids: string[], sharedContext?: Context): Promise delete(id: string, sharedContext?: Context): Promise + /** + * Delete a service zone + * @param ids + * @param sharedContext + */ + deleteServiceZones(ids: string[], sharedContext?: Context): Promise + deleteServiceZones(id: string, sharedContext?: Context): Promise + + /** + * Delete a shippingOption + * @param ids + * @param sharedContext + */ + deleteShippingOptions(ids: string[], sharedContext?: Context): Promise + deleteShippingOptions(id: string, sharedContext?: Context): Promise + + /** + * Retrieve a fulfillment set + * @param id + * @param config + * @param sharedContext + */ retrieve( id: string, - config?: FindConfig, + config?: FindConfig, sharedContext?: Context - ): Promise + ): Promise + /** + * Retrieve a service zone + * @param id + * @param config + * @param sharedContext + */ + retrieveServiceZone( + id: string, + config?: FindConfig, + sharedContext?: Context + ): Promise + + /** + * Retrieve a shipping option + * @param id + * @param config + * @param sharedContext + */ + retrieveShippingOption( + id: string, + config?: FindConfig, + sharedContext?: Context + ): Promise + + /** + * List fulfillment sets + * @param filters + * @param config + * @param sharedContext + */ list( - filters?: any, // TODO Create appropriate filter type - config?: FindConfig, + filters?: FilterableFulfillmentSetProps, + config?: FindConfig, sharedContext?: Context - ): Promise + ): Promise + /** + * List service zones + * @param filters + * @param config + * @param sharedContext + */ + listServiceZones( + filters?: FilterableServiceZoneProps, + config?: FindConfig, + sharedContext?: Context + ): Promise + + /** + * List shipping options + * @param filters + * @param config + * @param sharedContext + */ + listShippingOptions( + filters?: FilterableShippingOptionProps, + config?: FindConfig, + sharedContext?: Context + ): Promise + + /** + * List and count fulfillment sets + * @param filters + * @param config + * @param sharedContext + */ listAndCount( - filters?: any, // TODO Create appropriate filter type - config?: FindConfig, + filters?: FilterableFulfillmentSetProps, + config?: FindConfig, sharedContext?: Context - ): Promise<[FulfillmentDTO[], number]> + ): Promise<[FulfillmentSetDTO[], number]> + /** + * List and count service zones + * @param filters + * @param config + * @param sharedContext + */ + listAndCountServiceZones( + filters?: FilterableServiceZoneProps, + config?: FindConfig, + sharedContext?: Context + ): Promise<[ServiceZoneDTO[], number]> + + /** + * List and count shipping options + * @param filters + * @param config + * @param sharedContext + */ + listAndCountShippingOptions( + filters?: FilterableShippingOptionProps, + config?: FindConfig, + sharedContext?: Context + ): Promise<[ShippingOptionDTO[], number]> + + /** + * Soft delete fulfillment sets + * @param fulfillmentIds + * @param config + * @param sharedContext + */ softDelete( fulfillmentIds: string[], config?: SoftDeleteReturn, sharedContext?: Context ): Promise | void> + /** + * Soft delete service zones + * @param serviceZoneIds + * @param config + * @param sharedContext + */ + softDeleteServiceZones( + serviceZoneIds: string[], + config?: SoftDeleteReturn, + sharedContext?: Context + ): Promise | void> + + /** + * Soft delete shipping options + * @param shippingOptionsIds + * @param config + * @param sharedContext + */ + softDeleteShippingOptions( + shippingOptionsIds: string[], + config?: SoftDeleteReturn, + sharedContext?: Context + ): Promise | void> + restore( fulfillmentIds: string[], config?: RestoreReturn,