patch: cameroon specific dashboard queries

This commit is contained in:
2022-08-26 07:23:26 +00:00
parent c490f28a96
commit 8456ea78f8
3 changed files with 69 additions and 8 deletions

View File

@@ -7,6 +7,7 @@ import (
"time"
"github.com/georgysavva/scany/pgxscan"
"github.com/jackc/pgx/v4"
"github.com/labstack/echo/v4"
)
@@ -18,15 +19,25 @@ type lineChartRes struct {
func handleNewRegistrations(c echo.Context) error {
var (
api = c.Get("api").(*api)
qP = c.QueryParams()
rows pgx.Rows
err error
data []lineChartRes
)
from, to := date_range.ParseDateRange(c.QueryParams())
from, to := date_range.ParseDateRange(qP)
rows, err := api.db.Query(context.Background(), api.q["new-user-registrations"], from, to)
if err != nil {
return err
if qP.Get("country") == "cmr" {
rows, err = api.db.Query(context.Background(), api.q["new-user-registrations-cmr"], from, to)
if err != nil {
return err
}
} else {
rows, err = api.db.Query(context.Background(), api.q["new-user-registrations"], from, to)
if err != nil {
return err
}
}
if err := pgxscan.ScanAll(&data, rows); err != nil {
@@ -39,15 +50,25 @@ func handleNewRegistrations(c echo.Context) error {
func handleTransactionsCount(c echo.Context) error {
var (
api = c.Get("api").(*api)
qP = c.QueryParams()
rows pgx.Rows
err error
data []lineChartRes
)
from, to := date_range.ParseDateRange(c.QueryParams())
from, to := date_range.ParseDateRange(qP)
rows, err := api.db.Query(context.Background(), api.q["transactions-count"], from, to)
if err != nil {
return err
if qP.Get("country") == "cmr" {
rows, err = api.db.Query(context.Background(), api.q["transactions-count-cmr"], from, to)
if err != nil {
return err
}
} else {
rows, err = api.db.Query(context.Background(), api.q["transactions-count"], from, to)
if err != nil {
return err
}
}
if err := pgxscan.ScanAll(&data, rows); err != nil {