Skip to content

Commit 500a9d6

Browse files
bug fixes
1 parent e1ab7cd commit 500a9d6

1 file changed

Lines changed: 26 additions & 15 deletions

File tree

lambdas/supplier-allocator/src/services/supplier-config.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,25 @@ export async function getVolumeGroupDetails(
1919
groupId: string,
2020
deps: Deps,
2121
): Promise<VolumeGroup> {
22-
const groupDetails = await deps.supplierConfigRepo.getVolumeGroup(groupId);
22+
const groupDetails: VolumeGroup =
23+
await deps.supplierConfigRepo.getVolumeGroup(groupId);
2324

2425
if (
25-
groupDetails &&
26-
(groupDetails.status !== "PROD" ||
27-
new Date(groupDetails.startDate) > new Date() ||
28-
(groupDetails.endDate && new Date(groupDetails.endDate) < new Date()))
26+
groupDetails.status === "PROD" &&
27+
new Date(groupDetails.startDate) <= new Date() &&
28+
(!groupDetails.endDate || new Date(groupDetails.endDate) >= new Date())
2929
) {
30-
deps.logger.error({
31-
description: "Volume group is not active based on status and dates",
32-
groupId,
33-
status: groupDetails.status,
34-
startDate: groupDetails.startDate,
35-
endDate: groupDetails.endDate,
36-
});
37-
throw new Error(`Volume group with id ${groupId} is not active`);
30+
return groupDetails;
3831
}
39-
return groupDetails;
32+
33+
deps.logger.error({
34+
description: "Volume group is not active based on status and dates",
35+
groupId,
36+
status: groupDetails.status,
37+
startDate: groupDetails.startDate,
38+
endDate: groupDetails.endDate,
39+
});
40+
throw new Error(`Volume group with id ${groupId} is not active`);
4041
}
4142

4243
export async function getSupplierAllocationsForVolumeGroup(
@@ -99,5 +100,15 @@ export async function getSupplierDetails(
99100
missingSuppliers: missingSupplierIds,
100101
});
101102
}
102-
return supplierDetails;
103+
const activeSuppliers = supplierDetails.filter((s) => s.status === "PROD");
104+
if (activeSuppliers.length === 0) {
105+
deps.logger.error({
106+
description: "No active suppliers found for supplier allocations",
107+
supplierIds,
108+
});
109+
throw new Error(
110+
`No active suppliers found for supplier ids ${supplierIds.join(", ")}`,
111+
);
112+
}
113+
return activeSuppliers;
103114
}

0 commit comments

Comments
 (0)