Corrected Errors in Workintimes

Introduced Error Logging to Supabase
This commit is contained in:
2025-01-07 16:43:24 +01:00
parent ff1685a721
commit 26fef320ef
7 changed files with 162 additions and 102 deletions

View File

@@ -11,17 +11,10 @@ definePageMeta({
const dataStore = useDataStore()
const profileStore = useProfileStore()
const supabase = useSupabaseClient()
const user = useSupabaseUser()
const toast = useToast()
const router = useRouter()
const timeInfo = ref({
profile: "",
start: "",
end: null,
notes: null,
})
const filterUser = ref(profileStore.activeProfile.id || "")
@@ -108,53 +101,8 @@ const columns = [
]
const runningTimeInfo = ref({})
const startTime = async () => {
console.log("started")
timeInfo.value = {
profile: profileStore.activeProfile.id,
startDate: dayjs(),
tenant: profileStore.currentTenant,
state: "Im Web gestartet"
}
const {data,error} = await supabase
.from("workingtimes")
.insert([timeInfo.value])
.select()
if(error) {
console.log(error)
} else if(data) {
//timeInfo.value = data[0]
await dataStore.fetchWorkingTimes()
runningTimeInfo.value = timeInfo.value//dataStore.times.find(time => time.profile === profileStore.activeProfile.id && !time.endDate)
}
}
const stopStartedTime = async () => {
runningTimeInfo.value.endDate = dayjs()
runningTimeInfo.value.state = "Im Web gestoppt"
const {data,error} = await supabase
.from("workingtimes")
.update(runningTimeInfo.value)
.eq('id',runningTimeInfo.value.id)
.select()
console.log(data)
if(error) {
console.log(error)
} else {
toast.add({title: "Zeit erfolgreich gestoppt"})
runningTimeInfo.value = {}
dataStore.fetchWorkingTimes()
}
}
if(dataStore.workingtimes.find(time => time.profile === profileStore.activeProfile.id && !time.endDate)) {
runningTimeInfo.value = dataStore.workingtimes.find(time => time.profile === profileStore.activeProfile.id && !time.end)
}
const getDuration = (time) => {
const minutes = Math.floor(dayjs(time.endDate).diff(dayjs(time.startDate),'minutes',true))
@@ -185,17 +133,19 @@ const expand = ref({
row: {}
})
const setEndDate = (row) => {
row.startDate = dayjs(row.startDate).toISOString()
row.endDate = dayjs(row.endDate).set("year", dayjs(row.startDate).get("year")).set("month", dayjs(row.startDate).get("month")).set("date", dayjs(row.startDate).get("date"))
row.endDate = dayjs(row.endDate).toISOString()
}
</script>
<template>
<UDashboardNavbar title="Anwesenheiten">
<template #right>
<UButton
@click="startTime"
:disabled="runningTimeInfo.id "
>
Start
</UButton>
<UButton
@click="router.push(`/workingtimes/edit`)"
>
@@ -224,34 +174,6 @@ const expand = ref({
</UButton>
</template>
</UDashboardToolbar>
<div class="mx-3">
<UAlert
v-if="runningTimeInfo.startDate && !runningTimeInfo.endDate"
class="my-3"
title="Laufende Zeit:"
>
<template #description>
<p>Start: {{dayjs(runningTimeInfo.startDate).format("HH:mm")}}</p>
<p>Dauer: {{dayjs().diff(dayjs(runningTimeInfo.startDate),'minutes') > 59 ? `${Math.floor(dayjs().diff(dayjs(runningTimeInfo.startDate),'minutes') / 60)}:${dayjs().diff(dayjs(runningTimeInfo.startDate),'minutes') % 60} h` : dayjs().diff(dayjs(runningTimeInfo.startDate),'minutes') + ' min' }}</p>
<UFormGroup
class="mt-2"
label="Notizen:"
>
<UTextarea
v-model="runningTimeInfo.notes"
/>
</UFormGroup>
<UButton
class="mt-3"
@click="stopStartedTime"
:disabled="!runningTimeInfo.id"
>
Stop
</UButton>
</template>
</UAlert>
</div>
<UTable
class="mt-3"
@@ -287,6 +209,7 @@ const expand = ref({
</UTooltip>
</InputGroup>
<div class="p-4" v-if="!row.approved">
{{row}}
<UFormGroup label="Start:">
@@ -298,7 +221,7 @@ const expand = ref({
/>
<template #panel="{ close }">
<LazyDatePicker v-model="row.startDate" @close="row.endDate = row.startDate" mode="dateTime"/>
<LazyDatePicker v-model="row.startDate" @close="setEndDate(row)" mode="dateTime"/>
</template>
</UPopover>
</UFormGroup>