|
1 | 1 | 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'; |
2 | 5 |
|
3 | 6 | // ─── BPMN ──────────────────────────────────────────────────────────────────── |
4 | 7 |
|
5 | | -export async function listBpmn(): Promise<unknown[]> { |
| 8 | +export async function listBpmn(): Promise<Bpmn[]> { |
6 | 9 | if (!pool) return []; |
7 | | - const { rows } = await pool.query( |
| 10 | + const { rows } = await pool.query<BpmnRow>( |
8 | 11 | `SELECT lde_id, bpmn_process_id, name, description, xml, |
9 | 12 | process_role, called_element, linked_dmn_templates, |
10 | 13 | status, readonly, schema_version, created_at, updated_at |
11 | 14 | FROM process_definitions ORDER BY updated_at DESC` |
12 | 15 | ); |
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); |
28 | 17 | } |
29 | 18 |
|
30 | 19 | export async function upsertBpmn(p: { |
@@ -90,21 +79,15 @@ export async function getBpmnByBpmnProcessId(bpmnProcessId: string): Promise<unk |
90 | 79 |
|
91 | 80 | // ─── Forms ─────────────────────────────────────────────────────────────────── |
92 | 81 |
|
93 | | -export async function listForms(): Promise<unknown[]> { |
| 82 | +export async function listForms(): Promise<Form[]> { |
94 | 83 | 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` |
97 | 89 | ); |
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); |
108 | 91 | } |
109 | 92 |
|
110 | 93 | export async function upsertForm(f: { |
@@ -145,26 +128,17 @@ export async function deleteForm(id: string): Promise<void> { |
145 | 128 |
|
146 | 129 | // ─── Documents ─────────────────────────────────────────────────────────────── |
147 | 130 |
|
148 | | -export async function listDocuments(): Promise<unknown[]> { |
| 131 | +export async function listDocuments(): Promise<Document[]> { |
149 | 132 | 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` |
152 | 140 | ); |
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); |
168 | 142 | } |
169 | 143 |
|
170 | 144 | export async function upsertDocument(d: { |
|
0 commit comments