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

Replace `swapStaffRoleOrder` with `swapStaffRoleOrders` #57

Closed L-Mario564 closed 3 weeks ago

L-Mario564 commented 3 weeks ago

Why?

If multiple swaps are requested in the frontend, it would be slow to call swapStaffRoleOrder over and over again for each swap, so instead, we'll rename this procedure swapStaffRoleOrders and accept multiple swaps in one single procedure call.

How?

As mentioned before, swapStaffRoleOrder will be renamed swapStaffRoleOrders. As for the implementation for this procedure, instead of the input being:

v.object({
  tournamentId: positiveIntSchema,
  source: positiveIntSchema,
  target: positiveIntSchema
})

Make it:

v.object({
  tournamentId: positiveIntSchema,
  swaps: v.array(
    v.object({
      source: positiveIntSchema,
      target: positiveIntSchema
    }),
    [v.maxLength(25)]
  )
})

Since we're dealing with an array now, we need to filter out any redundant swaps (Example: Swap staff role 1 and 2, and then 2 and 1, that's redundant).

All checks already implemented in swapStaffRoleOrder must remain (error if tournament deleted or concluded, don't allow swapping defaults, etc.)