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) => {
|
||||
const { token } = req.params as { token: string };
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
// 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 = {
|
||||
...body,
|
||||
// Wir generieren Start/Ende, damit der Service kompatibel bleibt
|
||||
endDate: new Date(),
|
||||
startDate: dayjs().subtract(quantity, 'hour').toDate()
|
||||
// Wir mappen das deliveryDate auf die Zeitstempel
|
||||
// Start ist z.B. 08:00 Uhr am gewählten Tag, Ende ist Start + Menge
|
||||
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);
|
||||
|
||||
return reply.code(201).send(result);
|
||||
|
||||
} catch (error: any) {
|
||||
server.log.error(error);
|
||||
|
||||
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
|
||||
});
|
||||
return reply.code(500).send({ error: "Fehler beim Speichern", details: error.message });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
<script setup>
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
const props = defineProps({
|
||||
context: { type: Object, required: true },
|
||||
token: { type: String, required: true },
|
||||
@@ -12,8 +14,9 @@ const toast = useToast()
|
||||
const config = computed(() => props.context.config)
|
||||
const data = computed(() => props.context.data)
|
||||
|
||||
// Initiale Werte setzen (Quantity statt Start/EndDate)
|
||||
// Initiale Werte setzen
|
||||
const form = ref({
|
||||
deliveryDate: dayjs().format('YYYY-MM-DD'), // Standard: Heute
|
||||
profile: props.context.meta?.defaultProfileId || null,
|
||||
project: null,
|
||||
service: config.value?.defaults?.serviceId || null,
|
||||
@@ -25,11 +28,17 @@ const form = ref({
|
||||
const isSubmitting = ref(false)
|
||||
const errors = ref({})
|
||||
|
||||
// Validierung basierend auf JSON Config & neuen Anforderungen
|
||||
const validate = () => {
|
||||
errors.value = {}
|
||||
let isValid = true
|
||||
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) {
|
||||
errors.value.project = 'Pflichtfeld'
|
||||
isValid = false
|
||||
@@ -45,6 +54,13 @@ const validate = () => {
|
||||
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 (!form.value.dieselUsage || form.value.dieselUsage <= 0) {
|
||||
errors.value.diesel = 'Dieselverbrauch erforderlich'
|
||||
@@ -61,6 +77,7 @@ const submit = async () => {
|
||||
isSubmitting.value = true
|
||||
try {
|
||||
const payload = { ...form.value }
|
||||
|
||||
const headers = {}
|
||||
if (props.pin) headers['x-public-pin'] = props.pin
|
||||
|
||||
@@ -73,11 +90,18 @@ const submit = async () => {
|
||||
emit('success')
|
||||
} catch (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 {
|
||||
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>
|
||||
|
||||
<template>
|
||||
@@ -90,6 +114,20 @@ const submit = async () => {
|
||||
</template>
|
||||
|
||||
<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
|
||||
v-if="!context?.meta?.defaultProfileId && data?.profiles?.length > 0"
|
||||
label="Mitarbeiter"
|
||||
@@ -103,12 +141,13 @@ const submit = async () => {
|
||||
value-attribute="id"
|
||||
placeholder="Name auswählen..."
|
||||
searchable
|
||||
size="lg"
|
||||
/>
|
||||
</UFormGroup>
|
||||
|
||||
<UFormGroup
|
||||
v-if="data?.projects?.length > 0"
|
||||
:label="config.ui?.labels?.project || 'Projekt'"
|
||||
:label="config.ui?.labels?.project || 'Projekt / Auftrag'"
|
||||
:error="errors.project"
|
||||
required
|
||||
>
|
||||
@@ -119,12 +158,13 @@ const submit = async () => {
|
||||
value-attribute="id"
|
||||
placeholder="Wählen..."
|
||||
searchable
|
||||
size="lg"
|
||||
/>
|
||||
</UFormGroup>
|
||||
|
||||
<UFormGroup
|
||||
v-if="data?.services?.length > 0"
|
||||
:label="config?.ui?.labels?.service || 'Leistung'"
|
||||
:label="config?.ui?.labels?.service || 'Tätigkeit'"
|
||||
:error="errors.service"
|
||||
required
|
||||
>
|
||||
@@ -135,11 +175,11 @@ const submit = async () => {
|
||||
value-attribute="id"
|
||||
placeholder="Wählen..."
|
||||
searchable
|
||||
size="lg"
|
||||
/>
|
||||
</UFormGroup>
|
||||
|
||||
<UFormGroup
|
||||
v-if="config?.features?.timeTracking?.allowManualTime"
|
||||
label="Menge / Dauer"
|
||||
:error="errors.quantity"
|
||||
required
|
||||
@@ -152,9 +192,7 @@ const submit = async () => {
|
||||
placeholder="0.00"
|
||||
>
|
||||
<template #trailing>
|
||||
<span class="text-gray-500 text-sm pr-2">
|
||||
{{ data?.units?.[0]?.symbol || 'h' }}
|
||||
</span>
|
||||
<span class="text-gray-500 text-sm pr-2">{{ currentUnit }}</span>
|
||||
</template>
|
||||
</UInput>
|
||||
</UFormGroup>
|
||||
@@ -165,16 +203,17 @@ const submit = async () => {
|
||||
:error="errors.diesel"
|
||||
: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>
|
||||
<span class="text-gray-500 text-xs">Liter</span>
|
||||
</template>
|
||||
</UInput>
|
||||
</UFormGroup>
|
||||
|
||||
<UFormGroup :label="config?.ui?.labels?.description || 'Notiz'">
|
||||
<UTextarea v-model="form.description" :rows="3" />
|
||||
<UFormGroup :label="config?.ui?.labels?.description || 'Notiz / Vorkommnisse'">
|
||||
<UTextarea v-model="form.description" :rows="3" placeholder="Optional..." />
|
||||
</UFormGroup>
|
||||
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
|
||||
Reference in New Issue
Block a user