feat: locking days, if they are submitted and accepted

fixed #76
This commit is contained in:
2026-02-09 00:32:00 +01:00
parent 2d8747c971
commit 8911165c4b
13 changed files with 218 additions and 115 deletions

View File

@@ -13,8 +13,10 @@ package models
// the absence data is based on the entries in the "abwesenheit" database table
import (
"database/sql"
"encoding/json"
"log"
"log/slog"
"time"
)
@@ -295,3 +297,24 @@ func (a *Absence) Delete() error {
_, err = qStr.Exec(a.CounterId)
return err
}
func (a *Absence) IsSubmittedAndAccepted() bool {
qStr, err := DB.Prepare(`SELECT bestaetigt from wochen_report WHERE $1 = ANY(abwesenheiten) AND $2 >= woche_start AND $2 < woche_start + INTERVAL '1 week';`) // @> array contains
if err != nil {
slog.Warn("Error when preparing SQL Statement", "error", err)
return false
}
defer qStr.Close()
var isSubmittedAndChecked bool = false
err = qStr.QueryRow(a.CounterId, a.Date()).Scan(&isSubmittedAndChecked)
if err == sql.ErrNoRows {
// No rows found ==> not even submitted
return false
}
if err != nil {
slog.Warn("Unexpected error when executing SQL Statement", "error", err)
}
return isSubmittedAndChecked
}