Merged in feature/docresult (pull request #105)

Document Result Endpoint

* testing

* cleantesting

* progress

* query

* lint

* readme

* dockerclient

* api

* passtest

* tests

* test
This commit is contained in:
Michael McGuinness
2025-03-17 18:14:15 +00:00
parent f7c41c4ef3
commit 555b6d420b
105 changed files with 3276 additions and 2484 deletions
+32 -17
View File
@@ -1,25 +1,40 @@
-- name: GetDocument :one
SELECT id, clientId, hash FROM documents WHERE id = $1 LIMIT 1;
-- name: GetDocumentSummary :one
SELECT id, clientId, hash FROM documents WHERE id = $1;
-- name: GetDocumentExternal :one
WITH
docs AS (
SELECT id, hash, clientId
FROM documents
WHERE id = @documentId
),
namedResults AS (
SELECT
q.name,
dd.id,
d.value
FROM currentCollectorQueries AS q
JOIN docs as dd on dd.clientId = q.clientId
LEFT JOIN listValidDocumentResults(@documentId) AS d
ON d.queryId = q.queryId and q.name is not null
)
SELECT
d.id,
c.externalId AS clientId,
d.hash,
COALESCE(jsonb_object_agg(r.name, r.value) FILTER (WHERE r.name IS NOT NULL), '{}') AS fields
FROM docs AS d
JOIN clients AS c ON c.id = d.clientId
LEFT JOIN namedResults AS r ON d.id = r.id
GROUP BY d.id, c.externalId, d.hash;
-- name: ListDocumentsByClientExternalId :many
WITH client as (
SELECT id from clients where externalId = @clientId
),
docs as (
SELECT d.id
from documents as d
JOIN client as c on d.clientId = c.id
),
entries as (
SELECT
de.documentId,
de.bucket,
de.key,
ROW_NUMBER() OVER (PARTITION BY de.documentId ORDER BY de.id DESC) as rowNumber
FROM docs d
JOIN documentEntries de on d.id = de.documentId
)
SELECT documentId as id, bucket, key from entries WHERE rowNumber = 1;
SELECT d.id, d.hash
from documents as d
JOIN client as c on d.clientId = c.id;
-- name: CreateDocument :one
INSERT INTO documents (clientId, hash) VALUES ($1, $2) RETURNING id;