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

Update Correct StandMatch When Placing a Match Order #511

Merged
merged 3 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
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
33 changes: 8 additions & 25 deletions src/collections/match/operations/match-transfer-item.operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class MatchTransferItemOperation implements Operation {
if (activeCustomerItems.length !== 1) {
throw new BlError("blid not active").code(804);
}
const customerItem = activeCustomerItems[0];
const customerItem = activeCustomerItems[0]!;

const receiverUserMatch = receiverUserMatches.find((userMatch) =>
userMatch.expectedItems.includes(customerItem?.item as string),
Expand All @@ -101,24 +101,19 @@ export class MatchTransferItemOperation implements Operation {
throw new BlError("Item not in receiver expectedItems").code(805);
}

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (receiverUserMatch.receivedCustomerItems.includes(customerItem.id)) {
throw new BlError("Receiver has already received this item").code(806);
} // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const senderMatches = await getAllMatchesForUser(customerItem.customer);
}
const senderMatches = await getAllMatchesForUser(
customerItem.customer as string,
);
const senderUserMatches = senderMatches.filter(
(match) => match._variant === MatchVariant.UserMatch,
) as UserMatch[];
const senderUserMatch = senderUserMatches.find(
(userMatch) =>
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
userMatch.expectedItems.includes(String(customerItem.item)) &&
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
!userMatch.deliveredCustomerItems.includes(String(customerItem.item)),
userMatch.expectedItems.includes(customerItem.item as string) &&
!userMatch.deliveredCustomerItems.includes(customerItem.item as string),
);

if (
Expand Down Expand Up @@ -150,17 +145,13 @@ export class MatchTransferItemOperation implements Operation {
{
receivedCustomerItems: [
...receiverUserMatch.receivedCustomerItems,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
customerItem.id,
],
},
new SystemUser(),
);

const receiverOrder = await createMatchOrder(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
customerItem,
receiverUserDetailId,
false,
Expand All @@ -181,21 +172,15 @@ export class MatchTransferItemOperation implements Operation {
{
deliveredCustomerItems: [
...senderUserMatch.deliveredCustomerItems,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
customerItem.id,
],
},
new SystemUser(),
);

const senderOrder = await createMatchOrder(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
customerItem,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
customerItem.customer,
customerItem.customer as string,
true,
);

Expand All @@ -207,8 +192,6 @@ export class MatchTransferItemOperation implements Operation {
}

await customerItemStorage.update(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
customerItem.id,
{
returned: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ export class OrderPlaceOperation implements Operation {
for (const customerItem of returnCustomerItems) {
const foundStandMatch = standMatches.find(
(standMatch) =>
standMatch.customer === customerItem.customer &&
standMatch.expectedHandoffItems.includes(String(customerItem.item)) &&
!standMatch.deliveredItems.includes(String(customerItem.item)),
);
Expand All @@ -322,6 +323,7 @@ export class OrderPlaceOperation implements Operation {
for (const customerItem of handoutCustomerItems) {
const foundStandMatch = standMatches.find(
(standMatch) =>
standMatch.customer === customerItem.customer &&
standMatch.expectedPickupItems.includes(String(customerItem.item)) &&
!standMatch.receivedItems.includes(String(customerItem.item)),
);
Expand Down
Loading