refactor(agent-actions): ♻️ Remove confidence field from AgentActionsDto and update validation logic and numeric transformations

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
autocommit 2026-05-17 07:48:21 -07:00
parent 26a273a55e
commit 9b59904ea3
3 changed files with 18 additions and 2 deletions

View file

@ -0,0 +1,17 @@
import type { ValueTransformer } from 'typeorm';
/**
* TypeORM transformer for PG `numeric` columns.
*
* Postgres returns numeric/decimal as `string` to preserve arbitrary precision.
* For bounded-precision domain values (e.g. confidence 0..1 at 3 decimals) the
* floating-point loss is below resolution, so we expose `number` on the entity
* and through DTOs. This keeps validation (@IsNumber, @Min, @Max) honest.
*
* DO NOT use for monetary or unbounded-precision fields those must stay `string`.
*/
export const numericTransformer: ValueTransformer = {
to: (value: number | null | undefined): number | null | undefined => value,
from: (value: string | null | undefined): number | null | undefined =>
value === null || value === undefined ? value : Number(value),
};

View file

@ -69,7 +69,7 @@ export class CreateAgentActionDto {
@Type(() => Date)
approved_at?: Date | null;
@ApiProperty({ type: 'object', required: false, nullable: true, additionalProperties: {} })
@ApiProperty({ type: Object, required: false, nullable: true })
@IsOptional()
@IsObject()
outcome_json?: Record<string, unknown> | null;

View file

@ -44,7 +44,6 @@ export class AgentActionsService {
approved_by: input.approved_by ?? null,
approved_at: input.approved_at ?? null,
outcome_json: input.outcome_json ?? null,
confidence: input.confidence.toFixed(3),
});
const saved = await this.repo.save(entity);
await this.cache.publish({