diff --git a/internal/tools/for_rules.go b/internal/tools/for_rules.go index cf72857..74fbb25 100644 --- a/internal/tools/for_rules.go +++ b/internal/tools/for_rules.go @@ -44,15 +44,23 @@ import ( // return forUpdate //} -func ToCreatedUpdateQuestionRules(questionsTypeMap map[model.EntityType][]model.Question, currentFields []model.Field) (map[model.EntityType][]models.AddLeadsFields, map[int]int) { - toUpdate := make(map[int]int) // на обновление ключ id вопроса значение id кастомного поля для тех у кого имя совпадает +type ToUpdate struct { + FieldID int + Entity model.EntityType +} + +func ToCreatedUpdateQuestionRules(questionsTypeMap map[model.EntityType][]model.Question, currentFields []model.Field) (map[model.EntityType][]models.AddLeadsFields, map[int]ToUpdate) { + toUpdate := make(map[int]ToUpdate) // на обновление ключ id вопроса значение id кастомного поля для тех у кого имя совпадает toCreated := make(map[model.EntityType][]models.AddLeadsFields) for entity, questions := range questionsTypeMap { for _, question := range questions { matched := false for _, field := range currentFields { if question.Title == field.Name && entity == field.Entity { - toUpdate[int(question.Id)] = int(field.Amoid) + toUpdate[int(question.Id)] = ToUpdate{ + FieldID: int(field.Amoid), + Entity: entity, + } matched = true break } diff --git a/internal/workers_methods/methods.go b/internal/workers_methods/methods.go index e042d89..1e95ca5 100644 --- a/internal/workers_methods/methods.go +++ b/internal/workers_methods/methods.go @@ -663,19 +663,21 @@ func (m *Methods) CheckFieldRule(ctx context.Context, token string, msg models.K } } - constructFieldRules := func(fieldRuleArrCurrent []model.FieldRule, questions []model.Question, fieldRule *[]model.FieldRule) { + constructFieldRules := func(fieldRuleArrCurrent []model.FieldRule, questions []model.Question, fieldRule *[]model.FieldRule, currentEntity model.EntityType) { for _, rules := range fieldRuleArrCurrent { for questionID := range rules.Questionid { for _, question := range questions { - if fieldID, ok := toUpdate[questionID]; ok { - ruleMap := make(map[int]int) - ruleMap[questionID] = fieldID - *fieldRule = append(*fieldRule, model.FieldRule{Questionid: ruleMap}) - break + if dataQues, ok := toUpdate[questionID]; ok { + if dataQues.Entity == currentEntity { + ruleMap := make(map[int]int) + ruleMap[questionID] = dataQues.FieldID + *fieldRule = append(*fieldRule, model.FieldRule{Questionid: ruleMap}) + break + } } if questionID == int(question.Id) { for _, field := range newFields { - if question.Title == field.Name { + if question.Title == field.Name && field.Entity == currentEntity { ruleMap := make(map[int]int) ruleMap[questionID] = int(field.Amoid) *fieldRule = append(*fieldRule, model.FieldRule{Questionid: ruleMap}) @@ -687,9 +689,9 @@ func (m *Methods) CheckFieldRule(ctx context.Context, token string, msg models.K } } - constructFieldRules(currentFieldsRule.Lead, leadQuestions, &lead) - constructFieldRules(currentFieldsRule.Customer, customerQuestions, &customer) - constructFieldRules(currentFieldsRule.Company, companyQuestions, &company) + constructFieldRules(currentFieldsRule.Lead, leadQuestions, &lead, model.LeadsType) + constructFieldRules(currentFieldsRule.Customer, customerQuestions, &customer, model.CustomersType) + constructFieldRules(currentFieldsRule.Company, companyQuestions, &company, model.CompaniesType) err = m.repo.AmoRepo.UpdateFieldRules(ctx, model.Fieldsrule{ Lead: lead,