From db27d4b9645e310e992e045a0feb4330da1db4b3 Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 2 May 2024 20:02:03 +0300 Subject: [PATCH] fix error json scalar --- internal/workers_methods/methods.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/internal/workers_methods/methods.go b/internal/workers_methods/methods.go index 6ca04e2..6d050cb 100644 --- a/internal/workers_methods/methods.go +++ b/internal/workers_methods/methods.go @@ -496,15 +496,12 @@ func (m *Methods) CheckFieldRule(ctx context.Context, token string, accountID st newFields = append(newFields, tools.ToField(createdFields.Embedded.CustomFields, entity)...) } - defer func() { + if len(newFields) > 0 { + err = m.repo.AmoRepo.CheckFields(ctx, newFields, accountID) if err != nil { - m.logger.Error("error updating fields rule in db", zap.Error(err)) + m.logger.Error("error updating fields rule in db Check Fields", zap.Error(err)) + return err } - }() - - err = m.repo.AmoRepo.CheckFields(ctx, newFields, accountID) - if err != nil { - return err } constructFieldRules := func(fieldRuleArrCurrent []model.FieldRule, questions []model.Question, fieldRule *[]model.FieldRule) { @@ -535,11 +532,18 @@ func (m *Methods) CheckFieldRule(ctx context.Context, token string, accountID st constructFieldRules(currentFieldsRule.Contact, contactQuestions, &contact) constructFieldRules(currentFieldsRule.Customer, customerQuestions, &customer) constructFieldRules(currentFieldsRule.Company, companyQuestions, &company) - // todo pq: cannot call json_array_elements on a scalar - return m.repo.AmoRepo.UpdateFieldRules(ctx, model.Fieldsrule{ + + err = m.repo.AmoRepo.UpdateFieldRules(ctx, model.Fieldsrule{ Lead: lead, Customer: customer, Company: company, Contact: contact, }, accountID, req.QuizID) + + if err != nil { + m.logger.Error("error updating fields rule in db", zap.Error(err)) + return err + } + + return nil }