fix double revise letter
This commit is contained in:
@@ -76,15 +76,15 @@ func (r *ApprovalFlowRepository) List(ctx context.Context, filter ListApprovalFl
|
||||
|
||||
// Build base query for counting
|
||||
countQuery := r.db.WithContext(ctx).Model(&entities.ApprovalFlow{})
|
||||
|
||||
|
||||
if filter.DepartmentID != nil {
|
||||
countQuery = countQuery.Where("department_id = ?", *filter.DepartmentID)
|
||||
}
|
||||
|
||||
|
||||
if filter.IsActive != nil {
|
||||
countQuery = countQuery.Where("is_active = ?", *filter.IsActive)
|
||||
}
|
||||
|
||||
|
||||
if filter.Search != nil && *filter.Search != "" {
|
||||
like := "%" + *filter.Search + "%"
|
||||
countQuery = countQuery.Where("name ILIKE ? OR description ILIKE ?", like, like)
|
||||
@@ -97,15 +97,15 @@ func (r *ApprovalFlowRepository) List(ctx context.Context, filter ListApprovalFl
|
||||
|
||||
// Build query for fetching data - BUAT QUERY BARU DARI AWAL
|
||||
dataQuery := r.db.WithContext(ctx).Model(&entities.ApprovalFlow{})
|
||||
|
||||
|
||||
if filter.DepartmentID != nil {
|
||||
dataQuery = dataQuery.Where("department_id = ?", *filter.DepartmentID)
|
||||
}
|
||||
|
||||
|
||||
if filter.IsActive != nil {
|
||||
dataQuery = dataQuery.Where("is_active = ?", *filter.IsActive)
|
||||
}
|
||||
|
||||
|
||||
if filter.Search != nil && *filter.Search != "" {
|
||||
like := "%" + *filter.Search + "%"
|
||||
dataQuery = dataQuery.Where("name ILIKE ? OR description ILIKE ?", like, like)
|
||||
@@ -239,18 +239,33 @@ func (r *LetterOutgoingApprovalRepository) ListByLetter(ctx context.Context, let
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingApprovalRepository) ListByLetterAndLasRevisionNumber(ctx context.Context, letterID uuid.UUID, revisionNumber int) ([]entities.LetterOutgoingApproval, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
var list []entities.LetterOutgoingApproval
|
||||
if err := db.WithContext(ctx).
|
||||
Preload("Step.ApproverRole").
|
||||
Preload("Step.ApproverUser").
|
||||
Preload("Approver").
|
||||
Where("letter_id = ? AND revision_number = ?", letterID, revisionNumber).
|
||||
Order("created_at ASC").
|
||||
Find(&list).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (r *LetterOutgoingApprovalRepository) GetPendingApprovals(ctx context.Context, userID uuid.UUID) ([]entities.LetterOutgoingApproval, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
var list []entities.LetterOutgoingApproval
|
||||
|
||||
|
||||
if err := db.WithContext(ctx).
|
||||
Preload("Letter").
|
||||
Preload("Step").
|
||||
Joins("JOIN approval_flow_steps afs ON afs.id = letter_outgoing_approvals.step_id").
|
||||
Where("letter_outgoing_approvals.status = ? AND (afs.approver_user_id = ? OR afs.approver_role_id IN (SELECT role_id FROM user_roles WHERE user_id = ?))",
|
||||
Where("letter_outgoing_approvals.status = ? AND (afs.approver_user_id = ? OR afs.approver_role_id IN (SELECT role_id FROM user_roles WHERE user_id = ?))",
|
||||
entities.ApprovalStatusPending, userID, userID).
|
||||
Find(&list).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user