update store

This commit is contained in:
Pascal Fischer
2024-04-30 11:43:48 +02:00
parent 68e971cb82
commit 1f182411c6
2 changed files with 28 additions and 4 deletions

View File

@@ -1,7 +1,6 @@
package server
import (
"errors"
"os"
"path/filepath"
"strings"
@@ -580,7 +579,15 @@ func (s *FileStore) GetAccountByPeerPubKey(peerKey string) (*Account, error) {
}
func (s *FileStore) GetAccountIDByPeerPubKey(peerKey string) (string, error) {
return "", errors.New("not implemented")
s.mux.Lock()
defer s.mux.Unlock()
accountID, ok := s.PeerKeyID2AccountID[peerKey]
if !ok {
return "", status.Errorf(status.NotFound, "provided peer key doesn't exists %s", peerKey)
}
return accountID, nil
}
// GetInstallationID returns the installation ID from the store

View File

@@ -289,7 +289,15 @@ func (s *SqliteStore) SavePeerStatus(accountID, peerID string, peerStatus nbpeer
"peer_status_requires_approval": peerStatus.RequiresApproval,
})
return result.Error
if result.Error != nil {
return result.Error
}
if result.RowsAffected == 0 {
return status.Errorf(status.NotFound, "peer %s not found", peerID)
}
return nil
}
func (s *SqliteStore) SavePeerLocation(accountID string, peerWithLocation *nbpeer.Peer) error {
@@ -303,7 +311,16 @@ func (s *SqliteStore) SavePeerLocation(accountID string, peerWithLocation *nbpee
"location_city_name": location.CityName,
"location_geo_name_id": location.GeoNameID,
})
return result.Error
if result.Error != nil {
return result.Error
}
if result.RowsAffected == 0 {
return status.Errorf(status.NotFound, "peer %s not found", peerWithLocation.ID)
}
return nil
}
// DeleteHashedPAT2TokenIDIndex is noop in Sqlite