databag/net/server/internal/api_setNodeAccountStatus.go

39 lines
846 B
Go
Raw Normal View History

2022-06-07 17:54:33 +00:00
package databag
import (
2022-07-22 19:28:14 +00:00
"databag/internal/store"
"github.com/gorilla/mux"
2022-06-07 17:54:33 +00:00
"net/http"
2022-07-22 19:28:14 +00:00
"strconv"
2022-06-07 17:54:33 +00:00
)
2022-07-29 22:03:40 +00:00
//SetNodeAccountStatus sets disabled status of account
2022-06-07 17:54:33 +00:00
func SetNodeAccountStatus(w http.ResponseWriter, r *http.Request) {
2022-07-22 19:28:14 +00:00
// get referenced account id
params := mux.Vars(r)
accountID, res := strconv.ParseUint(params["accountID"], 10, 32)
if res != nil {
ErrResponse(w, http.StatusBadRequest, res)
return
}
2024-05-21 07:56:25 +00:00
if code, err := ParamSessionToken(r); err != nil {
2022-07-22 19:28:14 +00:00
ErrResponse(w, code, err)
return
}
var flag bool
if err := ParseRequest(r, w, &flag); err != nil {
ErrResponse(w, http.StatusBadRequest, err)
return
}
if err := store.DB.Model(store.Account{}).Where("id = ?", accountID).Update("disabled", flag).Error; err != nil {
ErrResponse(w, http.StatusInternalServerError, err)
return
}
WriteResponse(w, nil)
2022-06-07 17:54:33 +00:00
}