6648cdf1cb
Client External ID * normalizeexternalid * cleanopenapi * cleanopenapi * changingpublic * noprecommit * testing * precommit * processtest * nodb * tests * tests
32 lines
620 B
Go
32 lines
620 B
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
type Status string
|
|
|
|
const (
|
|
NOT_SYNCED Status = "not_synced"
|
|
NOT_SYNCING Status = "not_syncing"
|
|
IN_SYNC Status = "in_sync"
|
|
)
|
|
|
|
func (s *Service) GetStatusByExternalId(ctx context.Context, id string) (Status, error) {
|
|
client, err := s.cfg.GetDBQueries().GetClientByExternalId(ctx, id)
|
|
if err != nil {
|
|
return NOT_SYNCING, err
|
|
} else if !client.Cansync {
|
|
return NOT_SYNCING, nil
|
|
}
|
|
|
|
issynced, err := s.cfg.GetDBQueries().IsClientSynced(ctx, client.ID)
|
|
if err != nil {
|
|
return NOT_SYNCING, err
|
|
} else if issynced {
|
|
return IN_SYNC, nil
|
|
}
|
|
|
|
return NOT_SYNCED, nil
|
|
}
|