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:
20
device/get.go
Normal file
20
device/get.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package device
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/traggo/server/auth"
|
||||
"github.com/traggo/server/generated/gqlmodel"
|
||||
"github.com/traggo/server/model"
|
||||
)
|
||||
|
||||
// Devices returns all devices.
|
||||
func (r *ResolverForDevice) Devices(ctx context.Context) ([]*gqlmodel.Device, error) {
|
||||
user := auth.GetUser(ctx)
|
||||
var devices []model.Device
|
||||
find := r.DB.Where(&model.Device{UserID: user.ID}).Order("active_at DESC").Find(&devices)
|
||||
var result []*gqlmodel.Device
|
||||
copier.Copy(&result, &devices)
|
||||
return result, find.Error
|
||||
}
|
||||
Reference in New Issue
Block a user