sqldb: fix end date filter when querying invoices

Previously, the SQL implementation of the invoice query simply
converted the start and end timestamps to time and used them
in SQL queries to check for inclusivity. However, this logic
failed when the start and end timestamps were equal.

This commit addresses and corrects this issue.
This commit is contained in:
Andras Banki-Horvath 2024-08-30 16:31:04 +02:00
parent b57910ee3a
commit 06d4267a76
No known key found for this signature in database
GPG Key ID: 80E5375C094198D8
3 changed files with 5 additions and 3 deletions

View File

@ -925,8 +925,10 @@ func (i *SQLStore) QueryInvoices(ctx context.Context,
}
if q.CreationDateEnd != 0 {
// We need to add 1 to the end date as we're
// checking less than the end date in SQL.
params.CreatedBefore = sqldb.SQLTime(
time.Unix(q.CreationDateEnd, 0).UTC(),
time.Unix(q.CreationDateEnd+1, 0).UTC(),
)
}

View File

@ -78,7 +78,7 @@ WHERE (
created_at >= $6 OR
$6 IS NULL
) AND (
created_at <= $7 OR
created_at < $7 OR
$7 IS NULL
) AND (
CASE

View File

@ -76,7 +76,7 @@ WHERE (
created_at >= sqlc.narg('created_after') OR
sqlc.narg('created_after') IS NULL
) AND (
created_at <= sqlc.narg('created_before') OR
created_at < sqlc.narg('created_before') OR
sqlc.narg('created_before') IS NULL
) AND (
CASE