From 103ecf2faea41be3f8fb478a7047681dd4bd8d42 Mon Sep 17 00:00:00 2001 From: KoreX Labs Date: Mon, 14 Sep 2026 14:06:26 -0300 Subject: [PATCH] fix(api): prevent NaN act version during mobile create --- api-v3/package-lock.json | 4 ++-- api-v3/package.json | 2 +- api-v3/src/inspection-acts/inspection-acts.service.ts | 11 +++++++---- api-v3/src/version.ts | 2 +- api-v3/test/unit/f4-health-metadata.test.ts | 2 +- api-v3/test/unit/f6-3-mobile-act-finding-flow.test.ts | 9 +++++++++ 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/api-v3/package-lock.json b/api-v3/package-lock.json index d59ccea..3dd3e47 100644 --- a/api-v3/package-lock.json +++ b/api-v3/package-lock.json @@ -1,12 +1,12 @@ { "name": "dhv2-api", - "version": "0.29.0-2", + "version": "0.29.0-3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "dhv2-api", - "version": "0.29.0-2", + "version": "0.29.0-3", "license": "UNLICENSED", "dependencies": { "@nestjs/common": "^11.0.0", diff --git a/api-v3/package.json b/api-v3/package.json index 49be4ae..14ec496 100644 --- a/api-v3/package.json +++ b/api-v3/package.json @@ -1,6 +1,6 @@ { "name": "dhv2-api", - "version": "0.29.0-2", + "version": "0.29.0-3", "private": true, "license": "UNLICENSED", "scripts": { diff --git a/api-v3/src/inspection-acts/inspection-acts.service.ts b/api-v3/src/inspection-acts/inspection-acts.service.ts index caa757b..ac5a29e 100644 --- a/api-v3/src/inspection-acts/inspection-acts.service.ts +++ b/api-v3/src/inspection-acts/inspection-acts.service.ts @@ -728,10 +728,13 @@ export class InspectionActsService { principal: AuthPrincipal, ): Promise { const [row] = (await manager.query(` - UPDATE inspection_acts - SET current_version = current_version + 1 - WHERE id = $1 - RETURNING current_version AS "versionNumber" + WITH updated AS ( + UPDATE inspection_acts + SET current_version = current_version + 1 + WHERE id = $1 + RETURNING current_version + ) + SELECT current_version AS "versionNumber" FROM updated `, [act.id])) as Array<{ versionNumber: number }>; const versionNumber = Number(row.versionNumber); act.currentVersion = versionNumber; diff --git a/api-v3/src/version.ts b/api-v3/src/version.ts index e67ed4b..52d4458 100644 --- a/api-v3/src/version.ts +++ b/api-v3/src/version.ts @@ -1,2 +1,2 @@ -export const API_VERSION = '0.29.0-2'; +export const API_VERSION = '0.29.0-3'; export const API_PHASE = 'F6.1'; \ No newline at end of file diff --git a/api-v3/test/unit/f4-health-metadata.test.ts b/api-v3/test/unit/f4-health-metadata.test.ts index 062fdfd..d164e12 100644 --- a/api-v3/test/unit/f4-health-metadata.test.ts +++ b/api-v3/test/unit/f4-health-metadata.test.ts @@ -8,5 +8,5 @@ test('health metadata reports the current F6.1 release', () => { assert.equal(API_PHASE, 'F6.1'); const pkg = JSON.parse(readFileSync(resolve(process.cwd(), 'package.json'), 'utf8')) as { version: string }; assert.equal(API_VERSION, pkg.version); - assert.equal(API_VERSION, '0.29.0-2'); + assert.equal(API_VERSION, '0.29.0-3'); }); \ No newline at end of file diff --git a/api-v3/test/unit/f6-3-mobile-act-finding-flow.test.ts b/api-v3/test/unit/f6-3-mobile-act-finding-flow.test.ts index 4eb200a..5a1c430 100644 --- a/api-v3/test/unit/f6-3-mobile-act-finding-flow.test.ts +++ b/api-v3/test/unit/f6-3-mobile-act-finding-flow.test.ts @@ -63,3 +63,12 @@ test('F6.1 Acta urgency is null while drafting and is persisted atomically at lo assert.match(migration, /ALTER COLUMN urgency DROP NOT NULL/); assert.match(migration, /SET urgency=NULL WHERE status='DRAFT'/); }); + +test('F6.3 Acta version capture uses a SELECT-shaped CTE so TypeORM never turns the version into NaN', () => { + const service = source('src/inspection-acts/inspection-acts.service.ts'); + + assert.match(service, /WITH updated AS \(/); + assert.match(service, /RETURNING current_version/); + assert.match(service, /SELECT current_version AS "versionNumber" FROM updated/); + assert.match(service, /const versionNumber = Number\(row\.versionNumber\)/); +});