68 lines
1.6 KiB
SQL
68 lines
1.6 KiB
SQL
-- name: CreateWallet :one
|
|
INSERT INTO wallets (
|
|
is_withdraw,
|
|
is_bettable,
|
|
is_transferable,
|
|
user_id
|
|
)
|
|
VALUES ($1, $2, $3, $4)
|
|
RETURNING *;
|
|
-- name: CreateCustomerWallet :one
|
|
INSERT INTO customer_wallets (
|
|
customer_id,
|
|
company_id,
|
|
regular_wallet_id,
|
|
static_wallet_id
|
|
)
|
|
VALUES ($1, $2, $3, $4)
|
|
RETURNING *;
|
|
-- name: GetAllWallets :many
|
|
SELECT *
|
|
FROM wallets;
|
|
-- name: GetWalletByID :one
|
|
SELECT *
|
|
FROM wallets
|
|
WHERE id = $1;
|
|
-- name: GetWalletByUserID :many
|
|
SELECT *
|
|
FROM wallets
|
|
WHERE user_id = $1;
|
|
-- name: GetCustomerWallet :one
|
|
SELECT cw.id,
|
|
cw.customer_id,
|
|
cw.company_id,
|
|
rw.id AS regular_id,
|
|
rw.balance AS regular_balance,
|
|
sw.id AS static_id,
|
|
sw.balance AS static_balance,
|
|
rw.updated_at as regular_updated_at,
|
|
sw.updated_at as static_updated_at,
|
|
cw.created_at
|
|
FROM customer_wallets cw
|
|
JOIN wallets rw ON cw.regular_wallet_id = rw.id
|
|
JOIN wallets sw ON cw.static_wallet_id = sw.id
|
|
WHERE cw.customer_id = $1
|
|
AND cw.company_id = $2;
|
|
-- name: GetAllBranchWallets :many
|
|
SELECT wallets.id,
|
|
wallets.balance,
|
|
wallets.is_active,
|
|
wallets.updated_at,
|
|
wallets.created_at,
|
|
branches.name,
|
|
branches.location,
|
|
branches.branch_manager_id,
|
|
branches.company_id,
|
|
branches.is_self_owned
|
|
FROM branches
|
|
JOIN wallets ON branches.wallet_id = wallets.id;
|
|
-- name: UpdateBalance :exec
|
|
UPDATE wallets
|
|
SET balance = $1,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $2;
|
|
-- name: UpdateWalletActive :exec
|
|
UPDATE wallets
|
|
SET is_active = $1,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $2; |