added soft deleted
This commit is contained in:
1 parent
d1a6fcaadc
commit
e0d03730de
36 files changed
+327
-217
No files matched your search
@@ -137,7 +137,7 @@ func (r *repository) loanOrdersMetric(ctx context.Context, branchIds []int64, wi
|
||||
extra = append(extra, branchIds)
|
||||
where = fmt.Sprintf(" AND branch_id = ANY($%d)", len(extra)+4)
|
||||
}
|
||||
query := metricSQL(`FROM loan_orders WHERE true` + where)
|
||||
query := metricSQL(`FROM loan_orders WHERE deleted_at IS NULL` + where)
|
||||
return r.scanMetric(ctx, query, append(dateArgs(win), extra...)...)
|
||||
}
|
||||
|
||||
@@ -146,9 +146,9 @@ func (r *repository) activeCardsMetric(ctx context.Context, branchIds []int64, w
|
||||
var extra []interface{}
|
||||
if len(branchIds) > 0 {
|
||||
extra = append(extra, branchIds)
|
||||
where = fmt.Sprintf(" AND EXISTS (SELECT 1 FROM branch_user bu WHERE bu.user_id = c.user_id AND bu.branch_id = ANY($%d))", len(extra)+4)
|
||||
where = fmt.Sprintf(" AND EXISTS (SELECT 1 FROM branch_user bu WHERE bu.user_id = c.user_id AND bu.branch_id = ANY($%d) AND bu.deleted_at IS NULL)", len(extra)+4)
|
||||
}
|
||||
query := metricSQL(`FROM cards c WHERE true` + where)
|
||||
query := metricSQL(`FROM cards c WHERE c.deleted_at IS NULL` + where)
|
||||
return r.scanMetric(ctx, query, append(dateArgs(win), extra...)...)
|
||||
}
|
||||
|
||||
@@ -157,9 +157,9 @@ func (r *repository) activeCustomersMetric(ctx context.Context, branchIds []int6
|
||||
var extra []interface{}
|
||||
if len(branchIds) > 0 {
|
||||
extra = append(extra, branchIds)
|
||||
where += fmt.Sprintf(" AND EXISTS (SELECT 1 FROM branch_user bu WHERE bu.user_id = u.id AND bu.branch_id = ANY($%d))", len(extra)+4)
|
||||
where += fmt.Sprintf(" AND EXISTS (SELECT 1 FROM branch_user bu WHERE bu.user_id = u.id AND bu.branch_id = ANY($%d) AND bu.deleted_at IS NULL)", len(extra)+4)
|
||||
}
|
||||
query := metricSQL(`FROM users u WHERE true` + where)
|
||||
query := metricSQL(`FROM users u WHERE u.deleted_at IS NULL` + where)
|
||||
return r.scanMetric(ctx, query, append(dateArgs(win), extra...)...)
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ func (r *repository) onlinePaymentsMetric(ctx context.Context, branchIds []int64
|
||||
extra = append(extra, branchIds)
|
||||
where = fmt.Sprintf(" AND branch_id = ANY($%d)", len(extra)+4)
|
||||
}
|
||||
query := metricSQL(`FROM visa_master_payment_orders WHERE true` + where)
|
||||
query := metricSQL(`FROM visa_master_payment_orders WHERE deleted_at IS NULL` + where)
|
||||
return r.scanMetric(ctx, query, append(dateArgs(win), extra...)...)
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ func (r *repository) monthlyCounts(ctx context.Context, table string, branchIds
|
||||
query := fmt.Sprintf(`
|
||||
SELECT EXTRACT(MONTH FROM created_at)::int, COUNT(*)
|
||||
FROM %s
|
||||
WHERE EXTRACT(YEAR FROM created_at) = $1%s
|
||||
WHERE EXTRACT(YEAR FROM created_at) = $1 AND deleted_at IS NULL%s
|
||||
GROUP BY 1`, table, where)
|
||||
|
||||
rows, err := r.client.Query(ctx, query, args...)
|
||||
@@ -270,7 +270,7 @@ func (r *repository) dailyCounts(ctx context.Context, table string, branchIds []
|
||||
query := fmt.Sprintf(`
|
||||
SELECT created_at::date, COUNT(*)
|
||||
FROM %s
|
||||
WHERE created_at >= $1%s
|
||||
WHERE created_at >= $1 AND deleted_at IS NULL%s
|
||||
GROUP BY 1`, table, where)
|
||||
|
||||
rows, err := r.client.Query(ctx, query, args...)
|
||||
@@ -321,7 +321,7 @@ func (r *repository) loanStatusBreakdown(ctx context.Context, branchIds []int64)
|
||||
query := fmt.Sprintf(`
|
||||
SELECT %s, COUNT(*)
|
||||
FROM loan_orders
|
||||
WHERE true%s
|
||||
WHERE deleted_at IS NULL%s
|
||||
GROUP BY 1`, loanStatusBucketSQL, where)
|
||||
|
||||
rows, err := r.client.Query(ctx, query, args...)
|
||||
@@ -369,7 +369,7 @@ func (r *repository) recentActivity(ctx context.Context, branchIds []int64, limi
|
||||
query := fmt.Sprintf(`
|
||||
SELECT id, unique_id, customer_name, customer_surname, loan_amount, status, created_at
|
||||
FROM loan_orders
|
||||
WHERE true%s
|
||||
WHERE deleted_at IS NULL%s
|
||||
ORDER BY created_at DESC, id DESC
|
||||
LIMIT $%d`, where, len(args))
|
||||
|
||||
|
||||
Reference in new issue
Block a user