Skip to content

Commit

Permalink
fix: unit creation issue for good
Browse files Browse the repository at this point in the history
Unit id was incorrectly used to retrieve the created unit status by id..

Signed-off-by: Alexander Trost <[email protected]>
  • Loading branch information
galexrt committed Oct 11, 2024
1 parent d1a8900 commit 9dc6857
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/components/centrum/settings/UnitsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ const columns = [
</template>
</UDashboardNavbar>

<DataErrorBlock v-if="error" :title="$t('common.unable_to_load', [$t('common.unit')])" :retry="refresh" />
<DataErrorBlock v-if="error" :title="$t('common.unable_to_load', [$t('common.unit', 2)])" :retry="refresh" />
<UTable
v-else
:loading="loading"
:columns="columns"
:rows="units?.units"
:empty-state="{ icon: 'i-mdi-car', label: $t('common.not_found', [$t('common.units', 2)]) }"
:empty-state="{ icon: 'i-mdi-car', label: $t('common.not_found', [$t('common.unit', 2)]) }"
>
<template #name-data="{ row: unit }">
<div class="text-gray-900 dark:text-white">
Expand Down
9 changes: 4 additions & 5 deletions gen/go/proto/services/centrum/manager/units.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,12 @@ func (s *Manager) CreateUnit(ctx context.Context, job string, unit *centrum.Unit
if err != nil {
return nil, err
}
unit.Id = uint64(lastId)

// A new unit shouldn't have a status, so we make sure we add one
if unit.Status, err = s.AddUnitStatus(ctx, tx, job, &centrum.UnitStatus{
CreatedAt: timestamp.Now(),
UnitId: uint64(lastId),
UnitId: unit.Id,
Status: centrum.StatusUnit_STATUS_UNIT_UNAVAILABLE,
}, false); err != nil {
return nil, err
Expand All @@ -408,12 +409,10 @@ func (s *Manager) CreateUnit(ctx context.Context, job string, unit *centrum.Unit
}

// Load new/updated unit from database
if err := s.LoadUnitsFromDB(ctx, uint64(lastId)); err != nil {
if err := s.LoadUnitsFromDB(ctx, unit.Id); err != nil {
return nil, err
}

unit.Id = uint64(lastId)

data, err := proto.Marshal(unit)
if err != nil {
return nil, err
Expand Down Expand Up @@ -570,7 +569,7 @@ func (s *Manager) GetUnitStatus(ctx context.Context, tx qrm.DB, job string, id u
),
).
WHERE(
tUnitStatus.UnitID.EQ(jet.Uint64(id)),
tUnitStatus.ID.EQ(jet.Uint64(id)),
).
ORDER_BY(tUnitStatus.ID.DESC()).
LIMIT(1)
Expand Down

0 comments on commit 9dc6857

Please sign in to comment.