Skip to content

Commit b5f9254

Browse files
committed
update parseTicketIds:
- check for duplicates - print tickets
1 parent 6002cbe commit b5f9254

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

examples/ticket/utils/parseTicketIds.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,22 @@ export function parseTicketIds(minCount: number = 1): string[] {
1414
.map((id) => id.trim())
1515
.filter((id) => id.length > 0);
1616

17+
// Check for duplicates
18+
const uniqueTicketIds = new Set(ticketIds);
19+
if (uniqueTicketIds.size !== ticketIds.length) {
20+
const duplicates = ticketIds.filter((item, index) => ticketIds.indexOf(item) !== index);
21+
const uniqueDuplicates = Array.from(new Set(duplicates));
22+
throw new Error(`Duplicate ticket IDs found: ${uniqueDuplicates.join(", ")}`);
23+
}
24+
1725
if (ticketIds.length < minCount) {
1826
throw new Error(`Not enough tickets provided! Found ${ticketIds.length} but need at least ${minCount}.`);
1927
}
2028

29+
console.log("\nParsed Ticket IDs:");
30+
ticketIds.forEach((id, index) => {
31+
console.log(` ${(index + 1).toString().padStart(2, " ")}. ${id}`);
32+
});
33+
2134
return ticketIds;
2235
}

0 commit comments

Comments
 (0)