fix: refactored sql request for get days + highlight invalid bookings and ignore them for calculation
Some checks failed
Tests / Run Go Tests (push) Failing after 1m14s
Some checks failed
Tests / Run Go Tests (push) Failing after 1m14s
fixed #77
This commit is contained in:
@@ -36,6 +36,7 @@ type Booking struct {
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
CounterId int `json:"counter_id"`
|
||||
BookingType BookingType `json:"anwesenheit_typ"`
|
||||
Valid bool `json:"valid"`
|
||||
}
|
||||
|
||||
type IDatabase interface {
|
||||
@@ -252,12 +253,13 @@ func (b *Booking) Update(nb Booking) {
|
||||
func checkLastBooking(b Booking) bool {
|
||||
var check_in_out int
|
||||
slog.Info("Checking with timestamp:", "timestamp", b.Timestamp.String())
|
||||
stmt, err := DB.Prepare((`SELECT check_in_out FROM "anwesenheit" WHERE "card_uid" = $1 AND "timestamp"::DATE <= $2::DATE ORDER BY "timestamp" DESC LIMIT 1;`))
|
||||
stmt, err := DB.Prepare((`SELECT check_in_out FROM "anwesenheit" WHERE "card_uid" = $1 AND "timestamp" <= $2 ORDER BY "timestamp" DESC LIMIT 1;`))
|
||||
if err != nil {
|
||||
log.Fatalf("Error preparing query: %v", err)
|
||||
return false
|
||||
}
|
||||
err = stmt.QueryRow(b.CardUID, b.Timestamp).Scan(&check_in_out)
|
||||
slog.Info("Checking last bookings check_in_out", "Check", check_in_out)
|
||||
if err == sql.ErrNoRows {
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user