diff --git a/frontend/components/displayRunningTime.vue b/frontend/components/displayRunningTime.vue index 277ac86..df84f2e 100644 --- a/frontend/components/displayRunningTime.vue +++ b/frontend/components/displayRunningTime.vue @@ -2,8 +2,8 @@ import dayjs from "dayjs"; const profileStore = useProfileStore(); -const supabase = useSupabaseClient() const toast = useToast() +const staffTime = useStaffTime() const runningTimeInfo = ref({}) @@ -11,12 +11,9 @@ const projects = ref([]) const platform = ref("default") const setupPage = async () => { - runningTimeInfo.value = (await supabase.from("times").select().eq("profile", profileStore.activeProfile.id).is("endDate", null).single()).data || {} - - //projects.value = (await useSupabaseSelect("projects")) - - - + const rows = await staffTime.list({ user_id: profileStore.activeProfile?.user_id || profileStore.activeProfile?.id }) + runningTimeInfo.value = rows.find((r) => !r.stopped_at && r.type === "work") || {} + projects.value = await useEntities("projects").select("*") } setupPage() @@ -26,47 +23,25 @@ setupPage() }*/ const startTime = async () => { - console.log("started") - runningTimeInfo.value = { - profile: profileStore.activeProfile.id, - startDate: dayjs(), - tenant: profileStore.currentTenant, - state: platform.value === "mobile" ? "In der App gestartet" : "Im Web gestartet", - source: "Dashboard" - } - - const {data,error} = await supabase - .from("times") - .insert([runningTimeInfo.value]) - .select() - if(error) { + try { + await staffTime.start("Arbeitszeit") + toast.add({title: "Projektzeit erfolgreich gestartet"}) + await setupPage() + } catch (error) { console.log(error) toast.add({title: "Fehler beim starten der Projektzeit",color:"rose"}) - } else if(data) { - toast.add({title: "Projektzeit erfolgreich gestartet"}) - runningTimeInfo.value = data[0] - //console.log(runningTimeInfo.value) } } const stopStartedTime = async () => { - runningTimeInfo.value.endDate = dayjs() - runningTimeInfo.value.state = platform.value === "mobile" ? "In der App gestoppt" : "Im Web gestoppt" - - const {error,status} = await supabase - .from("times") - .update(runningTimeInfo.value) - .eq('id',runningTimeInfo.value.id) - - if(error) { - console.log(error) - let errorId = await useError().logError(`${status} - ${JSON.stringify(error)}`) - toast.add({title: errorId ? `Fehler beim stoppen der Projektzeit (Fehler ID: ${errorId})` : `Fehler beim stoppen der Projektzeit`,color:"rose"}) - - - } else { + try { + await staffTime.stop() toast.add({title: "Projektzeit erfolgreich gestoppt"}) runningTimeInfo.value = {} + } catch (error) { + console.log(error) + let errorId = await useError().logError(`${JSON.stringify(error)}`) + toast.add({title: errorId ? `Fehler beim stoppen der Projektzeit (Fehler ID: ${errorId})` : `Fehler beim stoppen der Projektzeit`,color:"rose"}) } } @@ -74,9 +49,9 @@ const stopStartedTime = async () => {