Clear appointments on anime delete

This commit is contained in:
daru
2022-05-28 14:14:44 +02:00
parent 231cecedd8
commit 864aa5695a

15
nuss.go
View File

@@ -257,6 +257,21 @@ func DeleteUserFromAppointment(username string, animeId int64, meeting time.Time
} }
func DeleteAnime(tx *nutsdb.Tx, keyBytes []byte) error { func DeleteAnime(tx *nutsdb.Tx, keyBytes []byte) error {
// clear appointments
appoints, err := tx.GetAll(bucketAppoint)
if err == nil {
animeId, err := BytesToInt64(keyBytes)
if err == nil {
for _, e := range appoints {
// decode appointment list
dbAnimeId, _, err := BytesToInt64AndDate(e.Key)
if err == nil && dbAnimeId == animeId {
tx.Delete(bucketAppoint, e.Key)
}
}
}
}
tx.Delete(bucketChat, keyBytes) tx.Delete(bucketChat, keyBytes)
return tx.Delete(bucketAnime, keyBytes) return tx.Delete(bucketAnime, keyBytes)
} }