brackt/app/models/commissioner.ts
Chris Parsons eb7aa42cef
Add implementation plan for commissioner-without-team feature (#6)
* Add implementation plan for commissioner-without-team feature

https://claude.ai/code/session_01NSRMSYtb7jSFbngDS8okn3

* Allow commissioners to exist without owning a team

- Add opt-out checkbox on league creation ("I want to play in this league")
  so the creator can be commissioner-only without claiming a team
- Add Commissioner Management card to league settings with add/remove
  commissioner UI; guards against removing the last commissioner
- Add countCommissionersByLeagueId model helper for the last-commissioner guard
- Show "No team" indicator on the league homepage next to commissioners
  who don't own a team in the current season

https://claude.ai/code/session_01NSRMSYtb7jSFbngDS8okn3

* Fix code review issues in commissioner management

- Add success/error feedback banners to commissioner add/remove actions
- Gate allUsers query to admin-only (prevents exposing all users to non-admin commissioners)
- Prevent commissioner self-removal in both action (server) and UI (client)
- Add "(you)" label next to current user in commissioner list
- Remove all unnecessary `any` type casts in favor of inferred types

https://claude.ai/code/session_01NSRMSYtb7jSFbngDS8okn3

* Allow commissioners to add league members as co-commissioners

Non-admin commissioners can now add users who already own a team in
the league as co-commissioners. Admins still see the full user list.
Previously the add-commissioner form was admin-only.

https://claude.ai/code/session_01NSRMSYtb7jSFbngDS8okn3

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-20 08:45:09 -08:00

81 lines
2.2 KiB
TypeScript

import { eq, and } from "drizzle-orm";
import { database } from "~/database/context";
import * as schema from "~/database/schema";
export type Commissioner = typeof schema.commissioners.$inferSelect;
export type NewCommissioner = typeof schema.commissioners.$inferInsert;
export async function createCommissioner(
data: NewCommissioner
): Promise<Commissioner> {
const db = database();
const [commissioner] = await db
.insert(schema.commissioners)
.values(data)
.returning();
return commissioner;
}
export async function findCommissionersByLeagueId(
leagueId: string
): Promise<Commissioner[]> {
const db = database();
return await db.query.commissioners.findMany({
where: eq(schema.commissioners.leagueId, leagueId),
orderBy: (commissioners, { asc }) => [asc(commissioners.createdAt)],
});
}
export async function findCommissionersByUserId(
userId: string
): Promise<Commissioner[]> {
const db = database();
return await db.query.commissioners.findMany({
where: eq(schema.commissioners.userId, userId),
orderBy: (commissioners, { desc }) => [desc(commissioners.createdAt)],
});
}
export async function isCommissioner(
leagueId: string,
userId: string
): Promise<boolean> {
const db = database();
const commissioner = await db.query.commissioners.findFirst({
where: and(
eq(schema.commissioners.leagueId, leagueId),
eq(schema.commissioners.userId, userId)
),
});
return !!commissioner;
}
export async function countCommissionersByLeagueId(
leagueId: string
): Promise<number> {
const db = database();
const commissioners = await db.query.commissioners.findMany({
where: eq(schema.commissioners.leagueId, leagueId),
});
return commissioners.length;
}
export async function deleteCommissioner(id: string): Promise<void> {
const db = database();
await db.delete(schema.commissioners).where(eq(schema.commissioners.id, id));
}
export async function removeCommissionerByLeagueAndUser(
leagueId: string,
userId: string
): Promise<void> {
const db = database();
await db
.delete(schema.commissioners)
.where(
and(
eq(schema.commissioners.leagueId, leagueId),
eq(schema.commissioners.userId, userId)
)
);
}