feat(fulfillment): implementation part 2 (#6408)
**What**
> [!NOTE]
> I can see this pr becoming huge, so I d like to get this partial one merged 👍
- Fixes shared connection usage (mikro orm compare the instance to its own package and therefore was resulting in not trully reusing the provided connection leading to exhausting the connection pool as multiple connections was created and end up not being all destroyed properly under the hood, discovered in my integration tests)
- Create shipping options method implementation
- DTO's definition and service interface update
- integration tests
- Re work of the indexes with new util update
- Test runner utils to remove a big chunk of the boilerplate of the packages integrations
FIXES CORE-1742
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Dictionary, FilterQuery, Order } from "./utils"
|
||||
import { Dictionary, FilterQuery, OperatorMap, Order } from "./utils"
|
||||
|
||||
export { FilterQuery, OperatorMap } from "./utils"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { FulfillmentSetDTO } from "./fulfillment-set"
|
||||
import { FilterableGeoZoneProps, GeoZoneDTO } from "./geo-zone"
|
||||
import { ShippingOptionDTO } from "./shipping-option"
|
||||
import { BaseFilterable } from "../../dal"
|
||||
import { BaseFilterable, OperatorMap } from "../../dal"
|
||||
|
||||
export interface ServiceZoneDTO {
|
||||
id: string
|
||||
@@ -17,8 +17,8 @@ export interface ServiceZoneDTO {
|
||||
|
||||
export interface FilterableServiceZoneProps
|
||||
extends BaseFilterable<FilterableServiceZoneProps> {
|
||||
id?: string | string[]
|
||||
name?: string | string[]
|
||||
id?: string | string[] | OperatorMap<string | string[]>
|
||||
name?: string | string[] | OperatorMap<string | string[]>
|
||||
geo_zones?: FilterableGeoZoneProps
|
||||
shipping_options?: any // TODO
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ShippingOptionDTO } from "./shipping-option"
|
||||
import { BaseFilterable } from "../../dal"
|
||||
import { BaseFilterable, OperatorMap } from "../../dal"
|
||||
|
||||
export interface ShippingOptionRuleDTO {
|
||||
id: string
|
||||
@@ -15,8 +15,8 @@ export interface ShippingOptionRuleDTO {
|
||||
|
||||
export interface FilterableShippingOptionRuleProps
|
||||
extends BaseFilterable<FilterableShippingOptionRuleProps> {
|
||||
id?: string | string[]
|
||||
attribute?: string | string[]
|
||||
operator?: string | string[]
|
||||
value?: string | string[]
|
||||
id?: string | string[] | OperatorMap<string | string[]>
|
||||
attribute?: string | string[] | OperatorMap<string | string[]>
|
||||
operator?: string | string[] | OperatorMap<string | string[]>
|
||||
value?: string | string[] | OperatorMap<string | string[]>
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ShippingOptionDTO } from "./shipping-option"
|
||||
import { BaseFilterable } from "../../dal"
|
||||
import { BaseFilterable, OperatorMap } from "../../dal"
|
||||
|
||||
export interface ShippingOptionTypeDTO {
|
||||
id: string
|
||||
@@ -15,8 +15,8 @@ export interface ShippingOptionTypeDTO {
|
||||
|
||||
export interface FilterableShippingOptionTypeProps
|
||||
extends BaseFilterable<FilterableShippingOptionTypeProps> {
|
||||
id?: string | string[]
|
||||
label?: string | string[]
|
||||
description?: string | string[]
|
||||
code?: string | string[]
|
||||
id?: string | string[] | OperatorMap<string | string[]>
|
||||
label?: string | string[] | OperatorMap<string | string[]>
|
||||
description?: string | string[] | OperatorMap<string | string[]>
|
||||
code?: string | string[] | OperatorMap<string | string[]>
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
FilterableShippingOptionRuleProps,
|
||||
ShippingOptionRuleDTO,
|
||||
} from "./shipping-option-rule"
|
||||
import { BaseFilterable } from "../../dal"
|
||||
import { BaseFilterable, OperatorMap } from "../../dal"
|
||||
|
||||
export type ShippingOptionPriceType = "calculated" | "flat"
|
||||
|
||||
@@ -35,9 +35,12 @@ export interface ShippingOptionDTO {
|
||||
|
||||
export interface FilterableShippingOptionProps
|
||||
extends BaseFilterable<FilterableShippingOptionProps> {
|
||||
id?: string | string[]
|
||||
name?: string | string[]
|
||||
price_type?: ShippingOptionPriceType | ShippingOptionPriceType[]
|
||||
id?: string | string[] | OperatorMap<string | string[]>
|
||||
name?: string | string[] | OperatorMap<string | string[]>
|
||||
price_type?:
|
||||
| ShippingOptionPriceType
|
||||
| ShippingOptionPriceType[]
|
||||
| OperatorMap<ShippingOptionPriceType | ShippingOptionPriceType[]>
|
||||
service_zone?: FilterableServiceZoneProps
|
||||
shipping_option_type?: FilterableShippingOptionTypeProps
|
||||
rules?: FilterableShippingOptionRuleProps
|
||||
|
||||
@@ -1,11 +1,24 @@
|
||||
import { ShippingOptionDTO } from "./shipping-option"
|
||||
import {
|
||||
FilterableShippingOptionProps,
|
||||
ShippingOptionDTO,
|
||||
} from "./shipping-option"
|
||||
import { BaseFilterable, OperatorMap } from "../../dal"
|
||||
|
||||
export interface ShippingProfileDTO {
|
||||
id: string
|
||||
name: string
|
||||
type: string
|
||||
metadata: Record<string, unknown> | null
|
||||
shipping_options: ShippingOptionDTO[]
|
||||
created_at: Date
|
||||
updated_at: Date
|
||||
deleted_at: Date | null
|
||||
}
|
||||
|
||||
export interface FilterableShippingProfileProps
|
||||
extends BaseFilterable<FilterableShippingProfileProps> {
|
||||
id?: string | string[] | OperatorMap<string | string[]>
|
||||
name?: string | string[] | OperatorMap<string | string[]>
|
||||
type?: string | string[] | OperatorMap<string | string[]>
|
||||
shipping_options?: FilterableShippingOptionProps
|
||||
}
|
||||
|
||||
@@ -7,21 +7,21 @@ interface CreateGeoZoneBaseDTO {
|
||||
metadata?: Record<string, any> | null
|
||||
}
|
||||
|
||||
interface CreateCountryGeoZoneDTO extends CreateGeoZoneBaseDTO {
|
||||
export interface CreateCountryGeoZoneDTO extends CreateGeoZoneBaseDTO {
|
||||
type: "country"
|
||||
}
|
||||
|
||||
interface CreateProvinceGeoZoneDTO extends CreateGeoZoneBaseDTO {
|
||||
export interface CreateProvinceGeoZoneDTO extends CreateGeoZoneBaseDTO {
|
||||
type: "province"
|
||||
province_code: string
|
||||
}
|
||||
|
||||
interface CreateCityGeoZoneDTO extends CreateGeoZoneBaseDTO {
|
||||
export interface CreateCityGeoZoneDTO extends CreateGeoZoneBaseDTO {
|
||||
type: "city"
|
||||
city: string
|
||||
}
|
||||
|
||||
interface CreateZipGeoZoneDTO extends CreateGeoZoneBaseDTO {
|
||||
export interface CreateZipGeoZoneDTO extends CreateGeoZoneBaseDTO {
|
||||
type: "zip"
|
||||
postal_expression: Record<string, any>
|
||||
}
|
||||
@@ -32,25 +32,25 @@ export type CreateGeoZoneDTO =
|
||||
| CreateCityGeoZoneDTO
|
||||
| CreateZipGeoZoneDTO
|
||||
|
||||
interface UpdateGeoZoneBaseDTO extends Partial<CreateGeoZoneBaseDTO> {
|
||||
export interface UpdateGeoZoneBaseDTO extends Partial<CreateGeoZoneBaseDTO> {
|
||||
id: string
|
||||
}
|
||||
|
||||
interface UpdateCountryGeoZoneDTO extends UpdateGeoZoneBaseDTO {
|
||||
export interface UpdateCountryGeoZoneDTO extends UpdateGeoZoneBaseDTO {
|
||||
type: "country"
|
||||
}
|
||||
|
||||
interface UpdateProvinceGeoZoneDTO extends UpdateGeoZoneBaseDTO {
|
||||
export interface UpdateProvinceGeoZoneDTO extends UpdateGeoZoneBaseDTO {
|
||||
type: "province"
|
||||
province_code: string
|
||||
}
|
||||
|
||||
interface UpdateCityGeoZoneDTO extends UpdateGeoZoneBaseDTO {
|
||||
export interface UpdateCityGeoZoneDTO extends UpdateGeoZoneBaseDTO {
|
||||
type: "city"
|
||||
city: string
|
||||
}
|
||||
|
||||
interface UpdateZipGeoZoneDTO extends UpdateGeoZoneBaseDTO {
|
||||
export interface UpdateZipGeoZoneDTO extends UpdateGeoZoneBaseDTO {
|
||||
type: "zip"
|
||||
postal_expression: Record<string, any>
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from "./shipping-profile"
|
||||
export * from "./shipping-option-type"
|
||||
export * from "./shipping-option-rule"
|
||||
export * from "./geo-zone"
|
||||
|
||||
@@ -1,13 +1,29 @@
|
||||
import { CreateGeoZoneDTO } from "./geo-zone"
|
||||
import {
|
||||
CreateCityGeoZoneDTO,
|
||||
CreateCountryGeoZoneDTO,
|
||||
CreateProvinceGeoZoneDTO,
|
||||
CreateZipGeoZoneDTO,
|
||||
} from "./geo-zone"
|
||||
|
||||
export interface CreateServiceZoneDTO {
|
||||
name: string
|
||||
fulfillment_set_id: string
|
||||
geo_zones?: Omit<CreateGeoZoneDTO, "service_zone_id">[]
|
||||
geo_zones?: (
|
||||
| Omit<CreateCountryGeoZoneDTO, "service_zone_id">
|
||||
| Omit<CreateProvinceGeoZoneDTO, "service_zone_id">
|
||||
| Omit<CreateCityGeoZoneDTO, "service_zone_id">
|
||||
| Omit<CreateZipGeoZoneDTO, "service_zone_id">
|
||||
)[]
|
||||
}
|
||||
|
||||
export interface UpdateServiceZoneDTO {
|
||||
id: string
|
||||
name?: string
|
||||
geo_zones?: (Omit<CreateGeoZoneDTO, "service_zone_id"> | { id: string })[]
|
||||
geo_zones?: (
|
||||
| Omit<CreateCountryGeoZoneDTO, "service_zone_id">
|
||||
| Omit<CreateProvinceGeoZoneDTO, "service_zone_id">
|
||||
| Omit<CreateCityGeoZoneDTO, "service_zone_id">
|
||||
| Omit<CreateZipGeoZoneDTO, "service_zone_id">
|
||||
| { id: string }
|
||||
)[]
|
||||
}
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
import {
|
||||
CreateShippingOptionTypeDTO,
|
||||
UpdateShippingOptionTypeDTO,
|
||||
} from "./shipping-option-type"
|
||||
import { CreateShippingOptionTypeDTO } from "./shipping-option-type"
|
||||
import { ShippingOptionPriceType } from "../common"
|
||||
import {
|
||||
CreateShippingOptionRuleDTO,
|
||||
UpdateShippingOptionRuleDTO,
|
||||
} from "./shipping-option-rule"
|
||||
import { CreateShippingOptionRuleDTO } from "./shipping-option-rule"
|
||||
|
||||
export interface CreateShippingOptionDTO {
|
||||
name: string
|
||||
@@ -26,12 +20,10 @@ export interface UpdateShippingOptionDTO {
|
||||
service_zone_id?: string
|
||||
shipping_profile_id?: string
|
||||
service_provider_id?: string
|
||||
type:
|
||||
| Omit<CreateShippingOptionTypeDTO, "shipping_option_id">
|
||||
| Omit<UpdateShippingOptionTypeDTO, "shipping_option_id">
|
||||
type: Omit<CreateShippingOptionTypeDTO, "shipping_option_id"> | { id: string }
|
||||
data?: Record<string, unknown> | null
|
||||
rules?: (
|
||||
| Omit<CreateShippingOptionRuleDTO, "shipping_option_id">
|
||||
| Omit<UpdateShippingOptionRuleDTO, "shipping_option_id">
|
||||
| { id: string }
|
||||
)[]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
export interface CreateShippingProfileDTO {
|
||||
name: string
|
||||
type?: string
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
|
||||
export interface UpdateShippingProfileDTO
|
||||
extends Partial<CreateShippingProfileDTO> {}
|
||||
@@ -4,10 +4,12 @@ import {
|
||||
FilterableGeoZoneProps,
|
||||
FilterableServiceZoneProps,
|
||||
FilterableShippingOptionProps,
|
||||
FilterableShippingProfileProps,
|
||||
FulfillmentSetDTO,
|
||||
GeoZoneDTO,
|
||||
ServiceZoneDTO,
|
||||
ShippingOptionDTO,
|
||||
ShippingProfileDTO,
|
||||
} from "./common"
|
||||
import { FindConfig } from "../common"
|
||||
import { Context } from "../shared-context"
|
||||
@@ -22,6 +24,7 @@ import {
|
||||
UpdateServiceZoneDTO,
|
||||
UpdateShippingOptionDTO,
|
||||
} from "./mutations"
|
||||
import { CreateShippingProfileDTO } from "./mutations/shipping-profile"
|
||||
|
||||
export interface IFulfillmentModuleService extends IModuleService {
|
||||
/**
|
||||
@@ -66,6 +69,21 @@ export interface IFulfillmentModuleService extends IModuleService {
|
||||
sharedContext?: Context
|
||||
): Promise<ShippingOptionDTO>
|
||||
|
||||
/**
|
||||
* Create a new shipping profile
|
||||
* @param data
|
||||
* @param sharedContext
|
||||
*/
|
||||
createShippingProfiles(
|
||||
data: CreateShippingProfileDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<ShippingProfileDTO[]>
|
||||
|
||||
createShippingProfiles(
|
||||
data: CreateShippingProfileDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<ShippingProfileDTO>
|
||||
|
||||
/**
|
||||
* Create a new geo zone
|
||||
* @param data
|
||||
@@ -122,6 +140,20 @@ export interface IFulfillmentModuleService extends IModuleService {
|
||||
sharedContext?: Context
|
||||
): Promise<ShippingOptionDTO>
|
||||
|
||||
/**
|
||||
* Update a shipping profile
|
||||
* @param data
|
||||
* @param sharedContext
|
||||
*/
|
||||
updateShippingProfiles(
|
||||
data: CreateShippingProfileDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<ShippingProfileDTO[]>
|
||||
updateShippingProfiles(
|
||||
data: CreateShippingProfileDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<ShippingProfileDTO>
|
||||
|
||||
/**
|
||||
* Update a geo zone
|
||||
* @param data
|
||||
@@ -160,6 +192,14 @@ export interface IFulfillmentModuleService extends IModuleService {
|
||||
deleteShippingOptions(ids: string[], sharedContext?: Context): Promise<void>
|
||||
deleteShippingOptions(id: string, sharedContext?: Context): Promise<void>
|
||||
|
||||
/**
|
||||
* Delete a shipping profile
|
||||
* @param ids
|
||||
* @param sharedContext
|
||||
*/
|
||||
deleteShippingProfiles(ids: string[], sharedContext?: Context): Promise<void>
|
||||
deleteShippingProfiles(id: string, sharedContext?: Context): Promise<void>
|
||||
|
||||
/**
|
||||
* Delete a geo zone
|
||||
* @param ids
|
||||
@@ -204,6 +244,18 @@ export interface IFulfillmentModuleService extends IModuleService {
|
||||
sharedContext?: Context
|
||||
): Promise<ShippingOptionDTO>
|
||||
|
||||
/**
|
||||
* Retrieve a shipping profile
|
||||
* @param id
|
||||
* @param config
|
||||
* @param sharedContext
|
||||
*/
|
||||
retrieveShippingProfile(
|
||||
id: string,
|
||||
config?: FindConfig<ShippingProfileDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<ShippingProfileDTO>
|
||||
|
||||
/**
|
||||
* Retrieve a geo zone
|
||||
* @param id
|
||||
@@ -252,6 +304,18 @@ export interface IFulfillmentModuleService extends IModuleService {
|
||||
sharedContext?: Context
|
||||
): Promise<ShippingOptionDTO[]>
|
||||
|
||||
/**
|
||||
* List shipping profiles
|
||||
* @param filters
|
||||
* @param config
|
||||
* @param sharedContext
|
||||
*/
|
||||
listShippingProfiles(
|
||||
filters?: FilterableShippingProfileProps,
|
||||
config?: FindConfig<ShippingProfileDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<ShippingProfileDTO[]>
|
||||
|
||||
/**
|
||||
* List geo zones
|
||||
* @param filters
|
||||
@@ -300,6 +364,18 @@ export interface IFulfillmentModuleService extends IModuleService {
|
||||
sharedContext?: Context
|
||||
): Promise<[ShippingOptionDTO[], number]>
|
||||
|
||||
/**
|
||||
* List and count shipping profiles
|
||||
* @param filters
|
||||
* @param config
|
||||
* @param sharedContext
|
||||
*/
|
||||
listAndCountShippingProfiles(
|
||||
filters?: FilterableShippingProfileProps,
|
||||
config?: FindConfig<ShippingProfileDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<[ShippingProfileDTO[], number]>
|
||||
|
||||
/**
|
||||
* List and count geo zones
|
||||
* @param filters
|
||||
@@ -348,6 +424,18 @@ export interface IFulfillmentModuleService extends IModuleService {
|
||||
sharedContext?: Context
|
||||
): Promise<Record<string, string[]> | void>
|
||||
|
||||
/**
|
||||
* Soft delete shipping profiles
|
||||
* @param shippingProfileIds
|
||||
* @param config
|
||||
* @param sharedContext
|
||||
*/
|
||||
softDeleteShippingProfiles<TReturnableLinkableKeys extends string = string>(
|
||||
shippingProfileIds: string[],
|
||||
config?: SoftDeleteReturn<TReturnableLinkableKeys>,
|
||||
sharedContext?: Context
|
||||
): Promise<Record<string, string[]> | void>
|
||||
|
||||
/**
|
||||
* Soft delete geo zones
|
||||
* @param geoZoneIds
|
||||
@@ -365,4 +453,6 @@ export interface IFulfillmentModuleService extends IModuleService {
|
||||
config?: RestoreReturn<TReturnableLinkableKeys>,
|
||||
sharedContext?: Context
|
||||
): Promise<Record<string, string[]> | void>
|
||||
|
||||
// TODO defined the other restore methods
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user