feat(fulfillment): Separate list and context rules validation (#6674)

**What**

- Add method to validate fulfillment option from the provider
- Separate list/list and count from context rules validation and add listShippingOptionsForContext

FIXES CORE-1861
This commit is contained in:
Adrien de Peretti
2024-03-15 13:25:51 +00:00
committed by GitHub
parent 1956dce80a
commit 3188e703b3
16 changed files with 1011 additions and 326 deletions
@@ -1,4 +1,7 @@
import { FulfillmentSetDTO } from "./fulfillment-set"
import {
FilterableFulfillmentSetProps,
FulfillmentSetDTO,
} from "./fulfillment-set"
import { FilterableGeoZoneProps, GeoZoneDTO } from "./geo-zone"
import { ShippingOptionDTO } from "./shipping-option"
import { BaseFilterable, OperatorMap } from "../../dal"
@@ -20,5 +23,6 @@ export interface FilterableServiceZoneProps
id?: string | string[] | OperatorMap<string | string[]>
name?: string | string[] | OperatorMap<string | string[]>
geo_zones?: FilterableGeoZoneProps
fulfillment_set?: FilterableFulfillmentSetProps
shipping_options?: any // TODO
}
@@ -39,9 +39,7 @@ export interface FilterableShippingOptionProps
extends BaseFilterable<FilterableShippingOptionProps> {
id?: string | string[] | OperatorMap<string | string[]>
name?: string | string[] | OperatorMap<string | string[]>
fulfillment_set_id?: string | string[] | OperatorMap<string | string[]>
shipping_profile_id?: string | string[] | OperatorMap<string | string[]>
fulfillment_set_type?: string | string[] | OperatorMap<string | string[]>
price_type?:
| ShippingOptionPriceType
| ShippingOptionPriceType[]
@@ -49,5 +47,22 @@ export interface FilterableShippingOptionProps
service_zone?: FilterableServiceZoneProps
shipping_option_type?: FilterableShippingOptionTypeProps
rules?: FilterableShippingOptionRuleProps
context?: Record<string, unknown>
}
export interface FilterableShippingOptionForContextProps
extends FilterableShippingOptionProps {
fulfillment_set_id?: string | string[] | OperatorMap<string | string[]>
fulfillment_set_type?: string | string[] | OperatorMap<string | string[]>
/**
* The address is a shortcut to filter through geo_zones
* and build opinionated validation and filtering around the geo_zones.
* For custom filtering you can go through the service_zone.geo_zones directly.
*/
address?: {
country_code?: string
province_code?: string
city?: string
postal_expression?: string
}
context?: Record<string, any>
}
@@ -18,11 +18,14 @@ export interface CreateProvinceGeoZoneDTO extends CreateGeoZoneBaseDTO {
export interface CreateCityGeoZoneDTO extends CreateGeoZoneBaseDTO {
type: "city"
province_code: string
city: string
}
export interface CreateZipGeoZoneDTO extends CreateGeoZoneBaseDTO {
type: "zip"
province_code: string
city: string
postal_expression: Record<string, any>
}
@@ -47,12 +50,15 @@ export interface UpdateProvinceGeoZoneDTO extends UpdateGeoZoneBaseDTO {
export interface UpdateCityGeoZoneDTO extends UpdateGeoZoneBaseDTO {
type: "city"
city: string
province_code?: string
city?: string
}
export interface UpdateZipGeoZoneDTO extends UpdateGeoZoneBaseDTO {
type: "zip"
postal_expression: Record<string, any>
province_code?: string
city?: string
postal_expression?: Record<string, any>
}
export type UpdateGeoZoneDTO =
+30 -2
View File
@@ -3,6 +3,7 @@ import {
FilterableFulfillmentSetProps,
FilterableGeoZoneProps,
FilterableServiceZoneProps,
FilterableShippingOptionForContextProps,
FilterableShippingOptionProps,
FilterableShippingOptionRuleProps,
FilterableShippingOptionTypeProps,
@@ -326,13 +327,24 @@ export interface IFulfillmentModuleService extends IModuleService {
sharedContext?: Context
): Promise<ShippingOptionDTO[]>
/**
* List and count shipping options
* List shipping options and eventually filter the result based on the context and their rules
* @param filters
* @param config
* @param sharedContext
*/
listShippingOptionsForContext(
filters: FilterableShippingOptionForContextProps,
config?: FindConfig<ShippingOptionDTO>,
sharedContext?: Context
): Promise<ShippingOptionDTO[]>
/**
* List and count shipping options without taking into account the context
* @param filters
* @param config
* @param sharedContext
*/
listAndCountShippingOptions(
filters?: FilterableShippingOptionProps,
filters?: Omit<FilterableShippingOptionProps, "context">,
config?: FindConfig<ShippingOptionDTO>,
sharedContext?: Context
): Promise<[ShippingOptionDTO[], number]>
@@ -664,4 +676,20 @@ export interface IFulfillmentModuleService extends IModuleService {
retrieveFulfillmentOptions(
providerId: string
): Promise<Record<string, unknown>[]>
/**
* Validate the given shipping option fulfillment option from the provided data
*/
validateFulfillmentOption(
providerId: string,
data: Record<string, unknown>
): Promise<boolean>
/**
* Validate if the given shipping option is valid for a given context
*/
validateShippingOption(
shippingOptionId: string,
context: Record<string, unknown>
): Promise<boolean>
}