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