small fixes and refactoring

This commit is contained in:
2025-04-10 09:11:17 +02:00
parent e60f19ee27
commit 19251eefed
10 changed files with 34 additions and 15 deletions

View File

@@ -68,7 +68,7 @@ func (u *User) GetAll() ([]User, error) {
// Returns true if there is a booking 1 for today -> meaning the user is at work
// Returns false if there is no booking today or the user is already booked out of the system
func (u *User) CheckAnwesenheit() bool {
qStr, err := DB.Prepare((`SELECT check_in_out FROM anwesenheit WHERE card_uid = $1 AND "timestamp" >= now()::date + interval '1h' ORDER BY "timestamp" DESC`))
qStr, err := DB.Prepare((`SELECT check_in_out FROM anwesenheit WHERE card_uid = $1 AND "timestamp" >= now()::date + interval '1h' ORDER BY "timestamp" DESC LIMIT 1;`))
if err != nil {
fmt.Printf("Error preparing query statement %v\n", err)
return false
@@ -79,12 +79,12 @@ func (u *User) CheckAnwesenheit() bool {
if err != nil {
return false
}
return check_in_out == 1
return check_in_out%2 == 1
}
// Creates a new booking for the user -> check_in_out will be 255 for automatic check out
// Creates a new booking for the user -> check_in_out will be 254 for automatic check out
func (u *User) Logout() error {
booking := (*Booking).New(nil, u.CardUID, 0, 255)
booking := (*Booking).New(nil, u.CardUID, 0, 254)
err := booking.Insert()
if err != nil {
fmt.Printf("Error inserting booking %v\n", err)