Yimaru-BackEnd/db/query/company.sql
Samuel Tariku c00110a503 feat: Enhance league, odds, events and bets functionality
- Updated league handling to ensure valid page size checks and improved error handling for sport ID parsing.
- Introduced new endpoint to update global league settings with comprehensive validation and error logging.
- Refactored odds settings management, including saving, removing, and updating odds settings with enhanced validation.
- Added tenant slug retrieval by token, ensuring proper user and company validation.
- Improved middleware to check for active company status and adjusted route permissions for various endpoints.
- Added SQL script to fix auto-increment desynchronization across multiple tables.
2025-10-05 23:45:31 +03:00

55 lines
1.4 KiB
SQL

-- name: CreateCompany :one
INSERT INTO companies (
name,
slug,
admin_id,
wallet_id,
deducted_percentage
)
VALUES ($1, $2, $3, $4, $5)
RETURNING *;
-- name: GetAllCompanies :many
SELECT *
FROM companies_details
WHERE (
name ILIKE '%' || sqlc.narg('query') || '%'
OR admin_first_name ILIKE '%' || sqlc.narg('query') || '%'
OR admin_last_name ILIKE '%' || sqlc.narg('query') || '%'
OR admin_phone_number ILIKE '%' || sqlc.narg('query') || '%'
OR sqlc.narg('query') IS NULL
)
AND (
created_at > sqlc.narg('created_before')
OR sqlc.narg('created_before') IS NULL
)
AND (
created_at < sqlc.narg('created_after')
OR sqlc.narg('created_after') IS NULL
);
-- name: GetCompanyByID :one
SELECT *
FROM companies_details
WHERE id = $1;
-- name: GetCompanyUsingSlug :one
SELECT *
FROM companies
WHERE slug = $1;
-- name: SearchCompanyByName :many
SELECT *
FROM companies_details
WHERE name ILIKE '%' || $1 || '%';
-- name: UpdateCompany :one
UPDATE companies
SET name = COALESCE(sqlc.narg(name), name),
admin_id = COALESCE(sqlc.narg(admin_id), admin_id),
is_active = COALESCE(sqlc.narg(is_active), is_active),
deducted_percentage = COALESCE(
sqlc.narg(deducted_percentage),
deducted_percentage
),
updated_at = CURRENT_TIMESTAMP
WHERE id = $1
RETURNING *;
-- name: DeleteCompany :exec
DELETE FROM companies
WHERE id = $1;