amocrm/internal/tools/for_rules.go

46 lines
1.1 KiB
Go
Raw Normal View History

package tools
import (
"amocrm/internal/models"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
)
2024-04-29 22:36:49 +00:00
func ToCreatedUpdate(utms []model.UTM, fields []model.Field) ([]models.AddLeadsFields, []int32) {
var toCreated []models.AddLeadsFields
var toUpdate []int32
for _, utm := range utms {
2024-04-29 22:36:49 +00:00
matched := false
for _, field := range fields {
if utm.Name == field.Name {
toUpdate = append(toUpdate, int32(utm.ID))
matched = true
break
}
}
2024-04-29 22:36:49 +00:00
if !matched {
toCreated = append(toCreated, models.AddLeadsFields{Type: model.TypeAmoText, Name: utm.Name})
}
}
return toCreated, toUpdate
}
2024-04-29 22:36:49 +00:00
func MatchingUTMs(utms []model.UTM, fields []models.CustomField) []model.UTM {
var forUpdate []model.UTM
for _, utm := range utms {
for _, field := range fields {
if utm.Name == field.Name {
updUtm := model.UTM{
ID: utm.ID,
Amofieldid: int32(field.ID),
Quizid: utm.Quizid,
Accountid: utm.Accountid,
Name: field.Name,
}
forUpdate = append(forUpdate, updUtm)
}
}
}
return forUpdate
}