-
Notifications
You must be signed in to change notification settings - Fork 12
/
user_service.go
36 lines (30 loc) · 1.18 KB
/
user_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package service
import (
"context"
"github.com/openline-ai/openline-customer-os/packages/runner/sync-customer-os-data/entity"
"github.com/openline-ai/openline-customer-os/packages/runner/sync-customer-os-data/repository"
)
type UserService interface {
GetIdForReferencedUser(ctx context.Context, tenant, externalSystem string, user entity.ReferencedUser) (string, error)
}
type userService struct {
repositories *repository.Repositories
}
func NewUserService(repositories *repository.Repositories) UserService {
return &userService{
repositories: repositories,
}
}
func (s *userService) GetIdForReferencedUser(ctx context.Context, tenant, externalSystemId string, user entity.ReferencedUser) (string, error) {
if !user.Available() {
return "", nil
}
if user.ReferencedById() {
return s.repositories.UserRepository.GetUserIdById(ctx, tenant, user.Id)
} else if user.ReferencedByExternalId() {
return s.repositories.UserRepository.GetUserIdByExternalId(ctx, tenant, user.ExternalId, externalSystemId)
} else if user.ReferencedByExternalOwnerId() {
return s.repositories.UserRepository.GetUserIdByExternalOwnerId(ctx, tenant, user.ExternalIdSecond, externalSystemId)
}
return "", nil
}