FIX[BE]: fixing issue failed delivery order, fixing unique constraint sales order

This commit is contained in:
aguhh18
2025-11-24 14:35:20 +07:00
parent 1ceda3623e
commit 99688c8e11
7 changed files with 117 additions and 42 deletions
@@ -109,11 +109,10 @@ func (s *salesOrdersService) CreateOne(c *fiber.Ctx, req *validation.Create) (*e
return nil, fiber.NewError(fiber.StatusBadRequest, "Invalid date format")
}
nextSeq, err := s.MarketingRepo.GetNextSequence(c.Context())
soNumber, err := s.MarketingRepo.NextSoNumber(context.Background(), nil)
if err != nil {
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to generate SO number")
}
soNumber := fmt.Sprintf("SO-%05d", nextSeq)
var marketing *entity.Marketing
err = s.MarketingRepo.DB().WithContext(c.Context()).Transaction(func(dbTransaction *gorm.DB) error {
@@ -321,21 +320,24 @@ func (s salesOrdersService) UpdateOne(c *fiber.Ctx, req *validation.Update, id u
}
}
if latestApproval != nil {
actorID := uint(1) // todo: ambil dari auth context
action := entity.ApprovalActionUpdated
_, err := approvalSvcTx.CreateApproval(
c.Context(),
utils.ApprovalWorkflowMarketing,
id,
approvalutils.ApprovalStep(latestApproval.StepNumber),
&action,
actorID,
nil)
if err != nil {
if !errors.Is(err, gorm.ErrDuplicatedKey) {
return fiber.NewError(fiber.StatusInternalServerError, "Failed to create update approval")
if *latestApproval.Action != entity.ApprovalActionUpdated {
actorID := uint(1) // todo: ambil dari auth context
action := entity.ApprovalActionUpdated
_, err := approvalSvcTx.CreateApproval(
c.Context(),
utils.ApprovalWorkflowMarketing,
id,
utils.MarketingStepPengajuan,
&action,
actorID,
nil)
if err != nil {
if !errors.Is(err, gorm.ErrDuplicatedKey) {
return fiber.NewError(fiber.StatusInternalServerError, "Failed to create update approval")
}
}
}
}
return nil