Change for Agrar
This commit is contained in:
@@ -23,41 +23,30 @@ export default async function publiclinksNonAuthenticatedRoutes(server: FastifyI
|
|||||||
server.post("/workflows/submit/:token", async (req, reply) => {
|
server.post("/workflows/submit/:token", async (req, reply) => {
|
||||||
const { token } = req.params as { token: string };
|
const { token } = req.params as { token: string };
|
||||||
const pin = req.headers['x-public-pin'] as string | undefined;
|
const pin = req.headers['x-public-pin'] as string | undefined;
|
||||||
|
|
||||||
// Payload vom Frontend (enthält nun 'quantity' statt 'startDate/endDate')
|
|
||||||
const body = req.body as any;
|
const body = req.body as any;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/**
|
|
||||||
* TRANSFORMATION
|
|
||||||
* Wenn das Backend weiterhin Zeiträume erwartet, bauen wir diese hier:
|
|
||||||
* Wir nehmen 'jetzt' als Ende und rechnen die 'quantity' (Stunden) zurück.
|
|
||||||
*/
|
|
||||||
const quantity = parseFloat(body.quantity) || 0;
|
const quantity = parseFloat(body.quantity) || 0;
|
||||||
|
|
||||||
|
// Wir nutzen das vom User gewählte deliveryDate
|
||||||
|
// Falls kein Datum geschickt wurde, Fallback auf Heute
|
||||||
|
const baseDate = body.deliveryDate ? dayjs(body.deliveryDate) : dayjs();
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
...body,
|
...body,
|
||||||
// Wir generieren Start/Ende, damit der Service kompatibel bleibt
|
// Wir mappen das deliveryDate auf die Zeitstempel
|
||||||
endDate: new Date(),
|
// Start ist z.B. 08:00 Uhr am gewählten Tag, Ende ist Start + Menge
|
||||||
startDate: dayjs().subtract(quantity, 'hour').toDate()
|
startDate: baseDate.hour(8).minute(0).toDate(),
|
||||||
|
endDate: baseDate.hour(8).add(quantity, 'hour').toDate(),
|
||||||
|
deliveryDate: baseDate.format('YYYY-MM-DD')
|
||||||
};
|
};
|
||||||
|
|
||||||
// Service aufrufen
|
|
||||||
const result = await publicLinkService.submitFormData(server, token, payload, pin);
|
const result = await publicLinkService.submitFormData(server, token, payload, pin);
|
||||||
|
|
||||||
return reply.code(201).send(result);
|
return reply.code(201).send(result);
|
||||||
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
server.log.error(error);
|
server.log.error(error);
|
||||||
|
return reply.code(500).send({ error: "Fehler beim Speichern", details: error.message });
|
||||||
if (error.message === "Link_NotFound") return reply.code(404).send({ error: "Link ungültig" });
|
|
||||||
if (error.message === "Pin_Required") return reply.code(401).send({ error: "PIN erforderlich" });
|
|
||||||
if (error.message === "Pin_Invalid") return reply.code(403).send({ error: "PIN ist falsch" });
|
|
||||||
if (error.message === "Profile_Missing") return reply.code(400).send({ error: "Profil fehlt" });
|
|
||||||
|
|
||||||
return reply.code(500).send({
|
|
||||||
error: "Fehler beim Speichern",
|
|
||||||
details: error.message
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
context: { type: Object, required: true },
|
context: { type: Object, required: true },
|
||||||
token: { type: String, required: true },
|
token: { type: String, required: true },
|
||||||
@@ -12,8 +14,9 @@ const toast = useToast()
|
|||||||
const config = computed(() => props.context.config)
|
const config = computed(() => props.context.config)
|
||||||
const data = computed(() => props.context.data)
|
const data = computed(() => props.context.data)
|
||||||
|
|
||||||
// Initiale Werte setzen (Quantity statt Start/EndDate)
|
// Initiale Werte setzen
|
||||||
const form = ref({
|
const form = ref({
|
||||||
|
deliveryDate: dayjs().format('YYYY-MM-DD'), // Standard: Heute
|
||||||
profile: props.context.meta?.defaultProfileId || null,
|
profile: props.context.meta?.defaultProfileId || null,
|
||||||
project: null,
|
project: null,
|
||||||
service: config.value?.defaults?.serviceId || null,
|
service: config.value?.defaults?.serviceId || null,
|
||||||
@@ -25,11 +28,17 @@ const form = ref({
|
|||||||
const isSubmitting = ref(false)
|
const isSubmitting = ref(false)
|
||||||
const errors = ref({})
|
const errors = ref({})
|
||||||
|
|
||||||
|
// Validierung basierend auf JSON Config & neuen Anforderungen
|
||||||
const validate = () => {
|
const validate = () => {
|
||||||
errors.value = {}
|
errors.value = {}
|
||||||
let isValid = true
|
let isValid = true
|
||||||
const validationRules = config.value.validation || {}
|
const validationRules = config.value.validation || {}
|
||||||
|
|
||||||
|
if (!form.value.deliveryDate) {
|
||||||
|
errors.value.deliveryDate = 'Datum erforderlich'
|
||||||
|
isValid = false
|
||||||
|
}
|
||||||
|
|
||||||
if (!form.value.project && data.value.projects?.length > 0) {
|
if (!form.value.project && data.value.projects?.length > 0) {
|
||||||
errors.value.project = 'Pflichtfeld'
|
errors.value.project = 'Pflichtfeld'
|
||||||
isValid = false
|
isValid = false
|
||||||
@@ -45,6 +54,13 @@ const validate = () => {
|
|||||||
isValid = false
|
isValid = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Profil nur validieren, wenn Auswahl nötig und möglich ist
|
||||||
|
if (!form.value.profile && data.value.profiles?.length > 0 && !props.context.meta.defaultProfileId) {
|
||||||
|
errors.value.profile = 'Bitte Mitarbeiter wählen'
|
||||||
|
isValid = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Feature: Agriculture Diesel
|
||||||
if (config.value.features?.agriculture?.showDieselUsage && validationRules.requireDiesel) {
|
if (config.value.features?.agriculture?.showDieselUsage && validationRules.requireDiesel) {
|
||||||
if (!form.value.dieselUsage || form.value.dieselUsage <= 0) {
|
if (!form.value.dieselUsage || form.value.dieselUsage <= 0) {
|
||||||
errors.value.diesel = 'Dieselverbrauch erforderlich'
|
errors.value.diesel = 'Dieselverbrauch erforderlich'
|
||||||
@@ -61,6 +77,7 @@ const submit = async () => {
|
|||||||
isSubmitting.value = true
|
isSubmitting.value = true
|
||||||
try {
|
try {
|
||||||
const payload = { ...form.value }
|
const payload = { ...form.value }
|
||||||
|
|
||||||
const headers = {}
|
const headers = {}
|
||||||
if (props.pin) headers['x-public-pin'] = props.pin
|
if (props.pin) headers['x-public-pin'] = props.pin
|
||||||
|
|
||||||
@@ -73,11 +90,18 @@ const submit = async () => {
|
|||||||
emit('success')
|
emit('success')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.add({ title: 'Fehler beim Speichern', color: 'red' })
|
toast.add({ title: 'Fehler beim Speichern', color: 'red', icon: 'i-heroicons-exclamation-triangle' })
|
||||||
} finally {
|
} finally {
|
||||||
isSubmitting.value = false
|
isSubmitting.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hilfsfunktion für die dynamische Einheiten-Anzeige
|
||||||
|
const currentUnit = computed(() => {
|
||||||
|
if (!form.value.service) return data.value?.units?.[0]?.symbol || 'h'
|
||||||
|
const selectedService = data.value.services?.find(s => s.id === form.value.service)
|
||||||
|
return selectedService?.unitSymbol || data.value?.units?.[0]?.symbol || 'h'
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -90,6 +114,20 @@ const submit = async () => {
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<div class="space-y-5">
|
<div class="space-y-5">
|
||||||
|
|
||||||
|
<UFormGroup
|
||||||
|
label="Datum der Ausführung"
|
||||||
|
:error="errors.deliveryDate"
|
||||||
|
required
|
||||||
|
>
|
||||||
|
<UInput
|
||||||
|
v-model="form.deliveryDate"
|
||||||
|
type="date"
|
||||||
|
size="lg"
|
||||||
|
icon="i-heroicons-calendar-days"
|
||||||
|
/>
|
||||||
|
</UFormGroup>
|
||||||
|
|
||||||
<UFormGroup
|
<UFormGroup
|
||||||
v-if="!context?.meta?.defaultProfileId && data?.profiles?.length > 0"
|
v-if="!context?.meta?.defaultProfileId && data?.profiles?.length > 0"
|
||||||
label="Mitarbeiter"
|
label="Mitarbeiter"
|
||||||
@@ -103,12 +141,13 @@ const submit = async () => {
|
|||||||
value-attribute="id"
|
value-attribute="id"
|
||||||
placeholder="Name auswählen..."
|
placeholder="Name auswählen..."
|
||||||
searchable
|
searchable
|
||||||
|
size="lg"
|
||||||
/>
|
/>
|
||||||
</UFormGroup>
|
</UFormGroup>
|
||||||
|
|
||||||
<UFormGroup
|
<UFormGroup
|
||||||
v-if="data?.projects?.length > 0"
|
v-if="data?.projects?.length > 0"
|
||||||
:label="config.ui?.labels?.project || 'Projekt'"
|
:label="config.ui?.labels?.project || 'Projekt / Auftrag'"
|
||||||
:error="errors.project"
|
:error="errors.project"
|
||||||
required
|
required
|
||||||
>
|
>
|
||||||
@@ -119,12 +158,13 @@ const submit = async () => {
|
|||||||
value-attribute="id"
|
value-attribute="id"
|
||||||
placeholder="Wählen..."
|
placeholder="Wählen..."
|
||||||
searchable
|
searchable
|
||||||
|
size="lg"
|
||||||
/>
|
/>
|
||||||
</UFormGroup>
|
</UFormGroup>
|
||||||
|
|
||||||
<UFormGroup
|
<UFormGroup
|
||||||
v-if="data?.services?.length > 0"
|
v-if="data?.services?.length > 0"
|
||||||
:label="config?.ui?.labels?.service || 'Leistung'"
|
:label="config?.ui?.labels?.service || 'Tätigkeit'"
|
||||||
:error="errors.service"
|
:error="errors.service"
|
||||||
required
|
required
|
||||||
>
|
>
|
||||||
@@ -135,11 +175,11 @@ const submit = async () => {
|
|||||||
value-attribute="id"
|
value-attribute="id"
|
||||||
placeholder="Wählen..."
|
placeholder="Wählen..."
|
||||||
searchable
|
searchable
|
||||||
|
size="lg"
|
||||||
/>
|
/>
|
||||||
</UFormGroup>
|
</UFormGroup>
|
||||||
|
|
||||||
<UFormGroup
|
<UFormGroup
|
||||||
v-if="config?.features?.timeTracking?.allowManualTime"
|
|
||||||
label="Menge / Dauer"
|
label="Menge / Dauer"
|
||||||
:error="errors.quantity"
|
:error="errors.quantity"
|
||||||
required
|
required
|
||||||
@@ -152,9 +192,7 @@ const submit = async () => {
|
|||||||
placeholder="0.00"
|
placeholder="0.00"
|
||||||
>
|
>
|
||||||
<template #trailing>
|
<template #trailing>
|
||||||
<span class="text-gray-500 text-sm pr-2">
|
<span class="text-gray-500 text-sm pr-2">{{ currentUnit }}</span>
|
||||||
{{ data?.units?.[0]?.symbol || 'h' }}
|
|
||||||
</span>
|
|
||||||
</template>
|
</template>
|
||||||
</UInput>
|
</UInput>
|
||||||
</UFormGroup>
|
</UFormGroup>
|
||||||
@@ -165,16 +203,17 @@ const submit = async () => {
|
|||||||
:error="errors.diesel"
|
:error="errors.diesel"
|
||||||
:required="config?.validation?.requireDiesel"
|
:required="config?.validation?.requireDiesel"
|
||||||
>
|
>
|
||||||
<UInput v-model="form.dieselUsage" type="number" step="0.1" placeholder="0.0">
|
<UInput v-model="form.dieselUsage" type="number" step="0.1" placeholder="0.0" size="lg">
|
||||||
<template #trailing>
|
<template #trailing>
|
||||||
<span class="text-gray-500 text-xs">Liter</span>
|
<span class="text-gray-500 text-xs">Liter</span>
|
||||||
</template>
|
</template>
|
||||||
</UInput>
|
</UInput>
|
||||||
</UFormGroup>
|
</UFormGroup>
|
||||||
|
|
||||||
<UFormGroup :label="config?.ui?.labels?.description || 'Notiz'">
|
<UFormGroup :label="config?.ui?.labels?.description || 'Notiz / Vorkommnisse'">
|
||||||
<UTextarea v-model="form.description" :rows="3" />
|
<UTextarea v-model="form.description" :rows="3" placeholder="Optional..." />
|
||||||
</UFormGroup>
|
</UFormGroup>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<template #footer>
|
<template #footer>
|
||||||
|
|||||||
Reference in New Issue
Block a user