add tags to creating deals
This commit is contained in:
parent
ddb837035d
commit
57a4f69e18
2
go.sum
2
go.sum
@ -132,7 +132,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6 h1:oV+/HNX+JPoQ3/GUx08hio7d45WpY0AMGrFs7j70QlA=
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240608115230-da2584a374f6 h1:IKvZcF5A5lXwVH2nW8GR/pvH5sCR0iPmzDglBaQzO9k=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240608115230-da2584a374f6/go.mod h1:n66zm88Dh12+idyfqh0vU5nd9BZYxM6Pv0XYnmy0398=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240608132031-6395b9fa3a2b h1:+E8b916azpe0S+pBZ9CnatJEtSmd3gkEwdh2NiYbVLg=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240608132031-6395b9fa3a2b/go.mod h1:n66zm88Dh12+idyfqh0vU5nd9BZYxM6Pv0XYnmy0398=
|
||||
|
@ -145,3 +145,31 @@ func ConstructUTMFields(utmMap model.UTMSavingMap, currentFields []model.Field)
|
||||
|
||||
return fields
|
||||
}
|
||||
|
||||
func ConstructAmoTags(currentTags []model.Tag, ruleTags model.TagsToAdd) []models.Tag {
|
||||
var tagsToAmo []models.Tag
|
||||
ruleTagMap := make(map[int64]struct{})
|
||||
|
||||
mapConstruct := func(idsArray []int64) {
|
||||
for _, id := range idsArray {
|
||||
ruleTagMap[id] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
mapConstruct(ruleTags.Lead)
|
||||
mapConstruct(ruleTags.Contact)
|
||||
mapConstruct(ruleTags.Company)
|
||||
mapConstruct(ruleTags.Customer)
|
||||
|
||||
for _, tag := range currentTags {
|
||||
if _, ok := ruleTagMap[tag.ID]; ok {
|
||||
tagsToAmo = append(tagsToAmo, models.Tag{
|
||||
ID: int(tag.Amoid),
|
||||
Name: tag.Name,
|
||||
Color: tag.Color,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return tagsToAmo
|
||||
}
|
||||
|
@ -71,6 +71,13 @@ func (wc *PostDeals) startFetching(ctx context.Context) {
|
||||
wc.logger.Error("error getting all user answers by result session", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
userTags, err := wc.amoRepo.AmoRepo.GetUserTagsByID(ctx, result.AmoAccountID)
|
||||
if err != nil {
|
||||
wc.logger.Error("error getting user tags by ano account id", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
// За один запрос можно передать не более 50 сделок.
|
||||
deal := models.DealReq{
|
||||
Name: fmt.Sprintf("deal quiz number %d", result.QuizID),
|
||||
@ -88,6 +95,7 @@ func (wc *PostDeals) startFetching(ctx context.Context) {
|
||||
},
|
||||
// строка которая будет возвращенна в респонсе чтоб понимать кто есть что
|
||||
RequestID: strconv.Itoa(int(result.AnswerID)),
|
||||
TagsToAdd: tools.ConstructAmoTags(userTags, result.TagsToAdd),
|
||||
}
|
||||
|
||||
leadFields, contactData, companyData, customerToCreate, err := wc.constructField(ctx, allAnswers, result)
|
||||
|
25
tests/tools/construct_test.go
Normal file
25
tests/tools/construct_test.go
Normal file
@ -0,0 +1,25 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"amocrm/internal/tools"
|
||||
"fmt"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_ConstructAmoTags(t *testing.T) {
|
||||
color := "Red"
|
||||
currentTags := []model.Tag{
|
||||
{ID: 1, Name: "First", Amoid: 111, Color: &color},
|
||||
{ID: 2, Name: "Iron Man", Amoid: 222, Color: nil},
|
||||
{ID: 3, Name: "Lionel Messi", Amoid: 333, Color: nil},
|
||||
}
|
||||
ruleTags := model.TagsToAdd{
|
||||
Lead: []int64{1},
|
||||
Contact: []int64{2, 3},
|
||||
Company: []int64{},
|
||||
Customer: []int64{},
|
||||
}
|
||||
|
||||
fmt.Println(tools.ConstructAmoTags(currentTags, ruleTags))
|
||||
}
|
Loading…
Reference in New Issue
Block a user