build auth sms
This commit is contained in:
commit
1e2d10b3ce
|
@ -0,0 +1,58 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"git.selly.red/Selly-Modules/natsio"
|
||||
"git.selly.red/Selly-Modules/natsio/model"
|
||||
"git.selly.red/Selly-Modules/natsio/subject"
|
||||
)
|
||||
|
||||
// SupplierRole ...
|
||||
type SupplierRole struct{}
|
||||
|
||||
// GetSupplierRole ...
|
||||
func GetSupplierRole() SupplierRole {
|
||||
return SupplierRole{}
|
||||
}
|
||||
|
||||
func (s SupplierRole) CreateRole(p model.CreateRoleRequest) (*model.CreateRoleResponse, error) {
|
||||
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateOwner, toBytes(p))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r struct {
|
||||
Data *model.CreateRoleResponse `json:"data"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(msg.Data, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.Error != "" {
|
||||
return nil, errors.New(r.Error)
|
||||
}
|
||||
|
||||
return r.Data, nil
|
||||
}
|
||||
|
||||
func (s SupplierRole) UpdateRole(p model.UpdateRoleRequest) error {
|
||||
msg, err := natsio.GetServer().Request(subject.SupplierRole.Update, toBytes(p))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var r struct {
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(msg.Data, &r); err != nil {
|
||||
return err
|
||||
}
|
||||
if r.Error != "" {
|
||||
return errors.New(r.Error)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -16,14 +16,14 @@ func GetSupplierUser() SupplierUser {
|
|||
return SupplierUser{}
|
||||
}
|
||||
|
||||
func (s SupplierUser) CreateSupplierOwnerUsers(p model.CreateSupplierOwnerUserRequest) (*model.CreateSupplierUserOwnerResponse, error) {
|
||||
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateSupplierOwnerUser, toBytes(p))
|
||||
func (s SupplierUser) CreateSupplierOwnerUsers(p model.CreateOwnerRequest) (*model.CreateOwnerResponse, error) {
|
||||
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateOwner, toBytes(p))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r struct {
|
||||
Data *model.CreateSupplierUserOwnerResponse `json:"data"`
|
||||
Data *model.CreateOwnerResponse `json:"data"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
|
@ -37,8 +37,8 @@ func (s SupplierUser) CreateSupplierOwnerUsers(p model.CreateSupplierOwnerUserRe
|
|||
return r.Data, nil
|
||||
}
|
||||
|
||||
func (s SupplierUser) UpdateSupplierOwnerUsers(p model.UpdateSupplierOwnerUserRequest) error {
|
||||
msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateSupplierOwnerUser, toBytes(p))
|
||||
func (s SupplierUser) UpdateSupplierOwnerUsers(p model.UpdateOwnerRequest) error {
|
||||
msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateOwner, toBytes(p))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -57,14 +57,14 @@ func (s SupplierUser) UpdateSupplierOwnerUsers(p model.UpdateSupplierOwnerUserRe
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s SupplierUser) CreateSupplierStaffUsers(p model.CreateSupplierStaffUserRequest) (*model.CreateSupplierUserStaffResponse, error) {
|
||||
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateSupplierStaffUser, toBytes(p))
|
||||
func (s SupplierUser) CreateSupplierStaffUsers(p model.CreateStaffRequest) (*model.CreateStaffResponse, error) {
|
||||
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateStaff, toBytes(p))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r struct {
|
||||
Data *model.CreateSupplierUserStaffResponse `json:"data"`
|
||||
Data *model.CreateStaffResponse `json:"data"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
|
@ -78,8 +78,8 @@ func (s SupplierUser) CreateSupplierStaffUsers(p model.CreateSupplierStaffUserRe
|
|||
return r.Data, nil
|
||||
}
|
||||
|
||||
func (s SupplierUser) UpdateSupplierStaffUsers(p model.CreateSupplierStaffUserRequest) error {
|
||||
msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateSupplierStaffUser, toBytes(p))
|
||||
func (s SupplierUser) UpdateSupplierStaffUsers(p model.UpdateStaffRequest) error {
|
||||
msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateStaff, toBytes(p))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -97,3 +97,44 @@ func (s SupplierUser) UpdateSupplierStaffUsers(p model.CreateSupplierStaffUserRe
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SupplierUser) UpdateStatus(p model.UpdateStatusRequest) error {
|
||||
msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateStaff, toBytes(p))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var r struct {
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(msg.Data, &r); err != nil {
|
||||
return err
|
||||
}
|
||||
if r.Error != "" {
|
||||
return errors.New(r.Error)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SupplierUser) ResetPassword(p model.ResetPasswordRequest) (*model.ResetPasswordResponse, error) {
|
||||
msg, err := natsio.GetServer().Request(subject.SupplierUser.ResetPassword, toBytes(p))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r struct {
|
||||
Data *model.ResetPasswordResponse `json:"data"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(msg.Data, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.Error != "" {
|
||||
return nil, errors.New(r.Error)
|
||||
}
|
||||
|
||||
return r.Data, nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package model
|
||||
|
||||
type CreateRoleRequest struct {
|
||||
Name string `json:"name"`
|
||||
Code string `json:"code"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type UpdateRoleRequest struct {
|
||||
ID string `json:"_id"`
|
||||
Name string `json:"name"`
|
||||
Code string `json:"code"`
|
||||
Type string `json:"type"`
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package model
|
||||
|
||||
type CreateRoleResponse struct {
|
||||
ID string `json:"_id"`
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package model
|
||||
|
||||
type CreateSupplierOwnerUserRequest struct {
|
||||
type CreateOwnerRequest struct {
|
||||
Name string `json:"name"`
|
||||
Phone string `json:"phone"`
|
||||
Email string `json:"email"`
|
||||
|
@ -9,7 +9,7 @@ type CreateSupplierOwnerUserRequest struct {
|
|||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type UpdateSupplierOwnerUserRequest struct {
|
||||
type UpdateOwnerRequest struct {
|
||||
ID string `json:"_id"`
|
||||
SupplierID string `json:"supplierId"`
|
||||
Name string `json:"name"`
|
||||
|
@ -18,7 +18,7 @@ type UpdateSupplierOwnerUserRequest struct {
|
|||
RoleID string `json:"roleId"`
|
||||
}
|
||||
|
||||
type CreateSupplierStaffUserRequest struct {
|
||||
type CreateStaffRequest struct {
|
||||
Name string `json:"name"`
|
||||
Phone string `json:"phone"`
|
||||
Email string `json:"email"`
|
||||
|
@ -28,14 +28,24 @@ type CreateSupplierStaffUserRequest struct {
|
|||
Warehouses []string `json:"warehouses"`
|
||||
}
|
||||
|
||||
type UpdateSupplierStaffUserRequest struct {
|
||||
type UpdateStaffRequest struct {
|
||||
ID string `json:"_id"`
|
||||
Name string `json:"name"`
|
||||
Phone string `json:"phone"`
|
||||
Email string `json:"email"`
|
||||
SupplierID string `json:"supplierId"`
|
||||
Role string `json:"role"`
|
||||
RoleID string `json:"roleId"`
|
||||
Password string `json:"password"`
|
||||
SupplierUserWarehouseID string `json:"supplierUserWarehouseId"`
|
||||
Warehouses []string `json:"warehouses"`
|
||||
RoleId string `json:"roleId"`
|
||||
}
|
||||
|
||||
type UpdateStatusRequest struct {
|
||||
ID string `json:"_id"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type ResetPasswordRequest struct {
|
||||
ID string `json:"_id"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package model
|
||||
|
||||
type CreateSupplierUserOwnerResponse struct {
|
||||
type CreateOwnerResponse struct {
|
||||
ID string `json:"_id"`
|
||||
}
|
||||
|
||||
type CreateSupplierUserStaffResponse struct {
|
||||
type CreateStaffResponse struct {
|
||||
ID string `json:"_id"`
|
||||
}
|
||||
|
||||
type GetListPermissionResponse struct {
|
||||
Permission []string `json:"permission"`
|
||||
type ResetPasswordResponse struct {
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ var prefixes = struct {
|
|||
AuthSMS string
|
||||
Selly string
|
||||
SupplierUser string
|
||||
SupplierRole string
|
||||
}{
|
||||
Communication: "communication",
|
||||
Order: "order",
|
||||
|
@ -24,4 +25,5 @@ var prefixes = struct {
|
|||
AuthSMS: "auth_sms",
|
||||
Selly: "selly",
|
||||
SupplierUser: "supplier_user",
|
||||
SupplierRole: "supplier_role",
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package subject
|
||||
|
||||
import "fmt"
|
||||
|
||||
func getRoleValue(val string) string {
|
||||
return fmt.Sprintf("%s.%s", prefixes.SupplierRole, val)
|
||||
}
|
||||
|
||||
var SupplierRole = struct {
|
||||
Create string
|
||||
Update string
|
||||
}{
|
||||
Create: getRoleValue("create"),
|
||||
Update: getRoleValue("update"),
|
||||
}
|
|
@ -2,18 +2,24 @@ package subject
|
|||
|
||||
import "fmt"
|
||||
|
||||
func getAuthSMSValue(val string) string {
|
||||
func getSupplierUserValue(val string) string {
|
||||
return fmt.Sprintf("%s.%s", prefixes.SupplierUser, val)
|
||||
}
|
||||
|
||||
var SupplierUser = struct {
|
||||
CreateSupplierOwnerUser string
|
||||
UpdateSupplierOwnerUser string
|
||||
CreateSupplierStaffUser string
|
||||
UpdateSupplierStaffUser string
|
||||
// Users
|
||||
CreateOwner string
|
||||
UpdateOwner string
|
||||
CreateStaff string
|
||||
UpdateStaff string
|
||||
UpdateStatus string
|
||||
ResetPassword string
|
||||
}{
|
||||
CreateSupplierOwnerUser: getAuthSMSValue("create_supplier_owner_user"),
|
||||
UpdateSupplierOwnerUser: getAuthSMSValue("update_supplier_owner_user"),
|
||||
CreateSupplierStaffUser: getAuthSMSValue("create_supplier_staff_user"),
|
||||
UpdateSupplierStaffUser: getAuthSMSValue("update_supplier_staff_user"),
|
||||
// Users
|
||||
CreateOwner: getSupplierUserValue("create_owner"),
|
||||
UpdateOwner: getSupplierUserValue("update_owner"),
|
||||
CreateStaff: getSupplierUserValue("create_staff"),
|
||||
UpdateStaff: getSupplierUserValue("update_staff"),
|
||||
UpdateStatus: getSupplierUserValue("update_status"),
|
||||
ResetPassword: getSupplierUserValue("reset_password"),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue