Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

fix: register multiple standmatch items at a time #514

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 44 additions & 22 deletions src/collections/order/operations/place/order-place.operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ export class OrderPlaceOperation implements Operation {
(match) => match._variant === MatchVariant.StandMatch,
) as StandMatch[];

// Register items as delivered
// Discover items to register delivery of
const matchToDeliveredItemsMap = new Map<string, Set<string>>();
for (const customerItem of returnCustomerItems) {
const foundStandMatch = standMatches.find(
(standMatch) =>
Expand All @@ -304,22 +305,33 @@ export class OrderPlaceOperation implements Operation {
!standMatch.deliveredItems.includes(String(customerItem.item)),
);
if (foundStandMatch) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await this._matchStorage.update(
matchToDeliveredItemsMap.set(
foundStandMatch.id,
{
deliveredItems: [
...foundStandMatch.deliveredItems,
customerItem.item as string,
],
},
new SystemUser(),
new Set([
...(matchToDeliveredItemsMap.get(foundStandMatch.id) ?? []),
...foundStandMatch.deliveredItems,
customerItem.item as string,
]),
);
}
}

// Register items as received
// Register delivery
for (const [
standMatchId,
deliveredItems,
] of matchToDeliveredItemsMap.entries()) {
await this._matchStorage.update(
standMatchId,
{
deliveredItems: Array.from(deliveredItems),
},
new SystemUser(),
);
}

// Discover items to register receiving of
const matchToReceivedItemsMap = new Map<string, Set<string>>();
for (const customerItem of handoutCustomerItems) {
const foundStandMatch = standMatches.find(
(standMatch) =>
Expand All @@ -328,20 +340,30 @@ export class OrderPlaceOperation implements Operation {
!standMatch.receivedItems.includes(String(customerItem.item)),
);
if (foundStandMatch) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await this._matchStorage.update(
matchToReceivedItemsMap.set(
foundStandMatch.id,
{
receivedItems: [
...foundStandMatch.receivedItems,
customerItem.item as string,
],
},
new SystemUser(),
new Set([
...(matchToReceivedItemsMap.get(foundStandMatch.id) ?? []),
...foundStandMatch.receivedItems,
customerItem.item as string,
]),
);
}
}

// Register receiving
for (const [
standMatchId,
receivedItems,
] of matchToReceivedItemsMap.entries()) {
await this._matchStorage.update(
standMatchId,
{
receivedItems: Array.from(receivedItems),
},
new SystemUser(),
);
}
}

public async run(
Expand Down
Loading