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

Error: The match is locked. How would you update a match? #140

Closed dioveath closed 2 years ago

dioveath commented 2 years ago
      <div>
        { matchGames.map((m) =>

      <div key={m.id}>
            { m?.opponent1?.id } vs { m?.opponent2?.id }
        <input name="" type="number" value="" />
        <input name="" type="number" value="" />
        <button onClick={() => {

              m.opponent1.score = 3;
              if(m.opponent2)
                m.opponent2.score = 2;

              manager.update.match(m)

              render();
            }}> Submit Score </button>
          </div>
        )}
      </div>

So, I want to update the scores as a manager/organizer. It says it's currently locked. or Where should I be handling the matches?

dioveath commented 2 years ago

So, I found out that I was trying to update a match with one of the opponents BYE in it. Here is the change, I made just so anyone would find it helpful.


              if(m.status === Status.Locked) {
                console.log(m.status);
                return;
              }

              let score1 = opponent1[index]?.current.value || 0;
              let score2 = opponent2[index]?.current.value || 0;

              await manager.update.match({
                id: m.id,
                opponent1: { id: m.opponent1.id, score: score1, result: score1 > score2 ? 'win' : 'loss' },
                opponent2: { id: m?.opponent2?.id, score: score2, result: score2 > score1 ? 'win' : 'loss' }
              })

              const data = await manager.get.tournamentData(1234);              

              render();
Drarig29 commented 2 years ago

The BYE could be in both opponent1 and opponent2 so I suggest you do the following change:

              if(m.status === Status.Locked) {
                console.log(m.status);
                return;
              }

              let score1 = opponent1[index]?.current.value || 0;
              let score2 = opponent2[index]?.current.value || 0;

              await manager.update.match({
                id: m.id,
-               opponent1: { id: m.opponent1.id, score: score1, result: score1 > score2 ? 'win' : 'loss' },
+               opponent1: { id: m?.opponent1?.id, score: score1, result: score1 > score2 ? 'win' : 'loss' },
                opponent2: { id: m?.opponent2?.id, score: score2, result: score2 > score1 ? 'win' : 'loss' }
              })

              const data = await manager.get.tournamentData(1234);              

              render();
dioveath commented 2 years ago

Okay sure. Thanks for the update!