sub delete for loop

This commit is contained in:
mr
2026-04-22 11:38:21 +02:00
parent 5cda4fdd40
commit c208e2ccef
2 changed files with 9 additions and 5 deletions

View File

@@ -82,18 +82,22 @@ func GenericDeleteOne(id string, a Accessor) (DBObject, int, error) {
if res == nil {
return res, code, errors.New("not found")
}
return GenericDelete(res, a)
}
func GenericDelete(res DBObject, a Accessor) (DBObject, int, error) {
if !res.CanDelete() {
return nil, 403, errors.New("you are not allowed to delete :" + a.GetType().String())
}
if a.ShouldVerifyAuth() && !res.VerifyAuth("delete", a.GetRequest()) {
return nil, 403, errors.New("you are not allowed to access " + a.GetType().String())
}
_, code, err = mongo.MONGOService.DeleteOne(id, a.GetType().String())
_, code, err := mongo.MONGOService.DeleteOne(res.GetID(), a.GetType().String())
if err != nil {
a.GetLogger().Error().Msg("Could not delete " + id + " to db. Error: " + err.Error())
a.GetLogger().Error().Msg("Could not delete " + res.GetID() + " to db. Error: " + err.Error())
return nil, code, err
}
go NotifyChange(a.GetType(), id, res, true)
go NotifyChange(a.GetType(), res.GetID(), res, true)
return res, 200, nil
}