mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
feat: bulk approve endpoint for marketings and expenses
This commit is contained in:
@@ -5,10 +5,13 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
m "gitlab.com/mbugroup/lti-api.git/internal/middleware"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/modules/marketing/dto"
|
||||
service "gitlab.com/mbugroup/lti-api.git/internal/modules/marketing/services"
|
||||
validation "gitlab.com/mbugroup/lti-api.git/internal/modules/marketing/validations"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/response"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/utils"
|
||||
approvalutils "gitlab.com/mbugroup/lti-api.git/internal/utils/approvals"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
@@ -152,3 +155,64 @@ func (u *DeliveryOrdersController) UpdateOne(c *fiber.Ctx) error {
|
||||
Data: result,
|
||||
})
|
||||
}
|
||||
|
||||
func (u *DeliveryOrdersController) BulkApproveToStatus(c *fiber.Ctx) error {
|
||||
req := new(validation.BulkApprovalRequest)
|
||||
|
||||
if err := c.BodyParser(req); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid request body")
|
||||
}
|
||||
|
||||
targetStep, err := req.ResolveTarget()
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
}
|
||||
|
||||
if req.RequiresDate(targetStep) && strings.TrimSpace(req.Date) == "" {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "date is required for DELIVERY bulk approval")
|
||||
}
|
||||
|
||||
if err := ensureMarketingBulkApprovalPermission(c, targetStep); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
results, err := u.DeliveryOrdersService.BulkApproveToStatus(c, req, targetStep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var (
|
||||
data interface{}
|
||||
message = "Bulk approve marketing successfully"
|
||||
)
|
||||
if len(results) == 1 {
|
||||
data = results[0]
|
||||
} else {
|
||||
message = "Bulk approve marketings successfully"
|
||||
data = results
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).
|
||||
JSON(response.Success{
|
||||
Code: fiber.StatusOK,
|
||||
Status: "success",
|
||||
Message: message,
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
||||
func ensureMarketingBulkApprovalPermission(c *fiber.Ctx, targetStep approvalutils.ApprovalStep) error {
|
||||
requiredPerms := []string{m.P_SalesOrderApproval}
|
||||
|
||||
if targetStep == utils.MarketingDeliveryOrder {
|
||||
requiredPerms = append(requiredPerms, m.P_DeliveryUpdateOne)
|
||||
}
|
||||
|
||||
for _, perm := range requiredPerms {
|
||||
if !m.HasPermission(c, perm) {
|
||||
return fiber.NewError(fiber.StatusForbidden, "Insufficient permission")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user