From eb11a09e4384e6626c36d26de4546abf167cd727 Mon Sep 17 00:00:00 2001 From: Alex Tideman Date: Wed, 23 Oct 2024 11:43:31 -0500 Subject: [PATCH] Encode header fields if they exist on schedule edit (#2405) * Encode header fields if they exist on schedule edit * Add try catch for header fields encoding --- src/lib/stores/schedules.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/lib/stores/schedules.ts b/src/lib/stores/schedules.ts index 872b5d109..9645dfd17 100644 --- a/src/lib/stores/schedules.ts +++ b/src/lib/stores/schedules.ts @@ -14,6 +14,7 @@ import type { ScheduleSpecParameters, } from '$lib/types/schedule'; import { encodePayloads } from '$lib/utilities/encode-payload'; +import { stringifyWithBigInt } from '$lib/utilities/parse-with-big-int'; import { routeForSchedule, routeForSchedules } from '$lib/utilities/route-for'; import { convertDaysAndMonths, @@ -204,6 +205,23 @@ export const submitEditSchedule = async ( }, }; + const fields = body.schedule.action.startWorkflow?.header?.fields; + if (fields && Object.keys(fields).length > 0) { + try { + const entries = Object.entries(fields); + for (const [key, value] of entries) { + const encodedValue = await encodePayloads( + stringifyWithBigInt(value), + 'json/plain', + ); + fields[key] = encodedValue[0]; + } + } catch (e) { + error.set(`${translate('data-encoder.encode-error')}: ${e?.message}`); + return; + } + } + if (preset === 'existing') { body.schedule.spec = schedule.spec; } else {