mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Fix config chickin
This commit is contained in:
@@ -28,6 +28,7 @@ import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/sirupsen/logrus"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
type ChickinService interface {
|
||||
@@ -518,6 +519,21 @@ func (s chickinService) Approval(c *fiber.Ctx, req *validation.Approve) ([]entit
|
||||
touchedProductWarehouseIDs := make(map[uint]struct{})
|
||||
|
||||
for _, approvableID := range approvableIDs {
|
||||
// Re-check latest approval inside transaction to prevent double-approve races.
|
||||
var latest entity.Approval
|
||||
if err := dbTransaction.WithContext(c.Context()).
|
||||
Table("approvals").
|
||||
Where("approvable_type = ? AND approvable_id = ?", utils.ApprovalWorkflowChickin.String(), approvableID).
|
||||
Order("id DESC").
|
||||
Limit(1).
|
||||
Clauses(clause.Locking{Strength: "UPDATE"}).
|
||||
Take(&latest).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to recheck approval status")
|
||||
}
|
||||
if latest.Id != 0 && latest.StepNumber != uint16(utils.ChickinStepPengajuan) {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("ProjectFlockKandang %d sudah tidak berada di tahap PENGAJUAN", approvableID))
|
||||
}
|
||||
|
||||
if _, err := approvalSvc.CreateApproval(
|
||||
c.Context(),
|
||||
utils.ApprovalWorkflowChickin,
|
||||
|
||||
Reference in New Issue
Block a user