diff --git a/@platform/codebase/@features/platform-api/src/common/numeric.transformer.ts b/@platform/codebase/@features/platform-api/src/common/numeric.transformer.ts new file mode 100644 index 0000000..749cbcc --- /dev/null +++ b/@platform/codebase/@features/platform-api/src/common/numeric.transformer.ts @@ -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), +}; diff --git a/@platform/codebase/@features/platform-api/src/modules/agent-actions/agent-actions.dto.ts b/@platform/codebase/@features/platform-api/src/modules/agent-actions/agent-actions.dto.ts index 72ffcc7..bc53f18 100644 --- a/@platform/codebase/@features/platform-api/src/modules/agent-actions/agent-actions.dto.ts +++ b/@platform/codebase/@features/platform-api/src/modules/agent-actions/agent-actions.dto.ts @@ -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 | null; diff --git a/@platform/codebase/@features/platform-api/src/modules/agent-actions/agent-actions.service.ts b/@platform/codebase/@features/platform-api/src/modules/agent-actions/agent-actions.service.ts index 6902d52..8d0b61a 100644 --- a/@platform/codebase/@features/platform-api/src/modules/agent-actions/agent-actions.service.ts +++ b/@platform/codebase/@features/platform-api/src/modules/agent-actions/agent-actions.service.ts @@ -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({