change scheduling mode to enum in rounds, change appreance of scheduling
mode picker in competition
This commit is contained in:
parent
592da87c26
commit
95d8988876
16 changed files with 159 additions and 115 deletions
|
@ -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>
|
||||
|
|
7
src/lib/components/rounds/round.svelte
Normal file
7
src/lib/components/rounds/round.svelte
Normal 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)}
|
|
@ -1,7 +0,0 @@
|
|||
<script lang="ts">
|
||||
import CreateRound from './create-round.svelte';
|
||||
|
||||
let { rounds, createForm } = $props();
|
||||
</script>
|
||||
|
||||
<CreateRound data={{ form: createForm }} />
|
|
@ -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
|
||||
|
|
38
src/lib/server/db/queries/competitions.ts
Normal file
38
src/lib/server/db/queries/competitions.ts
Normal 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
|
||||
});
|
||||
}
|
7
src/lib/server/db/queries/rounds.ts
Normal file
7
src/lib/server/db/queries/rounds.ts
Normal 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);
|
||||
}
|
|
@ -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
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
|
@ -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 }>({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue