Database changes: - Add unified_id, contact_id, phone columns to clpr_claims table - Create indexes for fast lookup by these fields - Migrate existing data from payload to new columns - SQL migration: docs/SQL_ALTER_CLPR_CLAIMS_ADD_FIELDS.sql SQL improvements: - Simplify claimsave query: remove complex claim_lookup logic - Use UPSERT (INSERT ON CONFLICT) with known claim_id - Always return claim (fix NULL issue) - Store unified_id, contact_id, phone directly in table columns - SQL: docs/SQL_CLAIMSAVE_UPSERT_SIMPLE.sql Workflow enhancements: - Add branch for form submissions WITHOUT files - Create 6 new nodes: extract, prepare, save, redis, respond - Separate flow for has_files=false in IF node - Instructions: docs/N8N_FORM_GET_NO_FILES_INSTRUCTIONS.md - Node config: docs/N8N_FORM_GET_NO_FILES_BRANCH.json Migration stats: - Total claims: 81 - With unified_id: 77 - Migrated from payload: 2 Next steps: 1. Add 6 nodes to n8n workflow form_get (ID: 8ZVMTsuH7Cmw7snw) 2. Connect TRUE branch of IF node to extract_webhook_data_no_files 3. Test form submission without files 4. Verify PostgreSQL save and Redis event
40 lines
1.4 KiB
JavaScript
40 lines
1.4 KiB
JavaScript
// ========================================
|
|
// Code Node: Формирование Response для фронта
|
|
// (перед финальной Response нодой)
|
|
// ========================================
|
|
|
|
// Получаем данные из предыдущих шагов
|
|
const claimResult = $node["CreateWebContact"].json.result;
|
|
const sessionData = JSON.parse($('Code in JavaScript1').first().json.redis_value);
|
|
const userData = $node["user_get"].json; // ← Данные из PostgreSQL: Find or Create User
|
|
|
|
// Формируем ответ в формате, который ожидает фронт
|
|
return {
|
|
success: true,
|
|
result: {
|
|
claim_id: sessionData.claim_id,
|
|
contact_id: sessionData.contact_id,
|
|
project_id: sessionData.project_id,
|
|
|
|
// Unified ID из PostgreSQL (обязательно!)
|
|
unified_id: userData.unified_id || userData.unified_id, // из ноды user_get
|
|
|
|
// Данные заявки
|
|
ticket_id: claimResult.ticket_id,
|
|
ticket_number: claimResult.ticket_number,
|
|
title: claimResult.title,
|
|
category: claimResult.category,
|
|
status: claimResult.status,
|
|
|
|
// Метаданные
|
|
event_type: sessionData.event_type,
|
|
current_step: sessionData.current_step,
|
|
updated_at: sessionData.updated_at,
|
|
|
|
// Дополнительно
|
|
is_new_contact: claimResult.is_new_contact || false
|
|
}
|
|
};
|
|
|
|
|