Skip to content

Commit

Permalink
feat: change create watcher function logic
Browse files Browse the repository at this point in the history
  • Loading branch information
serezhaolshan committed May 24, 2024
1 parent 4a11286 commit b9e26b2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions services/watcher/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,15 +493,18 @@ func (s *service) GetWatcherHistoryPrices(ctx context.Context) *CGData {
}

func (s *service) CreateWatcher(ctx context.Context, pushToken string, deviceId string) error {
//if watcher with deviceId exists then update, not create
//if watcher with deviceId exists, delete it before create, not create

dbWatcher, err := s.repository.GetWatcher(ctx, bson.M{"device_id": deviceId})
if err != nil {
return err
}

if deviceId != "" && dbWatcher != nil {
return s.UpdateWatcherPushToken(ctx, dbWatcher.PushToken, pushToken, deviceId)
err := s.DeleteWatcher(ctx, dbWatcher.PushToken)
if err != nil {
return err
}
}

encodePushToken := base64.StdEncoding.EncodeToString([]byte(pushToken))
Expand Down

0 comments on commit b9e26b2

Please sign in to comment.