Data/Raceresults: Implement entering race results
All checks were successful
Build Formula11 Docker Image / pocketbase-docker (push) Successful in 50s
All checks were successful
Build Formula11 Docker Image / pocketbase-docker (push) Successful in 50s
This commit is contained in:
@ -1,7 +1,45 @@
|
|||||||
import type { Driver, Race, RaceResult } from "$lib/schema";
|
import {
|
||||||
|
form_data_clean,
|
||||||
|
form_data_ensure_keys,
|
||||||
|
form_data_get_and_remove_id,
|
||||||
|
form_data_remove,
|
||||||
|
} from "$lib/form";
|
||||||
|
import type { Driver, Graphic, Race, RaceResult } from "$lib/schema";
|
||||||
import type { Actions, PageServerLoad } from "./$types";
|
import type { Actions, PageServerLoad } from "./$types";
|
||||||
|
|
||||||
export const actions = {} as Actions;
|
export const actions = {
|
||||||
|
create_raceresult: async ({ request, locals }) => {
|
||||||
|
if (!locals.admin) return { unauthorized: true };
|
||||||
|
|
||||||
|
const data: FormData = form_data_clean(await request.formData());
|
||||||
|
form_data_ensure_keys(data, ["race", "pxxs"]);
|
||||||
|
form_data_remove(data, ["pxxs_codes", "dnfs_codes"]);
|
||||||
|
|
||||||
|
await locals.pb.collection("raceresults").create(data);
|
||||||
|
},
|
||||||
|
|
||||||
|
update_raceresult: async ({ request, locals }) => {
|
||||||
|
if (!locals.admin) return { unauthorized: true };
|
||||||
|
|
||||||
|
const data: FormData = form_data_clean(await request.formData());
|
||||||
|
form_data_remove(data, ["pxxs_codes", "dnfs_codes"]);
|
||||||
|
const id: string = form_data_get_and_remove_id(data);
|
||||||
|
|
||||||
|
console.dir(data, { depth: null });
|
||||||
|
|
||||||
|
await locals.pb.collection("raceresults").update(id, data);
|
||||||
|
},
|
||||||
|
|
||||||
|
delete_raceresult: async ({ request, locals }) => {
|
||||||
|
if (!locals.admin) return { unauthorized: true };
|
||||||
|
|
||||||
|
const data: FormData = form_data_clean(await request.formData());
|
||||||
|
form_data_remove(data, ["pxxs_codes", "dnfs_codes"]);
|
||||||
|
const id: string = form_data_get_and_remove_id(data);
|
||||||
|
|
||||||
|
await locals.pb.collection("raceresults").delete(id);
|
||||||
|
},
|
||||||
|
} as Actions;
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ fetch, locals }) => {
|
export const load: PageServerLoad = async ({ fetch, locals }) => {
|
||||||
// TODO: Duplicated code from racepicks/+page.server.ts
|
// TODO: Duplicated code from racepicks/+page.server.ts
|
||||||
@ -39,9 +77,23 @@ export const load: PageServerLoad = async ({ fetch, locals }) => {
|
|||||||
return drivers;
|
return drivers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: Duplicated code from racepicks/+page.server.ts + users/+page.server.ts
|
||||||
|
const fetch_graphics = async (): Promise<Graphic[]> => {
|
||||||
|
const graphics: Graphic[] = await locals.pb
|
||||||
|
.collection("graphics")
|
||||||
|
.getFullList({ fetch: fetch });
|
||||||
|
|
||||||
|
graphics.map((graphic: Graphic) => {
|
||||||
|
graphic.file_url = locals.pb.files.getURL(graphic, graphic.file);
|
||||||
|
});
|
||||||
|
|
||||||
|
return graphics;
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
results: await fetch_raceresults(),
|
results: await fetch_raceresults(),
|
||||||
races: await fetch_races(),
|
races: await fetch_races(),
|
||||||
drivers: await fetch_drivers(),
|
drivers: await fetch_drivers(),
|
||||||
|
graphics: await fetch_graphics(),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
import type { PageData } from "./$types";
|
import type { PageData } from "./$types";
|
||||||
import { Button, Table, type TableColumn } from "$lib/components";
|
import { Button, Table, type TableColumn } from "$lib/components";
|
||||||
import { get_by_value } from "$lib/database";
|
import { get_by_value } from "$lib/database";
|
||||||
import type { Driver } from "$lib/schema";
|
|
||||||
import { PXX_COLORS } from "$lib/config";
|
import { PXX_COLORS } from "$lib/config";
|
||||||
|
|
||||||
let { data }: { data: PageData } = $props();
|
let { data }: { data: PageData } = $props();
|
||||||
@ -65,6 +64,9 @@
|
|||||||
component: "raceResultCard",
|
component: "raceResultCard",
|
||||||
meta: {
|
meta: {
|
||||||
disable_inputs: !data.admin,
|
disable_inputs: !data.admin,
|
||||||
|
drivers: data.drivers,
|
||||||
|
races: data.races,
|
||||||
|
result: get_by_value(data.results, "id", id),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -74,10 +76,12 @@
|
|||||||
const create_result_handler = (event: Event) => {
|
const create_result_handler = (event: Event) => {
|
||||||
const modalSettings: ModalSettings = {
|
const modalSettings: ModalSettings = {
|
||||||
type: "component",
|
type: "component",
|
||||||
component: "raceResultsCard",
|
component: "raceResultCard",
|
||||||
meta: {
|
meta: {
|
||||||
require_inputs: true,
|
|
||||||
disable_inputs: !data.admin,
|
disable_inputs: !data.admin,
|
||||||
|
drivers: data.drivers,
|
||||||
|
races: data.races,
|
||||||
|
require_inputs: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user