Skip to content

Commit d50d4d5

Browse files
committed
fix: typed the DB rows properly
1 parent d7baaac commit d50d4d5

5 files changed

Lines changed: 162 additions & 49 deletions

File tree

packages/backend/src/db/mappers.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// db/mappers.ts
2+
3+
import { BpmnRow, FormRow, DocumentRow } from './types';
4+
import { Bpmn, Form, Document } from '../domain/types';
5+
6+
export function mapBpmn(row: BpmnRow): Bpmn {
7+
return {
8+
id: row.lde_id,
9+
bpmnProcessId: row.bpmn_process_id,
10+
name: row.name,
11+
description: row.description ?? undefined,
12+
xml: row.xml,
13+
processRole: row.process_role,
14+
calledElement: row.called_element ?? undefined,
15+
linkedDmnTemplates: row.linked_dmn_templates ?? [],
16+
status: row.status,
17+
readonly: row.readonly,
18+
schemaVersion: row.schema_version,
19+
createdAt: row.created_at,
20+
updatedAt: row.updated_at,
21+
};
22+
}
23+
24+
export function mapForm(r: FormRow): Form {
25+
return {
26+
id: r.id,
27+
name: r.name,
28+
description: r.description ?? undefined,
29+
schema: typeof r.schema === 'string' ? JSON.parse(r.schema) : r.schema,
30+
status: r.status,
31+
createdAt: r.created_at,
32+
updatedAt: r.updated_at,
33+
readonly: false,
34+
};
35+
}
36+
37+
export function mapDocument(r: DocumentRow): Document {
38+
return {
39+
id: r.id,
40+
name: r.name,
41+
description: r.description ?? undefined,
42+
processKey: r.process_key ?? undefined,
43+
serviceId: r.service_id ?? undefined,
44+
schemaVersion: r.schema_version,
45+
zones: typeof r.zones === 'string' ? JSON.parse(r.zones) : r.zones,
46+
bindings: typeof r.bindings === 'string' ? JSON.parse(r.bindings) : r.bindings,
47+
assets: typeof r.assets === 'string' ? JSON.parse(r.assets) : r.assets,
48+
status: r.status,
49+
createdAt: r.created_at,
50+
updatedAt: r.updated_at,
51+
readonly: false,
52+
};
53+
}

