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
49 lines
2.0 KiB
JavaScript
49 lines
2.0 KiB
JavaScript
// ========================================
|
||
// Code Node: Формирование Response для фронта (безопасная версия с проверками)
|
||
// (перед финальной Response нодой)
|
||
// ========================================
|
||
|
||
// Получаем данные из предыдущих шагов
|
||
const claimResult = $node["CreateWebContact"]?.json?.result || {};
|
||
const sessionDataItem = $('Code in JavaScript1')?.first();
|
||
const sessionData = sessionDataItem?.json?.redis_value
|
||
? JSON.parse(sessionDataItem.json.redis_value)
|
||
: {};
|
||
const userData = $node["user_get"]?.json || {}; // ← Данные из PostgreSQL: Find or Create User
|
||
|
||
// Проверяем наличие unified_id (критически важно!)
|
||
if (!userData.unified_id) {
|
||
console.error('❌ ОШИБКА: unified_id не получен из ноды user_get!');
|
||
// Можно либо выбросить ошибку, либо продолжить без unified_id (не рекомендуется)
|
||
}
|
||
|
||
// Формируем ответ в формате, который ожидает фронт
|
||
return {
|
||
success: true,
|
||
result: {
|
||
claim_id: sessionData.claim_id || claimResult.claim_id,
|
||
contact_id: sessionData.contact_id || claimResult.contact_id,
|
||
project_id: sessionData.project_id,
|
||
|
||
// Unified ID из PostgreSQL (обязательно!)
|
||
unified_id: userData.unified_id, // из ноды user_get (PostgreSQL: Find or Create User)
|
||
|
||
// Данные заявки
|
||
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 || 1,
|
||
updated_at: sessionData.updated_at || new Date().toISOString(),
|
||
|
||
// Дополнительно
|
||
is_new_contact: claimResult.is_new_contact || false
|
||
}
|
||
};
|
||
|
||
|