create raffle ticket on every bet

This commit is contained in:
Asher Samuel 2025-09-17 12:07:16 +03:00
parent 7336dcfb5d
commit 28b59e8081

View File

@ -236,7 +236,43 @@ func (h *Handler) CreateBetInternal(c *fiber.Ctx, req domain.CreateBetReq, userI
return domain.CreateBetRes{}, err
}
// create raffle ticket here
// create raffle tickets
raffles, err := h.raffleSvc.GetRafflesOfCompany(c.Context(), int32(companyID))
if err != nil {
h.mongoLoggerSvc.Error("Failed to fetch raffle of company",
zap.Int("status_code", fiber.StatusInternalServerError),
zap.Int64("userID", userID),
zap.Int64("companyID", companyID),
zap.String("role", string(role)),
zap.Error(err),
zap.Time("timestamp", time.Now()),
)
}
for _, raffle := range raffles {
// TODO: only fetch pending raffles from db
if raffle.Status == "completed" {
continue
}
raffleTicket := domain.CreateRaffleTicket{
RaffleID: raffle.ID,
UserID: int32(userID),
}
_, err := h.raffleSvc.CreateRaffleTicket(c.Context(), raffleTicket)
if err != nil {
h.mongoLoggerSvc.Error("Failed to create raffle ticket",
zap.Int("status_code", fiber.StatusInternalServerError),
zap.Int64("raffleID", int64(raffle.ID)),
zap.Int64("userID", userID),
zap.Int64("companyID", companyID),
zap.String("role", string(role)),
zap.Error(err),
zap.Time("timestamp", time.Now()),
)
}
}
return res, nil
}