devicemngmt_old/action_get_staff_permission...

29 lines
795 B
Go
Raw Permalink Normal View History

2021-08-21 12:28:09 +00:00
package devicemngt
import (
"context"
"fmt"
2022-10-10 03:22:40 +00:00
"git.selly.red/Selly-Modules/logger"
2021-08-21 12:28:09 +00:00
)
2021-08-21 12:38:43 +00:00
// GetStaffPermissionsByToken ...
func (s Service) GetStaffPermissionsByToken(token string) (doc StaffPermissions) {
2021-08-21 12:28:09 +00:00
ctx := context.Background()
stm, args, _ := s.Builder.
2021-08-21 12:40:21 +00:00
Select("dm.id AS device_id, s.id, s.name, s.account_type, s.active, sr.permissions").
2021-08-21 12:28:09 +00:00
From(fmt.Sprintf("%s AS dm", TableDeviceMngt)).
2021-08-21 12:46:28 +00:00
LeftJoin(fmt.Sprintf("%s AS s ON s.id = dm.owner_id", TableStaff)).
LeftJoin(fmt.Sprintf("%s AS sr ON s.role_id = sr.id", TableStaffRole)).
2021-08-21 12:28:09 +00:00
Where("dm.auth_token = ?", token).
ToSql()
if err := s.DB.GetContext(ctx, &doc, stm, args...); err != nil {
2021-08-21 12:38:43 +00:00
logger.Error("devicemngt - GetStaffPermissionsByToken", logger.LogData{
2021-08-21 12:28:09 +00:00
"token": token,
"error": err.Error(),
})
}
return
}