mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-22 22:35:43 +00:00
feat: bulk approve endpoint for marketings and expenses
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/utils"
|
||||
approvalutils "gitlab.com/mbugroup/lti-api.git/internal/utils/approvals"
|
||||
)
|
||||
|
||||
type Create struct {
|
||||
CustomerId uint `json:"customer_id" validate:"required,gt=0"`
|
||||
SalesPersonId uint `json:"sales_person_id" validate:"required,gt=0"`
|
||||
@@ -33,3 +41,27 @@ type Approve struct {
|
||||
ApprovableIds []uint `json:"approvable_ids" validate:"required_strict,min=1,dive,gt=0"`
|
||||
Notes *string `json:"notes,omitempty" validate:"omitempty,max=500"`
|
||||
}
|
||||
|
||||
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 "SALES_ORDER":
|
||||
return utils.MarketingStepSalesOrder, nil
|
||||
case "DELIVERY", "DELIVERY_ORDER":
|
||||
return utils.MarketingDeliveryOrder, nil
|
||||
default:
|
||||
return 0, errors.New("status must be one of SALES_ORDER or DELIVERY")
|
||||
}
|
||||
}
|
||||
|
||||
func (r *BulkApprovalRequest) RequiresDate(target approvalutils.ApprovalStep) bool {
|
||||
return target == utils.MarketingDeliveryOrder
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user