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

View File

@@ -45,7 +45,7 @@ export const PATCH: RequestHandler = async ({ cookies, request }) => {
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 });
}
@@ -67,7 +67,11 @@ export const PATCH: RequestHandler = async ({ cookies, request }) => {
try {
const updated = await prisma.praktikumszeitraum.update({
where: { id },
data: { bezeichnung, startDatum, endDatum },
data: {
bezeichnung,
startDatum: new Date(startDatum),
endDatum: new Date(endDatum)
},
});
return json(updated);
} catch (e) {