feat: Exclude approved forms from drafts list
Added filtering to exclude approved/confirmed forms from drafts list: - Updated /drafts/list endpoint to filter out forms with status_code='approved' or is_confirmed=true - Created SQL script for n8n to mark forms as approved after processing Redis channel data - Forms marked as approved will no longer appear in drafts list SQL script: SQL_MARK_FORM_APPROVED.sql - Updates status_code to 'approved' - Sets is_confirmed = true - Uses claim_lookup CTE to find claim by id or payload->>'claim_id' Files: - backend/app/api/claims.py (updated drafts list queries) - docs/SQL_MARK_FORM_APPROVED.sql (new SQL script for n8n)
This commit is contained in:
@@ -201,6 +201,8 @@ async def list_drafts(
|
||||
c.updated_at
|
||||
FROM clpr_claims c
|
||||
WHERE c.unified_id = $1
|
||||
AND (c.status_code != 'approved' OR c.status_code IS NULL)
|
||||
AND (c.is_confirmed IS NULL OR c.is_confirmed = false)
|
||||
ORDER BY c.updated_at DESC
|
||||
LIMIT 20
|
||||
"""
|
||||
@@ -227,6 +229,8 @@ async def list_drafts(
|
||||
AND ua.channel_user_id = $1
|
||||
LIMIT 1
|
||||
)
|
||||
AND (c.status_code != 'approved' OR c.status_code IS NULL)
|
||||
AND (c.is_confirmed IS NULL OR c.is_confirmed = false)
|
||||
ORDER BY c.updated_at DESC
|
||||
LIMIT 20
|
||||
"""
|
||||
@@ -246,6 +250,8 @@ async def list_drafts(
|
||||
c.updated_at
|
||||
FROM clpr_claims c
|
||||
WHERE c.session_token = $1
|
||||
AND (c.status_code != 'approved' OR c.status_code IS NULL)
|
||||
AND (c.is_confirmed IS NULL OR c.is_confirmed = false)
|
||||
ORDER BY c.updated_at DESC
|
||||
LIMIT 20
|
||||
"""
|
||||
|
||||
41
docs/SQL_MARK_FORM_APPROVED.sql
Normal file
41
docs/SQL_MARK_FORM_APPROVED.sql
Normal file
@@ -0,0 +1,41 @@
|
||||
-- SQL скрипт для n8n: Отметка формы как подтвержденной после получения данных из Redis канала
|
||||
-- Используется после обработки события из канала clientright:webform:approve
|
||||
--
|
||||
-- Параметры:
|
||||
-- $1 = claim_id (UUID или текст)
|
||||
--
|
||||
-- Обновляет:
|
||||
-- - status_code = 'approved' (отмечает форму как подтвержденную)
|
||||
-- - is_confirmed = true (дополнительный флаг подтверждения)
|
||||
-- - updated_at = now() (время обновления)
|
||||
--
|
||||
-- После этого запись больше не будет показываться в списке черновиков
|
||||
|
||||
WITH claim_lookup AS (
|
||||
SELECT
|
||||
c.id,
|
||||
c.payload,
|
||||
c.status_code,
|
||||
c.is_confirmed
|
||||
FROM clpr_claims c
|
||||
WHERE c.id::text = $1::text
|
||||
OR c.payload->>'claim_id' = $1::text
|
||||
ORDER BY
|
||||
CASE WHEN c.id::text = $1::text THEN 1 ELSE 2 END,
|
||||
c.updated_at DESC
|
||||
LIMIT 1
|
||||
)
|
||||
UPDATE clpr_claims c
|
||||
SET
|
||||
status_code = 'approved',
|
||||
is_confirmed = true,
|
||||
updated_at = now()
|
||||
FROM claim_lookup cl
|
||||
WHERE c.id = cl.id
|
||||
RETURNING
|
||||
c.id,
|
||||
c.payload->>'claim_id' AS claim_id,
|
||||
c.status_code,
|
||||
c.is_confirmed,
|
||||
c.updated_at;
|
||||
|
||||
Reference in New Issue
Block a user