feat: Complete wizard_answers to propertyName conversion from DB data
Problem: - Data comes from DB in wizard_answers format (answers to wizard questions) - Form confirmation expects propertyName format (structured data) - transformDraftToClaimPlanFormat tried to extract propertyName from DB, but it doesn't exist - Form shows empty because propertyName structure is empty Solution: 1. Added complete field mapping from wizard_answers to propertyName: - answersParsed.item → contract_or_service.subject - answersParsed.price → contract_or_service.amount_paid (normalized) - answersParsed.place_date → contract_or_service.agreement_date - answersParsed.cancel_date → contract_or_service.period_start - answersParsed.steps_taken → claim.description - answersParsed.expectation → claim.reason - payload.problem_description → claim.description and contract.subject 2. Added applicant data extraction: - phone from claim.phone, payload.phone, body.phone, or formData.phone - email from claim.email, payload.email, body.email, or formData.email - Other applicant fields (FIO, birth_date, INN) will be filled in confirmation form 3. Added default values: - case.category = 'consumer' - case.direction = 'web_form' 4. Enhanced logging: - Logs what data exists in DB - Logs wizard_answers keys - Logs conversion process Files: - frontend/src/pages/ClaimForm.tsx: Complete wizard_answers conversion
This commit is contained in:
@@ -328,27 +328,65 @@ export default function ClaimForm() {
|
||||
|
||||
if (!hasPropertyNameData && answersParsed && Object.keys(answersParsed).length > 0) {
|
||||
console.log('🔄 Преобразуем wizard_answers в propertyName формат');
|
||||
console.log('🔄 wizard_answers keys:', Object.keys(answersParsed));
|
||||
|
||||
// Маппинг полей из wizard_answers
|
||||
// Например: answersParsed.item → contract_or_service.subject
|
||||
// answersParsed.price → contract_or_service.amount_paid
|
||||
// и т.д.
|
||||
|
||||
// Если есть данные в wizard_answers, используем их для заполнения propertyName
|
||||
// Маппинг полей из wizard_answers в contract_or_service
|
||||
if (answersParsed.item && !contractData.subject) {
|
||||
contractData.subject = answersParsed.item;
|
||||
}
|
||||
if (answersParsed.price && !contractData.amount_paid) {
|
||||
contractData.amount_paid = answersParsed.price;
|
||||
contractData.amount_paid_fmt = answersParsed.price;
|
||||
// Нормализуем цену (убираем "рублей", пробелы и т.д.)
|
||||
const priceStr = String(answersParsed.price).replace(/\s+/g, '').replace(/руб(лей|ль|\.)?/gi, '').replace(/₽|р\.|р$/gi, '');
|
||||
contractData.amount_paid = priceStr;
|
||||
contractData.amount_paid_fmt = priceStr;
|
||||
}
|
||||
if (answersParsed.place_date && !contractData.agreement_date) {
|
||||
// Можно попытаться распарсить дату из place_date
|
||||
contractData.agreement_date = answersParsed.place_date;
|
||||
contractData.agreement_date_fmt = answersParsed.place_date;
|
||||
}
|
||||
if (answersParsed.cancel_date && !contractData.period_start) {
|
||||
contractData.period_start = answersParsed.cancel_date;
|
||||
contractData.period_start_fmt = answersParsed.cancel_date;
|
||||
}
|
||||
|
||||
// Маппинг полей из wizard_answers в claim
|
||||
if (answersParsed.steps_taken && !claimData.description) {
|
||||
claimData.description = answersParsed.steps_taken;
|
||||
}
|
||||
if (answersParsed.expectation && !claimData.reason) {
|
||||
// expectation может быть "refund", "replacement", "compensation", "other"
|
||||
claimData.reason = answersParsed.expectation === 'refund' ? 'consumer' : 'consumer';
|
||||
}
|
||||
|
||||
// Маппинг в case
|
||||
if (!caseData.category) {
|
||||
caseData.category = 'consumer'; // По умолчанию consumer
|
||||
}
|
||||
if (!caseData.direction) {
|
||||
caseData.direction = 'web_form';
|
||||
}
|
||||
|
||||
// Если есть problem_description, используем его для claim.description
|
||||
const problemDesc = payload.problem_description || body.problem_description;
|
||||
if (problemDesc && !claimData.description) {
|
||||
claimData.description = problemDesc;
|
||||
}
|
||||
if (problemDesc && !contractData.subject) {
|
||||
contractData.subject = problemDesc;
|
||||
}
|
||||
}
|
||||
|
||||
// Данные заявителя берутся из других источников (phone, email из claim или formData)
|
||||
// ФИО, дата рождения, ИНН будут заполняться в форме подтверждения
|
||||
const applicantPhone = claim.phone || payload.phone || body.phone || currentFormData.phone || null;
|
||||
const applicantEmail = claim.email || payload.email || body.email || currentFormData.email || null;
|
||||
|
||||
// Если есть данные заявителя в applicantData, используем их
|
||||
if (!applicantData.phone && applicantPhone) {
|
||||
applicantData.phone = applicantPhone;
|
||||
}
|
||||
if (!applicantData.email && applicantEmail) {
|
||||
applicantData.email = applicantEmail;
|
||||
}
|
||||
|
||||
// Формируем attachments_names из documents_meta
|
||||
|
||||
Reference in New Issue
Block a user