fix: fix wrong date calculation
This commit is contained in:
parent
4514ce44a2
commit
c8b7666971
4 changed files with 815 additions and 62 deletions
|
|
@ -244,3 +244,43 @@ func DeleteUser(db *sql.DB, id int) error {
|
|||
_, err := db.Exec("DELETE FROM users WHERE id = ?", id)
|
||||
return err
|
||||
}
|
||||
|
||||
func DeleteTimeEntriesByUserAndWeek(db *sql.DB, userID int, year int, week int) error {
|
||||
query := `
|
||||
DELETE FROM time_entries
|
||||
WHERE user_id = ?
|
||||
AND CAST(strftime('%W', date) AS INTEGER) = ?
|
||||
AND CAST(strftime('%Y', date) AS INTEGER) = ?
|
||||
`
|
||||
_, err := db.Exec(query, userID, week, year)
|
||||
return err
|
||||
}
|
||||
|
||||
func CheckUserHasEntriesForWeek(db *sql.DB, userID int, year int, week int) (bool, error) {
|
||||
// Berechne die Daten der Woche
|
||||
dates := calculateWeekDates(year, week)
|
||||
|
||||
// Hole alle Daten als Liste
|
||||
var dateList []string
|
||||
for _, date := range dates.Dates {
|
||||
dateList = append(dateList, date)
|
||||
}
|
||||
|
||||
// Prüfe ob Einträge existieren
|
||||
query := `
|
||||
SELECT COUNT(*)
|
||||
FROM time_entries
|
||||
WHERE user_id = ?
|
||||
AND date IN (?, ?, ?, ?, ?)
|
||||
`
|
||||
|
||||
var count int
|
||||
err := db.QueryRow(query, userID,
|
||||
dateList[0], dateList[1], dateList[2], dateList[3], dateList[4]).Scan(&count)
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return count > 0, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue