change scheduling mode to enum in rounds, change appreance of scheduling

mode picker in competition
This commit is contained in:
unurled 2025-07-07 22:51:37 +02:00
parent 592da87c26
commit 95d8988876
Signed by: unurled
GPG key ID: EFC5F5E709B47DDD
16 changed files with 159 additions and 115 deletions

View file

@ -26,6 +26,7 @@
credentials: 'include',
body: JSON.stringify({ scheduling_mode: schedulingMode })
});
console.log("response", response)
}
</script>
@ -37,13 +38,11 @@
>
{#each Object.values(SchedulingMode) as mode}
<button
class={cn(
'flex h-full w-full items-center gap-4 rounded-xl border',
schedulingMode === mode && ' border-green-500'
)}
class=
'flex h-full w-full items-center gap-4 rounded-xl'
onclick={() => (schedulingMode = mode)}
>
<Card class="w-full">
<Card class={cn("w-full", schedulingMode === mode && ' border-green-500')}>
<CardHeader class="flex justify-between">
<Label class="text-start">{$_(mode)}</Label>
</CardHeader>

View file

@ -0,0 +1,7 @@
<script lang="ts">
import type { Round } from '@/lib/server/db/schema/rounds';
let { round }: { round: Round } = $props();
</script>
{JSON.stringify(round)}

View file

@ -1,7 +0,0 @@
<script lang="ts">
import CreateRound from './create-round.svelte';
let { rounds, createForm } = $props();
</script>
<CreateRound data={{ form: createForm }} />

View file

@ -8,7 +8,6 @@ import * as matches from './schema/matches';
import * as permissions from './schema/permissions';
import * as roles from './schema/roles';
import * as rounds from './schema/rounds';
import * as schedulingmodes from './schema/schedulingmodes';
import * as sessions from './schema/sessions';
import * as teams from './schema/teams';
import * as users from './schema/users';
@ -26,7 +25,6 @@ export const db = drizzle(client, {
...permissions,
...roles,
...rounds,
...schedulingmodes,
...sessions,
...teams,
...users

View file

@ -0,0 +1,38 @@
import { eq } from 'drizzle-orm';
import { db } from '..';
import { competitions } from '../schema/competitions';
import type { Round } from '../schema/rounds';
export async function getCompetitionWithAll(id: number) {
return await db.query.competitions.findFirst({
where: eq(competitions.id, id),
with: {
breakperiods: true,
fields: true,
rounds: {
with: {
matches: true
}
},
teams: true
}
});
}
export async function getCompetitionsWithAll(skip: number = 0, take: number = 10) {
return await db.query.competitions.findMany({
orderBy: (competitions, { desc }) => [desc(competitions.start_date)],
with: {
breakperiods: true,
fields: true,
rounds: {
with: {
matches: true
}
},
teams: true
},
limit: take,
offset: skip
});
}

View file

@ -0,0 +1,7 @@
import { eq } from 'drizzle-orm';
import { db } from '..';
import { rounds, type RoundInsert } from '../schema/rounds';
export async function insertRound(competitionId: number, round: RoundInsert) {
return await db.insert(rounds).values(round);
}

View file

@ -1,12 +1,11 @@
import * as t from 'drizzle-orm/pg-core';
import { timestamps } from '../util';
import { eq, relations } from 'drizzle-orm';
import { relations } from 'drizzle-orm';
import { users } from './users';
import { breakperiods } from './breakperiods';
import { fields } from './fields';
import { teams } from './teams';
import { rounds } from './rounds';
import { db } from '..';
export const competitions = t.pgTable('competitions', {
id: t.serial('id').primaryKey(),
@ -30,39 +29,3 @@ export const competitionsRelations = relations(competitions, ({ one, many }) =>
}));
export type Competition = typeof competitions.$inferSelect;
export async function getCompetitionWithAll(id: number) {
return await db.query.competitions.findFirst({
where: eq(competitions.id, id),
with: {
breakperiods: true,
fields: true,
rounds: {
with: {
matches: true,
schedulingMode: true
}
},
teams: true
}
});
}
export async function getCompetitionsWithAll(skip: number = 0, take: number = 10) {
return await db.query.competitions.findMany({
orderBy: (competitions, { desc }) => [desc(competitions.start_date)],
with: {
breakperiods: true,
fields: true,
rounds: {
with: {
matches: true,
schedulingMode: true
}
},
teams: true
},
limit: take,
offset: skip
});
}

View file

@ -2,13 +2,15 @@ import { relations } from 'drizzle-orm';
import * as t from 'drizzle-orm/pg-core';
import { matches } from './matches';
import { competitions } from './competitions';
import { schedulingModes } from './schedulingmodes';
import { enumToPgEnum, SchedulingMode } from '../../../../types';
export const schedulingModes = t.pgEnum('scheduling_modes', enumToPgEnum(SchedulingMode));
export const rounds = t.pgTable('rounds', {
id: t.serial('id').primaryKey(),
nb_matches: t.integer('nb_matches').notNull(),
competition_id: t.integer('competition_id').notNull(),
scheduling_mode: t.integer('scheduling_mode').notNull()
scheduling_mode: schedulingModes('scheduling_modes')
});
export const roundsRelations = relations(rounds, ({ many, one }) => ({
@ -16,9 +18,9 @@ export const roundsRelations = relations(rounds, ({ many, one }) => ({
fields: [rounds.competition_id],
references: [competitions.id]
}),
matches: many(matches),
schedulingMode: one(schedulingModes, {
fields: [rounds.scheduling_mode],
references: [schedulingModes.id]
})
matches: many(matches)
}));
export type Round = typeof rounds.$inferSelect;
export type RoundInsert = typeof rounds.$inferInsert;

View file

@ -1,25 +0,0 @@
import * as t from 'drizzle-orm/pg-core';
import { timestamps } from '../util';
import { relations } from 'drizzle-orm';
import { rounds } from './rounds';
export const schedulingModes = t.pgTable('scheduling_modes', {
id: t.serial('id').primaryKey(),
name: t.text('name').notNull(),
description: t.text('description'),
algorithm: t.text('algorithm').notNull(),
config: t.jsonb('config').notNull(),
sequence_order: t.integer('sequence_order').notNull(),
status: t.text('status').notNull(),
round_id: t.integer('round_id').notNull(),
...timestamps
});
export const schedulingModesRelations = relations(schedulingModes, ({ one }) => ({
round: one(rounds, {
fields: [schedulingModes.round_id],
references: [rounds.id]
})
}));
export type SchedulingMode = typeof schedulingModes.$inferSelect;

View file

@ -1,9 +1,9 @@
import * as t from 'drizzle-orm/pg-core';
export const timestamps = {
updated_at: t.timestamp({ withTimezone: true, mode: 'date' }).default(new Date(Date.now())),
updated_at: t.timestamp({ withTimezone: true, mode: 'date' }).defaultNow(),
created_at: t.timestamp({ withTimezone: true, mode: 'date' }).defaultNow().notNull(),
deleted_at: t.timestamp({ withTimezone: true, mode: 'date' }).default(new Date())
deleted_at: t.timestamp({ withTimezone: true, mode: 'date' })
};
export const binaryHash = t.customType<{ data: Buffer; driverData: Buffer }>({