Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/flow_routing_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const (
)

func (a *App) CreateRoutingSchema(ctx context.Context, scheme *model.RoutingSchema) (*model.RoutingSchema, model.AppError) {
if scheme.Payload == nil {
scheme.Payload = []byte("{}")
}
return a.Store.RoutingSchema().Create(ctx, scheme)
}

Expand All @@ -40,7 +43,9 @@ func (a *App) UpdateRoutingSchema(ctx context.Context, scheme *model.RoutingSche
oldScheme.Type = scheme.Type
oldScheme.Debug = scheme.Debug
oldScheme.Description = scheme.Description
oldScheme.Payload = scheme.Payload
if scheme.Payload != nil {
oldScheme.Payload = scheme.Payload
}
oldScheme.Schema = scheme.Schema
oldScheme.Tags = scheme.Tags

Expand Down
17 changes: 9 additions & 8 deletions store/sqlstore/flow_routing_scheme_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package sqlstore
import (
"context"
"fmt"

"github.com/lib/pq"

"github.com/webitel/engine/model"
"github.com/webitel/engine/store"
)
Expand All @@ -29,7 +31,7 @@ select s.id, s.domain_id, s.name, s.created_at, call_center.cc_get_lookup(c.id,
from s
left join directory.wbt_user c on c.id = s.created_by
left join directory.wbt_user u on u.id = s.updated_by`,
map[string]interface{}{
map[string]any{
"DomainId": scheme.DomainId,
"Name": scheme.Name,
"Scheme": scheme.Schema,
Expand All @@ -55,7 +57,7 @@ from s
func (s SqlRoutingSchemaStore) GetAllPage(ctx context.Context, domainId int64, search *model.SearchRoutingSchema) ([]*model.RoutingSchema, model.AppError) {
var schemes []*model.RoutingSchema

f := map[string]interface{}{
f := map[string]any{
"DomainId": domainId,
"Q": search.GetQ(),
"Ids": pq.Array(search.Ids),
Expand Down Expand Up @@ -83,7 +85,7 @@ func (s SqlRoutingSchemaStore) GetAllPage(ctx context.Context, domainId int64, s
}
}

func (s SqlRoutingSchemaStore) Get(ctx context.Context, domainId int64, id int64) (*model.RoutingSchema, model.AppError) {
func (s SqlRoutingSchemaStore) Get(ctx context.Context, domainId, id int64) (*model.RoutingSchema, model.AppError) {
var rScheme *model.RoutingSchema
if err := s.GetReplica().WithContext(ctx).SelectOne(&rScheme, `select s.id,
s.domain_id,
Expand All @@ -103,7 +105,7 @@ from flow.acr_routing_scheme s
left join directory.wbt_user u on u.id = s.updated_by
where s.id = :Id
and s.domain_id = :DomainId
order by s.id`, map[string]interface{}{"Id": id, "DomainId": domainId}); err != nil {
order by s.id`, map[string]any{"Id": id, "DomainId": domainId}); err != nil {
return nil, model.NewCustomCodeError("store.sql_routing_schema.get.app_error", fmt.Sprintf("Id=%v, %s", id, err.Error()), extractCodeFromErr(err))
} else {
return rScheme, nil
Expand Down Expand Up @@ -131,7 +133,7 @@ select s.id, s.domain_id, s.description, s.name, s.created_at, call_center.cc_ge
s.updated_at, call_center.cc_get_lookup(u.id, u.name) as updated_by, s.scheme as schema, s.payload, s.debug, s.type, s.tags
from s
left join directory.wbt_user c on c.id = s.created_by
left join directory.wbt_user u on u.id = s.updated_by`, map[string]interface{}{
left join directory.wbt_user u on u.id = s.updated_by`, map[string]any{
"Name": scheme.Name,
"Scheme": scheme.Schema,
"Payload": scheme.Payload,
Expand All @@ -157,7 +159,7 @@ from s

func (s SqlRoutingSchemaStore) Delete(ctx context.Context, domainId, id int64) model.AppError {
if _, err := s.GetMaster().WithContext(ctx).Exec(`delete from flow.acr_routing_scheme c where c.id=:Id and c.domain_id = :DomainId`,
map[string]interface{}{"Id": id, "DomainId": domainId}); err != nil {
map[string]any{"Id": id, "DomainId": domainId}); err != nil {
return model.NewInternalError("store.sql_routing_schema.delete.app_error", fmt.Sprintf("Id=%v, %s", id, err.Error()))
}
return nil
Expand Down Expand Up @@ -186,14 +188,13 @@ from tags
limit :Limit
offset :Offset`

_, err := s.GetReplica().WithContext(ctx).Select(&res, fmt.Sprintf(q, sort), map[string]interface{}{
_, err := s.GetReplica().WithContext(ctx).Select(&res, fmt.Sprintf(q, sort), map[string]any{
"DomainId": domainId,
"Q": search.GetQ(),
"Limit": search.GetLimit(),
"Offset": search.GetOffset(),
"Type": pq.Array(search.Type),
})

if err != nil {
return nil, model.NewCustomCodeError("store.sql_routing_schema.tag_list.app_error", err.Error(), extractCodeFromErr(err))
}
Expand Down
Loading