snapshot of https://github.com/traggo/server.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
build / build (push) Failing after 3s
Some checks failed
build / build (push) Failing after 3s
This commit is contained in:
23
user/remove.go
Normal file
23
user/remove.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/traggo/server/generated/gqlmodel"
|
||||
"github.com/traggo/server/model"
|
||||
)
|
||||
|
||||
// RemoveUser removes a user
|
||||
func (r *ResolverForUser) RemoveUser(ctx context.Context, id int) (*gqlmodel.User, error) {
|
||||
user := model.User{ID: id}
|
||||
if r.DB.Find(&user).RecordNotFound() {
|
||||
return nil, fmt.Errorf("user with id %d does not exist", user.ID)
|
||||
}
|
||||
|
||||
remove := r.DB.Delete(&user)
|
||||
gqlUser := &gqlmodel.User{}
|
||||
copier.Copy(gqlUser, &user)
|
||||
return gqlUser, remove.Error
|
||||
}
|
||||
Reference in New Issue
Block a user