add method get device permissioms
This commit is contained in:
parent
83b85c2508
commit
e78f8befa1
|
@ -0,0 +1,28 @@
|
||||||
|
package devicemngt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/Selly-Modules/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetDevicePermissionsByToken ...
|
||||||
|
func (s Service) GetDevicePermissionsByToken(token string) (doc StaffDevicePermissions) {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
stm, args, _ := s.Builder.
|
||||||
|
Select("dm.id, s.account_type, sr.permissions").
|
||||||
|
From(fmt.Sprintf("%s AS dm", TableDeviceMngt)).
|
||||||
|
Join(fmt.Sprintf("LEFT JOIN %s s ON s.id = dm.owner_id", TableStaff)).
|
||||||
|
Join(fmt.Sprintf("LEFT JOIN %s sr ON s.role_id = sr.id", TableStaffRole)).
|
||||||
|
Where("dm.auth_token = ?", token).
|
||||||
|
ToSql()
|
||||||
|
if err := s.DB.GetContext(ctx, &doc, stm, args...); err != nil {
|
||||||
|
logger.Error("devicemngt - GetDevicePermissionsByToken", logger.LogData{
|
||||||
|
"token": token,
|
||||||
|
"error": err.Error(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
|
@ -3,6 +3,8 @@ package devicemngt
|
||||||
// Constant ...
|
// Constant ...
|
||||||
const (
|
const (
|
||||||
TableDeviceMngt = "device_managements"
|
TableDeviceMngt = "device_managements"
|
||||||
|
TableStaff = "staffs"
|
||||||
|
TableStaffRole = "staff_roles"
|
||||||
|
|
||||||
OwnerTypeStaff = "staff"
|
OwnerTypeStaff = "staff"
|
||||||
OwnerTypeSeller = "seller"
|
OwnerTypeSeller = "seller"
|
||||||
|
|
7
model.go
7
model.go
|
@ -55,3 +55,10 @@ type HeaderData struct {
|
||||||
OSVersion string
|
OSVersion string
|
||||||
AuthToken string
|
AuthToken string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StaffDevicePermissions ...
|
||||||
|
type StaffDevicePermissions struct {
|
||||||
|
ID string `db:"id"`
|
||||||
|
Permissions []string `db:"permissions"`
|
||||||
|
AccountType string `db:"account_type"`
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue