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:
24
device/remove.go
Normal file
24
device/remove.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package device
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/traggo/server/auth"
|
||||
"github.com/traggo/server/generated/gqlmodel"
|
||||
"github.com/traggo/server/model"
|
||||
)
|
||||
|
||||
// RemoveDevice removes a device
|
||||
func (r *ResolverForDevice) RemoveDevice(ctx context.Context, id int) (*gqlmodel.Device, error) {
|
||||
device := model.Device{ID: id}
|
||||
if r.DB.Where(&model.Device{UserID: auth.GetUser(ctx).ID}).Find(&device).RecordNotFound() {
|
||||
return nil, fmt.Errorf("device not found")
|
||||
}
|
||||
|
||||
remove := r.DB.Delete(&device)
|
||||
gqlDevice := &gqlmodel.Device{}
|
||||
copier.Copy(gqlDevice, &device)
|
||||
return gqlDevice, remove.Error
|
||||
}
|
||||
Reference in New Issue
Block a user