Zeitraeume Verwaltung in admin Bereich

This commit is contained in:
titver968
2025-06-04 14:28:50 +02:00
parent 72055bfb4b
commit 177eb03179
2 changed files with 25 additions and 13 deletions

View File

@@ -3,7 +3,13 @@
let bezeichnung = ''; let bezeichnung = '';
let startDatum = ''; let startDatum = '';
let endDatum = ''; let endDatum = '';
let zeitraeume = []; interface Zeitraum {
id: number;
bezeichnung: string;
startDatum: string;
endDatum: string;
}
let zeitraeume: Zeitraum[] = [];
let neuerBezeichnung = ''; let neuerBezeichnung = '';
let neuerstartDatum = ''; let neuerstartDatum = '';
let neuerendDatum = ''; let neuerendDatum = '';
@@ -17,8 +23,12 @@
function bearbeiten(d: { id: number; bezeichnung: string; startDatum: Date; endDatum: Date }) { function bearbeiten(d: { id: number; bezeichnung: string; startDatum: Date; endDatum: Date }) {
neuerBezeichnung = d.bezeichnung; neuerBezeichnung = d.bezeichnung;
neuerstartDatum = d.startDatum; neuerstartDatum = d.startDatum instanceof Date
neuerendDatum = d.endDatum; ? d.startDatum.toISOString().slice(0, 10)
: d.startDatum;
neuerendDatum = d.endDatum instanceof Date
? d.endDatum.toISOString().slice(0, 10)
: d.endDatum;
bearbeiteId = d.id; bearbeiteId = d.id;
} }
@@ -67,19 +77,19 @@
<input <input
bind:value={neuerBezeichnung} bind:value={neuerBezeichnung}
placeholder="Bezeichnung" placeholder="Bezeichnung"
class="input w-full sm:w-[30%] border rounded px-3 py-2" class="input w-full sm:w-[35%] border rounded px-3 py-2"
/> />
<input <input
type="date" type="date"
bind:value={neuerstartDatum} bind:value={neuerstartDatum}
placeholder="Startdatum" placeholder="Startdatum"
class="input w-full sm:w-[10%] border rounded px-3 py-2" class="input w-full sm:w-[20%] border rounded px-3 py-2"
/> />
<input <input
type="date" type="date"
bind:value={neuerendDatum} bind:value={neuerendDatum}
placeholder="Enddatum" placeholder="Enddatum"
class="input w-full sm:w-[10%] border rounded px-3 py-2" class="input w-full sm:w-[20%] border rounded px-3 py-2"
/> />
<button <button
on:click={() => { on:click={() => {
@@ -126,8 +136,9 @@
<button <button
on:click={() => { on:click={() => {
neuerBezeichnung = d.bezeichnung; neuerBezeichnung = d.bezeichnung;
neuerstartDatum = d.startDatum; //neuerstartDatum = d.startDatum;
neuerendDatum = d.endDatum; neuerstartDatum = d.startDatum ? d.startDatum.slice(0, 10) : '';
neuerendDatum = d.endDatum ? d.endDatum.slice(0, 10) : '';
bearbeiteId = d.id; bearbeiteId = d.id;
}} }}
class="text-blue-600 hover:underline" class="text-blue-600 hover:underline"
@@ -161,7 +172,4 @@
</div> </div>
<style> <style>
.input {
@apply border p-2 rounded w-full;
}
</style> </style>

View File

@@ -45,7 +45,7 @@ export const PATCH: RequestHandler = async ({ cookies, request }) => {
const { id, bezeichnung, startDatum, endDatum } = await request.json(); const { id, bezeichnung, startDatum, endDatum } = await request.json();
if (typeof id !== 'number' || isNaN(id) || !name || isValidDate(startDatum) || isValidDate(endDatum)) { if (typeof id !== 'number' || isNaN(id) || !bezeichnung || !isValidDate(startDatum) || !isValidDate(endDatum)) {
return json({ error: 'Ungültige Eingabedaten' }, { status: 400 }); return json({ error: 'Ungültige Eingabedaten' }, { status: 400 });
} }
@@ -67,7 +67,11 @@ export const PATCH: RequestHandler = async ({ cookies, request }) => {
try { try {
const updated = await prisma.praktikumszeitraum.update({ const updated = await prisma.praktikumszeitraum.update({
where: { id }, where: { id },
data: { bezeichnung, startDatum, endDatum }, data: {
bezeichnung,
startDatum: new Date(startDatum),
endDatum: new Date(endDatum)
},
}); });
return json(updated); return json(updated);
} catch (e) { } catch (e) {