Zeitraeume Verwaltung in admin Bereich
This commit is contained in:
@@ -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>
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user