206 lines
6.2 KiB
Go
206 lines
6.2 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: cashier.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const GetAllCashiers = `-- name: GetAllCashiers :many
|
|
SELECT users.id, users.first_name, users.last_name, users.email, users.phone_number, users.role, users.password, users.email_verified, users.phone_verified, users.created_at, users.updated_at, users.company_id, users.suspended_at, users.suspended,
|
|
branch_id,
|
|
branches.name AS branch_name,
|
|
branches.wallet_id AS branch_wallet,
|
|
branches.location As branch_location
|
|
FROM branch_cashiers
|
|
JOIN users ON branch_cashiers.user_id = users.id
|
|
JOIN branches ON branches.id = branch_id
|
|
WHERE (
|
|
first_name ILIKE '%' || $1 || '%'
|
|
OR last_name ILIKE '%' || $1 || '%'
|
|
OR phone_number ILIKE '%' || $1 || '%'
|
|
OR $1 IS NULL
|
|
)
|
|
AND (
|
|
users.created_at > $2
|
|
OR $2 IS NULL
|
|
)
|
|
AND (
|
|
users.created_at < $3
|
|
OR $3 IS NULL
|
|
)
|
|
`
|
|
|
|
type GetAllCashiersParams struct {
|
|
Query pgtype.Text `json:"query"`
|
|
CreatedBefore pgtype.Timestamptz `json:"created_before"`
|
|
CreatedAfter pgtype.Timestamptz `json:"created_after"`
|
|
}
|
|
|
|
type GetAllCashiersRow struct {
|
|
ID int64 `json:"id"`
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
Email pgtype.Text `json:"email"`
|
|
PhoneNumber pgtype.Text `json:"phone_number"`
|
|
Role string `json:"role"`
|
|
Password []byte `json:"password"`
|
|
EmailVerified bool `json:"email_verified"`
|
|
PhoneVerified bool `json:"phone_verified"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
CompanyID pgtype.Int8 `json:"company_id"`
|
|
SuspendedAt pgtype.Timestamptz `json:"suspended_at"`
|
|
Suspended bool `json:"suspended"`
|
|
BranchID int64 `json:"branch_id"`
|
|
BranchName string `json:"branch_name"`
|
|
BranchWallet int64 `json:"branch_wallet"`
|
|
BranchLocation string `json:"branch_location"`
|
|
}
|
|
|
|
func (q *Queries) GetAllCashiers(ctx context.Context, arg GetAllCashiersParams) ([]GetAllCashiersRow, error) {
|
|
rows, err := q.db.Query(ctx, GetAllCashiers, arg.Query, arg.CreatedBefore, arg.CreatedAfter)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetAllCashiersRow
|
|
for rows.Next() {
|
|
var i GetAllCashiersRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.FirstName,
|
|
&i.LastName,
|
|
&i.Email,
|
|
&i.PhoneNumber,
|
|
&i.Role,
|
|
&i.Password,
|
|
&i.EmailVerified,
|
|
&i.PhoneVerified,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.CompanyID,
|
|
&i.SuspendedAt,
|
|
&i.Suspended,
|
|
&i.BranchID,
|
|
&i.BranchName,
|
|
&i.BranchWallet,
|
|
&i.BranchLocation,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetCashierByID = `-- name: GetCashierByID :one
|
|
SELECT users.id, users.first_name, users.last_name, users.email, users.phone_number, users.role, users.password, users.email_verified, users.phone_verified, users.created_at, users.updated_at, users.company_id, users.suspended_at, users.suspended,
|
|
branch_id,
|
|
branches.name AS branch_name,
|
|
branches.wallet_id AS branch_wallet,
|
|
branches.location As branch_location
|
|
FROM branch_cashiers
|
|
JOIN users ON branch_cashiers.user_id = users.id
|
|
JOIN branches ON branches.id = branch_id
|
|
WHERE users.id = $1
|
|
`
|
|
|
|
type GetCashierByIDRow struct {
|
|
ID int64 `json:"id"`
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
Email pgtype.Text `json:"email"`
|
|
PhoneNumber pgtype.Text `json:"phone_number"`
|
|
Role string `json:"role"`
|
|
Password []byte `json:"password"`
|
|
EmailVerified bool `json:"email_verified"`
|
|
PhoneVerified bool `json:"phone_verified"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
CompanyID pgtype.Int8 `json:"company_id"`
|
|
SuspendedAt pgtype.Timestamptz `json:"suspended_at"`
|
|
Suspended bool `json:"suspended"`
|
|
BranchID int64 `json:"branch_id"`
|
|
BranchName string `json:"branch_name"`
|
|
BranchWallet int64 `json:"branch_wallet"`
|
|
BranchLocation string `json:"branch_location"`
|
|
}
|
|
|
|
func (q *Queries) GetCashierByID(ctx context.Context, id int64) (GetCashierByIDRow, error) {
|
|
row := q.db.QueryRow(ctx, GetCashierByID, id)
|
|
var i GetCashierByIDRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.FirstName,
|
|
&i.LastName,
|
|
&i.Email,
|
|
&i.PhoneNumber,
|
|
&i.Role,
|
|
&i.Password,
|
|
&i.EmailVerified,
|
|
&i.PhoneVerified,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.CompanyID,
|
|
&i.SuspendedAt,
|
|
&i.Suspended,
|
|
&i.BranchID,
|
|
&i.BranchName,
|
|
&i.BranchWallet,
|
|
&i.BranchLocation,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetCashiersByBranch = `-- name: GetCashiersByBranch :many
|
|
SELECT users.id, users.first_name, users.last_name, users.email, users.phone_number, users.role, users.password, users.email_verified, users.phone_verified, users.created_at, users.updated_at, users.company_id, users.suspended_at, users.suspended
|
|
FROM branch_cashiers
|
|
JOIN users ON branch_cashiers.user_id = users.id
|
|
JOIN branches ON branches.id = branch_id
|
|
WHERE branch_cashiers.branch_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetCashiersByBranch(ctx context.Context, branchID int64) ([]User, error) {
|
|
rows, err := q.db.Query(ctx, GetCashiersByBranch, branchID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []User
|
|
for rows.Next() {
|
|
var i User
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.FirstName,
|
|
&i.LastName,
|
|
&i.Email,
|
|
&i.PhoneNumber,
|
|
&i.Role,
|
|
&i.Password,
|
|
&i.EmailVerified,
|
|
&i.PhoneVerified,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.CompanyID,
|
|
&i.SuspendedAt,
|
|
&i.Suspended,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|