Skip to content

Commit

Permalink
fix: no rows error in account sync methods
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Trost <[email protected]>
  • Loading branch information
galexrt committed Jan 21, 2025
1 parent 691548a commit 43d3e74
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/components/jobs/timeclock/TimeclockList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ const selectedMode = computed({
});
const itemsAll = computed(() => [
{ label: t('common.time_ago.day'), icon: 'i-mdi-view-day', mode: TimeclockMode.DAILY },
{ label: t('common.time_ago.week'), icon: 'i-mdi-view-week', mode: TimeclockMode.WEEKLY },
{ label: t('common.day_view'), icon: 'i-mdi-view-day', mode: TimeclockMode.DAILY },
{ label: t('common.week_view'), icon: 'i-mdi-view-week', mode: TimeclockMode.WEEKLY },
{ label: t('common.time_range'), icon: 'i-mdi-calendar-range', mode: TimeclockMode.RANGE },
]);
</script>
Expand Down
4 changes: 3 additions & 1 deletion i18n/locales/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,9 @@
"allowed_file_types": "PNG, JPG (MAX. 2000x1500px)",
"default_lang": "Default Language",
"selected": "None selected | {n} selected",
"image_caching": "Please note that due to browser caching it can take up to 4 hours for the image to have updated for everyone."
"image_caching": "Please note that due to browser caching it can take up to 4 hours for the image to have updated for everyone.",
"day_view": "Daily View",
"week_view": "Weekly View"
},
"components": {
"partials": {
Expand Down
8 changes: 6 additions & 2 deletions services/sync/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package sync

import (
"context"
"errors"

"github.com/fivenet-app/fivenet/gen/go/proto/resources/accounts"
pbsync "github.com/fivenet-app/fivenet/gen/go/proto/services/sync"
"github.com/fivenet-app/fivenet/pkg/utils"
"github.com/fivenet-app/fivenet/query/fivenet/table"
jet "github.com/go-jet/jet/v2/mysql"
"github.com/go-jet/jet/v2/qrm"
)

func (s *Server) getAccount(ctx context.Context, identifier string) (*accounts.Account, *string, error) {
Expand All @@ -32,7 +34,9 @@ func (s *Server) getAccount(ctx context.Context, identifier string) (*accounts.A
Account: &accounts.Account{},
}
if err := selectStmt.QueryContext(ctx, s.db, acc); err != nil {
return nil, nil, err
if !errors.Is(err, qrm.ErrNoRows) {
return nil, nil, err
}
}

return acc.Account, acc.RegToken, nil
Expand All @@ -44,7 +48,7 @@ func (s *Server) RegisterAccount(ctx context.Context, req *pbsync.RegisterAccoun
return nil, err
}

if acc.Id > 0 {
if acc == nil || acc.Id > 0 {
// Account exists and no token reset has been requested
if !req.ResetToken {
return &pbsync.RegisterAccountResponse{
Expand Down
8 changes: 5 additions & 3 deletions services/sync/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ func (s *Server) handleUserOauth2(ctx context.Context, data *pbsync.AddActivityR
LIMIT(1)

if err := stmt.QueryContext(ctx, s.db, &accountId); err != nil {
return err
if !errors.Is(err, qrm.ErrNoRows) {
return err
}
}

if accountId == 0 {
Expand Down Expand Up @@ -246,9 +248,9 @@ func (s *Server) handleUserUpdate(ctx context.Context, data *pbsync.AddActivityR
if err := selectStmt.QueryContext(ctx, s.db, user); err != nil {
if !errors.Is(err, qrm.ErrNoRows) {
return err
} else {
return nil
}

return nil
}

updateSets := []jet.ColumnAssigment{}
Expand Down
8 changes: 6 additions & 2 deletions services/sync/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ func (s *Server) handleJobGrades(ctx context.Context, job *users.Job) (int64, er

currentGrades := []*users.JobGrade{}
if err := selectStmt.QueryContext(ctx, s.db, &currentGrades); err != nil {
return 0, err
if !errors.Is(err, qrm.ErrNoRows) {
return 0, err
}
}

toCreate, toUpdate, toDelete := []*users.JobGrade{}, []*users.JobGrade{}, []*users.JobGrade{}
Expand Down Expand Up @@ -476,7 +478,9 @@ func (s *Server) handleUserLicenses(ctx context.Context, identifier string, lice

currentLicenses := []string{}
if err := selectStmt.QueryContext(ctx, s.db, &currentLicenses); err != nil {
return err
if !errors.Is(err, qrm.ErrNoRows) {
return err
}
}

licensesList := []string{}
Expand Down

0 comments on commit 43d3e74

Please sign in to comment.