|
@@ -1,7 +1,10 @@
|
|
|
<script lang="ts">
|
|
<script lang="ts">
|
|
|
|
|
+ import { goto } from '$app/navigation';
|
|
|
|
|
+ import { page } from '$app/stores';
|
|
|
import { api_host, authToken } from '$lib';
|
|
import { api_host, authToken } from '$lib';
|
|
|
- import type { AppointmentInputs, AppointmentList, AppointmentTimes, WeekdayAppointment, WeekSelection } from '$lib/dbdata';
|
|
|
|
|
- import { authFetch, generateDateArray, getTimeSlots } from '$lib/funcs';
|
|
|
|
|
|
|
+ import type { Appointment, AppointmentDateTimes, AppointmentInputs, AppointmentList, AppointmentTimes, WeekdayAppointment, WeekSelection } from '$lib/dbdata';
|
|
|
|
|
+ import { authFetch, generateDateArray, getDateString, getTimeSlots } from '$lib/funcs';
|
|
|
|
|
+ import AppointmentConfirmDialog from '$lib/modules/AppointmentConfirmDialog.svelte';
|
|
|
import CreatorBaseInputs from '$lib/modules/CreatorBaseInputs.svelte';
|
|
import CreatorBaseInputs from '$lib/modules/CreatorBaseInputs.svelte';
|
|
|
import CreatorInputs from '$lib/modules/CreatorInputs.svelte';
|
|
import CreatorInputs from '$lib/modules/CreatorInputs.svelte';
|
|
|
import CreatorTimeInputs from '$lib/modules/CreatorTimeInputs.svelte';
|
|
import CreatorTimeInputs from '$lib/modules/CreatorTimeInputs.svelte';
|
|
@@ -14,11 +17,15 @@
|
|
|
let selectedWeek: number = parseInt(moment().startOf("isoWeek").format("YYYYWW"), 10);
|
|
let selectedWeek: number = parseInt(moment().startOf("isoWeek").format("YYYYWW"), 10);
|
|
|
let previousWeek: number = selectedWeek;
|
|
let previousWeek: number = selectedWeek;
|
|
|
let duration: number = 15;
|
|
let duration: number = 15;
|
|
|
- let dueDate: Date = new Date();
|
|
|
|
|
|
|
+ let dueDate: string = "";
|
|
|
let description: string = "test";
|
|
let description: string = "test";
|
|
|
let renderTimeSelection: boolean = false;
|
|
let renderTimeSelection: boolean = false;
|
|
|
let appointmentSaved: boolean = false;
|
|
let appointmentSaved: boolean = false;
|
|
|
let weekSelection: WeekSelection[] = generateDateArray(50);
|
|
let weekSelection: WeekSelection[] = generateDateArray(50);
|
|
|
|
|
+ let endpoint: "create" | "modify" = "create";
|
|
|
|
|
+ let appointmentId: string = "";
|
|
|
|
|
+ let oldAppointmentTimes: AppointmentDateTimes[] = [];
|
|
|
|
|
+
|
|
|
|
|
|
|
|
let appointmentList: AppointmentList[] = [
|
|
let appointmentList: AppointmentList[] = [
|
|
|
{
|
|
{
|
|
@@ -61,14 +68,6 @@
|
|
|
console.log(selectedWeek);
|
|
console.log(selectedWeek);
|
|
|
renderTimeSelection = false;
|
|
renderTimeSelection = false;
|
|
|
|
|
|
|
|
- /*
|
|
|
|
|
- const index = appointmentList.findIndex((entry) => entry.week === selectedWeek);
|
|
|
|
|
- if (index !== -1 && selectedWeekAppointments !== undefined) {
|
|
|
|
|
- appointmentList[index].appointments = selectedWeekAppointments;
|
|
|
|
|
- //console.log(appointmentList[index].appointments);
|
|
|
|
|
- }
|
|
|
|
|
- */
|
|
|
|
|
-
|
|
|
|
|
const ix = appointmentList.findIndex((entry) => entry.week === selectedWeek);
|
|
const ix = appointmentList.findIndex((entry) => entry.week === selectedWeek);
|
|
|
if (ix === -1) {
|
|
if (ix === -1) {
|
|
|
const tmp = {
|
|
const tmp = {
|
|
@@ -112,11 +111,14 @@
|
|
|
function convertAppointmentList() {
|
|
function convertAppointmentList() {
|
|
|
let times: AppointmentTimes[] = [];
|
|
let times: AppointmentTimes[] = [];
|
|
|
|
|
|
|
|
|
|
+ // on update match with existing booked appointments
|
|
|
|
|
+ console.log(oldAppointmentTimes);
|
|
|
|
|
+
|
|
|
appointmentList.forEach(entry => {
|
|
appointmentList.forEach(entry => {
|
|
|
entry.appointments.filter(element => element.active !== false).forEach(day => {
|
|
entry.appointments.filter(element => element.active !== false).forEach(day => {
|
|
|
day.times.forEach(time => {
|
|
day.times.forEach(time => {
|
|
|
// if (!time.start || !time.end)
|
|
// if (!time.start || !time.end)
|
|
|
- times = [... times, ...getTimeSlots(day.date, time.start, time.end, duration)];
|
|
|
|
|
|
|
+ times = [... times, ...getTimeSlots(day.date, time.start, time.end, duration, oldAppointmentTimes)];
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
});
|
|
});
|
|
@@ -129,24 +131,27 @@
|
|
|
if (!topic || !description || !dueDate || !location || !duration || !creatorInputs || !appointmentList) {
|
|
if (!topic || !description || !dueDate || !location || !duration || !creatorInputs || !appointmentList) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+ console.log(appointmentList);
|
|
|
const convertedTimes: AppointmentTimes[] = convertAppointmentList();
|
|
const convertedTimes: AppointmentTimes[] = convertAppointmentList();
|
|
|
console.log(convertedTimes);
|
|
console.log(convertedTimes);
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- const response = await authFetch(`${api_host}/api/users/create`, {
|
|
|
|
|
|
|
+ const response = await authFetch(`${api_host}/api/users/${endpoint}`, {
|
|
|
method: "POST",
|
|
method: "POST",
|
|
|
headers: {
|
|
headers: {
|
|
|
"Content-Type": "application/json",
|
|
"Content-Type": "application/json",
|
|
|
"Authorization": "Bearer " + $authToken
|
|
"Authorization": "Bearer " + $authToken
|
|
|
},
|
|
},
|
|
|
body: JSON.stringify({
|
|
body: JSON.stringify({
|
|
|
|
|
+ appointmentId: appointmentId,
|
|
|
title: topic,
|
|
title: topic,
|
|
|
description: description,
|
|
description: description,
|
|
|
dueDate: dueDate,
|
|
dueDate: dueDate,
|
|
|
place: location,
|
|
place: location,
|
|
|
duration: duration,
|
|
duration: duration,
|
|
|
times: convertedTimes,
|
|
times: convertedTimes,
|
|
|
- inputs: creatorInputs
|
|
|
|
|
|
|
+ inputs: creatorInputs,
|
|
|
|
|
+ timeSpans: appointmentList
|
|
|
})
|
|
})
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -161,9 +166,46 @@
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- onMount(() => {
|
|
|
|
|
- // implement editor if query id param was detected
|
|
|
|
|
|
|
+ async function loadAppointment(appointmentId: string) {
|
|
|
|
|
+ selectedWeekAppointments = undefined;
|
|
|
|
|
+ const response = await fetch(`${api_host}/api/schedule?appointmentId=${appointmentId}&isUser=true`, {
|
|
|
|
|
+ method: 'GET',
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ 'Content-Type': 'application/json'
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (response.status === 404) {
|
|
|
|
|
+ goto('/errors/404');
|
|
|
|
|
+ }
|
|
|
|
|
+ const resp = await response.json();
|
|
|
|
|
+ const js: Appointment = resp;
|
|
|
|
|
+ appointmentList = js.timeSpans;
|
|
|
|
|
|
|
|
|
|
+ topic = js.title;
|
|
|
|
|
+ creatorInputs = js.inputs;
|
|
|
|
|
+ location = js.place;
|
|
|
|
|
+ duration = js.duration;
|
|
|
|
|
+ dueDate = getDateString(js.dueDate);
|
|
|
|
|
+ console.log(js.dueDate);
|
|
|
|
|
+ description = js.description;
|
|
|
|
|
+ oldAppointmentTimes = js.times;
|
|
|
|
|
+ endpoint = "modify";
|
|
|
|
|
+
|
|
|
|
|
+ selectedWeekAppointments = appointmentList.find(
|
|
|
|
|
+ (entry) => entry.week === selectedWeek
|
|
|
|
|
+ )?.appointments;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $: console.log(dueDate);
|
|
|
|
|
+
|
|
|
|
|
+ onMount(async () => {
|
|
|
|
|
+ // implement editor if query id param was detected
|
|
|
|
|
+ const id = $page.url.searchParams.get('id');
|
|
|
|
|
+ if (id) {
|
|
|
|
|
+ appointmentId = id;
|
|
|
|
|
+ await loadAppointment(id);
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// get time slots before sending
|
|
// get time slots before sending
|
|
@@ -189,7 +231,7 @@
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
{#if appointmentSaved}
|
|
{#if appointmentSaved}
|
|
|
- <div class="snackbar green active">Erfolgreich erstellt</div>
|
|
|
|
|
|
|
+ <div class="snackbar green active">Erfolgreich gespeichert</div>
|
|
|
{/if}
|
|
{/if}
|
|
|
|
|
|
|
|
<style>
|
|
<style>
|