refactor: rename participant.ts model file to season-participant.ts

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Chris Parsons 2026-05-01 06:26:05 +00:00
parent 66145a9d78
commit fdf5fe8976
No known key found for this signature in database
2 changed files with 32 additions and 32 deletions

View file

@ -6,7 +6,7 @@ export * from "./team";
export * from "./commissioner";
export * from "./sport";
export * from "./sports-season";
export * from "./participant";
export * from "./season-participant";
export * from "./season-template";
export * from "./season-template-sport";
export * from "./season-sport";

View file

@ -2,13 +2,13 @@ import { eq, inArray, count, and, sql, asc, desc } from "drizzle-orm";
import { database } from "~/database/context";
import * as schema from "~/database/schema";
export type Participant = typeof schema.participants.$inferSelect;
export type NewParticipant = typeof schema.participants.$inferInsert;
export type Participant = typeof schema.seasonParticipants.$inferSelect;
export type NewParticipant = typeof schema.seasonParticipants.$inferInsert;
export async function createParticipant(data: NewParticipant): Promise<Participant> {
const db = database();
const [participant] = await db
.insert(schema.participants)
.insert(schema.seasonParticipants)
.values(data)
.returning();
return participant;
@ -17,15 +17,15 @@ export async function createParticipant(data: NewParticipant): Promise<Participa
export async function createManyParticipants(data: NewParticipant[]): Promise<Participant[]> {
const db = database();
return await db
.insert(schema.participants)
.insert(schema.seasonParticipants)
.values(data)
.returning();
}
export async function findParticipantById(id: string): Promise<Participant | undefined> {
const db = database();
return await db.query.participants.findFirst({
where: eq(schema.participants.id, id),
return await db.query.seasonParticipants.findFirst({
where: eq(schema.seasonParticipants.id, id),
with: {
sportsSeason: {
with: {
@ -43,11 +43,11 @@ export async function findParticipantByName(
const db = database();
const results = await db
.select()
.from(schema.participants)
.from(schema.seasonParticipants)
.where(
and(
eq(schema.participants.sportsSeasonId, sportsSeasonId),
sql`lower(${schema.participants.name}) = lower(${name})`
eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId),
sql`lower(${schema.seasonParticipants.name}) = lower(${name})`
)
)
.limit(1);
@ -56,8 +56,8 @@ export async function findParticipantByName(
export async function findParticipantsBySportsSeasonId(sportsSeasonId: string): Promise<Participant[]> {
const db = database();
return await db.query.participants.findMany({
where: eq(schema.participants.sportsSeasonId, sportsSeasonId),
return await db.query.seasonParticipants.findMany({
where: eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId),
orderBy: (participants, { asc: orderAsc }) => [orderAsc(participants.name)],
});
}
@ -66,8 +66,8 @@ export async function findParticipantsByExternalId(
externalId: string
): Promise<Participant[]> {
const db = database();
return await db.query.participants.findMany({
where: eq(schema.participants.externalId, externalId),
return await db.query.seasonParticipants.findMany({
where: eq(schema.seasonParticipants.externalId, externalId),
with: {
sportsSeason: {
with: {
@ -84,22 +84,22 @@ export async function updateParticipant(
): Promise<Participant> {
const db = database();
const [participant] = await db
.update(schema.participants)
.update(schema.seasonParticipants)
.set({ ...data, updatedAt: new Date() })
.where(eq(schema.participants.id, id))
.where(eq(schema.seasonParticipants.id, id))
.returning();
return participant;
}
export async function countAllParticipants(): Promise<number> {
const db = database();
const result = await db.select({ value: count() }).from(schema.participants);
const result = await db.select({ value: count() }).from(schema.seasonParticipants);
return result[0].value;
}
export async function deleteParticipant(id: string): Promise<void> {
const db = database();
await db.delete(schema.participants).where(eq(schema.participants.id, id));
await db.delete(schema.seasonParticipants).where(eq(schema.seasonParticipants.id, id));
}
export async function copyParticipantsFromSeason(
@ -146,17 +146,17 @@ export async function getParticipantsForSeasonWithSports(seasonId: string, provi
// Get all participants for these sports seasons with sport info
const participants = await db
.select({
id: schema.participants.id,
name: schema.participants.name,
id: schema.seasonParticipants.id,
name: schema.seasonParticipants.name,
sport: {
id: schema.sports.id,
name: schema.sports.name,
},
})
.from(schema.participants)
.from(schema.seasonParticipants)
.innerJoin(
schema.sportsSeasons,
eq(schema.participants.sportsSeasonId, schema.sportsSeasons.id)
eq(schema.seasonParticipants.sportsSeasonId, schema.sportsSeasons.id)
)
.innerJoin(
schema.sports,
@ -164,8 +164,8 @@ export async function getParticipantsForSeasonWithSports(seasonId: string, provi
)
.where(
sportsSeasonIds.length === 1
? eq(schema.participants.sportsSeasonId, sportsSeasonIds[0])
: inArray(schema.participants.sportsSeasonId, sportsSeasonIds)
? eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonIds[0])
: inArray(schema.seasonParticipants.sportsSeasonId, sportsSeasonIds)
);
return participants;
@ -183,18 +183,18 @@ export async function getDraftParticipants(seasonId: string) {
return await db
.select({
id: schema.participants.id,
name: schema.participants.name,
vorpValue: schema.participants.vorpValue,
id: schema.seasonParticipants.id,
name: schema.seasonParticipants.name,
vorpValue: schema.seasonParticipants.vorpValue,
sport: schema.sports,
})
.from(schema.participants)
.innerJoin(schema.sportsSeasons, eq(schema.participants.sportsSeasonId, schema.sportsSeasons.id))
.from(schema.seasonParticipants)
.innerJoin(schema.sportsSeasons, eq(schema.seasonParticipants.sportsSeasonId, schema.sportsSeasons.id))
.innerJoin(schema.sports, eq(schema.sportsSeasons.sportId, schema.sports.id))
.where(
sportsSeasonIds.length === 1
? eq(schema.participants.sportsSeasonId, sportsSeasonIds[0])
: inArray(schema.participants.sportsSeasonId, sportsSeasonIds)
? eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonIds[0])
: inArray(schema.seasonParticipants.sportsSeasonId, sportsSeasonIds)
)
.orderBy(desc(schema.participants.vorpValue), asc(schema.participants.name));
.orderBy(desc(schema.seasonParticipants.vorpValue), asc(schema.seasonParticipants.name));
}