duplicate user creation fix + sender balance check during wallet refill
This commit is contained in:
parent
788e3ee9a6
commit
8f2713b920
|
|
@ -260,6 +260,7 @@ FROM companies
|
||||||
JOIN wallets ON wallets.id = companies.wallet_id
|
JOIN wallets ON wallets.id = companies.wallet_id
|
||||||
JOIN users ON users.id = companies.admin_id;
|
JOIN users ON users.id = companies.admin_id;
|
||||||
;
|
;
|
||||||
|
|
||||||
CREATE VIEW branch_details AS
|
CREATE VIEW branch_details AS
|
||||||
SELECT branches.*,
|
SELECT branches.*,
|
||||||
CONCAT(users.first_name, ' ', users.last_name) AS manager_name,
|
CONCAT(users.first_name, ' ', users.last_name) AS manager_name,
|
||||||
|
|
@ -284,37 +285,40 @@ FROM tickets
|
||||||
LEFT JOIN ticket_outcomes ON tickets.id = ticket_outcomes.ticket_id
|
LEFT JOIN ticket_outcomes ON tickets.id = ticket_outcomes.ticket_id
|
||||||
GROUP BY tickets.id;
|
GROUP BY tickets.id;
|
||||||
-- Foreign Keys
|
-- Foreign Keys
|
||||||
|
|
||||||
|
ALTER TABLE users
|
||||||
|
ADD CONSTRAINT unique_email UNIQUE (email),
|
||||||
|
ADD CONSTRAINT unique_phone_number UNIQUE (phone_number);
|
||||||
ALTER TABLE refresh_tokens
|
ALTER TABLE refresh_tokens
|
||||||
ADD CONSTRAINT fk_refresh_tokens_users FOREIGN KEY (user_id) REFERENCES users(id);
|
ADD CONSTRAINT fk_refresh_tokens_users FOREIGN KEY (user_id) REFERENCES users(id);
|
||||||
ALTER TABLE bets
|
ALTER TABLE bets
|
||||||
ADD CONSTRAINT fk_bets_users FOREIGN KEY (user_id) REFERENCES users(id),
|
ADD CONSTRAINT fk_bets_users FOREIGN KEY (user_id) REFERENCES users(id),
|
||||||
ADD CONSTRAINT fk_bets_branches FOREIGN KEY (branch_id) REFERENCES branches(id);
|
ADD CONSTRAINT fk_bets_branches FOREIGN KEY (branch_id) REFERENCES branches(id);
|
||||||
ALTER TABLE wallets
|
ALTER TABLE wallets
|
||||||
ADD CONSTRAINT fk_wallets_users FOREIGN KEY (user_id) REFERENCES users(id);
|
ADD CONSTRAINT fk_wallets_users FOREIGN KEY (user_id) REFERENCES users(id);
|
||||||
ALTER TABLE customer_wallets
|
ALTER TABLE customer_wallets
|
||||||
ADD CONSTRAINT fk_customer_wallets_customers FOREIGN KEY (customer_id) REFERENCES users(id),
|
ADD CONSTRAINT fk_customer_wallets_customers FOREIGN KEY (customer_id) REFERENCES users(id),
|
||||||
ADD CONSTRAINT fk_customer_wallets_regular_wallet FOREIGN KEY (regular_wallet_id) REFERENCES wallets(id),
|
ADD CONSTRAINT fk_customer_wallets_regular_wallet FOREIGN KEY (regular_wallet_id) REFERENCES wallets(id),
|
||||||
ADD CONSTRAINT fk_customer_wallets_static_wallet FOREIGN KEY (static_wallet_id) REFERENCES wallets(id);
|
ADD CONSTRAINT fk_customer_wallets_static_wallet FOREIGN KEY (static_wallet_id) REFERENCES wallets(id);
|
||||||
ALTER TABLE wallet_transfer
|
ALTER TABLE wallet_transfer
|
||||||
ADD CONSTRAINT fk_wallet_transfer_receiver_wallet FOREIGN KEY (receiver_wallet_id) REFERENCES wallets(id),
|
ADD CONSTRAINT fk_wallet_transfer_receiver_wallet FOREIGN KEY (receiver_wallet_id) REFERENCES wallets(id),
|
||||||
ADD CONSTRAINT fk_wallet_transfer_sender_wallet FOREIGN KEY (sender_wallet_id) REFERENCES wallets(id),
|
ADD CONSTRAINT fk_wallet_transfer_sender_wallet FOREIGN KEY (sender_wallet_id) REFERENCES wallets(id),
|
||||||
ADD CONSTRAINT fk_wallet_transfer_cashier FOREIGN KEY (cashier_id) REFERENCES users(id);
|
ADD CONSTRAINT fk_wallet_transfer_cashier FOREIGN KEY (cashier_id) REFERENCES users(id);
|
||||||
ALTER TABLE transactions
|
ALTER TABLE transactions
|
||||||
ADD CONSTRAINT fk_transactions_branches FOREIGN KEY (branch_id) REFERENCES branches(id),
|
ADD CONSTRAINT fk_transactions_branches FOREIGN KEY (branch_id) REFERENCES branches(id),
|
||||||
ADD CONSTRAINT fk_transactions_cashiers FOREIGN KEY (cashier_id) REFERENCES users(id),
|
ADD CONSTRAINT fk_transactions_cashiers FOREIGN KEY (cashier_id) REFERENCES users(id),
|
||||||
ADD CONSTRAINT fk_transactions_bets FOREIGN KEY (bet_id) REFERENCES bets(id);
|
ADD CONSTRAINT fk_transactions_bets FOREIGN KEY (bet_id) REFERENCES bets(id);
|
||||||
ALTER TABLE branches
|
ALTER TABLE branches
|
||||||
ADD CONSTRAINT fk_branches_wallet FOREIGN KEY (wallet_id) REFERENCES wallets(id),
|
ADD CONSTRAINT fk_branches_wallet FOREIGN KEY (wallet_id) REFERENCES wallets(id),
|
||||||
ADD CONSTRAINT fk_branches_manager FOREIGN KEY (branch_manager_id) REFERENCES users(id);
|
ADD CONSTRAINT fk_branches_manager FOREIGN KEY (branch_manager_id) REFERENCES users(id);
|
||||||
ALTER TABLE branch_operations
|
ALTER TABLE branch_operations
|
||||||
ADD CONSTRAINT fk_branch_operations_operations FOREIGN KEY (operation_id) REFERENCES supported_operations(id) ON DELETE CASCADE,
|
ADD CONSTRAINT fk_branch_operations_operations FOREIGN KEY (operation_id) REFERENCES supported_operations(id) ON DELETE CASCADE,
|
||||||
ADD CONSTRAINT fk_branch_operations_branches FOREIGN KEY (branch_id) REFERENCES branches(id) ON DELETE CASCADE;
|
ADD CONSTRAINT fk_branch_operations_branches FOREIGN KEY (branch_id) REFERENCES branches(id) ON DELETE CASCADE;
|
||||||
ALTER TABLE branch_cashiers
|
ALTER TABLE branch_cashiers
|
||||||
ADD CONSTRAINT fk_branch_cashiers_users FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
ADD CONSTRAINT fk_branch_cashiers_users FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||||
ADD CONSTRAINT fk_branch_cashiers_branches FOREIGN KEY (branch_id) REFERENCES branches(id) ON DELETE CASCADE;
|
ADD CONSTRAINT fk_branch_cashiers_branches FOREIGN KEY (branch_id) REFERENCES branches(id) ON DELETE CASCADE;
|
||||||
|
|
||||||
ALTER TABLE companies
|
ALTER TABLE companies
|
||||||
ADD CONSTRAINT fk_companies_admin FOREIGN KEY (admin_id) REFERENCES users(id),
|
ADD CONSTRAINT fk_companies_admin FOREIGN KEY (admin_id) REFERENCES users(id),
|
||||||
ADD CONSTRAINT fk_companies_wallet FOREIGN KEY (wallet_id) REFERENCES wallets(id) ON DELETE CASCADE;
|
ADD CONSTRAINT fk_companies_wallet FOREIGN KEY (wallet_id) REFERENCES wallets(id) ON DELETE CASCADE;
|
||||||
----------------------------------------------seed data-------------------------------------------------------------
|
----------------------------------------------seed data-------------------------------------------------------------
|
||||||
-------------------------------------- DO NOT USE IN PRODUCTION-------------------------------------------------
|
-------------------------------------- DO NOT USE IN PRODUCTION-------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ CREATE TABLE IF NOT EXISTS wallet_threshold_notifications (
|
||||||
PRIMARY KEY (company_id, threshold)
|
PRIMARY KEY (company_id, threshold)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_wallet_threshold_notifications_company ON wallet_threshold_notifications(company_id)
|
CREATE INDEX idx_wallet_threshold_notifications_company ON wallet_threshold_notifications(company_id);
|
||||||
|
|
||||||
CREATE INDEX idx_notifications_recipient_id ON notifications (recipient_id);
|
CREATE INDEX idx_notifications_recipient_id ON notifications (recipient_id);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
-- name: GetAllCompanies :many
|
-- name: GetAllCompaniesBranch :many
|
||||||
SELECT id, name, wallet_id, admin_id, created_at
|
SELECT id, name, wallet_id, admin_id
|
||||||
FROM companies;
|
FROM companies;
|
||||||
|
|
||||||
-- name: GetBranchesByCompanyID :many
|
-- name: GetBranchesByCompanyID :many
|
||||||
|
|
|
||||||
|
|
@ -12,21 +12,11 @@ INSERT INTO users (
|
||||||
updated_at,
|
updated_at,
|
||||||
suspended,
|
suspended,
|
||||||
company_id
|
company_id
|
||||||
)
|
)
|
||||||
VALUES (
|
VALUES (
|
||||||
$1,
|
$1, $2, $3, $4, $5, $6,
|
||||||
$2,
|
$7, $8, $9, $10, $11, $12
|
||||||
$3,
|
)
|
||||||
$4,
|
|
||||||
$5,
|
|
||||||
$6,
|
|
||||||
$7,
|
|
||||||
$8,
|
|
||||||
$9,
|
|
||||||
$10,
|
|
||||||
$11,
|
|
||||||
$12
|
|
||||||
)
|
|
||||||
RETURNING id,
|
RETURNING id,
|
||||||
first_name,
|
first_name,
|
||||||
last_name,
|
last_name,
|
||||||
|
|
@ -39,6 +29,7 @@ RETURNING id,
|
||||||
updated_at,
|
updated_at,
|
||||||
suspended,
|
suspended,
|
||||||
company_id;
|
company_id;
|
||||||
|
|
||||||
-- name: GetUserByID :one
|
-- name: GetUserByID :one
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM users
|
FROM users
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ INSERT INTO branches (
|
||||||
is_self_owned
|
is_self_owned
|
||||||
)
|
)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6)
|
VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
RETURNING id, name, location, wallet_id, branch_manager_id, company_id, is_self_owned, created_at, updated_at
|
RETURNING id, name, location, is_active, wallet_id, branch_manager_id, company_id, is_self_owned, created_at, updated_at
|
||||||
`
|
`
|
||||||
|
|
||||||
type CreateBranchParams struct {
|
type CreateBranchParams struct {
|
||||||
|
|
@ -47,6 +47,7 @@ func (q *Queries) CreateBranch(ctx context.Context, arg CreateBranchParams) (Bra
|
||||||
&i.ID,
|
&i.ID,
|
||||||
&i.Name,
|
&i.Name,
|
||||||
&i.Location,
|
&i.Location,
|
||||||
|
&i.IsActive,
|
||||||
&i.WalletID,
|
&i.WalletID,
|
||||||
&i.BranchManagerID,
|
&i.BranchManagerID,
|
||||||
&i.CompanyID,
|
&i.CompanyID,
|
||||||
|
|
@ -154,7 +155,7 @@ func (q *Queries) DeleteBranchOperation(ctx context.Context, arg DeleteBranchOpe
|
||||||
}
|
}
|
||||||
|
|
||||||
const GetAllBranches = `-- name: GetAllBranches :many
|
const GetAllBranches = `-- name: GetAllBranches :many
|
||||||
SELECT id, name, location, wallet_id, branch_manager_id, company_id, is_self_owned, created_at, updated_at, manager_name, manager_phone_number
|
SELECT id, name, location, is_active, wallet_id, branch_manager_id, company_id, is_self_owned, created_at, updated_at, manager_name, manager_phone_number
|
||||||
FROM branch_details
|
FROM branch_details
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|
@ -171,6 +172,7 @@ func (q *Queries) GetAllBranches(ctx context.Context) ([]BranchDetail, error) {
|
||||||
&i.ID,
|
&i.ID,
|
||||||
&i.Name,
|
&i.Name,
|
||||||
&i.Location,
|
&i.Location,
|
||||||
|
&i.IsActive,
|
||||||
&i.WalletID,
|
&i.WalletID,
|
||||||
&i.BranchManagerID,
|
&i.BranchManagerID,
|
||||||
&i.CompanyID,
|
&i.CompanyID,
|
||||||
|
|
@ -216,7 +218,7 @@ func (q *Queries) GetAllSupportedOperations(ctx context.Context) ([]SupportedOpe
|
||||||
}
|
}
|
||||||
|
|
||||||
const GetBranchByCashier = `-- name: GetBranchByCashier :one
|
const GetBranchByCashier = `-- name: GetBranchByCashier :one
|
||||||
SELECT branches.id, branches.name, branches.location, branches.wallet_id, branches.branch_manager_id, branches.company_id, branches.is_self_owned, branches.created_at, branches.updated_at
|
SELECT branches.id, branches.name, branches.location, branches.is_active, branches.wallet_id, branches.branch_manager_id, branches.company_id, branches.is_self_owned, branches.created_at, branches.updated_at
|
||||||
FROM branch_cashiers
|
FROM branch_cashiers
|
||||||
JOIN branches ON branch_cashiers.branch_id = branches.id
|
JOIN branches ON branch_cashiers.branch_id = branches.id
|
||||||
WHERE branch_cashiers.user_id = $1
|
WHERE branch_cashiers.user_id = $1
|
||||||
|
|
@ -229,6 +231,7 @@ func (q *Queries) GetBranchByCashier(ctx context.Context, userID int64) (Branch,
|
||||||
&i.ID,
|
&i.ID,
|
||||||
&i.Name,
|
&i.Name,
|
||||||
&i.Location,
|
&i.Location,
|
||||||
|
&i.IsActive,
|
||||||
&i.WalletID,
|
&i.WalletID,
|
||||||
&i.BranchManagerID,
|
&i.BranchManagerID,
|
||||||
&i.CompanyID,
|
&i.CompanyID,
|
||||||
|
|
@ -240,7 +243,7 @@ func (q *Queries) GetBranchByCashier(ctx context.Context, userID int64) (Branch,
|
||||||
}
|
}
|
||||||
|
|
||||||
const GetBranchByCompanyID = `-- name: GetBranchByCompanyID :many
|
const GetBranchByCompanyID = `-- name: GetBranchByCompanyID :many
|
||||||
SELECT id, name, location, wallet_id, branch_manager_id, company_id, is_self_owned, created_at, updated_at, manager_name, manager_phone_number
|
SELECT id, name, location, is_active, wallet_id, branch_manager_id, company_id, is_self_owned, created_at, updated_at, manager_name, manager_phone_number
|
||||||
FROM branch_details
|
FROM branch_details
|
||||||
WHERE company_id = $1
|
WHERE company_id = $1
|
||||||
`
|
`
|
||||||
|
|
@ -258,6 +261,7 @@ func (q *Queries) GetBranchByCompanyID(ctx context.Context, companyID int64) ([]
|
||||||
&i.ID,
|
&i.ID,
|
||||||
&i.Name,
|
&i.Name,
|
||||||
&i.Location,
|
&i.Location,
|
||||||
|
&i.IsActive,
|
||||||
&i.WalletID,
|
&i.WalletID,
|
||||||
&i.BranchManagerID,
|
&i.BranchManagerID,
|
||||||
&i.CompanyID,
|
&i.CompanyID,
|
||||||
|
|
@ -278,7 +282,7 @@ func (q *Queries) GetBranchByCompanyID(ctx context.Context, companyID int64) ([]
|
||||||
}
|
}
|
||||||
|
|
||||||
const GetBranchByID = `-- name: GetBranchByID :one
|
const GetBranchByID = `-- name: GetBranchByID :one
|
||||||
SELECT id, name, location, wallet_id, branch_manager_id, company_id, is_self_owned, created_at, updated_at, manager_name, manager_phone_number
|
SELECT id, name, location, is_active, wallet_id, branch_manager_id, company_id, is_self_owned, created_at, updated_at, manager_name, manager_phone_number
|
||||||
FROM branch_details
|
FROM branch_details
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`
|
`
|
||||||
|
|
@ -290,6 +294,7 @@ func (q *Queries) GetBranchByID(ctx context.Context, id int64) (BranchDetail, er
|
||||||
&i.ID,
|
&i.ID,
|
||||||
&i.Name,
|
&i.Name,
|
||||||
&i.Location,
|
&i.Location,
|
||||||
|
&i.IsActive,
|
||||||
&i.WalletID,
|
&i.WalletID,
|
||||||
&i.BranchManagerID,
|
&i.BranchManagerID,
|
||||||
&i.CompanyID,
|
&i.CompanyID,
|
||||||
|
|
@ -303,7 +308,7 @@ func (q *Queries) GetBranchByID(ctx context.Context, id int64) (BranchDetail, er
|
||||||
}
|
}
|
||||||
|
|
||||||
const GetBranchByManagerID = `-- name: GetBranchByManagerID :many
|
const GetBranchByManagerID = `-- name: GetBranchByManagerID :many
|
||||||
SELECT id, name, location, wallet_id, branch_manager_id, company_id, is_self_owned, created_at, updated_at, manager_name, manager_phone_number
|
SELECT id, name, location, is_active, wallet_id, branch_manager_id, company_id, is_self_owned, created_at, updated_at, manager_name, manager_phone_number
|
||||||
FROM branch_details
|
FROM branch_details
|
||||||
WHERE branch_manager_id = $1
|
WHERE branch_manager_id = $1
|
||||||
`
|
`
|
||||||
|
|
@ -321,6 +326,7 @@ func (q *Queries) GetBranchByManagerID(ctx context.Context, branchManagerID int6
|
||||||
&i.ID,
|
&i.ID,
|
||||||
&i.Name,
|
&i.Name,
|
||||||
&i.Location,
|
&i.Location,
|
||||||
|
&i.IsActive,
|
||||||
&i.WalletID,
|
&i.WalletID,
|
||||||
&i.BranchManagerID,
|
&i.BranchManagerID,
|
||||||
&i.CompanyID,
|
&i.CompanyID,
|
||||||
|
|
@ -388,7 +394,7 @@ func (q *Queries) GetBranchOperations(ctx context.Context, branchID int64) ([]Ge
|
||||||
}
|
}
|
||||||
|
|
||||||
const SearchBranchByName = `-- name: SearchBranchByName :many
|
const SearchBranchByName = `-- name: SearchBranchByName :many
|
||||||
SELECT id, name, location, wallet_id, branch_manager_id, company_id, is_self_owned, created_at, updated_at, manager_name, manager_phone_number
|
SELECT id, name, location, is_active, wallet_id, branch_manager_id, company_id, is_self_owned, created_at, updated_at, manager_name, manager_phone_number
|
||||||
FROM branch_details
|
FROM branch_details
|
||||||
WHERE name ILIKE '%' || $1 || '%'
|
WHERE name ILIKE '%' || $1 || '%'
|
||||||
`
|
`
|
||||||
|
|
@ -406,6 +412,7 @@ func (q *Queries) SearchBranchByName(ctx context.Context, dollar_1 pgtype.Text)
|
||||||
&i.ID,
|
&i.ID,
|
||||||
&i.Name,
|
&i.Name,
|
||||||
&i.Location,
|
&i.Location,
|
||||||
|
&i.IsActive,
|
||||||
&i.WalletID,
|
&i.WalletID,
|
||||||
&i.BranchManagerID,
|
&i.BranchManagerID,
|
||||||
&i.CompanyID,
|
&i.CompanyID,
|
||||||
|
|
@ -433,7 +440,7 @@ SET name = COALESCE($2, name),
|
||||||
company_id = COALESCE($5, company_id),
|
company_id = COALESCE($5, company_id),
|
||||||
is_self_owned = COALESCE($6, is_self_owned)
|
is_self_owned = COALESCE($6, is_self_owned)
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
RETURNING id, name, location, wallet_id, branch_manager_id, company_id, is_self_owned, created_at, updated_at
|
RETURNING id, name, location, is_active, wallet_id, branch_manager_id, company_id, is_self_owned, created_at, updated_at
|
||||||
`
|
`
|
||||||
|
|
||||||
type UpdateBranchParams struct {
|
type UpdateBranchParams struct {
|
||||||
|
|
@ -459,6 +466,7 @@ func (q *Queries) UpdateBranch(ctx context.Context, arg UpdateBranchParams) (Bra
|
||||||
&i.ID,
|
&i.ID,
|
||||||
&i.Name,
|
&i.Name,
|
||||||
&i.Location,
|
&i.Location,
|
||||||
|
&i.IsActive,
|
||||||
&i.WalletID,
|
&i.WalletID,
|
||||||
&i.BranchManagerID,
|
&i.BranchManagerID,
|
||||||
&i.CompanyID,
|
&i.CompanyID,
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,7 @@ type Branch struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Location string `json:"location"`
|
Location string `json:"location"`
|
||||||
|
IsActive bool `json:"is_active"`
|
||||||
WalletID int64 `json:"wallet_id"`
|
WalletID int64 `json:"wallet_id"`
|
||||||
BranchManagerID int64 `json:"branch_manager_id"`
|
BranchManagerID int64 `json:"branch_manager_id"`
|
||||||
CompanyID int64 `json:"company_id"`
|
CompanyID int64 `json:"company_id"`
|
||||||
|
|
@ -130,6 +131,7 @@ type BranchDetail struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Location string `json:"location"`
|
Location string `json:"location"`
|
||||||
|
IsActive bool `json:"is_active"`
|
||||||
WalletID int64 `json:"wallet_id"`
|
WalletID int64 `json:"wallet_id"`
|
||||||
BranchManagerID int64 `json:"branch_manager_id"`
|
BranchManagerID int64 `json:"branch_manager_id"`
|
||||||
CompanyID int64 `json:"company_id"`
|
CompanyID int64 `json:"company_id"`
|
||||||
|
|
@ -313,6 +315,14 @@ type SupportedOperation struct {
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Team struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
TeamName string `json:"team_name"`
|
||||||
|
Country pgtype.Text `json:"country"`
|
||||||
|
Bet365ID pgtype.Int4 `json:"bet365_id"`
|
||||||
|
LogoUrl pgtype.Text `json:"logo_url"`
|
||||||
|
}
|
||||||
|
|
||||||
type Ticket struct {
|
type Ticket struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Amount int64 `json:"amount"`
|
Amount int64 `json:"amount"`
|
||||||
|
|
@ -351,25 +361,25 @@ type Transaction struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Amount int64 `json:"amount"`
|
Amount int64 `json:"amount"`
|
||||||
BranchID int64 `json:"branch_id"`
|
BranchID int64 `json:"branch_id"`
|
||||||
CompanyID int64 `json:"company_id"`
|
CompanyID pgtype.Int8 `json:"company_id"`
|
||||||
CashierID int64 `json:"cashier_id"`
|
CashierID pgtype.Int8 `json:"cashier_id"`
|
||||||
CashierName string `json:"cashier_name"`
|
CashierName pgtype.Text `json:"cashier_name"`
|
||||||
BetID int64 `json:"bet_id"`
|
BetID pgtype.Int8 `json:"bet_id"`
|
||||||
NumberOfOutcomes int64 `json:"number_of_outcomes"`
|
NumberOfOutcomes pgtype.Int8 `json:"number_of_outcomes"`
|
||||||
Type int64 `json:"type"`
|
Type pgtype.Int8 `json:"type"`
|
||||||
PaymentOption int64 `json:"payment_option"`
|
PaymentOption pgtype.Int8 `json:"payment_option"`
|
||||||
FullName string `json:"full_name"`
|
FullName pgtype.Text `json:"full_name"`
|
||||||
PhoneNumber string `json:"phone_number"`
|
PhoneNumber pgtype.Text `json:"phone_number"`
|
||||||
BankCode string `json:"bank_code"`
|
BankCode pgtype.Text `json:"bank_code"`
|
||||||
BeneficiaryName string `json:"beneficiary_name"`
|
BeneficiaryName pgtype.Text `json:"beneficiary_name"`
|
||||||
AccountName string `json:"account_name"`
|
AccountName pgtype.Text `json:"account_name"`
|
||||||
AccountNumber string `json:"account_number"`
|
AccountNumber pgtype.Text `json:"account_number"`
|
||||||
ReferenceNumber string `json:"reference_number"`
|
ReferenceNumber pgtype.Text `json:"reference_number"`
|
||||||
Verified bool `json:"verified"`
|
Verified bool `json:"verified"`
|
||||||
ApprovedBy pgtype.Int8 `json:"approved_by"`
|
ApprovedBy pgtype.Int8 `json:"approved_by"`
|
||||||
ApproverName pgtype.Text `json:"approver_name"`
|
ApproverName pgtype.Text `json:"approver_name"`
|
||||||
BranchLocation string `json:"branch_location"`
|
BranchLocation pgtype.Text `json:"branch_location"`
|
||||||
BranchName string `json:"branch_name"`
|
BranchName pgtype.Text `json:"branch_name"`
|
||||||
CreatedAt pgtype.Timestamp `json:"created_at"`
|
CreatedAt pgtype.Timestamp `json:"created_at"`
|
||||||
UpdatedAt pgtype.Timestamp `json:"updated_at"`
|
UpdatedAt pgtype.Timestamp `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
@ -459,6 +469,12 @@ type Wallet struct {
|
||||||
CashBalance pgtype.Numeric `json:"cash_balance"`
|
CashBalance pgtype.Numeric `json:"cash_balance"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type WalletThresholdNotification struct {
|
||||||
|
CompanyID int64 `json:"company_id"`
|
||||||
|
Threshold float64 `json:"threshold"`
|
||||||
|
NotifiedAt pgtype.Timestamptz `json:"notified_at"`
|
||||||
|
}
|
||||||
|
|
||||||
type WalletTransfer struct {
|
type WalletTransfer struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Amount int64 `json:"amount"`
|
Amount int64 `json:"amount"`
|
||||||
|
|
|
||||||
131
gen/db/monitor.sql.go
Normal file
131
gen/db/monitor.sql.go
Normal file
|
|
@ -0,0 +1,131 @@
|
||||||
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// sqlc v1.29.0
|
||||||
|
// source: monitor.sql
|
||||||
|
|
||||||
|
package dbgen
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
const CountThresholdNotifications = `-- name: CountThresholdNotifications :one
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM wallet_threshold_notifications
|
||||||
|
WHERE company_id = $1 AND threshold = $2
|
||||||
|
`
|
||||||
|
|
||||||
|
type CountThresholdNotificationsParams struct {
|
||||||
|
CompanyID int64 `json:"company_id"`
|
||||||
|
Threshold float64 `json:"threshold"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CountThresholdNotifications(ctx context.Context, arg CountThresholdNotificationsParams) (int64, error) {
|
||||||
|
row := q.db.QueryRow(ctx, CountThresholdNotifications, arg.CompanyID, arg.Threshold)
|
||||||
|
var count int64
|
||||||
|
err := row.Scan(&count)
|
||||||
|
return count, err
|
||||||
|
}
|
||||||
|
|
||||||
|
const CreateThresholdNotification = `-- name: CreateThresholdNotification :exec
|
||||||
|
INSERT INTO wallet_threshold_notifications (company_id, threshold)
|
||||||
|
VALUES ($1, $2)
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateThresholdNotificationParams struct {
|
||||||
|
CompanyID int64 `json:"company_id"`
|
||||||
|
Threshold float64 `json:"threshold"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateThresholdNotification(ctx context.Context, arg CreateThresholdNotificationParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, CreateThresholdNotification, arg.CompanyID, arg.Threshold)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const GetAllCompaniesBranch = `-- name: GetAllCompaniesBranch :many
|
||||||
|
SELECT id, name, wallet_id, admin_id
|
||||||
|
FROM companies
|
||||||
|
`
|
||||||
|
|
||||||
|
type GetAllCompaniesBranchRow struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
WalletID int64 `json:"wallet_id"`
|
||||||
|
AdminID int64 `json:"admin_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) GetAllCompaniesBranch(ctx context.Context) ([]GetAllCompaniesBranchRow, error) {
|
||||||
|
rows, err := q.db.Query(ctx, GetAllCompaniesBranch)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []GetAllCompaniesBranchRow
|
||||||
|
for rows.Next() {
|
||||||
|
var i GetAllCompaniesBranchRow
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.Name,
|
||||||
|
&i.WalletID,
|
||||||
|
&i.AdminID,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
const GetBranchesByCompanyID = `-- name: GetBranchesByCompanyID :many
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
location,
|
||||||
|
wallet_id,
|
||||||
|
branch_manager_id,
|
||||||
|
company_id,
|
||||||
|
is_self_owned
|
||||||
|
FROM branches
|
||||||
|
WHERE company_id = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
type GetBranchesByCompanyIDRow struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Location string `json:"location"`
|
||||||
|
WalletID int64 `json:"wallet_id"`
|
||||||
|
BranchManagerID int64 `json:"branch_manager_id"`
|
||||||
|
CompanyID int64 `json:"company_id"`
|
||||||
|
IsSelfOwned bool `json:"is_self_owned"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) GetBranchesByCompanyID(ctx context.Context, companyID int64) ([]GetBranchesByCompanyIDRow, error) {
|
||||||
|
rows, err := q.db.Query(ctx, GetBranchesByCompanyID, companyID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []GetBranchesByCompanyIDRow
|
||||||
|
for rows.Next() {
|
||||||
|
var i GetBranchesByCompanyIDRow
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.Name,
|
||||||
|
&i.Location,
|
||||||
|
&i.WalletID,
|
||||||
|
&i.BranchManagerID,
|
||||||
|
&i.CompanyID,
|
||||||
|
&i.IsSelfOwned,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
@ -58,22 +58,22 @@ RETURNING id, amount, branch_id, company_id, cashier_id, cashier_name, bet_id, n
|
||||||
type CreateTransactionParams struct {
|
type CreateTransactionParams struct {
|
||||||
Amount int64 `json:"amount"`
|
Amount int64 `json:"amount"`
|
||||||
BranchID int64 `json:"branch_id"`
|
BranchID int64 `json:"branch_id"`
|
||||||
CashierID int64 `json:"cashier_id"`
|
CashierID pgtype.Int8 `json:"cashier_id"`
|
||||||
BetID int64 `json:"bet_id"`
|
BetID pgtype.Int8 `json:"bet_id"`
|
||||||
Type int64 `json:"type"`
|
Type pgtype.Int8 `json:"type"`
|
||||||
PaymentOption int64 `json:"payment_option"`
|
PaymentOption pgtype.Int8 `json:"payment_option"`
|
||||||
FullName string `json:"full_name"`
|
FullName pgtype.Text `json:"full_name"`
|
||||||
PhoneNumber string `json:"phone_number"`
|
PhoneNumber pgtype.Text `json:"phone_number"`
|
||||||
BankCode string `json:"bank_code"`
|
BankCode pgtype.Text `json:"bank_code"`
|
||||||
BeneficiaryName string `json:"beneficiary_name"`
|
BeneficiaryName pgtype.Text `json:"beneficiary_name"`
|
||||||
AccountName string `json:"account_name"`
|
AccountName pgtype.Text `json:"account_name"`
|
||||||
AccountNumber string `json:"account_number"`
|
AccountNumber pgtype.Text `json:"account_number"`
|
||||||
ReferenceNumber string `json:"reference_number"`
|
ReferenceNumber pgtype.Text `json:"reference_number"`
|
||||||
NumberOfOutcomes int64 `json:"number_of_outcomes"`
|
NumberOfOutcomes pgtype.Int8 `json:"number_of_outcomes"`
|
||||||
BranchName string `json:"branch_name"`
|
BranchName pgtype.Text `json:"branch_name"`
|
||||||
BranchLocation string `json:"branch_location"`
|
BranchLocation pgtype.Text `json:"branch_location"`
|
||||||
CompanyID int64 `json:"company_id"`
|
CompanyID pgtype.Int8 `json:"company_id"`
|
||||||
CashierName string `json:"cashier_name"`
|
CashierName pgtype.Text `json:"cashier_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionParams) (Transaction, error) {
|
func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionParams) (Transaction, error) {
|
||||||
|
|
|
||||||
|
|
@ -57,21 +57,11 @@ INSERT INTO users (
|
||||||
updated_at,
|
updated_at,
|
||||||
suspended,
|
suspended,
|
||||||
company_id
|
company_id
|
||||||
)
|
)
|
||||||
VALUES (
|
VALUES (
|
||||||
$1,
|
$1, $2, $3, $4, $5, $6,
|
||||||
$2,
|
$7, $8, $9, $10, $11, $12
|
||||||
$3,
|
)
|
||||||
$4,
|
|
||||||
$5,
|
|
||||||
$6,
|
|
||||||
$7,
|
|
||||||
$8,
|
|
||||||
$9,
|
|
||||||
$10,
|
|
||||||
$11,
|
|
||||||
$12
|
|
||||||
)
|
|
||||||
RETURNING id,
|
RETURNING id,
|
||||||
first_name,
|
first_name,
|
||||||
last_name,
|
last_name,
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ type Branch struct {
|
||||||
WalletID int64
|
WalletID int64
|
||||||
BranchManagerID int64
|
BranchManagerID int64
|
||||||
CompanyID int64
|
CompanyID int64
|
||||||
|
IsSuspended bool
|
||||||
IsSelfOwned bool
|
IsSelfOwned bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -17,6 +18,7 @@ type BranchDetail struct {
|
||||||
WalletID int64
|
WalletID int64
|
||||||
BranchManagerID int64
|
BranchManagerID int64
|
||||||
CompanyID int64
|
CompanyID int64
|
||||||
|
IsSuspended bool
|
||||||
IsSelfOwned bool
|
IsSelfOwned bool
|
||||||
ManagerName string
|
ManagerName string
|
||||||
ManagerPhoneNumber string
|
ManagerPhoneNumber string
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ type User struct {
|
||||||
ID int64
|
ID int64
|
||||||
FirstName string
|
FirstName string
|
||||||
LastName string
|
LastName string
|
||||||
Email string
|
Email string `json:"email"`
|
||||||
PhoneNumber string
|
PhoneNumber string `json:"phone_number"`
|
||||||
Password []byte
|
Password []byte
|
||||||
Role Role
|
Role Role
|
||||||
//
|
//
|
||||||
|
|
@ -29,6 +29,7 @@ type User struct {
|
||||||
//
|
//
|
||||||
CompanyID ValidInt64
|
CompanyID ValidInt64
|
||||||
}
|
}
|
||||||
|
|
||||||
type RegisterUserReq struct {
|
type RegisterUserReq struct {
|
||||||
FirstName string
|
FirstName string
|
||||||
LastName string
|
LastName string
|
||||||
|
|
@ -62,6 +63,7 @@ type UpdateUserReq struct {
|
||||||
FirstName ValidString
|
FirstName ValidString
|
||||||
LastName ValidString
|
LastName ValidString
|
||||||
Suspended ValidBool
|
Suspended ValidBool
|
||||||
|
|
||||||
CompanyID ValidInt64
|
CompanyID ValidInt64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,18 +14,18 @@ func convertDBTransaction(transaction dbgen.Transaction) domain.Transaction {
|
||||||
ID: transaction.ID,
|
ID: transaction.ID,
|
||||||
Amount: domain.Currency(transaction.Amount),
|
Amount: domain.Currency(transaction.Amount),
|
||||||
BranchID: transaction.BranchID,
|
BranchID: transaction.BranchID,
|
||||||
CashierID: transaction.CashierID,
|
CashierID: transaction.CashierID.Int64,
|
||||||
BetID: transaction.BetID,
|
BetID: transaction.BetID.Int64,
|
||||||
NumberOfOutcomes: transaction.NumberOfOutcomes,
|
NumberOfOutcomes: transaction.NumberOfOutcomes.Int64,
|
||||||
Type: domain.TransactionType(transaction.Type),
|
Type: domain.TransactionType(transaction.Type.Int64),
|
||||||
PaymentOption: domain.PaymentOption(transaction.PaymentOption),
|
PaymentOption: domain.PaymentOption(transaction.PaymentOption.Int64),
|
||||||
FullName: transaction.FullName,
|
FullName: transaction.FullName.String,
|
||||||
PhoneNumber: transaction.PhoneNumber,
|
PhoneNumber: transaction.PhoneNumber.String,
|
||||||
BankCode: transaction.BankCode,
|
BankCode: transaction.BankCode.String,
|
||||||
BeneficiaryName: transaction.BeneficiaryName,
|
BeneficiaryName: transaction.BeneficiaryName.String,
|
||||||
AccountName: transaction.AccountName,
|
AccountName: transaction.AccountName.String,
|
||||||
AccountNumber: transaction.AccountNumber,
|
AccountNumber: transaction.AccountNumber.String,
|
||||||
ReferenceNumber: transaction.ReferenceNumber,
|
ReferenceNumber: transaction.ReferenceNumber.String,
|
||||||
ApprovedBy: domain.ValidInt64{
|
ApprovedBy: domain.ValidInt64{
|
||||||
Value: transaction.ApprovedBy.Int64,
|
Value: transaction.ApprovedBy.Int64,
|
||||||
Valid: transaction.ApprovedBy.Valid,
|
Valid: transaction.ApprovedBy.Valid,
|
||||||
|
|
@ -33,10 +33,10 @@ func convertDBTransaction(transaction dbgen.Transaction) domain.Transaction {
|
||||||
CreatedAt: transaction.CreatedAt.Time,
|
CreatedAt: transaction.CreatedAt.Time,
|
||||||
UpdatedAt: transaction.UpdatedAt.Time,
|
UpdatedAt: transaction.UpdatedAt.Time,
|
||||||
Verified: transaction.Verified,
|
Verified: transaction.Verified,
|
||||||
BranchName: transaction.BranchName,
|
BranchName: transaction.BranchName.String,
|
||||||
BranchLocation: transaction.BranchLocation,
|
BranchLocation: transaction.BranchLocation.String,
|
||||||
CashierName: transaction.CashierName,
|
CashierName: transaction.CashierName.String,
|
||||||
CompanyID: transaction.CompanyID,
|
CompanyID: transaction.CompanyID.Int64,
|
||||||
ApproverName: domain.ValidString{
|
ApproverName: domain.ValidString{
|
||||||
Value: transaction.ApproverName.String,
|
Value: transaction.ApproverName.String,
|
||||||
Valid: transaction.ApprovedBy.Valid,
|
Valid: transaction.ApprovedBy.Valid,
|
||||||
|
|
@ -48,22 +48,22 @@ func convertCreateTransaction(transaction domain.CreateTransaction) dbgen.Create
|
||||||
return dbgen.CreateTransactionParams{
|
return dbgen.CreateTransactionParams{
|
||||||
Amount: int64(transaction.Amount),
|
Amount: int64(transaction.Amount),
|
||||||
BranchID: transaction.BranchID,
|
BranchID: transaction.BranchID,
|
||||||
CashierID: transaction.CashierID,
|
CashierID: pgtype.Int8{Int64: transaction.CashierID, Valid: true},
|
||||||
BetID: transaction.BetID,
|
BetID: pgtype.Int8{Int64: transaction.BetID, Valid: true},
|
||||||
Type: int64(transaction.Type),
|
Type: pgtype.Int8{Int64: int64(transaction.Type), Valid: true},
|
||||||
PaymentOption: int64(transaction.PaymentOption),
|
PaymentOption: pgtype.Int8{Int64: int64(transaction.PaymentOption), Valid: true},
|
||||||
FullName: transaction.FullName,
|
FullName: pgtype.Text{String: transaction.FullName, Valid: transaction.FullName != ""},
|
||||||
PhoneNumber: transaction.PhoneNumber,
|
PhoneNumber: pgtype.Text{String: transaction.PhoneNumber, Valid: transaction.PhoneNumber != ""},
|
||||||
BankCode: transaction.BankCode,
|
BankCode: pgtype.Text{String: transaction.BankCode, Valid: transaction.BankCode != ""},
|
||||||
BeneficiaryName: transaction.BeneficiaryName,
|
BeneficiaryName: pgtype.Text{String: transaction.BeneficiaryName, Valid: transaction.BeneficiaryName != ""},
|
||||||
AccountName: transaction.AccountName,
|
AccountName: pgtype.Text{String: transaction.AccountName, Valid: transaction.AccountName != ""},
|
||||||
AccountNumber: transaction.AccountNumber,
|
AccountNumber: pgtype.Text{String: transaction.AccountNumber, Valid: transaction.AccountNumber != ""},
|
||||||
ReferenceNumber: transaction.ReferenceNumber,
|
ReferenceNumber: pgtype.Text{String: transaction.ReferenceNumber, Valid: transaction.ReferenceNumber != ""},
|
||||||
NumberOfOutcomes: transaction.NumberOfOutcomes,
|
NumberOfOutcomes: pgtype.Int8{Int64: transaction.NumberOfOutcomes, Valid: true},
|
||||||
BranchName: transaction.BranchName,
|
BranchName: pgtype.Text{String: transaction.BranchName, Valid: transaction.BranchName != ""},
|
||||||
BranchLocation: transaction.BranchLocation,
|
BranchLocation: pgtype.Text{String: transaction.BranchLocation, Valid: transaction.BranchLocation != ""},
|
||||||
CashierName: transaction.CashierName,
|
CashierName: pgtype.Text{String: transaction.CashierName, Valid: transaction.CashierName != ""},
|
||||||
CompanyID: transaction.CompanyID,
|
CompanyID: pgtype.Int8{Int64: transaction.CompanyID, Valid: true},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,13 @@ func (s *Service) RefillWallet(ctx context.Context, transfer domain.CreateTransf
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to receiver
|
// Add to receiver
|
||||||
|
senderWallet, err := s.GetWalletByID(ctx, transfer.SenderWalletID.Value)
|
||||||
|
if err != nil {
|
||||||
|
return domain.Transfer{}, err
|
||||||
|
} else if senderWallet.Balance < transfer.Amount {
|
||||||
|
return domain.Transfer{}, ErrInsufficientBalance
|
||||||
|
}
|
||||||
|
|
||||||
err = s.walletStore.UpdateBalance(ctx, receiverWallet.ID, receiverWallet.Balance+transfer.Amount)
|
err = s.walletStore.UpdateBalance(ctx, receiverWallet.ID, receiverWallet.Balance+transfer.Amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return domain.Transfer{}, err
|
return domain.Transfer{}, err
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ func GetLogsHandler(appCtx context.Context) fiber.Handler {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, "Cursor decoding error: "+err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, "Cursor decoding error: "+err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return c.JSON(logs)
|
return c.JSON(logs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user