packages/backend/src/db/types.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// db/types.ts
2+
3+
export type BpmnRow = {
4+
lde_id: string;
5+
bpmn_process_id: string;
6+
name: string;
7+
description: string | null;
8+
xml: string;
9+
process_role: string;
10+
called_element: string | null;
11+
linked_dmn_templates: string[] | null;
12+
status: string;
13+
readonly: boolean;
14+
schema_version: number;
15+
created_at: Date;
16+
updated_at: Date;
17+
};
18+
19+
export type FormRow = {
20+
id: string;
21+
name: string;
22+
description: string | null;
23+
schema: string; // stored as JSON string
24+
status: string;
25+
created_at: Date;
26+
updated_at: Date;
27+
};
28+
29+
export type DocumentRow = {
30+
id: string;
31+
name: string;
32+
description: string | null;
33+
process_key: string | null;
34+
service_id: string | null;
35+
schema_version: number;
36+
zones: string;
37+
bindings: string;
38+
assets: string;
39+
status: string;
40+
created_at: Date;
41+
updated_at: Date;
42+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// domain/types.ts
2+
3+
export type Bpmn = {
4+
id: string;
5+
bpmnProcessId: string;
6+
name: string;
7+
description?: string;
8+
xml: string;
9+
processRole: string;
10+
calledElement?: string;
11+
linkedDmnTemplates: string[];
12+
status: string;
13+
readonly: boolean;
14+
schemaVersion: number;
15+
createdAt: Date;
16+
updatedAt: Date;
17+
};
18+
19+
export type Form = {
20+
id: string;
21+
name: string;
22+
description?: string;
23+
schema: Record<string, unknown>;
24+
status: string;
25+
createdAt: Date;
26+
updatedAt: Date;
27+
readonly: boolean;
28+
};
29+
30+
export type Document = {
31+
id: string;
32+
name: string;
33+
description?: string;
34+
processKey?: string;
35+
serviceId?: string;
36+
schemaVersion: number;
37+
zones: unknown;
38+
bindings: unknown;
39+
assets: unknown;
40+
status: string;
41+
createdAt: Date;
42+
updatedAt: Date;
43+
readonly: boolean;
44+
};

packages/backend/src/services/assets.service.ts

Lines changed: 22 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
11
import pool from '../db/pool';
2+
import { BpmnRow, FormRow, DocumentRow } from '../db/types';
3+
import { Bpmn, Form, Document } from '../domain/types';
4+
import { mapBpmn, mapForm, mapDocument } from '../db/mappers';
25

36
// ─── BPMN ────────────────────────────────────────────────────────────────────
47

5-
export async function listBpmn(): Promise<unknown[]> {
8+
export async function listBpmn(): Promise<Bpmn[]> {
69
if (!pool) return [];
7-
const { rows } = await pool.query(
10+
const { rows } = await pool.query<BpmnRow>(
811
`SELECT lde_id, bpmn_process_id, name, description, xml,
912
process_role, called_element, linked_dmn_templates,
1013
status, readonly, schema_version, created_at, updated_at
1114
FROM process_definitions ORDER BY updated_at DESC`
1215
);
13-
return rows.map((r) => ({
14-
id: r.lde_id,
15-
bpmnProcessId: r.bpmn_process_id,
16-
name: r.name,
17-
description: r.description ?? undefined,
18-
xml: r.xml,
19-
processRole: r.process_role,
20-
calledElement: r.called_element ?? undefined,
21-
linkedDmnTemplates: r.linked_dmn_templates ?? [],
22-
status: r.status,
23-
readonly: r.readonly,
24-
schemaVersion: r.schema_version,
25-
createdAt: r.created_at,
26-
updatedAt: r.updated_at,
27-
}));
16+
return rows.map(mapBpmn);
2817
}
2918

3019
export async function upsertBpmn(p: {
@@ -90,21 +79,15 @@ export async function getBpmnByBpmnProcessId(bpmnProcessId: string): Promise<unk
9079

9180
// ─── Forms ───────────────────────────────────────────────────────────────────
9281

93-
export async function listForms(): Promise<unknown[]> {
82+
export async function listForms(): Promise<Form[]> {
9483
if (!pool) return [];
95-
const { rows } = await pool.query(
96-
'SELECT id, name, description, schema, status, created_at, updated_at FROM form_schemas ORDER BY updated_at DESC'
84+
85+
const { rows } = await pool.query<FormRow>(
86+
`SELECT id, name, description, schema, status, created_at, updated_at
87+
FROM form_schemas
88+
ORDER BY updated_at DESC`
9789
);
98-
return rows.map((r) => ({
99-
id: r.id,
100-
name: r.name,
101-
description: r.description ?? undefined,
102-
schema: r.schema,
103-
status: r.status,
104-
createdAt: r.created_at,
105-
updatedAt: r.updated_at,
106-
readonly: false,
107-
}));
90+
return rows.map(mapForm);
10891
}
10992

11093
export async function upsertForm(f: {
@@ -145,26 +128,17 @@ export async function deleteForm(id: string): Promise<void> {
145128

146129
// ─── Documents ───────────────────────────────────────────────────────────────
147130

148-
export async function listDocuments(): Promise<unknown[]> {
131+
export async function listDocuments(): Promise<Document[]> {
149132
if (!pool) return [];
150-
const { rows } = await pool.query(
151-
'SELECT id, name, description, process_key, service_id, schema_version, zones, bindings, assets, status, created_at, updated_at FROM document_templates ORDER BY updated_at DESC'
133+
134+
const { rows } = await pool.query<DocumentRow>(
135+
`SELECT id, name, description, process_key, service_id,
136+
schema_version, zones, bindings, assets, status,
137+
created_at, updated_at
138+
FROM document_templates
139+
ORDER BY updated_at DESC`
152140
);
153-
return rows.map((r) => ({
154-
id: r.id,
155-
name: r.name,
156-
description: r.description ?? undefined,
157-
processKey: r.process_key ?? undefined,
158-
serviceId: r.service_id ?? undefined,
159-
schemaVersion: r.schema_version,
160-
zones: r.zones,
161-
bindings: r.bindings,
162-
assets: r.assets,
163-
status: r.status,
164-
createdAt: r.created_at,
165-
updatedAt: r.updated_at,
166-
readonly: false,
167-
}));
141+
return rows.map(mapDocument);
168142
}
169143

170144
export async function upsertDocument(d: {

packages/ropa-site/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ <h1>Register van verwerkingsactiviteiten</h1>
427427

428428
// ── Config ────────────────────────────────────────────────────────────────
429429
const API_URL =
430-
'https://acc.backend.linkeddata.open-regels.nl/v1/ropa/public?organisation=flevoland';
430+
'http://localhost:3001/v1/ropa/public?organisation=flevoland';
431431

432432
// ── Dutch labels ──────────────────────────────────────────────────────────
433433
const CAT_NL = {

0 commit comments

Comments
 (0)