mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 21:41:55 +00:00
Fix{BE-222] fixing approval status when updated and delete timestamz on children of marketing table
This commit is contained in:
@@ -270,7 +270,6 @@ func (s salesOrdersService) UpdateOne(c *fiber.Ctx, req *validation.Update, id u
|
||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to update marketing product")
|
||||
}
|
||||
|
||||
// Ensure delivery product exists; if not, create default
|
||||
if _, err := invDeliveryRepoTx.GetByMarketingProductID(c.Context(), old.Id); err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
mdp := &entity.MarketingDeliveryProduct{
|
||||
@@ -321,21 +320,21 @@ func (s salesOrdersService) UpdateOne(c *fiber.Ctx, req *validation.Update, id u
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if latestApproval != nil && latestApproval.StepNumber == 2 {
|
||||
if latestApproval != nil {
|
||||
actorID := uint(1) // todo: ambil dari auth context
|
||||
resetNote := ""
|
||||
action := entity.ApprovalActionUpdated
|
||||
_, err := approvalSvcTx.CreateApproval(
|
||||
c.Context(),
|
||||
utils.ApprovalWorkflowMarketing,
|
||||
id,
|
||||
utils.MarketingStepPengajuan,
|
||||
approvalutils.ApprovalStep(latestApproval.StepNumber),
|
||||
&action,
|
||||
actorID,
|
||||
&resetNote)
|
||||
nil)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to reset approval status")
|
||||
if !errors.Is(err, gorm.ErrDuplicatedKey) {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to create update approval")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -371,7 +370,7 @@ func (s salesOrdersService) DeleteOne(c *fiber.Ctx, id uint) error {
|
||||
if len(marketing.Products) > 0 {
|
||||
for _, product := range marketing.Products {
|
||||
if err := marketingDeliveryProductRepoTx.DeleteMany(c.Context(), func(db *gorm.DB) *gorm.DB {
|
||||
return db.Where("marketing_product_id = ?", product.Id)
|
||||
return db.Where("marketing_product_id = ?", product.Id).Unscoped()
|
||||
}); err != nil && err != gorm.ErrRecordNotFound {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to delete sales order products")
|
||||
}
|
||||
@@ -379,7 +378,7 @@ func (s salesOrdersService) DeleteOne(c *fiber.Ctx, id uint) error {
|
||||
}
|
||||
|
||||
if err := marketingProductRepoTx.DeleteMany(c.Context(), func(db *gorm.DB) *gorm.DB {
|
||||
return db.Where("marketing_id = ?", id)
|
||||
return db.Where("marketing_id = ?", id).Unscoped()
|
||||
}); err != nil && err != gorm.ErrRecordNotFound {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to delete sales order products")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user