sub delete for loop
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user