Skip to content

Commit

Permalink
fix(lint): solve all lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerald Baulig committed Nov 15, 2024
1 parent c816cfe commit 804a240
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 55 deletions.
98 changes: 55 additions & 43 deletions src/services/fulfillment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ import {
createOperationStatusCode,
ResponseMap,
Courier,
unique,
} from './../utils.js';
import { Stub } from './../stub.js';

Expand Down Expand Up @@ -596,12 +597,12 @@ export class FulfillmentService
...Object.values(address_map).map(
item => item.payload?.country_id
),
...fulfillments?.map(
...(fulfillments?.map(
item => item.packaging?.sender?.address?.country_id
),
...fulfillments?.map(
) ?? []),
...(fulfillments?.map(
item => item.packaging?.recipient?.address?.country_id
),
) ?? []),
],
this.country_service,
this.tech_user ?? subject,
Expand Down Expand Up @@ -775,15 +776,18 @@ export class FulfillmentService
'Courier'
);

couriers.every(
courier => courier.payload?.shop_ids?.includes(
item.shop_id
if (!couriers.every(
courier => courier.payload?.shop_ids?.includes(
item.shop_id
)
)
) || throwStatusCode<any>(
'Fulfillment',
item.id,
this.status_codes.SHOP_ID_NOT_IDENTICAL,
);
) {
throwStatusCode<any>(
'Fulfillment',
item.id,
this.status_codes.SHOP_ID_NOT_IDENTICAL,
);
}

const credentials = await this.getByIds(
credential_map,
Expand All @@ -798,8 +802,8 @@ export class FulfillmentService
const status: Status[] = [
sender_country?.status,
recipient_country?.status,
...products?.map(p => p?.status),
...couriers?.map(c => c?.status),
...(products?.map(p => p?.status) ?? []),
...(couriers?.map(c => c?.status) ?? []),
];

const shop_country = await this.getById(
Expand Down Expand Up @@ -897,10 +901,12 @@ export class FulfillmentService
const variant = product.variants.find(
v => v.id === p.variant_id
);
variant.attributes = [
...(variant.attributes ?? []),
...(product.attributes ?? []),
];
variant.attributes = unique(
[
...(product.attributes ?? []),
...(variant.attributes ?? []),
]
);
const courier = courier_map[product.courier_id]?.payload;
const stub = Stub.getInstance(courier);
const taxes = product.tax_ids.map(
Expand Down Expand Up @@ -1169,18 +1175,21 @@ export class FulfillmentService
subject: request.subject
}, context);

upsert_results.items.forEach(item => {
if (this.emitters && item.payload.fulfillment_state in this.emitters) {
switch (item.payload.fulfillment_state) {
case FulfillmentState.INVALID:
case FulfillmentState.FAILED:
this.isEventsEnabled && this.topic?.emit(this.emitters[item.payload.fulfillment_state], item);
default:
this.isEventsEnabled && this.topic?.emit(this.emitters[item.payload.fulfillment_state], item.payload);
break;
if (this.isEventsEnabled) {
upsert_results.items.forEach(item => {
if (this.emitters && item.payload.fulfillment_state in this.emitters) {
switch (item.payload.fulfillment_state) {
case FulfillmentState.INVALID:
case FulfillmentState.FAILED:
this.topic?.emit(this.emitters[item.payload.fulfillment_state], item);
break;
default:
this.topic?.emit(this.emitters[item.payload.fulfillment_state], item.payload);
break;
}
}
}
});
});
}

upsert_results.items.push(
...merged.filter(item => item.payload?.labels?.length === 0)
Expand Down Expand Up @@ -1321,17 +1330,17 @@ export class FulfillmentService
context
)
).then(
updates => updates.items.forEach(
updates => this.isEventsEnabled && updates.items.forEach(
item => {
response_map[item.payload?.id ?? item.status?.id] = item;
if (this.emitters && item.payload.fulfillment_state in this.emitters) {
switch (item.payload.fulfillment_state) {
case FulfillmentState.INVALID:
case FulfillmentState.FAILED:
this.isEventsEnabled && this.topic?.emit(this.emitters[item.payload.fulfillment_state], item);
this.topic?.emit(this.emitters[item.payload.fulfillment_state], item);
break;
default:
this.isEventsEnabled && this.topic?.emit(this.emitters[item.payload.fulfillment_state], item.payload);
this.topic?.emit(this.emitters[item.payload.fulfillment_state], item.payload);
break;
}
}
Expand Down Expand Up @@ -1465,18 +1474,21 @@ export class FulfillmentService
subject: request.subject
}, context);

update_results.items.forEach(item => {
if (this.emitters && item.payload.fulfillment_state in this.emitters) {
switch (item.payload.fulfillment_state) {
case FulfillmentState.INVALID:
case FulfillmentState.FAILED:
this.isEventsEnabled && this.topic?.emit(this.emitters[item.payload.fulfillment_state], item);
default:
this.isEventsEnabled && this.topic?.emit(this.emitters[item.payload.fulfillment_state], item.payload);
break;
if (this.isEventsEnabled) {
update_results.items.forEach(item => {
if (this.emitters && item.payload.fulfillment_state in this.emitters) {
switch (item.payload.fulfillment_state) {
case FulfillmentState.INVALID:
case FulfillmentState.FAILED:
this.topic?.emit(this.emitters[item.payload.fulfillment_state], item);
break;
default:
this.topic?.emit(this.emitters[item.payload.fulfillment_state], item.payload);
break;
}
}
}
});
});
}

update_results.items.push(
...items.filter(i => i.status?.code !== 200)
Expand Down
14 changes: 8 additions & 6 deletions src/services/fulfillment_product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ const countItems = (goods: Item[], container: Container) => {
container.getLevels().forEach((level) =>
level.forEach((a) => {
const item = item_map.get(a.getBox().getName());
item && (item.quantity += 1);
if (item) {
item.quantity += 1
}
})
);
return [...item_map.values()];
Expand Down Expand Up @@ -412,7 +414,7 @@ export class FulfillmentProductService
if (response.operation_status?.code === 200) {
return response.items?.reduce(
(a: ResponseMap<T>, b: Response<T>) => {
a[b.payload?.id!] = b;
a[b.payload?.id] = b;
return a;
},
{}
Expand Down Expand Up @@ -868,7 +870,7 @@ export class FulfillmentProductService
).then(
response => response.items.reduce(
(a: ResponseMap<FulfillmentProduct>, b) => {
a[b.payload?.id ?? b.status?.id!] = b;
a[b.payload?.id ?? b.status?.id] = b;
return a;
},
{} as ResponseMap<FulfillmentProduct>
Expand Down Expand Up @@ -959,11 +961,11 @@ export class FulfillmentProductService
shipping: null
});

const courier_ids = new Set<string>();
const solutions: FulfillmentSolution[] = offer_lists.map(
offers => packer.canFit(offers, goods)
).map(
containers => {
const courier_ids = new Set<string>();
const parcels = containers.map((container): Parcel => {
const [product_id, variant_id] = container.getOffer().name.split('\t');
const product = product_map[product_id].payload;
Expand Down Expand Up @@ -1053,9 +1055,9 @@ export class FulfillmentProductService
}
).sort(
(a, b) => Math.min(
...a.amounts?.map(am => am.net)
...(a.amounts?.map(am => am.net) ?? [])
) - Math.min(
...b.amounts?.map(am => am.net)
...(b.amounts?.map(am => am.net) ?? [])
)
);

Expand Down
13 changes: 8 additions & 5 deletions src/stubs/dhl_soap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import {
FlatAggregatedFulfillment,
throwOperationStatusCode,
unique,
} from '../utils.js';
import { Stub } from '../stub.js';
import {
Expand Down Expand Up @@ -442,7 +443,7 @@ export class DHLSoap extends Stub {
}

protected parseService (attributes: Attribute[]) {
return attributes?.reverse().filter((att: Attribute) =>
return attributes?.filter((att: Attribute) =>
att.id?.startsWith(this.urns.dhl_service)
).map(att=> ({
[att.value]: {
Expand Down Expand Up @@ -641,10 +642,12 @@ export class DHLSoap extends Stub {
)
) ?? {})
}
variant.attributes = [
...(variant.attributes ?? []),
...(request.product?.attributes ?? []),
];
variant.attributes = unique(
[
...(request.product.attributes ?? []),
...(variant.attributes ?? []),
]
);
return {
sequenceNumber: i + 1,
Shipment: {
Expand Down
10 changes: 9 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
OperationStatus,
Status
} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/status.js';
import { Attribute } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/attribute.js';

export type CRUDClient = Client<TaxServiceDefinition>
| Client<UserServiceDefinition>
Expand Down Expand Up @@ -271,4 +272,11 @@ export const mergeFulfillments = (fulfillments: FlatAggregatedFulfillment[]): Fu
}
});
return Object.values(merged_fulfillments);
};
};

export const unique = <T extends {[key: string]: any}>(objs: T[], by = 'id'): T[] => [
...new Map<string, T>(
objs.map(
o => [o[by], o]
)).values()
];

0 comments on commit 804a240

Please sign in to comment.