define nats func - supplier balance

This commit is contained in:
Sinh 2022-11-03 16:02:43 +07:00
parent b345cd5395
commit aeec881299
4 changed files with 89 additions and 1 deletions

View File

@ -155,3 +155,56 @@ func (s Supplier) CreateCashflow(p model.SupplierCashflowCreatePayload) (*model.
} }
return r.Data, nil return r.Data, nil
} }
func (s Supplier) UpdateBalance(p model.SupplierUpdateBalanceReq) (*model.SupplierUpdateBalanceRes, error) {
msg, err := natsio.GetServer().Request(subject.Supplier.UpdateBalance, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Error string `json:"error"`
Data *model.SupplierUpdateBalanceRes `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
}
func (s Supplier) GetCurrentBalance(p model.SupplierGetCurrentBalanceReq) (*model.SupplierGetCurrentBalanceRes, error) {
msg, err := natsio.GetServer().Request(subject.Supplier.GetCurrentBalance, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Error string `json:"error"`
Data *model.SupplierGetCurrentBalanceRes `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
}
func (s Supplier) DeleteCashflow(p model.SupplierDeleteCashflowReq) error {
msg, err := natsio.GetServer().Request(subject.Supplier.DeleteCashflow, 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
}

View File

@ -48,3 +48,15 @@ type SupplierCashflowCreatePayload struct {
Value float64 `json:"value"` Value float64 `json:"value"`
ClickAction *ClickAction `json:"clickAction"` ClickAction *ClickAction `json:"clickAction"`
} }
type SupplierUpdateBalanceReq struct {
SupplierID string `json:"supplierId"`
}
type SupplierGetCurrentBalanceReq struct {
SupplierID string `json:"supplierId"`
}
type SupplierDeleteCashflowReq struct {
CashflowID string `json:"cashflowId"`
}

View File

@ -38,4 +38,21 @@ type SupplierShort struct {
ID string `json:"_id"` ID string `json:"_id"`
Name string `json:"name"` Name string `json:"name"`
Logo interface{} `json:"logo"` Logo interface{} `json:"logo"`
} }
type SupplierUpdateBalanceRes struct {
CurrentCash float64 `json:"currentCash"`
TotalPendingCash float64 `json:"totalPendingCash"`
OrderPendingCash float64 `json:"orderPendingCash"`
OrderWaitingForReconcileCash float64 `json:"orderWaitingForReconcileCash"`
OrderReconciledCash float64 `json:"orderReconciledCash"`
WithdrawPendingCash float64 `json:"withdrawPendingCash"`
WithdrawSuccessCash float64 `json:"withdrawSuccessCash"`
WithdrawRejectCash float64 `json:"withdrawRejectCash"`
ChangeBalanceRequestApproved float64 `json:"changeBalanceRequestApproved"`
UpdatedAt string `json:"updatedAt"`
}
type SupplierGetCurrentBalanceRes struct {
CurrentCash float64 `json:"currentCash"`
}

View File

@ -11,9 +11,15 @@ var Supplier = struct {
GetSupplierContractBySupplierID string GetSupplierContractBySupplierID string
FindAll string FindAll string
CreateCashflow string CreateCashflow string
DeleteCashflow string
UpdateBalance string
GetCurrentBalance string
}{ }{
GetListSupplierInfo: getSupplierValue("get_list_supplier_info"), GetListSupplierInfo: getSupplierValue("get_list_supplier_info"),
GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"), GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"),
FindAll: getSupplierValue("find_all"), FindAll: getSupplierValue("find_all"),
CreateCashflow: getSupplierValue("create_cashflow"), CreateCashflow: getSupplierValue("create_cashflow"),
DeleteCashflow: getSupplierValue("delete_cashflow"),
UpdateBalance: getSupplierValue("update_balance"),
GetCurrentBalance: getSupplierValue("get_current_balance"),
} }