Skip to content

Commit

Permalink
fix: guard against empty array when setting new line id (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinstark authored Jul 8, 2024
1 parent e3c655e commit 17866aa
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/production_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ export class ProductionManager extends EventEmitter {
production: Production,
newLineName: string
): Promise<Production | undefined> {
const nextLineId =
Math.max(...production.lines.map((line) => parseInt(line.id, 10))) + 1;
const nextLineId = production.lines.length
? Math.max(...production.lines.map((line) => parseInt(line.id, 10))) + 1
: 1;

production.lines.push({
name: newLineName,
id: nextLineId.toString(),
Expand Down

0 comments on commit 17866aa

Please sign in to comment.