diff --git a/authentication.go b/authentication.go index 4e747f5..0992675 100644 --- a/authentication.go +++ b/authentication.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "github.com/Selly-Modules/natsio" + "go.mongodb.org/mongo-driver/bson" ) // Client ... @@ -69,3 +70,9 @@ func toBytes(data interface{}) []byte { b, _ := json.Marshal(data) return b } + +// bsonToBytes ... +func bsonToBytes(data interface{}) []byte { + b, _ := bson.Marshal(data) + return b +} diff --git a/constants.go b/constants.go index 05abcfe..1840ff6 100644 --- a/constants.go +++ b/constants.go @@ -5,8 +5,10 @@ const ( SubjectRequestNatsGetPermission = "authentication.request.staff.list_permission" SubjectRequestNatsSyncStaff = "authentication.request.staff.sync_data" - SubjectRequestNatsStaffCreate = "authentication.request.staff.create" - SubjectRequestNatsStaffUpdate = "authentication.request.staff.update" + SubjectRequestNatsStaffCreate = "authentication.request.staff.create" + SubjectRequestNatsStaffUpdate = "authentication.request.staff.update" + SubjectRequestNatsStaffGetInfo = "authentication.request.staff.get_info" + SubjectRequestNatsStaffGetList = "authentication.request.staff.list" SubjectRequestNatsAddLogs = "authentication.request.logs.create" SubjectRequestNatsLogsGetList = "authentication.request.logs.list" diff --git a/request.go b/request.go index f22a5f2..325255c 100644 --- a/request.go +++ b/request.go @@ -29,6 +29,16 @@ func (Request) UpdateStaff(payload Staff) (*Response, error) { 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 ... func (Request) SaveLog(payload Log) (*Response, error) { return requestNats(SubjectRequestNatsAddLogs, toBytes(payload)) diff --git a/struct.go b/struct.go index 1f65f8a..01cafaf 100644 --- a/struct.go +++ b/struct.go @@ -24,6 +24,16 @@ type GetTokenByPhoneResponse struct { 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 ... type Log struct { Reference string `json:"reference"` @@ -73,14 +83,25 @@ type Config struct { Nats natsio.Config } +// Agent ... +type Agent struct { + Source string `json:"source"` + IP string `json:"ip"` + Platform string `json:"platform"` + Version string `json:"version"` +} + // StaffCheckPermissionBody ... type StaffCheckPermissionBody struct { - StaffID string `json:"staffId"` - Token string `json:"token"` - Permission []string `json:"permission"` - Source string `json:"source"` - Code string `json:"code,omitempty"` - IsRoot string `json:"isRoot"` + StaffID string `json:"staffId"` + Token string `json:"token"` + Permission []string `json:"permission"` + Source string `json:"source"` + Code string `json:"code,omitempty"` + IsRoot string `json:"isRoot"` + Agent Agent `json:"agent"` + DeviceId string `json:"deviceId"` + Payload PayloadCheckPermission `json:"payload"` } // PayloadCheckPermission ...