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:
@@ -1,7 +1,12 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"mime/multipart"
|
||||
"strings"
|
||||
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/utils"
|
||||
approvalutils "gitlab.com/mbugroup/lti-api.git/internal/utils/approvals"
|
||||
)
|
||||
|
||||
type Create struct {
|
||||
@@ -66,3 +71,31 @@ type ApprovalRequest struct {
|
||||
ApprovableIds []uint `json:"approvable_ids" validate:"required,min=1,dive,gt=0"`
|
||||
Notes *string `json:"notes" form:"notes"`
|
||||
}
|
||||
|
||||
type BulkApprovalRequest struct {
|
||||
ApprovableIds []uint `json:"approvable_ids" validate:"required,min=1,dive,gt=0"`
|
||||
Status string `json:"status" validate:"required,max=100"`
|
||||
Date string `json:"date,omitempty" validate:"omitempty,datetime=2006-01-02"`
|
||||
Notes *string `json:"notes,omitempty" validate:"omitempty,max=500"`
|
||||
}
|
||||
|
||||
func (r *BulkApprovalRequest) ResolveTarget() (approvalutils.ApprovalStep, error) {
|
||||
status := strings.ToUpper(strings.ReplaceAll(strings.TrimSpace(r.Status), " ", "_"))
|
||||
|
||||
switch status {
|
||||
case "HEAD_AREA", "APPROVAL_HEAD_AREA":
|
||||
return utils.ExpenseStepHeadArea, nil
|
||||
case "UNIT_VICE_PRESIDENT", "APPROVAL_UNIT_VICE_PRESIDENT", "BUSINESS_UNIT_VICE_PRESIDENT", "APPROVAL_BUSINESS_UNIT_VICE_PRESIDENT":
|
||||
return utils.ExpenseStepUnitVicePresident, nil
|
||||
case "FINANCE", "APPROVAL_FINANCE":
|
||||
return utils.ExpenseStepFinance, nil
|
||||
case "REALISASI":
|
||||
return utils.ExpenseStepRealisasi, nil
|
||||
default:
|
||||
return 0, errors.New("status must be one of HEAD_AREA, UNIT_VICE_PRESIDENT, FINANCE, or REALISASI")
|
||||
}
|
||||
}
|
||||
|
||||
func (r *BulkApprovalRequest) RequiresDate(target approvalutils.ApprovalStep) bool {
|
||||
return target == utils.ExpenseStepRealisasi
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user