From 48e585dc163b66da7b1a279b0974c1515687c4a3 Mon Sep 17 00:00:00 2001 From: Sinh Date: Mon, 19 Sep 2022 11:10:23 +0700 Subject: [PATCH 01/11] update OR request model --- model/warehouse_request.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/model/warehouse_request.go b/model/warehouse_request.go index 543fc68..4e15ff7 100644 --- a/model/warehouse_request.go +++ b/model/warehouse_request.go @@ -29,9 +29,11 @@ type InsuranceOpts struct { // OutboundRequestItem ... type OutboundRequestItem struct { - SupplierSKU string `json:"supplierSKU"` - Quantity int64 `json:"quantity"` - UnitCode string `json:"unitCode"` + SupplierSKU string `json:"supplierSKU"` + Quantity int64 `json:"quantity"` + UnitCode string `json:"unitCode"` + Price float64 `json:"price"` + Name string `json:"name"` } // CustomerInfo ... From b5ba7c7bf1866b83b1062cc7545a43a37fe0e691 Mon Sep 17 00:00:00 2001 From: Sinh Date: Mon, 19 Sep 2022 14:18:51 +0700 Subject: [PATCH 02/11] update OR nats model --- model/warehouse_request.go | 1 + 1 file changed, 1 insertion(+) diff --git a/model/warehouse_request.go b/model/warehouse_request.go index 4e15ff7..7bf920f 100644 --- a/model/warehouse_request.go +++ b/model/warehouse_request.go @@ -58,6 +58,7 @@ type UpdateOutboundRequestLogisticInfoPayload struct { ShippingLabel string `json:"shippingLabel"` TrackingCode string `json:"trackingCode"` ORCode string `json:"orCode"` + TPLCode string `json:"tplCode"` } // CancelOutboundRequest ... From 9e4e6868a495e446c59d3ac82d033fafb256d340 Mon Sep 17 00:00:00 2001 From: Sinh Date: Mon, 19 Sep 2022 15:01:54 +0700 Subject: [PATCH 03/11] add warehouse subject --- subject/warehouse.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/subject/warehouse.go b/subject/warehouse.go index 5d0a81c..b6be006 100644 --- a/subject/warehouse.go +++ b/subject/warehouse.go @@ -14,6 +14,7 @@ var Warehouse = struct { SyncORStatus string WebhookTNC string WebhookGlobalCare string + WebhookOnPoint string FindOne string FindByCondition string Distinct string @@ -30,6 +31,7 @@ var Warehouse = struct { SyncORStatus: getWarehouseValue("sync_or_status"), WebhookTNC: getWarehouseValue("webhook_tnc"), WebhookGlobalCare: getWarehouseValue("webhook_global_care"), + WebhookOnPoint: getWarehouseValue("webhook_on_point"), FindOne: getWarehouseValue("find_one"), FindByCondition: getWarehouseValue("find_all_by_condition"), Distinct: getWarehouseValue("distinct"), From 73181bc5836149a8c1cc07f0ae7c4af08476b162 Mon Sep 17 00:00:00 2001 From: Sinh Date: Wed, 21 Sep 2022 17:40:49 +0700 Subject: [PATCH 04/11] add order func --- client/order.go | 21 +++++++++++++++++++++ model/order_request.go | 10 ++++++++++ model/order_response.go | 34 ++++++++++++++++++++++++++++++++++ subject/order.go | 2 ++ 4 files changed, 67 insertions(+) create mode 100644 model/order_response.go diff --git a/client/order.go b/client/order.go index 7d23cee..db325a1 100644 --- a/client/order.go +++ b/client/order.go @@ -98,3 +98,24 @@ func (o Order) ORNotUpdateStatus(p model.OrderORsNotUpdateStatus) error { } return nil } + +// GetSupplierOrders ... +func (o Order) GetSupplierOrders(p model.OrderSupplierQuery) (*model.SupplierOrderList, error) { + msg, err := natsio.GetServer().Request(subject.Order.GetSupplierOrders, toBytes(p)) + if err != nil { + return nil, err + } + var ( + r struct { + Data model.SupplierOrderList `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/order_request.go b/model/order_request.go index af4989d..ba920f4 100644 --- a/model/order_request.go +++ b/model/order_request.go @@ -38,3 +38,13 @@ type OrderUpdateLogisticInfoFailed struct { type OrderORsNotUpdateStatus struct { ORCodes []string `json:"orCodes"` } + +// OrderSupplierQuery ... +type OrderSupplierQuery struct { + Limit int64 `json:"limit"` + Page int64 `json:"page"` + FromDate string `json:"fromDate"` + ToDate string `json:"toDate"` + SupplierID string `json:"supplierId"` + WarehouseIDs []string `json:"warehouseIDs"` +} diff --git a/model/order_response.go b/model/order_response.go new file mode 100644 index 0000000..cbde555 --- /dev/null +++ b/model/order_response.go @@ -0,0 +1,34 @@ +package model + +import "time" + +// SupplierOrderList ... +type SupplierOrderList struct { + List []SupplierOrder `json:"list"` + Total int64 `json:"total" example:"100"` + Limit int64 `json:"limit" example:"20"` +} + +// SupplierOrder ... +type SupplierOrder struct { + ID string `json:"_id"` + Code string `json:"code"` + CreatedAt time.Time `json:"createdAt"` + Status string `json:"status"` + Items []SupplierOrderItem `json:"items"` + Delivery SupplierOrderDelivery `json:"delivery"` +} + +// SupplierOrderItem ... +type SupplierOrderItem struct { + ID string `json:"_id" example:"1231"` + SupplierSKU string `json:"supplierSku" example:"SUPPLIER_SKU"` + Quantity int64 `json:"quantity" example:"2"` +} + +// SupplierOrderDelivery ... +type SupplierOrderDelivery struct { + Code string `json:"code" example:"123187287"` + Status string `json:"status" enums:"waiting_to_confirm,waiting_to_pick,picking,picked,delay_pickup,pickup_failed,delivering,delay_delivery,delivered,cancelled,delivery_failed,waiting_to_return,returning,delay_return,compensation,returned"` + TPLCode string `json:"tplCode" enums:"SLY,GHTK,GHN,SSC,SPY,VTP,SE,NTL,BEST"` +} diff --git a/subject/order.go b/subject/order.go index 1452de3..017f2be 100644 --- a/subject/order.go +++ b/subject/order.go @@ -12,10 +12,12 @@ var Order = struct { ChangeDeliveryStatus string UpdateLogisticInfoFailed string ORNotUpdateStatus string + GetSupplierOrders string }{ UpdateORStatus: getOrderValue("update_outbound_request_status"), CancelDelivery: getOrderValue("cancel_delivery"), ChangeDeliveryStatus: getOrderValue("change_delivery_status"), UpdateLogisticInfoFailed: getOrderValue("update_logistic_info_failed"), ORNotUpdateStatus: getOrderValue("outbound_request_not_update_status"), + GetSupplierOrders: getOrderValue("get_supplier_orders"), } From d06719b0e6b4377ebbd82e1cd9da5fd12cafd2f2 Mon Sep 17 00:00:00 2001 From: Sinh Date: Thu, 22 Sep 2022 09:34:16 +0700 Subject: [PATCH 05/11] define api get supplier orders --- model/order_response.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/model/order_response.go b/model/order_response.go index cbde555..c08f87a 100644 --- a/model/order_response.go +++ b/model/order_response.go @@ -11,12 +11,13 @@ type SupplierOrderList struct { // SupplierOrder ... type SupplierOrder struct { - ID string `json:"_id"` - Code string `json:"code"` - CreatedAt time.Time `json:"createdAt"` - Status string `json:"status"` - Items []SupplierOrderItem `json:"items"` - Delivery SupplierOrderDelivery `json:"delivery"` + ID string `json:"_id"` + Code string `json:"code"` + CreatedAt time.Time `json:"createdAt"` + Status string `json:"status"` + WarehouseStatus string `json:"warehouseStatus"` + Items []SupplierOrderItem `json:"items"` + Delivery SupplierOrderDelivery `json:"delivery"` } // SupplierOrderItem ... From 86845399e3dadfd3fffb251f3ce9cb1fe112470d Mon Sep 17 00:00:00 2001 From: Sinh Date: Wed, 5 Oct 2022 09:15:36 +0700 Subject: [PATCH 06/11] update onpoint payload --- model/warehouse_request.go | 1 + 1 file changed, 1 insertion(+) diff --git a/model/warehouse_request.go b/model/warehouse_request.go index 5563ef4..7c418a7 100644 --- a/model/warehouse_request.go +++ b/model/warehouse_request.go @@ -66,6 +66,7 @@ type UpdateOutboundRequestLogisticInfoPayload struct { TrackingCode string `json:"trackingCode"` ORCode string `json:"orCode"` TPLCode string `json:"tplCode"` + OrderCode string `json:"orderCode"` } // CancelOutboundRequest ... From 1b89d5f3684a21b701d8ba32a0c07339c0f25959 Mon Sep 17 00:00:00 2001 From: Sinh Date: Wed, 5 Oct 2022 09:19:54 +0700 Subject: [PATCH 07/11] update onpoint payload --- model/warehouse_request.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/model/warehouse_request.go b/model/warehouse_request.go index 7c418a7..b8ad0ff 100644 --- a/model/warehouse_request.go +++ b/model/warehouse_request.go @@ -66,19 +66,21 @@ type UpdateOutboundRequestLogisticInfoPayload struct { TrackingCode string `json:"trackingCode"` ORCode string `json:"orCode"` TPLCode string `json:"tplCode"` - OrderCode string `json:"orderCode"` + OrderID string `json:"orderId"` } // CancelOutboundRequest ... type CancelOutboundRequest struct { - ORCode string `json:"orCode"` - Note string `json:"note"` + ORCode string `json:"orCode"` + OrderID string `json:"orderId"` + Note string `json:"note"` } // SyncORStatusRequest ... type SyncORStatusRequest struct { ORCode string `json:"orCode"` OrderCode string `json:"orderCode"` + OrderID string `json:"orderId"` } // UpdateSupplierIsClosedRequest ... From 22396d8f40455bded146430a9de76a8aeafb53a4 Mon Sep 17 00:00:00 2001 From: Sinh Date: Mon, 17 Oct 2022 14:32:14 +0700 Subject: [PATCH 08/11] update nats payload --- model/warehouse_request.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/model/warehouse_request.go b/model/warehouse_request.go index b8ad0ff..4cd857a 100644 --- a/model/warehouse_request.go +++ b/model/warehouse_request.go @@ -2,17 +2,18 @@ package model // OutboundRequestPayload ... type OutboundRequestPayload struct { - OrderID string `json:"orderId"` - OrderCode string `json:"orderCode"` - TrackingCode string `json:"trackingCode"` - WarehouseID string `json:"warehouseId"` - SupplierID string `json:"supplierId"` - Note string `json:"note"` - CODAmount float64 `json:"codAmount"` - TPLCode string `json:"tplCode"` - Customer CustomerInfo `json:"customer"` - Items []OutboundRequestItem `json:"items"` - Insurance *InsuranceOpts `json:"insurance"` + OrderID string `json:"orderId"` + OrderCode string `json:"orderCode"` + TrackingCode string `json:"trackingCode"` + WarehouseID string `json:"warehouseId"` + SupplierID string `json:"supplierId"` + Note string `json:"note"` + CODAmount float64 `json:"codAmount"` + TPLCode string `json:"tplCode"` + Customer CustomerInfo `json:"customer"` + Items []OutboundRequestItem `json:"items"` + Insurance *InsuranceOpts `json:"insurance"` + PaymentMethod string `json:"paymentMethod"` } // InsuranceOpts ... From 91d8ffe40fd75c42de6041a0a4a33c060f1bb563 Mon Sep 17 00:00:00 2001 From: Sinh Date: Tue, 18 Oct 2022 14:57:14 +0700 Subject: [PATCH 09/11] add warehouse client method --- client/warehouse.go | 19 +++++++++++ model/warehouse_request.go | 8 +++++ subject/warehouse.go | 66 ++++++++++++++++++++------------------ 3 files changed, 61 insertions(+), 32 deletions(-) diff --git a/client/warehouse.go b/client/warehouse.go index 944c2cb..beb3a6f 100644 --- a/client/warehouse.go +++ b/client/warehouse.go @@ -3,6 +3,7 @@ package client import ( "encoding/json" "errors" + "fmt" "git.selly.red/Selly-Modules/natsio" "git.selly.red/Selly-Modules/natsio/model" @@ -163,3 +164,21 @@ func (w Warehouse) GetWarehouses(p model.GetWarehousesRequest) (*model.GetWareho } return r.Data, nil } + +// UpdateORDeliveryStatus ... +func (w Warehouse) UpdateORDeliveryStatus(p model.WarehouseORUpdateDeliveryStatus) error { + msg, err := natsio.GetServer().Request(subject.Warehouse.GetWarehouses, toBytes(p)) + if err != nil { + return err + } + var r struct { + Error string `json:"error"` + } + if err = json.Unmarshal(msg.Data, &r); err != nil { + return fmt.Errorf("nats: update_or_delivery_status %v", err) + } + if r.Error != "" { + return errors.New(r.Error) + } + return nil +} diff --git a/model/warehouse_request.go b/model/warehouse_request.go index 4cd857a..b6cecb1 100644 --- a/model/warehouse_request.go +++ b/model/warehouse_request.go @@ -105,3 +105,11 @@ type GetWarehousesRequest struct { Page int64 `json:"page"` Limit int64 `json:"limit"` } + +// WarehouseORUpdateDeliveryStatus ... +type WarehouseORUpdateDeliveryStatus struct { + ORCode string `json:"orCode"` + OrderCode string `json:"orderCode"` + OrderID string `json:"orderId"` + DeliveryStatus string `json:"deliveryStatus"` +} diff --git a/subject/warehouse.go b/subject/warehouse.go index f6f4cc8..bb184b5 100644 --- a/subject/warehouse.go +++ b/subject/warehouse.go @@ -9,39 +9,41 @@ func getWarehouseValue(val string) string { var Warehouse = struct { CreateWarehouseIntoServiceSupplier string UpdateWarehouseIntoServiceSupplier string - CreateOutboundRequest string - UpdateOutboundRequestLogistic string - CancelOutboundRequest string - GetConfiguration string - SyncORStatus string - WebhookTNC string - WebhookGlobalCare string - WebhookOnPoint string - FindOne string - FindByCondition string - Distinct string - Count string - AfterUpdateWarehouse string - AfterCreateWarehouse string - UpdateIsClosedSupplier string - GetWarehouses string + CreateOutboundRequest string + UpdateOutboundRequestLogistic string + CancelOutboundRequest string + GetConfiguration string + SyncORStatus string + WebhookTNC string + WebhookGlobalCare string + WebhookOnPoint string + FindOne string + FindByCondition string + Distinct string + Count string + AfterUpdateWarehouse string + AfterCreateWarehouse string + UpdateIsClosedSupplier string + GetWarehouses string + UpdateORDeliveryStatus string }{ CreateWarehouseIntoServiceSupplier: getWarehouseValue("create_warehouse_into_service_supplier"), UpdateWarehouseIntoServiceSupplier: getWarehouseValue("update_warehouse_into_service_supplier"), - AfterCreateWarehouse: getWarehouseValue("after_create_warehouse"), - AfterUpdateWarehouse: getWarehouseValue("after_update_warehouse"), - CreateOutboundRequest: getWarehouseValue("create_outbound_request"), - UpdateOutboundRequestLogistic: getWarehouseValue("update_outbound_request_logistic_info"), - CancelOutboundRequest: getWarehouseValue("cancel_outbound_request"), - GetConfiguration: getWarehouseValue("get_configuration"), - SyncORStatus: getWarehouseValue("sync_or_status"), - WebhookTNC: getWarehouseValue("webhook_tnc"), - WebhookGlobalCare: getWarehouseValue("webhook_global_care"), - WebhookOnPoint: getWarehouseValue("webhook_on_point"), - FindOne: getWarehouseValue("find_one"), - FindByCondition: getWarehouseValue("find_all_by_condition"), - Distinct: getWarehouseValue("distinct"), - Count: getWarehouseValue("count"), - UpdateIsClosedSupplier: getWarehouseValue("update_is_closed_supplier"), - GetWarehouses: getWarehouseValue("get_warehouses"), + AfterCreateWarehouse: getWarehouseValue("after_create_warehouse"), + AfterUpdateWarehouse: getWarehouseValue("after_update_warehouse"), + CreateOutboundRequest: getWarehouseValue("create_outbound_request"), + UpdateOutboundRequestLogistic: getWarehouseValue("update_outbound_request_logistic_info"), + CancelOutboundRequest: getWarehouseValue("cancel_outbound_request"), + GetConfiguration: getWarehouseValue("get_configuration"), + SyncORStatus: getWarehouseValue("sync_or_status"), + WebhookTNC: getWarehouseValue("webhook_tnc"), + WebhookGlobalCare: getWarehouseValue("webhook_global_care"), + WebhookOnPoint: getWarehouseValue("webhook_on_point"), + FindOne: getWarehouseValue("find_one"), + FindByCondition: getWarehouseValue("find_all_by_condition"), + Distinct: getWarehouseValue("distinct"), + Count: getWarehouseValue("count"), + UpdateIsClosedSupplier: getWarehouseValue("update_is_closed_supplier"), + GetWarehouses: getWarehouseValue("get_warehouses"), + UpdateORDeliveryStatus: getWarehouseValue("update_or_delivery_status"), } From 4bc71955633337d402f676e4487eacd5f6098a39 Mon Sep 17 00:00:00 2001 From: Sinh Date: Fri, 21 Oct 2022 09:26:37 +0700 Subject: [PATCH 10/11] update OR payload --- model/order_request.go | 1 + 1 file changed, 1 insertion(+) diff --git a/model/order_request.go b/model/order_request.go index ba920f4..bd1fa73 100644 --- a/model/order_request.go +++ b/model/order_request.go @@ -2,6 +2,7 @@ package model // OrderUpdateORStatus ... type OrderUpdateORStatus struct { + ID string `json:"id"` OrderCode string `json:"orderCode"` ORCode string `json:"orCode"` Status string `json:"status"` 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"), }