From 4fd0a89acd4eefb0e69d571824c28b59ff3e6877 Mon Sep 17 00:00:00 2001 From: buiphuan0211 <57066954+buiphuan0211@users.noreply.github.com> Date: Thu, 29 Dec 2022 13:49:04 +0700 Subject: [PATCH] edit check token supplier user --- client/supplier.go | 20 -------------------- client/supplier_user.go | 20 ++++++++++++++++++++ model/supplier_request.go | 6 ------ model/supplier_response.go | 7 ------- model/supplier_user_request.go | 6 ++++++ model/supplier_user_response.go | 13 +++++++++++++ subject/supplier.go | 2 -- subject/supplier_user.go | 2 ++ 8 files changed, 41 insertions(+), 35 deletions(-) diff --git a/client/supplier.go b/client/supplier.go index 56e0670..9b53826 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -178,23 +178,3 @@ func (s Supplier) UpdateWarehouseIntoServiceSupplier(p model.UpdateSupplierWareh } return nil } - -// CheckTokenSupplier ... -func (s Supplier) CheckTokenSupplier(p model.CheckTokenSupplierPayload) (*model.ResponseCheckTokenSupplier, error) { - msg, err := natsio.GetServer().Request(subject.Supplier.CheckTokenSupplier, toBytes(p)) - if err != nil { - return nil, err - } - - var r struct { - Error string `json:"error"` - Data *model.ResponseCheckTokenSupplier `json:"data"` - } - 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 -} diff --git a/client/supplier_user.go b/client/supplier_user.go index fb6a2db..535f973 100644 --- a/client/supplier_user.go +++ b/client/supplier_user.go @@ -138,3 +138,23 @@ func (s SupplierUser) ResetPassword(p model.ResetPasswordRequest) (*model.ResetP return r.Data, nil } + +// CheckTokenSupplier ... +func (s SupplierUser) CheckTokenSupplier(p model.CheckTokenSupplierUserPayload) (*model.ResponseCheckTokenSupplierUser, error) { + msg, err := natsio.GetServer().Request(subject.SupplierUser.CheckToken, toBytes(p)) + if err != nil { + return nil, err + } + + var r struct { + Error string `json:"error"` + Data *model.ResponseCheckTokenSupplierUser `json:"data"` + } + 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 +} diff --git a/model/supplier_request.go b/model/supplier_request.go index 7ba0018..18034af 100644 --- a/model/supplier_request.go +++ b/model/supplier_request.go @@ -52,9 +52,3 @@ type SupplierCountReq struct { IDs []string `json:"ids"` Status string `json:"status"` // active,inactive } - -// CheckTokenSupplierPayload ... -type CheckTokenSupplierPayload struct { - Token string `json:"token"` - Permissions []string `json:"permissions"` -} diff --git a/model/supplier_response.go b/model/supplier_response.go index 2c90904..2b9dd10 100644 --- a/model/supplier_response.go +++ b/model/supplier_response.go @@ -33,10 +33,3 @@ type SupplierAll struct { type SupplierCountRes struct { Total int64 `json:"total"` } - -// ResponseCheckTokenSupplier ... -type ResponseCheckTokenSupplier struct { - IsValid bool `json:"isValid"` - Reason string `json:"reason"` - Supplier ResponseSupplierInfo `json:"supplier"` -} diff --git a/model/supplier_user_request.go b/model/supplier_user_request.go index 66ccb17..2e1c066 100644 --- a/model/supplier_user_request.go +++ b/model/supplier_user_request.go @@ -49,3 +49,9 @@ type ResetPasswordRequest struct { ID string `json:"_id"` Password string `json:"password"` } + +// CheckTokenSupplierUserPayload ... +type CheckTokenSupplierUserPayload struct { + Token string `json:"token"` + Permissions []string `json:"permissions"` +} diff --git a/model/supplier_user_response.go b/model/supplier_user_response.go index 38a1d0c..3b98d1c 100644 --- a/model/supplier_user_response.go +++ b/model/supplier_user_response.go @@ -11,3 +11,16 @@ type CreateStaffResponse struct { type ResetPasswordResponse struct { Password string `json:"password"` } + +// ResponseCheckTokenSupplierUser ... +type ResponseCheckTokenSupplierUser struct { + IsValid bool `json:"isValid"` + Reason string `json:"reason"` + User ResponseSupplierUserInfo `json:"supplier"` +} + +type ResponseSupplierUserInfo struct { + ID string `json:"_id"` + Name string `json:"name"` + SupplierID string `json:"supplierId"` +} diff --git a/subject/supplier.go b/subject/supplier.go index fe041bf..edc797f 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -12,12 +12,10 @@ var Supplier = struct { FindAll string FindAllOld string Count string - CheckTokenSupplier string }{ GetListSupplierInfo: getSupplierValue("get_list_supplier_info"), GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"), FindAll: getSupplierValue("find_all"), FindAllOld: getSupplierValue("find_all_old"), Count: getSupplierValue("count"), - CheckTokenSupplier: getSupplierValue("check_token_supplier"), } diff --git a/subject/supplier_user.go b/subject/supplier_user.go index adc2f1f..f954898 100644 --- a/subject/supplier_user.go +++ b/subject/supplier_user.go @@ -14,6 +14,7 @@ var SupplierUser = struct { UpdateStaff string UpdateStatus string ResetPassword string + CheckToken string }{ // Users CreateOwner: getSupplierUserValue("create_owner"), @@ -22,4 +23,5 @@ var SupplierUser = struct { UpdateStaff: getSupplierUserValue("update_staff"), UpdateStatus: getSupplierUserValue("update_status"), ResetPassword: getSupplierUserValue("reset_password"), + CheckToken: getSupplierUserValue("check_token"), }