From f68155dccd080f408a539dc94855b82c9637c15f Mon Sep 17 00:00:00 2001 From: Samuel Tariku Date: Mon, 28 Apr 2025 21:31:25 +0300 Subject: [PATCH] fix: transfer using company wallet --- internal/web_server/handlers/transfer_handler.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/web_server/handlers/transfer_handler.go b/internal/web_server/handlers/transfer_handler.go index 7cff933..e3cfcc6 100644 --- a/internal/web_server/handlers/transfer_handler.go +++ b/internal/web_server/handlers/transfer_handler.go @@ -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 {