diff --git a/backend.models/Automation/TransactionAutomation.cs b/backend.models/Automation/TransactionAutomation.cs index dea0e08..ef04a06 100644 --- a/backend.models/Automation/TransactionAutomation.cs +++ b/backend.models/Automation/TransactionAutomation.cs @@ -156,7 +156,7 @@ public class ActionSetMetaValue : TransactionAutomationAction public override string Key => "set-meta-value"; public override int Version => 1; public required int FieldId { get; set; } - public required object? Value { get; set; } + public required ViewSetMetaField Value { get; set; } } #endregion diff --git a/backend/Services/AutomationService.cs b/backend/Services/AutomationService.cs index 5c31772..d833002 100644 --- a/backend/Services/AutomationService.cs +++ b/backend/Services/AutomationService.cs @@ -193,13 +193,9 @@ private async Task RunAction(TransactionAutomationAction action, Transaction tra _context.Transactions.Remove(transaction); break; case ActionSetMetaValue a: - await _meta.SetTransactionMetaValues(transaction.Id, user.Id, new List - { - new ViewSetMetaField { - MetaId = a.FieldId, - Value = a.Value, - } - }); + await _meta.SetTransactionMetaValues( + transaction.Id, + user.Id, new List { a.Value }); break; } } diff --git a/frontend/src/components/transaction/automation/SetMetaValueEditor.tsx b/frontend/src/components/transaction/automation/SetMetaValueEditor.tsx index 8def81c..bb5f5be 100644 --- a/frontend/src/components/transaction/automation/SetMetaValueEditor.tsx +++ b/frontend/src/components/transaction/automation/SetMetaValueEditor.tsx @@ -28,8 +28,8 @@ export function SetMetaValueEditor (props: TransactionActionEditorProps props.onChange({ ...props.action, value })} + onChange={value => props.onChange({ + ...props.action, + value: { + metaId: field.id, + type: field.valueType, + value + } + })} /> } ; diff --git a/frontend/src/models/automation/transactionAutomation.ts b/frontend/src/models/automation/transactionAutomation.ts index 2217f82..da8af59 100644 --- a/frontend/src/models/automation/transactionAutomation.ts +++ b/frontend/src/models/automation/transactionAutomation.ts @@ -2,7 +2,7 @@ import Decimal from "decimal.js"; import { DateTime } from "luxon"; import { SearchGroup } from "../search"; import { serializeTransactionLine, TransactionLine } from "../transaction"; -import { MetaFieldValue } from "../meta"; +import { serializeSetMetaFieldValue, SetMetaFieldValue } from "../meta"; export interface TransactionAutomation { id?: number @@ -82,7 +82,7 @@ export interface ActionSetCategory { export interface ActionSetMetaValue { key: "set-meta-value" fieldId: number | null - value: MetaFieldValue["value"] | null + value: SetMetaFieldValue | null } export interface ActionDelete { @@ -100,8 +100,8 @@ export function serializeTransactionAction (action: TransactionAction): Transact case "set-lines": return { ...action, value: action.value.map(serializeTransactionLine) } as any as TransactionAction; case "set-meta-value": - if (action.value !== null && (action.value as any).id !== undefined) { - return { ...action, value: (action.value as any).id } as any as TransactionAction; + if (action.value !== null) { + return { ...action, value: serializeSetMetaFieldValue(action.value) } as any as TransactionAction; } return action; default: diff --git a/frontend/src/models/meta.ts b/frontend/src/models/meta.ts index 9b05356..3522051 100644 --- a/frontend/src/models/meta.ts +++ b/frontend/src/models/meta.ts @@ -43,7 +43,7 @@ export function serializeSetMetaFieldValue (field: SetMetaFieldValue): SetMetaFi field.value = (field.value as Transaction).id as any; break; case FieldValueType.Attachment: - // Attachments are uploaded using a separate call, so non-null values are simply set to truee + // Attachments are uploaded using a separate call, so non-null values are simply set to true if (field.value !== null) { field.value = true; }