Merge pull request #4 from Selly-Modules/update-permission

Update permission
This commit is contained in:
trunglt251292 2022-07-01 09:26:53 +07:00 committed by GitHub
commit 6c89c989e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 8 deletions

View File

@ -5,6 +5,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/Selly-Modules/natsio" "github.com/Selly-Modules/natsio"
"go.mongodb.org/mongo-driver/bson"
) )
// Client ... // Client ...
@ -69,3 +70,9 @@ func toBytes(data interface{}) []byte {
b, _ := json.Marshal(data) b, _ := json.Marshal(data)
return b return b
} }
// bsonToBytes ...
func bsonToBytes(data interface{}) []byte {
b, _ := bson.Marshal(data)
return b
}

View File

@ -5,8 +5,10 @@ const (
SubjectRequestNatsGetPermission = "authentication.request.staff.list_permission" SubjectRequestNatsGetPermission = "authentication.request.staff.list_permission"
SubjectRequestNatsSyncStaff = "authentication.request.staff.sync_data" SubjectRequestNatsSyncStaff = "authentication.request.staff.sync_data"
SubjectRequestNatsStaffCreate = "authentication.request.staff.create" SubjectRequestNatsStaffCreate = "authentication.request.staff.create"
SubjectRequestNatsStaffUpdate = "authentication.request.staff.update" SubjectRequestNatsStaffUpdate = "authentication.request.staff.update"
SubjectRequestNatsStaffGetInfo = "authentication.request.staff.get_info"
SubjectRequestNatsStaffGetList = "authentication.request.staff.list"
SubjectRequestNatsAddLogs = "authentication.request.logs.create" SubjectRequestNatsAddLogs = "authentication.request.logs.create"
SubjectRequestNatsLogsGetList = "authentication.request.logs.list" SubjectRequestNatsLogsGetList = "authentication.request.logs.list"

View File

@ -29,6 +29,16 @@ func (Request) UpdateStaff(payload Staff) (*Response, error) {
return requestNats(SubjectRequestNatsStaffUpdate, toBytes(payload)) return requestNats(SubjectRequestNatsStaffUpdate, toBytes(payload))
} }
// GetInfoStaff ...
func (Request) GetInfoStaff(payload GetInfoStaff) (*Response, error) {
return requestNats(SubjectRequestNatsStaffGetInfo, bsonToBytes(payload))
}
// GetListStaff ...
func (Request) GetListStaff(payload GetInfoStaff) (*Response, error) {
return requestNats(SubjectRequestNatsStaffGetList, bsonToBytes(payload))
}
// SaveLog ... // SaveLog ...
func (Request) SaveLog(payload Log) (*Response, error) { func (Request) SaveLog(payload Log) (*Response, error) {
return requestNats(SubjectRequestNatsAddLogs, toBytes(payload)) return requestNats(SubjectRequestNatsAddLogs, toBytes(payload))

View File

@ -24,6 +24,16 @@ type GetTokenByPhoneResponse struct {
Token string `json:"token"` Token string `json:"token"`
} }
// GetInfoStaff
// Convert to bson bytes
// When partner use. Bson unmarshal convert to struct
type GetInfoStaff struct {
Condition interface{}
Page int64
Limit int64
Sort bson.D
}
// Log ... // Log ...
type Log struct { type Log struct {
Reference string `json:"reference"` Reference string `json:"reference"`
@ -73,14 +83,25 @@ type Config struct {
Nats natsio.Config Nats natsio.Config
} }
// Agent ...
type Agent struct {
Source string `json:"source"`
IP string `json:"ip"`
Platform string `json:"platform"`
Version string `json:"version"`
}
// StaffCheckPermissionBody ... // StaffCheckPermissionBody ...
type StaffCheckPermissionBody struct { type StaffCheckPermissionBody struct {
StaffID string `json:"staffId"` StaffID string `json:"staffId"`
Token string `json:"token"` Token string `json:"token"`
Permission []string `json:"permission"` Permission []string `json:"permission"`
Source string `json:"source"` Source string `json:"source"`
Code string `json:"code,omitempty"` Code string `json:"code,omitempty"`
IsRoot string `json:"isRoot"` IsRoot string `json:"isRoot"`
Agent Agent `json:"agent"`
DeviceId string `json:"deviceId"`
Payload PayloadCheckPermission `json:"payload"`
} }
// PayloadCheckPermission ... // PayloadCheckPermission ...