Skip to content

Commit 32bf2a7

Browse files
author
Gerald Baulig
committed
fix(solution): add direct product_id preference filter
1 parent d29da03 commit 32bf2a7

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/services/fulfillment_product.ts

+23-6
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,9 @@ export class FulfillmentProductService
485485
subject?: Subject,
486486
context?: any,
487487
): Promise<FulfillmentCourierListResponse> {
488+
const ids = [...new Set(
489+
query.preferences?.courier_ids?.map(id => id) ?? []
490+
).values()];
488491
const call = ReadRequest.fromPartial({
489492
filters: [
490493
{
@@ -494,13 +497,15 @@ export class FulfillmentProductService
494497
operation: Filter_Operation.in,
495498
value: query.shop_id
496499
},
497-
...(query.preferences?.courier_ids?.map(
498-
id => ({
500+
...(
501+
ids?.length ?
502+
[{
499503
field: '_key', // _key is faster
500-
operation: Filter_Operation.eq,
501-
value: id,
502-
})
503-
).filter(item => !!item) ?? [])
504+
operation: Filter_Operation.in,
505+
type: Filter_ValueType.ARRAY,
506+
value: JSON.stringify(ids),
507+
}] : []
508+
)
504509
],
505510
operator: FilterOp_Operator.and
506511
}
@@ -551,9 +556,21 @@ export class FulfillmentProductService
551556
throw this.operation_status_codes.COURIERS_NOT_FOUND;
552557
}
553558

559+
const ids = [...new Set(
560+
query.preferences?.courier_ids?.map(id => id) ?? []
561+
).values()];
554562
const call = ReadRequest.fromPartial({
555563
filters: [{
556564
filters: [
565+
...(
566+
ids?.length ?
567+
[{
568+
field: '_key', // _key is faster
569+
operation: Filter_Operation.in,
570+
type: Filter_ValueType.ARRAY,
571+
value: JSON.stringify(ids),
572+
}] : []
573+
),
557574
{
558575
field: 'courier_id',
559576
operation: Filter_Operation.in,

0 commit comments

Comments
 (0)