fix: transfer using company wallet
This commit is contained in:
parent
83b0c3e07f
commit
f68155dccd
|
|
@ -129,17 +129,21 @@ func (h *Handler) TransferToWallet(c *fiber.Ctx) error {
|
|||
// Get sender ID from the cashier
|
||||
userID := c.Locals("user_id").(int64)
|
||||
role := string(c.Locals("role").(domain.Role))
|
||||
companyID := c.Locals("company_id").(int64)
|
||||
|
||||
var senderID int64
|
||||
|
||||
//TODO: check to make sure that the cashiers aren't transferring TO branch wallet
|
||||
if role == string(domain.RoleCustomer) {
|
||||
h.logger.Error("Unauthorized access", "userID", userID, "role", role)
|
||||
return response.WriteJSON(c, fiber.StatusUnauthorized, "Unauthorized access", nil, nil)
|
||||
} else if role == string(domain.RoleBranchManager) || role == string(domain.RoleAdmin) || role == string(domain.RoleSuperAdmin) {
|
||||
// TODO Add a way for admins to reference branch wallet
|
||||
senderID = 0
|
||||
company, err := h.companySvc.GetCompanyByID(c.Context(), companyID)
|
||||
if err != nil {
|
||||
return response.WriteJSON(c, fiber.StatusInternalServerError, "Unauthorized access", nil, nil)
|
||||
}
|
||||
senderID = company.WalletID
|
||||
h.logger.Error("Will", "userID", userID, "role", role)
|
||||
return response.WriteJSON(c, fiber.StatusBadRequest, "Unauthorized access", nil, nil)
|
||||
} else {
|
||||
cashierBranch, err := h.branchSvc.GetBranchByCashier(c.Context(), userID)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user