Skip to content

Commit

Permalink
EPMUII-7929 follow suggestions in review
Browse files Browse the repository at this point in the history
  • Loading branch information
wvxiw8 committed Jul 11, 2024
1 parent 7e37075 commit e2d10b9
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions internal/repositories/equipment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package repositories
import (
"context"
"errors"
"fmt"
"time"

"entgo.io/ent/dialect/sql"
Expand Down Expand Up @@ -516,6 +517,7 @@ func (r *equipmentRepository) BlockEquipment(
return err
}

timeNow := time.Now()
// Get EquipmentStatusName for "not available" from DB.
eqStatusNotAvailable, err := tx.EquipmentStatusName.
Query().
Expand All @@ -525,8 +527,8 @@ func (r *equipmentRepository) BlockEquipment(
return err
}

// Get (if exists) EqupmentStatus for current Equipment.
// Note, that only one row with "not available" stauts may exist per single equipment id.
// Get (if exists) EquipmentStatus for current Equipment.
// Note, that only one row with "not available" status may exist per single equipment id.
eqToBlockStatus, err := tx.EquipmentStatus.
Query().
QueryEquipments().
Expand All @@ -543,16 +545,16 @@ func (r *equipmentRepository) BlockEquipment(
Update().
SetStartDate(startDate).
SetEndDate(endDate).
SetUpdatedAt(time.Now()).
SetUpdatedAt(timeNow).
Save(ctx)
} else if ent.IsNotFound(err) {
_, err = tx.EquipmentStatus.Create().
SetCreatedAt(time.Now()).
SetCreatedAt(timeNow).
SetEndDate(endDate).
SetStartDate(startDate).
SetEquipments(eqToBlock).
SetEquipmentStatusName(eqStatusNotAvailable).
SetUpdatedAt(time.Now()).
SetUpdatedAt(timeNow).
Save(ctx)
if err != nil {
return err
Expand Down

0 comments on commit e2d10b9

Please sign in to comment.