Kyoso-Team / kyoso

A web application that takes osu! tournaments beyonds spreadsheets.
http://kyoso.sh
GNU Affero General Public License v3.0
1 stars 1 forks source link

Update `updateTournament` procedure and simplify backend checks #51

Closed L-Mario564 closed 1 month ago

L-Mario564 commented 1 month ago

This PR updates the updateTournament tRPC procedure to match the specifications described in #48. I've also made a Checks class that simplifies common checks.

Example of these checks:

// before
if (!hasPermissions(staffMember, ['host', 'debug', 'manage_tournament'])) {
  throw new TRPCError({
    code: 'UNAUTHORIZED',
    message: 'You do not have the required permissions to update this tournament'
  });
}

// after
checks.staffHasPermissions(staffMember, ['host', 'debug', 'manage_tournament']);

When using in tRPC procedures, use TRPCChecks; when using in API routes, use APIChecks.

L-Mario564 commented 1 month ago

Everything seems good so far. Although TRPCChecks('create a tournament') kind of expression seems to be a bit of off-putting to me, but it's not that big of a deal anyway

As discussed on Discord, I'll update it so it reads better.

new TRPCChecks({ action: 'create a tournament' });