Drarig29 / brackets-manager.js

A simple library to manage tournament brackets (round-robin, single elimination, double elimination).
https://drarig29.github.io/brackets-docs
MIT License
253 stars 40 forks source link

When completed, consolation final archives the final #176

Closed Drarig29 closed 1 year ago

Drarig29 commented 1 year ago

I think I have also found an error. If you update the consolidation match before the final game, the final game gets archived.

await manager.create({
    name: 'Example',
    tournamentId: 0,
    type: 'single_elimination',
    seeding: ['Team 1', 'Team 2', 'Team 3', 'Team 4'],
    settings: { consolationFinal: true },
});

await manager.update.match({
    id: 0,
    opponent1: { score: 16, result: 'win' },
    opponent2: { score: 12 },
});

await manager.update.match({
    id: 1,
    opponent1: { score: 16, result: 'win' },
    opponent2: { score: 12 },
});

await manager.update.match({
    id: 3,
    opponent1: { score: 16, result: 'win' },
    opponent2: { score: 12 },
});

console.log((await manager.export()).match);

Here is the output

[
  {
    "id": 0,
    "number": 1,
    "stage_id": 0,
    "group_id": 0,
    "round_id": 0,
    "child_count": 0,
    "status": 4,
    "opponent1": {
      "id": 0,
      "position": 1,
      "score": 16,
      "result": "win"
    },
    "opponent2": {
      "id": 3,
      "position": 4,
      "score": 12,
      "result": "loss"
    }
  },
  {
    "id": 1,
    "number": 2,
    "stage_id": 0,
    "group_id": 0,
    "round_id": 0,
    "child_count": 0,
    "status": 4,
    "opponent1": {
      "id": 1,
      "position": 2,
      "score": 16,
      "result": "win"
    },
    "opponent2": {
      "id": 2,
      "position": 3,
      "score": 12,
      "result": "loss"
    }
  },
  {
    "id": 2,
    "number": 1,
    "stage_id": 0,
    "group_id": 0,
    "round_id": 1,
    "child_count": 0,
    "status": 5,
    "opponent1": {
      "id": 0
    },
    "opponent2": {
      "id": 1
    }
  },
  {
    "id": 3,
    "number": 1,
    "stage_id": 0,
    "group_id": 1,
    "round_id": 2,
    "child_count": 0,
    "status": 4,
    "opponent1": {
      "id": 3,
      "position": 1,
      "score": 16,
      "result": "win"
    },
    "opponent2": {
      "id": 2,
      "position": 2,
      "score": 12,
      "result": "loss"
    }
  }
]

Originally posted by @MrEngineerET in https://github.com/Drarig29/brackets-manager.js/discussions/168#discussioncomment-6324615