ch something
This commit is contained in:
1 parent
3b33e25703
commit
60787c8149
8 files changed
+383
-23
No files matched your search
@@ -109,8 +109,8 @@ func (r *repository) List(ctx context.Context, filter visamaster.ListFilter) (vi
|
||||
limitPlaceholder := len(args) + 1
|
||||
offsetPlaceholder := len(args) + 2
|
||||
query := fmt.Sprintf(
|
||||
`SELECT o.id, o.type, o.created_at, o.region, o.branch_id, b.name, p.name,
|
||||
o.passport_name, o.passport_surname, o.phone, o.status, o.paid
|
||||
`SELECT o.id, o.unique_id, o.type, o.created_at, o.region, p.region, o.branch_id, b.name, p.name,
|
||||
o.passport_name, o.passport_surname, o.phone, o.status, o.paid, `+paidThisMonthSQL+`
|
||||
FROM visa_master_payment_orders o
|
||||
LEFT JOIN branches b ON b.id = o.branch_id
|
||||
LEFT JOIN provinces p ON p.id = b.province_id%s ORDER BY o.id DESC LIMIT $%d OFFSET $%d`,
|
||||
@@ -150,6 +150,18 @@ func buildListQuery(filter visamaster.ListFilter) (whereClause string, args []in
|
||||
)`, n))
|
||||
}
|
||||
|
||||
// Case-insensitive and trimmed, the same match visamasterpay uses to
|
||||
// pick Sber fees and credentials.
|
||||
if filter.Type != "" {
|
||||
args = append(args, strings.TrimSpace(filter.Type))
|
||||
conditions = append(conditions, fmt.Sprintf("LOWER(TRIM(o.type)) = LOWER($%d)", len(args)))
|
||||
}
|
||||
|
||||
if filter.ExcludeType != "" {
|
||||
args = append(args, strings.TrimSpace(filter.ExcludeType))
|
||||
conditions = append(conditions, fmt.Sprintf("LOWER(TRIM(COALESCE(o.type, ''))) <> LOWER($%d)", len(args)))
|
||||
}
|
||||
|
||||
if filter.Status != nil {
|
||||
args = append(args, *filter.Status)
|
||||
conditions = append(conditions, fmt.Sprintf("o.status = $%d", len(args)))
|
||||
@@ -296,18 +308,29 @@ func jsonOrDefault(raw []byte, fallback string) json.RawMessage {
|
||||
return json.RawMessage(raw)
|
||||
}
|
||||
|
||||
// paidThisMonthSQL: the order has a successful payment whose payment_period
|
||||
// falls in the current month in Ashgabat time (UTC+5, as visamasterpay).
|
||||
const paidThisMonthSQL = `EXISTS (
|
||||
SELECT 1 FROM visa_master_order_payments vp
|
||||
WHERE vp.order_id = o.id AND vp.gateway_status = 'success' AND vp.deleted_at IS NULL
|
||||
AND date_trunc('month', vp.payment_period) = date_trunc('month', (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') + INTERVAL '5 hours')
|
||||
)`
|
||||
|
||||
func scanOrderListItem(row genericrepo.Scanner) (visamaster.VisaMasterPaymentOrderListItemDTO, error) {
|
||||
var item visamaster.VisaMasterPaymentOrderListItemDTO
|
||||
var branchId int64
|
||||
var branchNameJSON, provinceNameJSON []byte
|
||||
var regionNameJSON, branchNameJSON, provinceNameJSON []byte
|
||||
|
||||
if err := row.Scan(
|
||||
&item.Id, &item.Type, &item.CreatedAt, &item.Region, &branchId, &branchNameJSON, &provinceNameJSON,
|
||||
&item.PassportName, &item.PassportSurname, &item.Phone, &item.Status, &item.Paid,
|
||||
&item.Id, &item.UniqueId, &item.Type, &item.CreatedAt, &item.Region, ®ionNameJSON, &branchId, &branchNameJSON, &provinceNameJSON,
|
||||
&item.PassportName, &item.PassportSurname, &item.Phone, &item.Status, &item.Paid, &item.PaidThisMonth,
|
||||
); err != nil {
|
||||
return visamaster.VisaMasterPaymentOrderListItemDTO{}, err
|
||||
}
|
||||
|
||||
if err := shared.UnmarshalLocalized(regionNameJSON, &item.RegionName); err != nil {
|
||||
return visamaster.VisaMasterPaymentOrderListItemDTO{}, err
|
||||
}
|
||||
var branchName shared.LocalizedText
|
||||
if err := shared.UnmarshalLocalized(branchNameJSON, &branchName); err != nil {
|
||||
return visamaster.VisaMasterPaymentOrderListItemDTO{}, err
|
||||
|
||||
Reference in new issue
Block a user