mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
fix(BE): sorting by date approval get all
This commit is contained in:
@@ -15,7 +15,7 @@ type ApprovalService interface {
|
||||
WorkflowSteps(workflow approvalutils.ApprovalWorkflowKey) map[approvalutils.ApprovalStep]string
|
||||
WorkflowStepName(workflow approvalutils.ApprovalWorkflowKey, step approvalutils.ApprovalStep) (string, bool)
|
||||
CreateApproval(ctx context.Context, workflow approvalutils.ApprovalWorkflowKey, approvableID uint, step approvalutils.ApprovalStep, action *entity.ApprovalAction, actorID uint, note *string) (*entity.Approval, error)
|
||||
List(ctx context.Context, module string, approvableID *uint, page, limit int, search string) ([]entity.Approval, int64, error)
|
||||
List(ctx context.Context, module string, approvableID *uint, page, limit int, search string, sortByDate string) ([]entity.Approval, int64, error)
|
||||
ListByTarget(ctx context.Context, workflow approvalutils.ApprovalWorkflowKey, approvableID uint, modifier func(*gorm.DB) *gorm.DB) ([]entity.Approval, error)
|
||||
LatestByTarget(ctx context.Context, workflow approvalutils.ApprovalWorkflowKey, approvableID uint, modifier func(*gorm.DB) *gorm.DB) (*entity.Approval, error)
|
||||
LatestByTargets(ctx context.Context, workflow approvalutils.ApprovalWorkflowKey, approvableIDs []uint, modifier func(*gorm.DB) *gorm.DB) (map[uint]*entity.Approval, error)
|
||||
@@ -70,9 +70,14 @@ func (s *approvalService) List(
|
||||
approvableID *uint,
|
||||
page, limit int,
|
||||
search string,
|
||||
sortByDate string,
|
||||
) ([]entity.Approval, int64, error) {
|
||||
module = strings.TrimSpace(strings.ToUpper(module))
|
||||
search = strings.TrimSpace(search)
|
||||
sortByDate = strings.TrimSpace(strings.ToUpper(sortByDate))
|
||||
if sortByDate != "ASC" && sortByDate != "DESC" {
|
||||
sortByDate = "DESC"
|
||||
}
|
||||
|
||||
if limit <= 0 {
|
||||
limit = 10
|
||||
@@ -90,7 +95,7 @@ func (s *approvalService) List(
|
||||
func(db *gorm.DB) *gorm.DB {
|
||||
query := db.
|
||||
Where("approvable_type = ?", module).
|
||||
Order("action_at DESC").
|
||||
Order("action_at " + sortByDate).
|
||||
Preload("ActionUser")
|
||||
|
||||
if approvableID != nil {
|
||||
|
||||
@@ -44,6 +44,15 @@ func (u *ApprovalController) GetAll(c *fiber.Ctx) error {
|
||||
page := c.QueryInt("page", 1)
|
||||
limit := c.QueryInt("limit", 10)
|
||||
search := strings.TrimSpace(c.Query("search", ""))
|
||||
sortByDate := strings.TrimSpace(c.Query("sort_by_date", ""))
|
||||
if sortByDate == "" {
|
||||
sortByDate = "DESC"
|
||||
} else {
|
||||
sortByDate = strings.ToUpper(sortByDate)
|
||||
if sortByDate != "ASC" && sortByDate != "DESC" {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "sort_by_date must be either ASC or DESC")
|
||||
}
|
||||
}
|
||||
|
||||
query := &validation.Query{
|
||||
ModuleName: moduleName,
|
||||
@@ -52,6 +61,7 @@ func (u *ApprovalController) GetAll(c *fiber.Ctx) error {
|
||||
Page: page,
|
||||
Limit: limit,
|
||||
Search: search,
|
||||
SortByDate: sortByDate,
|
||||
}
|
||||
|
||||
records, totalResults, err := u.ApprovalService.List(
|
||||
@@ -61,6 +71,7 @@ func (u *ApprovalController) GetAll(c *fiber.Ctx) error {
|
||||
query.Page,
|
||||
query.Limit,
|
||||
query.Search,
|
||||
query.SortByDate,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -7,4 +7,5 @@ type Query struct {
|
||||
Page int `query:"page" validate:"omitempty,number,min=1"`
|
||||
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100,gt=0"`
|
||||
Search string `query:"search" validate:"omitempty,max=50"`
|
||||
SortByDate string `query:"sort_by_date" validate:"omitempty,oneof=ASC DESC"`
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ func (s closingService) getClosingSummaryByKandang(ctx context.Context, projectF
|
||||
statusProject := "Belum Selesai"
|
||||
var approvalDate string
|
||||
if s.ApprovalSvc != nil {
|
||||
records, _, err := s.ApprovalSvc.List(ctx, utils.ApprovalWorkflowProjectFlockKandang.String(), &kandang.Id, 1, 1000, "")
|
||||
records, _, err := s.ApprovalSvc.List(ctx, utils.ApprovalWorkflowProjectFlockKandang.String(), &kandang.Id, 1, 1000, "", "")
|
||||
if err != nil {
|
||||
s.Log.Errorf("Failed to fetch approvals for project flock kandang %d: %+v", kandang.Id, err)
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch approval data")
|
||||
@@ -542,7 +542,7 @@ func (s closingService) getApprovalStatuses(ctx context.Context, projectFlockID
|
||||
return "", "Belum Selesai", nil
|
||||
}
|
||||
|
||||
records, _, err := s.ApprovalSvc.List(ctx, utils.ApprovalWorkflowProjectFlock.String(), &projectFlockID, 1, 1000, "")
|
||||
records, _, err := s.ApprovalSvc.List(ctx, utils.ApprovalWorkflowProjectFlock.String(), &projectFlockID, 1, 1000, "", "")
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user