From 42874f493736868645f4b47b8dfcb0a1b1854ccc Mon Sep 17 00:00:00 2001 From: Nguyen Minh Date: Mon, 10 Oct 2022 09:06:20 +0700 Subject: [PATCH 01/11] seller-add-field-planPackage --- model/seller_response.go | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/model/seller_response.go b/model/seller_response.go index aec57b9..01c80e5 100644 --- a/model/seller_response.go +++ b/model/seller_response.go @@ -21,16 +21,25 @@ type ResponseListSellerInfoSupportChat struct { // ResponseSellerInfoSupportChat ... type ResponseSellerInfoSupportChat struct { - ID string `json:"_id"` - Name string `json:"name"` - Code string `json:"code"` - Membership SellerMembershipInfo `json:"membership"` - Info SellerContactInfo `json:"info"` - Team *TeamInfo `json:"team,omitempty"` - Statistic SellerStatistic `json:"statistic"` - TrackingTime *SellerTrackingTime `json:"trackingTime"` - Invitee *InviteeInfo `json:"invitee"` - CreatedAt time.Time `json:"createdAt"` + ID string `json:"_id"` + Name string `json:"name"` + Code string `json:"code"` + Membership SellerMembershipInfo `json:"membership"` + Info SellerContactInfo `json:"info"` + Team *TeamInfo `json:"team,omitempty"` + Statistic SellerStatistic `json:"statistic"` + TrackingTime *SellerTrackingTime `json:"trackingTime"` + Invitee *InviteeInfo `json:"invitee"` + CreatedAt time.Time `json:"createdAt"` + PlanPackage *SellerPlanPackageInfo `json:"planPackage"` +} + +// SellerPlanPackageInfo ... +type SellerPlanPackageInfo struct { + ID string `json:"_id"` + Name string `json:"name"` + Level int `json:"level"` + CreatedAt time.Time `json:"createdAt"` } // SellerTrackingTime ... From 9297f2d9bd8cf81f695d898568a1b8a6fca68c5c Mon Sep 17 00:00:00 2001 From: Tue Date: Thu, 20 Oct 2022 14:32:32 +0700 Subject: [PATCH 02/11] update auth sms --- client/authsms.go | 38 ++++++++++++++++++++++++++++++++++++++ model/authsms_request.go | 8 ++++++++ model/authsms_response.go | 5 +++++ subject/authsms.go | 13 +++++++++++++ subject/config.go | 2 ++ 5 files changed, 66 insertions(+) create mode 100644 client/authsms.go create mode 100644 model/authsms_request.go create mode 100644 model/authsms_response.go create mode 100644 subject/authsms.go diff --git a/client/authsms.go b/client/authsms.go new file mode 100644 index 0000000..d98be55 --- /dev/null +++ b/client/authsms.go @@ -0,0 +1,38 @@ +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" +) + +// AuthSMS ... +type AuthSMS struct{} + +// GetAutSMS ... +func GetAutSMS() AuthSMS { + return AuthSMS{} +} + +func (s AuthSMS) CreateUserSMSViaAuthSMS(p model.CreateUserSMSRequest) (*model.CreateUserSMSResponse, error) { + msg, err := natsio.GetServer().Request(subject.AuthSMS.CreateUserSMS, toBytes(p)) + if err != nil { + return nil, err + } + + var r struct { + Data *model.CreateUserSMSResponse `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 +} diff --git a/model/authsms_request.go b/model/authsms_request.go new file mode 100644 index 0000000..c0b3078 --- /dev/null +++ b/model/authsms_request.go @@ -0,0 +1,8 @@ +package model + +type CreateUserSMSRequest struct { + Name string `json:"name"` + Phone string `json:"phone"` + Email string `json:"email"` + Supplier string `json:"supplier"` +} diff --git a/model/authsms_response.go b/model/authsms_response.go new file mode 100644 index 0000000..0effbbc --- /dev/null +++ b/model/authsms_response.go @@ -0,0 +1,5 @@ +package model + +type CreateUserSMSResponse struct { + ID string `json:"_id"` +} diff --git a/subject/authsms.go b/subject/authsms.go new file mode 100644 index 0000000..4b7a0ad --- /dev/null +++ b/subject/authsms.go @@ -0,0 +1,13 @@ +package subject + +import "fmt" + +func getAuthSMSValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.AuthSMS, val) +} + +var AuthSMS = struct { + CreateUserSMS string +}{ + CreateUserSMS: getAuthSMSValue("create_user_sms"), +} diff --git a/subject/config.go b/subject/config.go index 4a2f9f3..ccc480e 100644 --- a/subject/config.go +++ b/subject/config.go @@ -9,6 +9,7 @@ var prefixes = struct { Bank string Supplier string Seller string + AuthSMS string }{ Communication: "communication", Order: "order", @@ -18,4 +19,5 @@ var prefixes = struct { Supplier: "supplier", Bank: "bank", Seller: "seller", + AuthSMS: "auth_sms", } From 546592f8ceaa2dbe42bbbfd6e7c4f8d7b3ffd7f4 Mon Sep 17 00:00:00 2001 From: Tue Date: Thu, 20 Oct 2022 15:10:42 +0700 Subject: [PATCH 03/11] update auth sms --- model/authsms_request.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/model/authsms_request.go b/model/authsms_request.go index c0b3078..4053ea9 100644 --- a/model/authsms_request.go +++ b/model/authsms_request.go @@ -5,4 +5,6 @@ type CreateUserSMSRequest struct { Phone string `json:"phone"` Email string `json:"email"` Supplier string `json:"supplier"` + RoleID string `json:"roleId"` + Password string `json:"password"` } From 25cb392d936dcea5c95935df52f3d471c326f660 Mon Sep 17 00:00:00 2001 From: Tue Date: Thu, 20 Oct 2022 15:17:50 +0700 Subject: [PATCH 04/11] update auth sms --- model/authsms_request.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/authsms_request.go b/model/authsms_request.go index 4053ea9..df718bd 100644 --- a/model/authsms_request.go +++ b/model/authsms_request.go @@ -5,6 +5,6 @@ type CreateUserSMSRequest struct { Phone string `json:"phone"` Email string `json:"email"` Supplier string `json:"supplier"` - RoleID string `json:"roleId"` + Role string `json:"role"` Password string `json:"password"` } From b35a018d0aad602fb574cea11cf65ab06726debd Mon Sep 17 00:00:00 2001 From: Nguyen Minh Date: Mon, 24 Oct 2022 10:07:14 +0700 Subject: [PATCH 05/11] rerun --- client/seller.go | 1 - 1 file changed, 1 deletion(-) diff --git a/client/seller.go b/client/seller.go index 1d06208..8a45867 100644 --- a/client/seller.go +++ b/client/seller.go @@ -79,7 +79,6 @@ func (s Seller) GetListSellerInfoSupportChatByIDs(p model.GetListSellerSupportCh if err := json.Unmarshal(msg.Data, &r); err != nil { return nil, err } - if r.Error != "" { return nil, errors.New(r.Error) From 6293e62cb42ab82857756b9d1a101483b0d221c2 Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Mon, 24 Oct 2022 10:41:18 +0700 Subject: [PATCH 06/11] [Update] Response warehouse --- model/warehouse_response.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/model/warehouse_response.go b/model/warehouse_response.go index 07969dc..b608c37 100644 --- a/model/warehouse_response.go +++ b/model/warehouse_response.go @@ -26,6 +26,13 @@ type WarehouseConfiguration struct { Delivery WarehouseDelivery `json:"delivery"` Other WarehouseOther `json:"other"` Food WarehouseFood `json:"food"` + AutoConfirmOrder WareOrderConfirm `json:"autoConfirmOrder"` +} + +// WareOrderConfirm ... +type WareOrderConfirm struct { + IsEnable bool `json:"isEnable"` + ConfirmDelayInSeconds int64 `json:"confirmDelayInSeconds"` } // WarehouseFood ... From 6065636a5998e3e3aaea3428d8cbdc52fc3f4259 Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Mon, 24 Oct 2022 10:43:29 +0700 Subject: [PATCH 07/11] [Update] Response warehouse --- model/warehouse_response.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/model/warehouse_response.go b/model/warehouse_response.go index b608c37..c667290 100644 --- a/model/warehouse_response.go +++ b/model/warehouse_response.go @@ -18,19 +18,19 @@ type OutboundRequestResponse struct { // WarehouseConfiguration ... type WarehouseConfiguration struct { - Warehouse string `json:"warehouse"` - DoesSupportSellyExpress bool `json:"doesSupportSellyExpress"` - Supplier WarehouseSupplier `json:"supplier"` - Order WarehouseOrder `json:"order"` - Partner WarehousePartner `json:"partner"` - Delivery WarehouseDelivery `json:"delivery"` - Other WarehouseOther `json:"other"` - Food WarehouseFood `json:"food"` - AutoConfirmOrder WareOrderConfirm `json:"autoConfirmOrder"` + Warehouse string `json:"warehouse"` + DoesSupportSellyExpress bool `json:"doesSupportSellyExpress"` + Supplier WarehouseSupplier `json:"supplier"` + Order WarehouseOrder `json:"order"` + Partner WarehousePartner `json:"partner"` + Delivery WarehouseDelivery `json:"delivery"` + Other WarehouseOther `json:"other"` + Food WarehouseFood `json:"food"` + AutoConfirmOrder WarehouseOrderConfirm `json:"autoConfirmOrder"` } -// WareOrderConfirm ... -type WareOrderConfirm struct { +// WarehouseOrderConfirm ... +type WarehouseOrderConfirm struct { IsEnable bool `json:"isEnable"` ConfirmDelayInSeconds int64 `json:"confirmDelayInSeconds"` } From 9a2bd21534926fd23efc35ff8847543273d98f56 Mon Sep 17 00:00:00 2001 From: Tue Date: Tue, 25 Oct 2022 15:27:05 +0700 Subject: [PATCH 08/11] build auth sms --- client/authsms.go | 38 ------------------- client/supplier_user.go | 38 +++++++++++++++++++ ...ms_request.go => supplier_user_request.go} | 2 +- ..._response.go => supplier_user_response.go} | 2 +- subject/authsms.go | 8 ++-- subject/config.go | 4 +- 6 files changed, 46 insertions(+), 46 deletions(-) delete mode 100644 client/authsms.go create mode 100644 client/supplier_user.go rename model/{authsms_request.go => supplier_user_request.go} (84%) rename model/{authsms_response.go => supplier_user_response.go} (50%) diff --git a/client/authsms.go b/client/authsms.go deleted file mode 100644 index d98be55..0000000 --- a/client/authsms.go +++ /dev/null @@ -1,38 +0,0 @@ -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" -) - -// AuthSMS ... -type AuthSMS struct{} - -// GetAutSMS ... -func GetAutSMS() AuthSMS { - return AuthSMS{} -} - -func (s AuthSMS) CreateUserSMSViaAuthSMS(p model.CreateUserSMSRequest) (*model.CreateUserSMSResponse, error) { - msg, err := natsio.GetServer().Request(subject.AuthSMS.CreateUserSMS, toBytes(p)) - if err != nil { - return nil, err - } - - var r struct { - Data *model.CreateUserSMSResponse `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 -} diff --git a/client/supplier_user.go b/client/supplier_user.go new file mode 100644 index 0000000..f5abc1f --- /dev/null +++ b/client/supplier_user.go @@ -0,0 +1,38 @@ +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" +) + +// SupplierUser ... +type SupplierUser struct{} + +// GetSupplierUser ... +func GetSupplierUser() SupplierUser { + return SupplierUser{} +} + +func (s SupplierUser) CreateSupplierUserS(p model.CreateSupplierUserRequest) (*model.CreateSupplierUserResponse, error) { + msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateSupplierUser, toBytes(p)) + if err != nil { + return nil, err + } + + var r struct { + Data *model.CreateSupplierUserResponse `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 +} diff --git a/model/authsms_request.go b/model/supplier_user_request.go similarity index 84% rename from model/authsms_request.go rename to model/supplier_user_request.go index df718bd..6dc9df8 100644 --- a/model/authsms_request.go +++ b/model/supplier_user_request.go @@ -1,6 +1,6 @@ package model -type CreateUserSMSRequest struct { +type CreateSupplierUserRequest struct { Name string `json:"name"` Phone string `json:"phone"` Email string `json:"email"` diff --git a/model/authsms_response.go b/model/supplier_user_response.go similarity index 50% rename from model/authsms_response.go rename to model/supplier_user_response.go index 0effbbc..9583b76 100644 --- a/model/authsms_response.go +++ b/model/supplier_user_response.go @@ -1,5 +1,5 @@ package model -type CreateUserSMSResponse struct { +type CreateSupplierUserResponse struct { ID string `json:"_id"` } diff --git a/subject/authsms.go b/subject/authsms.go index 4b7a0ad..fd63148 100644 --- a/subject/authsms.go +++ b/subject/authsms.go @@ -3,11 +3,11 @@ package subject import "fmt" func getAuthSMSValue(val string) string { - return fmt.Sprintf("%s.%s", prefixes.AuthSMS, val) + return fmt.Sprintf("%s.%s", prefixes.SupplierUser, val) } -var AuthSMS = struct { - CreateUserSMS string +var SupplierUser = struct { + CreateSupplierUser string }{ - CreateUserSMS: getAuthSMSValue("create_user_sms"), + CreateSupplierUser: getAuthSMSValue("create_supplier_user"), } diff --git a/subject/config.go b/subject/config.go index ccc480e..d50d9d4 100644 --- a/subject/config.go +++ b/subject/config.go @@ -9,7 +9,7 @@ var prefixes = struct { Bank string Supplier string Seller string - AuthSMS string + SupplierUser string }{ Communication: "communication", Order: "order", @@ -19,5 +19,5 @@ var prefixes = struct { Supplier: "supplier", Bank: "bank", Seller: "seller", - AuthSMS: "auth_sms", + SupplierUser: "supplier_user", } From 1c62c3c710c20646c6b8d8d3dde6efd0f3cd113f Mon Sep 17 00:00:00 2001 From: Tue Date: Thu, 27 Oct 2022 09:09:48 +0700 Subject: [PATCH 09/11] build auth sms --- client/supplier_user.go | 69 +++++++++++++++++++++++++++++++-- model/supplier_user_request.go | 45 +++++++++++++++++---- model/supplier_user_response.go | 6 ++- subject/authsms.go | 10 ++++- 4 files changed, 116 insertions(+), 14 deletions(-) diff --git a/client/supplier_user.go b/client/supplier_user.go index f5abc1f..8bb10c5 100644 --- a/client/supplier_user.go +++ b/client/supplier_user.go @@ -16,15 +16,15 @@ func GetSupplierUser() SupplierUser { return SupplierUser{} } -func (s SupplierUser) CreateSupplierUserS(p model.CreateSupplierUserRequest) (*model.CreateSupplierUserResponse, error) { - msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateSupplierUser, toBytes(p)) +func (s SupplierUser) CreateSupplierOwnerUsers(p model.CreateSupplierOwnerUserRequest) (*model.CreateSupplierUserOwnerResponse, error) { + msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateSupplierOwnerUser, toBytes(p)) if err != nil { return nil, err } var r struct { - Data *model.CreateSupplierUserResponse `json:"data"` - Error string `json:"error"` + Data *model.CreateSupplierUserOwnerResponse `json:"data"` + Error string `json:"error"` } if err = json.Unmarshal(msg.Data, &r); err != nil { @@ -36,3 +36,64 @@ func (s SupplierUser) CreateSupplierUserS(p model.CreateSupplierUserRequest) (*m return r.Data, nil } + +func (s SupplierUser) UpdateSupplierOwnerUsers(p model.UpdateSupplierOwnerUserRequest) error { + msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateSupplierOwnerUser, 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) CreateSupplierStaffUsers(p model.CreateSupplierStaffUserRequest) (*model.CreateSupplierUserStaffResponse, error) { + msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateSupplierStaffUser, toBytes(p)) + if err != nil { + return nil, err + } + + var r struct { + Data *model.CreateSupplierUserStaffResponse `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 SupplierUser) UpdateSupplierStaffUsers(p model.CreateSupplierStaffUserRequest) error { + msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateSupplierStaffUser, 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 +} diff --git a/model/supplier_user_request.go b/model/supplier_user_request.go index 6dc9df8..f4556b2 100644 --- a/model/supplier_user_request.go +++ b/model/supplier_user_request.go @@ -1,10 +1,41 @@ package model -type CreateSupplierUserRequest struct { - Name string `json:"name"` - Phone string `json:"phone"` - Email string `json:"email"` - Supplier string `json:"supplier"` - Role string `json:"role"` - Password string `json:"password"` +type CreateSupplierOwnerUserRequest struct { + Name string `json:"name"` + Phone string `json:"phone"` + Email string `json:"email"` + SupplierID string `json:"supplierId"` + RoleID string `json:"roleId"` + Password string `json:"password"` +} + +type UpdateSupplierOwnerUserRequest struct { + ID string `json:"_id"` + SupplierID string `json:"supplierId"` + Name string `json:"name"` + Phone string `json:"phone"` + Email string `json:"email"` + RoleID string `json:"roleId"` +} + +type CreateSupplierStaffUserRequest struct { + Name string `json:"name"` + Phone string `json:"phone"` + Email string `json:"email"` + SupplierID string `json:"supplierId"` + RoleID string `json:"roleId"` + Password string `json:"password"` + Warehouses []string `json:"warehouses"` +} + +type UpdateSupplierStaffUserRequest 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"` + Password string `json:"password"` + Warehouses []string `json:"warehouses"` + RoleId string `json:"roleId"` } diff --git a/model/supplier_user_response.go b/model/supplier_user_response.go index 9583b76..7241bad 100644 --- a/model/supplier_user_response.go +++ b/model/supplier_user_response.go @@ -1,5 +1,9 @@ package model -type CreateSupplierUserResponse struct { +type CreateSupplierUserOwnerResponse struct { + ID string `json:"_id"` +} + +type CreateSupplierUserStaffResponse struct { ID string `json:"_id"` } diff --git a/subject/authsms.go b/subject/authsms.go index fd63148..7abb4c7 100644 --- a/subject/authsms.go +++ b/subject/authsms.go @@ -7,7 +7,13 @@ func getAuthSMSValue(val string) string { } var SupplierUser = struct { - CreateSupplierUser string + CreateSupplierOwnerUser string + UpdateSupplierOwnerUser string + CreateSupplierStaffUser string + UpdateSupplierStaffUser string }{ - CreateSupplierUser: getAuthSMSValue("create_supplier_user"), + CreateSupplierOwnerUser: getAuthSMSValue("create_supplier_owner_user"), + UpdateSupplierOwnerUser: getAuthSMSValue("update_supplier_owner_user"), + CreateSupplierStaffUser: getAuthSMSValue("create_supplier_staff_user"), + UpdateSupplierStaffUser: getAuthSMSValue("update_supplier_staff_user"), } From 81c7be03045969d8b763930f92fe5d28fe6ef37e Mon Sep 17 00:00:00 2001 From: Tue Date: Thu, 27 Oct 2022 09:17:57 +0700 Subject: [PATCH 10/11] build auth sms --- subject/{authsms.go => supplier_user.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename subject/{authsms.go => supplier_user.go} (100%) diff --git a/subject/authsms.go b/subject/supplier_user.go similarity index 100% rename from subject/authsms.go rename to subject/supplier_user.go From e324b88fe6a68527739ab3533dc08a6e8fe4f2f6 Mon Sep 17 00:00:00 2001 From: Tue Date: Fri, 28 Oct 2022 09:31:39 +0700 Subject: [PATCH 11/11] build authsms --- client/supplier_role.go | 58 +++++++++++++++++++++++++++++ client/supplier_user.go | 65 +++++++++++++++++++++++++++------ model/supplier_role_request.go | 14 +++++++ model/supplier_role_response.go | 5 +++ model/supplier_user_request.go | 36 +++++++++++------- model/supplier_user_response.go | 8 +++- subject/config.go | 2 + subject/supplier_role.go | 15 ++++++++ subject/supplier_user.go | 24 +++++++----- 9 files changed, 191 insertions(+), 36 deletions(-) create mode 100644 client/supplier_role.go create mode 100644 model/supplier_role_request.go create mode 100644 model/supplier_role_response.go create mode 100644 subject/supplier_role.go diff --git a/client/supplier_role.go b/client/supplier_role.go new file mode 100644 index 0000000..3bf068d --- /dev/null +++ b/client/supplier_role.go @@ -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 +} diff --git a/client/supplier_user.go b/client/supplier_user.go index 8bb10c5..fb6a2db 100644 --- a/client/supplier_user.go +++ b/client/supplier_user.go @@ -16,15 +16,15 @@ 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"` - Error string `json:"error"` + Data *model.CreateOwnerResponse `json:"data"` + Error string `json:"error"` } if err = json.Unmarshal(msg.Data, &r); err != nil { @@ -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,15 +57,15 @@ 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"` - Error string `json:"error"` + Data *model.CreateStaffResponse `json:"data"` + Error string `json:"error"` } if err = json.Unmarshal(msg.Data, &r); err != nil { @@ -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 +} diff --git a/model/supplier_role_request.go b/model/supplier_role_request.go new file mode 100644 index 0000000..6402622 --- /dev/null +++ b/model/supplier_role_request.go @@ -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"` +} diff --git a/model/supplier_role_response.go b/model/supplier_role_response.go new file mode 100644 index 0000000..d7b68fc --- /dev/null +++ b/model/supplier_role_response.go @@ -0,0 +1,5 @@ +package model + +type CreateRoleResponse struct { + ID string `json:"_id"` +} diff --git a/model/supplier_user_request.go b/model/supplier_user_request.go index f4556b2..66ccb17 100644 --- a/model/supplier_user_request.go +++ b/model/supplier_user_request.go @@ -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 { - ID string `json:"_id"` - Name string `json:"name"` - Phone string `json:"phone"` - Email string `json:"email"` - SupplierID string `json:"supplierId"` - Role string `json:"role"` - Password string `json:"password"` - Warehouses []string `json:"warehouses"` - RoleId string `json:"roleId"` +type UpdateStaffRequest struct { + ID string `json:"_id"` + Name string `json:"name"` + Phone string `json:"phone"` + Email string `json:"email"` + SupplierID string `json:"supplierId"` + RoleID string `json:"roleId"` + Password string `json:"password"` + SupplierUserWarehouseID string `json:"supplierUserWarehouseId"` + Warehouses []string `json:"warehouses"` +} + +type UpdateStatusRequest struct { + ID string `json:"_id"` + Status string `json:"status"` +} + +type ResetPasswordRequest struct { + ID string `json:"_id"` + Password string `json:"password"` } diff --git a/model/supplier_user_response.go b/model/supplier_user_response.go index 7241bad..38a1d0c 100644 --- a/model/supplier_user_response.go +++ b/model/supplier_user_response.go @@ -1,9 +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 ResetPasswordResponse struct { + Password string `json:"password"` +} diff --git a/subject/config.go b/subject/config.go index d50d9d4..90a014f 100644 --- a/subject/config.go +++ b/subject/config.go @@ -10,6 +10,7 @@ var prefixes = struct { Supplier string Seller string SupplierUser string + SupplierRole string }{ Communication: "communication", Order: "order", @@ -20,4 +21,5 @@ var prefixes = struct { Bank: "bank", Seller: "seller", SupplierUser: "supplier_user", + SupplierRole: "supplier_role", } diff --git a/subject/supplier_role.go b/subject/supplier_role.go new file mode 100644 index 0000000..8915759 --- /dev/null +++ b/subject/supplier_role.go @@ -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"), +} diff --git a/subject/supplier_user.go b/subject/supplier_user.go index 7abb4c7..adc2f1f 100644 --- a/subject/supplier_user.go +++ b/subject/supplier_user.go @@ -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"), }