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

Commit

Permalink
fix: register multiple standmatch items at a time (#514)
Browse files Browse the repository at this point in the history
Previously, there was a bug where handing out or in multiple items in
one order would cause only one (the last one) to be registered in the
StandMatch. That is now fixed.
  • Loading branch information
LarsSelbekk authored Jun 11, 2024
1 parent 1bc1899 commit 8ff8cde
Showing 1 changed file with 44 additions and 22 deletions.
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

0 comments on commit 8ff8cde

Please sign in to comment.