Skip to content

Commit

Permalink
fix(solution): add direct product_id preference filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerald Baulig committed Nov 8, 2024
1 parent d29da03 commit 32bf2a7
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/services/fulfillment_product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,9 @@ export class FulfillmentProductService
subject?: Subject,
context?: any,
): Promise<FulfillmentCourierListResponse> {
const ids = [...new Set(
query.preferences?.courier_ids?.map(id => id) ?? []
).values()];
const call = ReadRequest.fromPartial({
filters: [
{
Expand All @@ -494,13 +497,15 @@ export class FulfillmentProductService
operation: Filter_Operation.in,
value: query.shop_id
},
...(query.preferences?.courier_ids?.map(
id => ({
...(
ids?.length ?
[{
field: '_key', // _key is faster
operation: Filter_Operation.eq,
value: id,
})
).filter(item => !!item) ?? [])
operation: Filter_Operation.in,
type: Filter_ValueType.ARRAY,
value: JSON.stringify(ids),
}] : []
)
],
operator: FilterOp_Operator.and
}
Expand Down Expand Up @@ -551,9 +556,21 @@ export class FulfillmentProductService
throw this.operation_status_codes.COURIERS_NOT_FOUND;
}

const ids = [...new Set(
query.preferences?.courier_ids?.map(id => id) ?? []
).values()];
const call = ReadRequest.fromPartial({
filters: [{
filters: [
...(
ids?.length ?
[{
field: '_key', // _key is faster
operation: Filter_Operation.in,
type: Filter_ValueType.ARRAY,
value: JSON.stringify(ids),
}] : []
),
{
field: 'courier_id',
operation: Filter_Operation.in,
Expand Down

0 comments on commit 32bf2a7

Please sign in to comment.