fix: transfer using company wallet

This commit is contained in:
Samuel Tariku 2025-04-28 21:31:25 +03:00
parent 83b0c3e07f
commit f68155dccd

View File

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