first commit
This commit is contained in:
commit
0bf8b29220
54
.cursor/rules/backend-documentation.mdc
Normal file
54
.cursor/rules/backend-documentation.mdc
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
---
|
||||||
|
description: Documentation standards for backend TypeScript code (JSDoc comments)
|
||||||
|
globs: backend/src/**/*.ts
|
||||||
|
alwaysApply: false
|
||||||
|
---
|
||||||
|
|
||||||
|
# Backend documentation conventions
|
||||||
|
|
||||||
|
Every new or modified backend file must include clear JSDoc comments so maintenance stays easy (Spring Boot–style readability).
|
||||||
|
|
||||||
|
## Required comments
|
||||||
|
|
||||||
|
1. **File / module** — One block at the top describing the layer and responsibility:
|
||||||
|
- `models/` → entity mapped to a DB table
|
||||||
|
- `dto/` → API/query projection (not a full entity)
|
||||||
|
- `repositories/` → data access (SQL)
|
||||||
|
- `services/` → business logic
|
||||||
|
- `controllers/` → HTTP handlers (thin; delegate to services)
|
||||||
|
- `middleware/` → Express pipeline hooks
|
||||||
|
|
||||||
|
## Layer dependencies (Spring Boot style)
|
||||||
|
|
||||||
|
- **Controller → Service only** — never import repositories or run SQL in controllers.
|
||||||
|
- **Service → Repository (+ other services when needed)** — business logic, decryption, orchestration.
|
||||||
|
- **Repository → Models / DTO row types** — SQL and data mapping only; no HTTP concerns.
|
||||||
|
- **Exceptions kept as-is** when justified: background jobs (`depositMonitorService`), `authService` reading `settingsRepository` directly for token policy, `middleware` calling `authService.verifyToken`.
|
||||||
|
|
||||||
|
2. **Every exported function** — JSDoc with:
|
||||||
|
- What it does (one sentence)
|
||||||
|
- `@param` for non-obvious parameters
|
||||||
|
- `@returns` when the return value is not obvious
|
||||||
|
- `@throws` when the function throws domain errors
|
||||||
|
|
||||||
|
3. **Non-exported helpers** — Comment when logic is non-obvious (crypto, blockchain, ledger locking, etc.).
|
||||||
|
|
||||||
|
4. **Interfaces / types in models & dto** — Brief description of what they represent and which table/view they map to.
|
||||||
|
|
||||||
|
## Style
|
||||||
|
|
||||||
|
- Write comments in **English** (matches existing codebase).
|
||||||
|
- Prefer **why** over **what** when the code is self-explanatory.
|
||||||
|
- Do not restate obvious one-liners (`return rows[0] || null` needs no comment).
|
||||||
|
- Keep comments up to date when changing behavior.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
/**
|
||||||
|
* Finds a user by email hash (used for login and uniqueness checks).
|
||||||
|
* @param emailHash SHA-256 hash of normalized email
|
||||||
|
* @returns User row or null if not found
|
||||||
|
*/
|
||||||
|
export async function findByEmailHash(emailHash: string): Promise<User | null> {
|
||||||
|
```
|
||||||
29
.cursor/rules/prediqo-mobile-documentation.mdc
Normal file
29
.cursor/rules/prediqo-mobile-documentation.mdc
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
description: Documentation standards for Flutter/Dart code in prediqo_mobile
|
||||||
|
globs: prediqo_mobile/lib/**/*.dart
|
||||||
|
alwaysApply: false
|
||||||
|
---
|
||||||
|
|
||||||
|
# Prediqo mobile documentation conventions
|
||||||
|
|
||||||
|
Apply clear Dart doc comments (`///`) for maintainability, aligned with backend/prediqo_web standards.
|
||||||
|
|
||||||
|
## Required comments
|
||||||
|
|
||||||
|
1. **File** — Library-level `///` block at top describing layer (presentation, bloc, repository, model, core).
|
||||||
|
2. **Classes & widgets** — `///` summary; document public constructors when not obvious.
|
||||||
|
3. **Public methods & functions** — `///` with purpose; mention side effects (API calls, navigation, state).
|
||||||
|
4. **Models & events/states** — Brief `///` on each class/field group when mapping to API or domain concepts.
|
||||||
|
|
||||||
|
## Style
|
||||||
|
|
||||||
|
- English comments.
|
||||||
|
- Use `///` (not block `/** */`) for Dart doc style.
|
||||||
|
- Skip trivial getters/setters unless behavior is non-obvious.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```dart
|
||||||
|
/// Loads the authenticated user's profile and pre-fills the edit form.
|
||||||
|
Future<void> _loadProfile() async {
|
||||||
|
```
|
||||||
31
.cursor/rules/prediqo-web-documentation.mdc
Normal file
31
.cursor/rules/prediqo-web-documentation.mdc
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
---
|
||||||
|
description: Documentation standards for Prediqo web React/TypeScript code
|
||||||
|
globs: prediqo_web/src/**/*.{ts,tsx}
|
||||||
|
alwaysApply: false
|
||||||
|
---
|
||||||
|
|
||||||
|
# Prediqo web documentation conventions
|
||||||
|
|
||||||
|
Apply the same readability standards as the backend when editing `prediqo_web/`.
|
||||||
|
|
||||||
|
## Required comments
|
||||||
|
|
||||||
|
1. **File / module** — Top-of-file block describing the feature or shared module role.
|
||||||
|
2. **Exported components & hooks** — JSDoc with purpose; `@param` for non-obvious props.
|
||||||
|
3. **Exported functions & services** — JSDoc with `@param`, `@returns`, `@throws` when relevant.
|
||||||
|
4. **Complex local helpers** — Brief comment when logic is non-obvious (export, DataGrid setup, token refresh).
|
||||||
|
|
||||||
|
## Style
|
||||||
|
|
||||||
|
- English comments (matches backend).
|
||||||
|
- Do not comment obvious JSX or one-liners.
|
||||||
|
- Keep comments updated when behavior changes.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
/**
|
||||||
|
* Protects routes: redirects unauthenticated users to login and non-admins away from admin pages.
|
||||||
|
*/
|
||||||
|
export function RequireAuth({ children, adminOnly }: RequireAuthProps) {
|
||||||
|
```
|
||||||
85
.env
Normal file
85
.env
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
# Docker Compose - copy to .env in this directory (repo root)
|
||||||
|
# Then: docker-compose up -d
|
||||||
|
|
||||||
|
# PostgreSQL (used by postgres service and DATABASE_URL for backend)
|
||||||
|
DATABASE_URL=postgresql://postgres@localhost:5432/crypto_wallet
|
||||||
|
DATABASE_PASSWORD=Japhni81!
|
||||||
|
POSTGRES_USER=postgres
|
||||||
|
POSTGRES_PASSWORD=Japhni81!
|
||||||
|
POSTGRES_DB=crypto_wallet
|
||||||
|
POSTGRES_PORT=5432
|
||||||
|
PGBOUNCER_PORT=6432
|
||||||
|
REDIS_PORT=6379
|
||||||
|
WS_PORT=4001
|
||||||
|
WORKER_ID=worker-1
|
||||||
|
|
||||||
|
# Backend
|
||||||
|
BACKEND_PORT=4000
|
||||||
|
JWT_SECRET=36763979244226452948404D635166546A576D5A7134743777217A25432A462D
|
||||||
|
# One-time first-admin setup (used on /setup until an administrator exists)
|
||||||
|
INITIAL_SETUP_TOKEN=36763979244226452948404D635166546A576D5A7134743777217A25432A462ED
|
||||||
|
JWT_ACCESS_EXPIRY=15m
|
||||||
|
JWT_REFRESH_EXPIRY=7d
|
||||||
|
|
||||||
|
# Required: 32-byte hex (64 chars) for AES-256 encryption
|
||||||
|
ENCRYPTION_KEY=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
|
||||||
|
|
||||||
|
# Required: BIP39 mnemonic (24 words) for HD wallet - keep secret
|
||||||
|
PLATFORM_MNEMONIC=world access act denial panther slab target snap frequent loyal pigeon soldier angry vanish reduce tomato praise educate convince copper mistake truck ordinary pelican
|
||||||
|
|
||||||
|
# Blockchain — testnet (development)
|
||||||
|
TRON_NODE_URL=https://api.shasta.trongrid.io
|
||||||
|
TRON_API_KEY=
|
||||||
|
TRON_CONFIRMATIONS=3
|
||||||
|
USDT_TRC20_CONTRACT=TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs
|
||||||
|
POLYGON_RPC_URL=https://rpc-amoy.polygon.technology
|
||||||
|
USDC_POLYGON_CONTRACT=0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582
|
||||||
|
POLYGON_CONFIRMATIONS=8
|
||||||
|
ALLOW_WITHDRAWALS=false
|
||||||
|
RATE_LIMIT_MAX=2000
|
||||||
|
|
||||||
|
# ===============================
|
||||||
|
# Backend - Mailer configuration
|
||||||
|
# ===============================
|
||||||
|
APP_PUBLIC_URL=https://prediqo.redirectme.net:9443
|
||||||
|
EMAIL_TRANSPORT=smtp # ou console en dev
|
||||||
|
SMTP_HOST=smtp.gmail.com
|
||||||
|
SMTP_USER=japhni81@gmail.com
|
||||||
|
SMTP_PASS=qsosxqrtoaoydcdf
|
||||||
|
EMAIL_FROM=noreply@prediqo.com
|
||||||
|
VERIFY_EMAIL_PATH=/verify-email
|
||||||
|
RESET_PASSWORD_PATH=/reset-password
|
||||||
|
PASSWORD_RESET_EXPIRY_HOURS=1
|
||||||
|
|
||||||
|
# ===============================
|
||||||
|
# Prediqo — ports dédiés (indépendant des autres apps du VPS)
|
||||||
|
# ===============================
|
||||||
|
# HTTP 9080 → redirige vers HTTPS 9443 une fois le certificat obtenu
|
||||||
|
PREDIQO_HTTP_PORT=9080
|
||||||
|
PREDIQO_HTTPS_PORT=9443
|
||||||
|
|
||||||
|
# ===============================
|
||||||
|
# Public domain
|
||||||
|
# ===============================
|
||||||
|
CERTBOT_EMAIL=japhni81@gmail.com
|
||||||
|
CERTBOT_DOMAIN1=prediqo.redirectme.net
|
||||||
|
|
||||||
|
# Frontend build-time URLs (HTTPS port 9443 — rebuild après changement)
|
||||||
|
VITE_API_BASE_URL=https://prediqo.redirectme.net:9443
|
||||||
|
VITE_WS_ENABLED=true
|
||||||
|
VITE_WS_URL=wss://prediqo.redirectme.net:9443/ws/v1/games/candle-predict
|
||||||
|
|
||||||
|
# ===============================
|
||||||
|
# Phase B — Docker Compose stack
|
||||||
|
# ===============================
|
||||||
|
# Host PostgreSQL (containers connect via host.docker.internal)
|
||||||
|
# Stop local PG only if using: docker compose --profile docker-db up -d
|
||||||
|
REDIS_URL=redis://localhost:6379
|
||||||
|
REDIS_ENABLED=true
|
||||||
|
REDIS_ROUND_CACHE=true
|
||||||
|
BET_ASYNC=true
|
||||||
|
ENGINE_ENABLED=false
|
||||||
|
WS_ENABLED=true
|
||||||
|
WS_PORT=4001
|
||||||
|
WS_PATH=/ws/v1/games/candle-predict
|
||||||
|
BACKEND_PORT=4000
|
||||||
58
.env.example
Normal file
58
.env.example
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
# Docker Compose + Phase B — copy to .env in repo root
|
||||||
|
# Launch: npm run phase-b:up (from repo root)
|
||||||
|
# Frontend: cd prediqo_web && npm run dev
|
||||||
|
|
||||||
|
# PostgreSQL (host — containers use host.docker.internal)
|
||||||
|
POSTGRES_USER=postgres
|
||||||
|
POSTGRES_PASSWORD=your_postgres_password
|
||||||
|
POSTGRES_DB=crypto_wallet
|
||||||
|
POSTGRES_PORT=5432
|
||||||
|
PGBOUNCER_PORT=6432
|
||||||
|
DATABASE_URL=postgresql://postgres:your_postgres_password@localhost:5432/crypto_wallet
|
||||||
|
DATABASE_PASSWORD=your_postgres_password
|
||||||
|
|
||||||
|
# Phase B ports
|
||||||
|
BACKEND_PORT=4000
|
||||||
|
WS_PORT=4001
|
||||||
|
REDIS_PORT=6379
|
||||||
|
WORKER_ID=worker-1
|
||||||
|
|
||||||
|
# Backend secrets
|
||||||
|
JWT_SECRET=your-super-secret-jwt-key-min-32-chars
|
||||||
|
JWT_ACCESS_EXPIRY=15m
|
||||||
|
JWT_REFRESH_EXPIRY=7d
|
||||||
|
ENCRYPTION_KEY=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
|
||||||
|
PLATFORM_MNEMONIC=word1 word2 ... word24
|
||||||
|
|
||||||
|
# Blockchain (testnet example)
|
||||||
|
TRON_NODE_URL=https://api.shasta.trongrid.io
|
||||||
|
TRON_CONFIRMATIONS=3
|
||||||
|
USDT_TRC20_CONTRACT=
|
||||||
|
POLYGON_RPC_URL=https://rpc-amoy.polygon.technology
|
||||||
|
POLYGON_CONFIRMATIONS=8
|
||||||
|
USDC_POLYGON_CONTRACT=
|
||||||
|
ALLOW_WITHDRAWALS=false
|
||||||
|
RATE_LIMIT_MAX=2000
|
||||||
|
|
||||||
|
# Ports dédiés Prediqo (n'utilise pas 80/443 du VPS)
|
||||||
|
PREDIQO_HTTP_PORT=9080
|
||||||
|
PREDIQO_HTTPS_PORT=9443
|
||||||
|
|
||||||
|
CERTBOT_EMAIL=your-email@example.com
|
||||||
|
CERTBOT_DOMAIN1=prediqo.redirectme.net
|
||||||
|
APP_PUBLIC_URL=https://prediqo.redirectme.net:9443
|
||||||
|
INITIAL_SETUP_TOKEN=your-random-setup-token-min-32-chars
|
||||||
|
|
||||||
|
VITE_API_BASE_URL=https://prediqo.redirectme.net:9443
|
||||||
|
VITE_WS_ENABLED=true
|
||||||
|
VITE_WS_URL=wss://prediqo.redirectme.net:9443/ws/v1/games/candle-predict
|
||||||
|
|
||||||
|
# Phase B feature flags (used by Docker services)
|
||||||
|
REDIS_ENABLED=true
|
||||||
|
REDIS_ROUND_CACHE=true
|
||||||
|
BET_ASYNC=true
|
||||||
|
WS_ENABLED=true
|
||||||
|
WS_PATH=/ws/v1/games/candle-predict
|
||||||
|
|
||||||
|
# Optional: containerized PostgreSQL instead of host
|
||||||
|
# docker compose --profile docker-db up -d
|
||||||
40
.env.testnet
Normal file
40
.env.testnet
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
# Docker Compose - copy to .env in this directory (repo root)
|
||||||
|
# Then: docker-compose up -d
|
||||||
|
|
||||||
|
# PostgreSQL (used by postgres service and DATABASE_URL for backend)
|
||||||
|
DATABASE_URL=postgresql://postgres@localhost:5432/crypto_wallet
|
||||||
|
DATABASE_PASSWORD=Japhni81!
|
||||||
|
POSTGRES_USER=postgres
|
||||||
|
POSTGRES_DB=crypto_wallet
|
||||||
|
POSTGRES_PORT=5432
|
||||||
|
|
||||||
|
# Backend
|
||||||
|
BACKEND_PORT=4000
|
||||||
|
JWT_SECRET=36763979244226452948404D635166546A576D5A7134743777217A25432A462D
|
||||||
|
JWT_ACCESS_EXPIRY=15m
|
||||||
|
JWT_REFRESH_EXPIRY=7d
|
||||||
|
# Allow more login attempts during testnet (default is 5 per 15 min)
|
||||||
|
LOGIN_RATE_LIMIT_MAX=20
|
||||||
|
|
||||||
|
# Required: 32-byte hex (64 chars) for AES-256 encryption
|
||||||
|
ENCRYPTION_KEY=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
|
||||||
|
|
||||||
|
# Required: BIP39 mnemonic (24 words) for HD wallet - keep secret
|
||||||
|
PLATFORM_MNEMONIC=world access act denial panther slab target snap frequent loyal pigeon soldier angry vanish reduce tomato praise educate convince copper mistake truck ordinary pelican
|
||||||
|
|
||||||
|
# TRON Shasta testnet (test TRX and USDT)
|
||||||
|
TRON_NODE_URL=https://api.shasta.trongrid.io
|
||||||
|
# Use fewer confirmations on testnet so deposits credit quickly (mainnet .env uses 20)
|
||||||
|
TRON_CONFIRMATIONS=3
|
||||||
|
# Shasta testnet USDT (TRC20) – required to detect USDT deposits on testnet
|
||||||
|
USDT_TRC20_CONTRACT=TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs
|
||||||
|
|
||||||
|
# Polygon Amoy testnet (test USDC)
|
||||||
|
POLYGON_RPC_URL=https://rpc-amoy.polygon.technology
|
||||||
|
USDC_POLYGON_CONTRACT=0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582
|
||||||
|
# Fewer confirmations on testnet so USDC deposits credit quickly (mainnet uses 64)
|
||||||
|
POLYGON_CONFIRMATIONS=8
|
||||||
|
|
||||||
|
# Email verification
|
||||||
|
APP_PUBLIC_URL=http://localhost:5173
|
||||||
|
EMAIL_TRANSPORT=console
|
||||||
6
.vscode/schemas/pubspec-minimal.json
vendored
Normal file
6
.vscode/schemas/pubspec-minimal.json
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||||
|
"title": "pubspec",
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": true
|
||||||
|
}
|
||||||
6
.vscode/settings.json
vendored
Normal file
6
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"yaml.schemaStore.enable": false,
|
||||||
|
"yaml.schemas": {
|
||||||
|
".vscode/schemas/pubspec-minimal.json": "**/pubspec.yaml"
|
||||||
|
}
|
||||||
|
}
|
||||||
274
README.md
Normal file
274
README.md
Normal file
@ -0,0 +1,274 @@
|
|||||||
|
# Prediqo
|
||||||
|
|
||||||
|
**Prediqo** is an online prediction games platform (web + mobile) where players use **cryptocurrencies** as the payment method. The stack includes a crypto wallet layer (**USDT TRC20**, **TRX**, **USDC Polygon**) managed by the platform, ready for game integration.
|
||||||
|
|
||||||
|
## Monorepo layout
|
||||||
|
|
||||||
|
| Folder | Role |
|
||||||
|
|--------|------|
|
||||||
|
| `backend/` | Node.js API (auth, wallet, ledger, admin, games-ready) |
|
||||||
|
| `prediqo_mobile/` | Flutter mobile app (play + wallet) |
|
||||||
|
| `prediqo_web/` | React web app (platform admin + player experience) |
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
- **Mobile**: Flutter (`prediqo_mobile`) — clean architecture, BLoC, Dio, secure storage
|
||||||
|
- **Web**: React + Vite (`prediqo_web`) — admin modules today; player/games modules planned
|
||||||
|
- **Backend**: Node.js + TypeScript + Express
|
||||||
|
- **Database**: PostgreSQL (users, wallets, ledger, transactions, audit logs)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- **User management**: Registration, login, JWT + refresh tokens, 2FA (TOTP)
|
||||||
|
- **HD wallet**: BIP39/BIP44; unique deposit address per user per asset
|
||||||
|
- **Ledger**: Internal ledger as source of truth; blockchain used for confirmation only
|
||||||
|
- **Deposits**: Monitoring with configurable confirmations (TRON: 20, Polygon: 64)
|
||||||
|
- **Withdrawals**: Hot wallet signing, balance lock, optional 2FA
|
||||||
|
- **Security**: AES-256 for private keys, rate limiting, audit logs
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Backend
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
- Node.js 18+
|
||||||
|
- PostgreSQL
|
||||||
|
|
||||||
|
### Setup (local)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd backend
|
||||||
|
cp .env.example .env
|
||||||
|
# Edit .env: DATABASE_URL, JWT_SECRET, ENCRYPTION_KEY (32-byte hex), PLATFORM_MNEMONIC (24-word BIP39)
|
||||||
|
npm install
|
||||||
|
npm run migrate
|
||||||
|
npm run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
**Important:** The `.env` file can be in `backend/` or the repo root; both are loaded. `DATABASE_URL` must match your PostgreSQL user and password.
|
||||||
|
|
||||||
|
**If you get "password authentication failed" (local PostgreSQL):**
|
||||||
|
- Use the same user/password you use to log in to PostgreSQL (often user `postgres` and the password you set during install).
|
||||||
|
- If your password contains special characters (`@`, `#`, `%`, `:`, `/`), URL-encode them in `DATABASE_URL` (e.g. `@` → `%40`, `#` → `%23`).
|
||||||
|
- Test the connection: `npm run db:test` (from `backend/`). Then try: `psql -U postgres -d crypto_wallet -h localhost` and enter your password to confirm it works.
|
||||||
|
|
||||||
|
Example `backend/.env`:
|
||||||
|
|
||||||
|
```
|
||||||
|
DATABASE_URL=postgresql://user:password@localhost:5432/crypto_wallet
|
||||||
|
JWT_SECRET=your-super-secret-jwt-key-min-32-chars
|
||||||
|
ENCRYPTION_KEY=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
|
||||||
|
PLATFORM_MNEMONIC=your twenty four word mnemonic phrase here ...
|
||||||
|
```
|
||||||
|
|
||||||
|
**PLATFORM_MNEMONIC:** Must be a valid BIP39 phrase (12 or 24 words from the [BIP39 English wordlist](https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt)). Do not use the placeholder; generate one once and keep it secret. Example (from project root): `cd backend && node -e "console.log(require('bip39').generateMnemonic(256))"` — then put the output in `.env` as `PLATFORM_MNEMONIC=word1 word2 ... word24`.
|
||||||
|
|
||||||
|
API runs at `http://localhost:4000`. Prefix: `/api/v1`.
|
||||||
|
|
||||||
|
### Environment
|
||||||
|
|
||||||
|
| Variable | Description |
|
||||||
|
|--------|-------------|
|
||||||
|
| `DATABASE_URL` | PostgreSQL connection string |
|
||||||
|
| `JWT_SECRET` | Secret for JWT (min 32 chars) |
|
||||||
|
| `ENCRYPTION_KEY` | 32-byte hex (64 chars) for AES-256 |
|
||||||
|
| `PLATFORM_MNEMONIC` | BIP39 mnemonic (12 or 24 words) for HD wallet; must be from the standard wordlist (see below) |
|
||||||
|
| `TRON_NODE_URL` | TronGrid API URL |
|
||||||
|
| `POLYGON_RPC_URL` | Polygon RPC URL |
|
||||||
|
| `USDC_POLYGON_CONTRACT` | USDC contract on Polygon |
|
||||||
|
| `USDT_TRC20_CONTRACT` | Optional override for USDT TRC20 (e.g. testnet token) |
|
||||||
|
|
||||||
|
### Testing with testnets (no real crypto)
|
||||||
|
|
||||||
|
You can run the backend against **testnets** to test deposits and withdrawals with free test tokens, then switch back to mainnet for real crypto.
|
||||||
|
|
||||||
|
1. **Use a separate `.env` (e.g. copy to `.env.testnet`) or override these in your current `.env`:**
|
||||||
|
- **TRON (Shasta testnet):**
|
||||||
|
`TRON_NODE_URL=https://api.shasta.trongrid.io`
|
||||||
|
Optionally set `USDT_TRC20_CONTRACT` to a Shasta test USDT token address if you use one (otherwise you can test TRX only).
|
||||||
|
- **Polygon (Amoy testnet):**
|
||||||
|
`POLYGON_RPC_URL=https://rpc-amoy.polygon.technology`
|
||||||
|
`USDC_POLYGON_CONTRACT=0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582`
|
||||||
|
(Official Circle USDC on Polygon Amoy; see [Circle USDC contract addresses](https://developers.circle.com/stablecoins/usdc-contract-addresses).)
|
||||||
|
2. **Get test tokens from faucets:**
|
||||||
|
- **TRON Shasta (test TRX):** e.g. [shasta.tronex.io](https://shasta.tronex.io/) or [faucet.triangleplatform.com/tron/shasta](https://faucet.triangleplatform.com/tron/shasta). Send your app’s TRON deposit address (from the Deposit screen) to receive test TRX.
|
||||||
|
- **Polygon Amoy (test USDC):** e.g. [faucet.circle.com](https://faucet.circle.com) (Circle) or other Amoy faucets. Use your app’s Polygon deposit address.
|
||||||
|
3. **Run the backend** with the testnet env; use the app to deposit (send test tokens to the shown address) and wait for the deposit monitor to credit the ledger. Then test withdrawals.
|
||||||
|
4. **When ready for production:** switch `.env` back to mainnet values (`TRON_NODE_URL=https://api.trongrid.io`, `POLYGON_RPC_URL=https://polygon-rpc.com`, `USDC_POLYGON_CONTRACT=0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359`, and remove or leave `USDT_TRC20_CONTRACT` unset). Use a **new** `PLATFORM_MNEMONIC` for production (do not reuse testnet mnemonic with real funds).
|
||||||
|
|
||||||
|
#### How to test deposit (exchange/wallet → platform)
|
||||||
|
|
||||||
|
1. **Get your platform deposit address**
|
||||||
|
- In the app: log in → **Deposit** → choose asset (e.g. TRX or USDC).
|
||||||
|
- Copy the address (and optionally use the QR code).
|
||||||
|
|
||||||
|
2. **Send funds to that address**
|
||||||
|
- **From an exchange:** In the exchange’s withdraw flow, choose the same network (e.g. TRON or Polygon), paste your **platform deposit address**, enter amount, confirm. (Use testnet on the exchange if it supports it; otherwise use mainnet with a small amount.)
|
||||||
|
- **From a wallet (e.g. TronLink, MetaMask):** Send the same asset on the same network to the **platform deposit address**.
|
||||||
|
- **Testnet only:** Use a faucet (see above) and enter your **platform deposit address** as the recipient; the faucet sends test tokens to your platform.
|
||||||
|
|
||||||
|
3. **Wait for the platform to credit the balance**
|
||||||
|
- The backend runs a **deposit monitor** every **60 seconds** (first run ~10 s after startup). It scans the chain for incoming transfers to your deposit address and credits your in-app balance once the required confirmations are met (e.g. 20 for TRON, 64 for Polygon).
|
||||||
|
- Refresh or reopen the dashboard; your balance should update after the next monitor run.
|
||||||
|
|
||||||
|
4. **Check the transaction**
|
||||||
|
- **Transactions** in the app should show the deposit with status **completed**.
|
||||||
|
|
||||||
|
#### How to test withdrawal (platform → exchange/wallet)
|
||||||
|
|
||||||
|
1. **Have balance and a hot wallet**
|
||||||
|
- Your in-app balance must be > 0 (from a prior deposit or a manual ledger credit for testing).
|
||||||
|
- Withdrawals are paid from a **hot wallet**. Ensure one is configured per asset (see [Hot wallet](#hot-wallet)).
|
||||||
|
|
||||||
|
2. **Get the destination address**
|
||||||
|
- **Exchange:** In the exchange, use “Deposit” for the same asset/network and copy the **deposit address** (and optional memo/tag if required).
|
||||||
|
- **Your own wallet:** Use the receiving address from TronLink, MetaMask, etc., on the same network.
|
||||||
|
|
||||||
|
3. **Withdraw in the app**
|
||||||
|
- In the app: **Withdraw** → choose asset → paste **destination address** → enter amount → enter **2FA code** → submit.
|
||||||
|
- The backend locks balance, sends from the hot wallet to that address, then marks the withdrawal completed.
|
||||||
|
|
||||||
|
4. **Confirm on chain**
|
||||||
|
- Check the destination wallet or exchange deposit history; the funds should appear after network confirmations. You can also look up the transaction ID (if shown in the app or logs) on a block explorer (e.g. Tronscan, Polygonscan).
|
||||||
|
|
||||||
|
In production, “exchange” is the same idea: **deposit** = user withdraws from exchange to the app’s deposit address; **withdraw** = user enters the exchange’s deposit address and the app sends from the platform to the exchange.
|
||||||
|
|
||||||
|
### Hot wallet
|
||||||
|
|
||||||
|
To enable withdrawals, insert a hot wallet per asset (e.g. via script or admin):
|
||||||
|
|
||||||
|
- Derive key from `PLATFORM_MNEMONIC` at a dedicated index (e.g. 0 for hot).
|
||||||
|
- Encrypt private key with app encryption.
|
||||||
|
- Insert into `hot_wallets` (wallet_type_id, address, encrypted_private_key).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Docker deployment
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
- Docker and Docker Compose
|
||||||
|
|
||||||
|
### Run with Docker Compose
|
||||||
|
|
||||||
|
From the **repository root** (`games_app/`):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Create env file for Compose (postgres + backend)
|
||||||
|
cp .env.example .env
|
||||||
|
|
||||||
|
# 2. Edit .env: set POSTGRES_PASSWORD, JWT_SECRET, ENCRYPTION_KEY, PLATFORM_MNEMONIC (required)
|
||||||
|
|
||||||
|
# 3. Start Postgres + backend
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
|
# 4. View logs
|
||||||
|
docker-compose logs -f backend
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Postgres:** exposed on `localhost:5432` (or `POSTGRES_PORT`).
|
||||||
|
- **Backend API:** exposed on `localhost:4000` (or `BACKEND_PORT`).
|
||||||
|
- The backend container runs migrations on startup, then the API.
|
||||||
|
- Compose uses the same `.env` for Postgres credentials and for `DATABASE_URL` (host `postgres`).
|
||||||
|
|
||||||
|
### Build backend image only
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd backend
|
||||||
|
docker build -t crypto-wallet-api .
|
||||||
|
```
|
||||||
|
|
||||||
|
### Local migrate when using Docker Postgres
|
||||||
|
|
||||||
|
If Postgres is running in Docker and you run migrations from the host:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd backend
|
||||||
|
# In .env use: DATABASE_URL=postgresql://cryptouser:cryptopass@localhost:5432/crypto_wallet
|
||||||
|
npm run migrate
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Prediqo Mobile (Flutter)
|
||||||
|
|
||||||
|
### Setup
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd prediqo_mobile
|
||||||
|
flutter pub get
|
||||||
|
```
|
||||||
|
|
||||||
|
Configure API base URL:
|
||||||
|
|
||||||
|
- Default: `http://10.0.2.2:4000` (Android emulator).
|
||||||
|
- For iOS simulator: `http://127.0.0.1:4000`.
|
||||||
|
- Run with: `flutter run --dart-define=API_BASE_URL=http://YOUR_IP:4000`
|
||||||
|
|
||||||
|
### Structure
|
||||||
|
|
||||||
|
- **core**: API client (Dio + auth interceptor), secure storage, theme
|
||||||
|
- **data**: Models, repository implementations
|
||||||
|
- **features**: auth (login, register, 2FA), wallet (dashboard, deposit, withdraw)
|
||||||
|
- **BLoC**: AuthBloc, WalletBloc
|
||||||
|
|
||||||
|
### Screens
|
||||||
|
|
||||||
|
- Login / Register
|
||||||
|
- Dashboard (balances, recent transactions, deposit/withdraw entry)
|
||||||
|
- Deposit (QR + copy address per asset)
|
||||||
|
- Withdraw (asset, address, amount, 2FA code)
|
||||||
|
- 2FA setup (QR for TOTP)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Prediqo Web (React)
|
||||||
|
|
||||||
|
### Setup
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd prediqo_web
|
||||||
|
npm install
|
||||||
|
npm run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
Configure API: copy `prediqo_web/.env.example` → `.env` with `VITE_API_BASE_URL=http://localhost:4000`.
|
||||||
|
|
||||||
|
**Modules (current & planned):**
|
||||||
|
- **Platform** — user management, settings, overview (implemented)
|
||||||
|
- **Player** — wallet + prediction games UI (to mirror mobile)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Deposit flow
|
||||||
|
|
||||||
|
1. User opens Deposit for an asset; app shows unique address (and QR).
|
||||||
|
2. User sends crypto to that address from an exchange or external wallet.
|
||||||
|
3. Backend deposit monitor polls blockchain; after required confirmations, ledger is credited and a transaction record is created.
|
||||||
|
|
||||||
|
## Withdrawal flow
|
||||||
|
|
||||||
|
1. User enters amount, destination address, and 2FA code.
|
||||||
|
2. Backend checks balance, locks amount, signs from hot wallet, broadcasts tx.
|
||||||
|
3. Ledger is updated after processing; user sees status in app.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Security
|
||||||
|
|
||||||
|
- Passwords hashed with Argon2.
|
||||||
|
- Private keys encrypted with AES-256 (key from env).
|
||||||
|
- 2FA (TOTP) for withdrawals and sensitive actions.
|
||||||
|
- Rate limiting on login and API.
|
||||||
|
- Audit log for login, deposits, withdrawals, admin actions.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Future upgrades (from spec)
|
||||||
|
|
||||||
|
- MPC/HSM instead of single HD wallet
|
||||||
|
- Multi-sig or MPC for hot wallet
|
||||||
|
- Policy engine for withdrawal approvals
|
||||||
|
- Real-time monitoring and anomaly detection
|
||||||
|
- Double-entry accounting and fraud detection
|
||||||
271
TESTING.md
Normal file
271
TESTING.md
Normal file
@ -0,0 +1,271 @@
|
|||||||
|
# Testing Deposit and Withdraw
|
||||||
|
|
||||||
|
This guide explains how to test deposits and withdrawals **without real crypto** first, then how to test with **real crypto from Binance** (or any exchange) once you’re confident.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Part 1: Test with no real coin (testnet)
|
||||||
|
|
||||||
|
Use **testnets** so you never spend real money. The app stays the same; only the **backend** is pointed at test networks.
|
||||||
|
|
||||||
|
### 1.1 Switch the backend to testnet
|
||||||
|
|
||||||
|
In your backend `.env` (or a copy like `.env.testnet`), set:
|
||||||
|
|
||||||
|
```env
|
||||||
|
# TRON Shasta testnet (test TRX and USDT)
|
||||||
|
TRON_NODE_URL=https://api.shasta.trongrid.io
|
||||||
|
TRON_CONFIRMATIONS=20
|
||||||
|
# Shasta testnet USDT (TRC20) contract – required to detect USDT deposits on testnet
|
||||||
|
USDT_TRC20_CONTRACT=TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs
|
||||||
|
|
||||||
|
# Polygon Amoy testnet (test USDC)
|
||||||
|
POLYGON_RPC_URL=https://rpc-amoy.polygon.technology
|
||||||
|
USDC_POLYGON_CONTRACT=0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582
|
||||||
|
POLYGON_CONFIRMATIONS=64
|
||||||
|
```
|
||||||
|
|
||||||
|
- Keep your existing `DATABASE_URL`, `JWT_SECRET`, `ENCRYPTION_KEY`, `PLATFORM_MNEMONIC` (this mnemonic is only for testnet; use a **new** one for mainnet later).
|
||||||
|
|
||||||
|
**Use the testnet env file when running the backend:**
|
||||||
|
Put your testnet variables in **`.env.testnet`** in the **repo root** (same folder as `backend/`). From the **backend** directory, run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run dev:testnet
|
||||||
|
```
|
||||||
|
|
||||||
|
This loads `../.env.testnet` so the backend uses Shasta/Amoy and your testnet contract settings. For mainnet, use `npm run dev` (loads `.env` from the backend directory).
|
||||||
|
If you prefer to keep `.env.testnet` inside `backend/`, use `ENV_FILE=.env.testnet npm run dev` instead (from the backend directory).
|
||||||
|
|
||||||
|
### 1.2 Get test tokens from faucets
|
||||||
|
|
||||||
|
Your “app deposit address” is the one shown in the app: **Deposit** → choose **TRX** or **USDC** → copy the address (or scan QR). Paste it into the faucet (or send it to the bot) as the recipient.
|
||||||
|
|
||||||
|
**TRX (TRON Shasta)** — try in this order if one is unavailable:
|
||||||
|
|
||||||
|
1. **Official TRON Shasta faucet (recommended):**
|
||||||
|
[https://shasta.tronex.io/join/getJoinPage](https://shasta.tronex.io/join/getJoinPage)
|
||||||
|
Paste your app TRX deposit address, complete the reCAPTCHA, click **Obtain**. Limit: once per address per 24 hours.
|
||||||
|
|
||||||
|
2. **Telegram / Discord bot (reliable backup):**
|
||||||
|
Join [TRON Developer Group (Telegram)](https://t.me/TronOfficialDevelopersGroupEn) or [TRON Discord](https://discord.com/invite/hqKvyAM). In the chat, type:
|
||||||
|
`!shasta YOUR_TRX_ADDRESS`
|
||||||
|
(e.g. `!shasta TEoXicFpDSFCdYAkCiHDdS1Tx7gN81iQXu`).
|
||||||
|
The bot sends 5,000 Shasta TRX to that address (max once per 24 hours per address). Type `!help` for other commands.
|
||||||
|
|
||||||
|
3. **Other faucets:**
|
||||||
|
[Triangle Shasta](https://faucet.triangleplatform.com/tron/shasta) — sometimes shows “Faucet is unavailable”; try again later or use the options above.
|
||||||
|
|
||||||
|
**USDT (TRON Shasta)** — test USDT on the same Shasta testnet:
|
||||||
|
|
||||||
|
1. **Telegram / Discord bot (recommended):**
|
||||||
|
In the same [TRON Developer Group (Telegram)](https://t.me/TronOfficialDevelopersGroupEn) or [TRON Discord](https://discord.com/invite/hqKvyAM), type:
|
||||||
|
`!shasta_usdt YOUR_TRON_ADDRESS`
|
||||||
|
(e.g. `!shasta_usdt TEoXicFpDSFCdYAkCiHDdS1Tx7gN81iQXu`).
|
||||||
|
The bot sends **5,000 test USDT** (Shasta TRC20) to that address. Use your app’s **USDT deposit address** from **Deposit → USDT (TRC20)**.
|
||||||
|
|
||||||
|
2. **Same TRON address:** Your app’s TRX and USDT (TRC20) on Shasta use the **same TRON address**; the backend credits the correct wallet (TRX vs USDT) based on the token.
|
||||||
|
|
||||||
|
3. **Bot limit:** The Telegram/Discord bot applies a **24h limit per requester** (your Telegram or Discord account), not per recipient address. So “You have requested 5000 coins (shasta) in the last 24 hours” means *you* have already used your allowance (e.g. with `!shasta` for one address). Creating another app account and using its address does **not** bypass the limit—the bot still sees the same requester. You must **wait ~24 hours** from your first request, or use a different Telegram/Discord account to request for another address. For testing both TRX and USDT on the same app account, request **USDT first** (`!shasta_usdt`) then TRX (`!shasta`) if the bot allows both within the limit.
|
||||||
|
|
||||||
|
**USDC (Polygon Amoy):**
|
||||||
|
|
||||||
|
- [Circle faucet](https://faucet.circle.com) — choose **Polygon Amoy**, then use your app’s USDC (Polygon) deposit address.
|
||||||
|
|
||||||
|
### 1.3 Test deposit (no real coin)
|
||||||
|
|
||||||
|
1. In the app: **Deposit** → choose **TRX**, **USDT (TRC20)**, or **USDC** (Polygon Amoy).
|
||||||
|
2. Copy the address (or use the QR code). For TRX and USDT on Shasta, the **same TRON address** is used; the backend detects which token was sent.
|
||||||
|
3. Get test tokens:
|
||||||
|
- **TRX:** faucet or `!shasta YOUR_ADDRESS` in Telegram/Discord.
|
||||||
|
- **USDT:** `!shasta_usdt YOUR_ADDRESS` in Telegram/Discord (see 1.2).
|
||||||
|
- **USDC:** Circle faucet (Polygon Amoy).
|
||||||
|
4. Wait 1–2 minutes. The backend’s deposit monitor runs about every 60 seconds and will credit your balance after confirmations.
|
||||||
|
5. Open **Wallet** (or pull to refresh); your balance should increase.
|
||||||
|
6. In **Wallet** → **See more** (transactions), you should see the deposit with status **completed**.
|
||||||
|
|
||||||
|
### 1.4 Test withdraw (no real coin) — TRX, USDT, USDC
|
||||||
|
|
||||||
|
Withdrawals are sent from the backend’s **hot wallet**. You must create hot wallets and fund them on the **same testnet** (Shasta for TRX/USDT, Amoy for USDC) before withdrawals will succeed.
|
||||||
|
|
||||||
|
#### Step 1: Create hot wallets (one-time)
|
||||||
|
|
||||||
|
From the **backend** directory, run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run seed-hot-wallets:testnet
|
||||||
|
```
|
||||||
|
|
||||||
|
This derives one TRON address (used for both TRX and USDT) and one Polygon address (for USDC) from your `PLATFORM_MNEMONIC`, saves them in the database, and prints the addresses. If hot wallets already exist, it skips and still prints the addresses.
|
||||||
|
|
||||||
|
#### Step 2: Fund the hot wallet addresses on testnet
|
||||||
|
|
||||||
|
You must send **test** tokens to these addresses so the backend can pay out withdrawals.
|
||||||
|
|
||||||
|
| Asset | Network | Hot wallet address (printed by script) | How to fund |
|
||||||
|
|-------|--------|----------------------------------------|-------------|
|
||||||
|
| **TRX** | Shasta | Same TRON address for TRX & USDT | `!shasta HOT_WALLET_TRON_ADDRESS` in Telegram/Discord, or [shasta.tronex.io](https://shasta.tronex.io/join/getJoinPage). |
|
||||||
|
| **USDT** | Shasta | Same TRON address as TRX | `!shasta_usdt HOT_WALLET_TRON_ADDRESS` (need TRX on that address for gas). So fund TRX first, then USDT. |
|
||||||
|
| **USDC** | Amoy | Polygon (0x...) address | [Circle faucet](https://faucet.circle.com) → choose **Polygon Amoy** → paste the hot wallet’s Polygon address. |
|
||||||
|
|
||||||
|
- **TRX:** The hot wallet needs TRX to send both TRX and USDT withdrawals (TRX pays for gas on Shasta).
|
||||||
|
- **USDT:** Send test USDT to the **same** TRON hot wallet address; ensure it already has some TRX for gas.
|
||||||
|
- **USDC:** Send test USDC to the hot wallet’s **Polygon** address on Amoy.
|
||||||
|
|
||||||
|
#### Step 3: Get a destination address (where you want to receive the withdrawal)
|
||||||
|
|
||||||
|
Use a **different** address from the hot wallet — e.g. your own wallet on the same testnet:
|
||||||
|
|
||||||
|
- **TRX & USDT:** A TRON Shasta address (e.g. create a second address in TronLink set to Shasta, or use a friend’s Shasta address).
|
||||||
|
- **USDC:** A Polygon Amoy address (e.g. MetaMask connected to Amoy; copy the “receive” address).
|
||||||
|
|
||||||
|
You can also use the **first user’s app deposit address** as the destination (e.g. withdraw from user 2 to user 1’s TRX address) to verify the flow.
|
||||||
|
|
||||||
|
#### Step 4: Withdraw in the app
|
||||||
|
|
||||||
|
1. **Backend** must be running with testnet: `npm run dev:testnet` (from backend).
|
||||||
|
2. In the **app**: log in as a user that has test balance (from earlier deposits).
|
||||||
|
3. Go to **Withdraw** → choose **TRX**, **USDT**, or **USDC**.
|
||||||
|
4. Paste the **destination address** (from Step 3). Ensure the **network** matches (TRX → TRON, USDT → TRC20/Shasta, USDC → Polygon Amoy).
|
||||||
|
5. Enter **amount** (e.g. a small amount ≤ your balance).
|
||||||
|
6. Enter your **2FA code** (TOTP) — see [How to get the 2FA code](#how-to-get-the-2fa-code) below if you haven’t set it up yet.
|
||||||
|
7. Submit. The backend sends from the hot wallet to that address.
|
||||||
|
8. Check the destination wallet or a block explorer (e.g. [Shasta Tronscan](https://shasta.tronscan.org), [Amoy on Oklink](https://www.oklink.com/amoy)) to confirm the tx.
|
||||||
|
|
||||||
|
**If withdrawal fails:**
|
||||||
|
|
||||||
|
- **“Withdrawal temporarily unavailable”** → No active hot wallet for that asset. Run `npm run seed-hot-wallets:testnet` and ensure the DB has a row per wallet type.
|
||||||
|
- **Transaction fails on chain** → Hot wallet has insufficient balance or gas. Fund the hot wallet (Step 2) and try again.
|
||||||
|
|
||||||
|
When testnet deposit and withdraw work for all three assets, you’re ready for real crypto (Part 2).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 1.5 Withdraw to “exchange” (testnet, no real coin) — TRX, USDT, USDC
|
||||||
|
|
||||||
|
This is the same as [1.4](#14-test-withdraw-no-real-coin--trx-usdt-usdc) but framed as **“user withdraws from your platform to an exchange”**. On testnet there is no real exchange; you use **your own testnet address** (or a second wallet) as the “exchange” destination. No real money is used.
|
||||||
|
|
||||||
|
#### Checklist (all three: TRX, USDT, USDC)
|
||||||
|
|
||||||
|
| Step | What to do |
|
||||||
|
|------|------------|
|
||||||
|
| **1. Backend on testnet** | Run backend with testnet env: `npm run dev:testnet` (from `backend/`). Ensure `.env.testnet` has Shasta + Amoy URLs and contracts (see [1.1](#11-switch-the-backend-to-testnet)). |
|
||||||
|
| **2. Seed hot wallets** | One-time: from `backend/`, run `npm run seed-hot-wallets:testnet`. Note the two printed addresses: **TRX & USDT (Shasta)** and **USDC (Polygon Amoy)**. |
|
||||||
|
| **3. Fund hot wallets** | Send **test** tokens to those addresses so the platform can pay withdrawals. See table below. |
|
||||||
|
| **4. User has balance** | In the app, the user must have balance (e.g. from [1.3](#13-test-deposit-no-real-coin) deposits or from **Transfer** from another user). |
|
||||||
|
| **5. Destination address** | For “withdraw to exchange” you need a **destination address on the same testnet**. Use e.g. a second TRON/Polygon wallet you control (TronLink Shasta, MetaMask Amoy), or the app’s own deposit address for another user. **Do not** use the hot wallet address. |
|
||||||
|
| **6. Withdraw in app** | App → **Withdraw** → choose **TRX**, **USDT**, or **USDC** → paste destination address → amount → 2FA → submit. |
|
||||||
|
| **7. Verify** | Check the destination on a block explorer (Shasta: [shasta.tronscan.org](https://shasta.tronscan.org), Amoy: [amoy.polygonscan.com](https://amoy.polygonscan.com)) to see the incoming tx. |
|
||||||
|
|
||||||
|
#### How to fund hot wallets (testnet, no real coin)
|
||||||
|
|
||||||
|
| Asset | Network | Hot wallet is… | How to fund (test only) |
|
||||||
|
|-------|--------|----------------|--------------------------|
|
||||||
|
| **TRX** | Shasta | Same TRON address for TRX & USDT | `!shasta HOT_WALLET_TRON_ADDRESS` in [Telegram](https://t.me/TronOfficialDevelopersGroupEn) or Discord, or [shasta.tronex.io](https://shasta.tronex.io/join/getJoinPage). |
|
||||||
|
| **USDT** | Shasta | Same TRON address as TRX | `!shasta_usdt HOT_WALLET_TRON_ADDRESS` in Telegram/Discord. That address must already have some TRX for gas. |
|
||||||
|
| **USDC** | Amoy | Polygon `0x…` address | [Circle faucet](https://faucet.circle.com) → **Polygon Amoy** → paste hot wallet’s Polygon address. |
|
||||||
|
|
||||||
|
#### Example: end-to-end test for each asset
|
||||||
|
|
||||||
|
**TRX (Shasta)**
|
||||||
|
1. Fund TRX hot wallet: `!shasta <TRON_HOT_ADDRESS>`.
|
||||||
|
2. In app: get TRX balance (deposit to your app TRX address from faucet, or use Transfer).
|
||||||
|
3. Get a destination: e.g. create a second Shasta address in TronLink, or use a friend’s.
|
||||||
|
4. App → Withdraw → TRX → paste destination → amount (e.g. 100) → 2FA → submit.
|
||||||
|
5. Check [shasta.tronscan.org](https://shasta.tronscan.org) for that destination address.
|
||||||
|
|
||||||
|
**USDT (Shasta)**
|
||||||
|
1. Fund TRX hot wallet first (TRX pays gas). Then fund USDT: `!shasta_usdt <TRON_HOT_ADDRESS>`.
|
||||||
|
2. In app: get USDT balance (deposit or Transfer).
|
||||||
|
3. Same TRON destination as above (Shasta).
|
||||||
|
4. App → Withdraw → USDT (TRC20) → paste destination → amount → 2FA → submit.
|
||||||
|
5. Check Shasta Tronscan for the USDT transfer to the destination.
|
||||||
|
|
||||||
|
**USDC (Polygon Amoy)**
|
||||||
|
1. Fund USDC hot wallet: Circle faucet → Polygon Amoy → hot wallet’s Polygon address.
|
||||||
|
2. In app: get USDC balance (deposit from Circle faucet to your app USDC address, or Transfer).
|
||||||
|
3. Get a destination: e.g. MetaMask on Amoy → copy “receive” address.
|
||||||
|
4. App → Withdraw → USDC (Polygon) → paste destination → amount → 2FA → submit.
|
||||||
|
5. Check [amoy.polygonscan.com](https://amoy.polygonscan.com) for the destination address.
|
||||||
|
|
||||||
|
**Important:** On testnet, “exchange” is just any valid address on that network. For real withdrawals to Binance (or another exchange), use the exchange’s **mainnet** deposit address and switch the backend to mainnet (Part 2).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### How to get the 2FA code
|
||||||
|
|
||||||
|
The app uses **TOTP** (time-based one-time password). You need to **enable 2FA once**, then use an **authenticator app** to get the 6-digit code each time you withdraw (or log in, if enabled).
|
||||||
|
|
||||||
|
1. **Enable 2FA (one-time)**
|
||||||
|
In the app: open **Account** (bottom tab) → tap **Two-factor authentication (2FA)**.
|
||||||
|
The app shows a **QR code**. Open an authenticator app on your phone (e.g. **Google Authenticator** or **Microsoft Authenticator**), add a new account by scanning that QR code, then enter the **6-digit code** the authenticator shows and tap **Enable 2FA**.
|
||||||
|
|
||||||
|
2. **Get the code when withdrawing**
|
||||||
|
When you are on the **Withdraw** screen, open the same authenticator app, find the entry for this app, and type the **current 6-digit code** (it changes about every 30 seconds). Enter that code in the “2FA Code” field and submit.
|
||||||
|
|
||||||
|
**Troubleshooting: I see deposits on Shasta Tronscan but the app shows 0 balance**
|
||||||
|
|
||||||
|
1. **Confirm the backend is using Shasta**
|
||||||
|
When you start the backend you should see: `TRON node: https://api.shasta.trongrid.io`.
|
||||||
|
If it shows `https://api.trongrid.io`, the backend is on **mainnet** and will not see Shasta transactions. Fix your `.env`: set `TRON_NODE_URL=https://api.shasta.trongrid.io` and restart.
|
||||||
|
|
||||||
|
2. **Restart the backend**
|
||||||
|
After changing `.env`, restart the backend so it loads Shasta. The deposit monitor runs about every 60 seconds; after one or two runs, balances should update.
|
||||||
|
|
||||||
|
3. **Scanner state after switching network**
|
||||||
|
If you previously ran the backend on mainnet, the deposit scanner may have saved a mainnet block number. The code now resets the scan range when that would be ahead of the current chain, so after pulling the latest backend and restarting, Shasta deposits should be picked up.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Part 2: Test with real crypto (e.g. from Binance)
|
||||||
|
|
||||||
|
Only do this **after** testnet tests succeed. Use **small amounts** first.
|
||||||
|
|
||||||
|
### 2.1 Switch the backend back to mainnet
|
||||||
|
|
||||||
|
In `.env`, use mainnet values:
|
||||||
|
|
||||||
|
```env
|
||||||
|
TRON_NODE_URL=https://api.trongrid.io
|
||||||
|
POLYGON_RPC_URL=https://polygon-rpc.com
|
||||||
|
USDC_POLYGON_CONTRACT=0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359
|
||||||
|
# Leave USDT_TRC20_CONTRACT unset (mainnet USDT uses DB/default)
|
||||||
|
```
|
||||||
|
|
||||||
|
Restart the backend. For production you should also use a **new** `PLATFORM_MNEMONIC` (do not reuse the one used on testnet).
|
||||||
|
|
||||||
|
### 2.2 Deposit real crypto from Binance
|
||||||
|
|
||||||
|
1. In the **app**: **Deposit** → choose **TRX**, **USDT**, or **USDC**.
|
||||||
|
2. Copy the **exact** deposit address (and note the **network** shown: TRON, TRON (TRC20), or Polygon).
|
||||||
|
3. In **Binance**:
|
||||||
|
- **Withdraw** → select the **same asset** (TRX, USDT, or USDC).
|
||||||
|
- Select the **same network** as in the app:
|
||||||
|
- **TRX** → **TRON**
|
||||||
|
- **USDT** → **TRON (TRC20)** — do **not** use ERC20 or other networks.
|
||||||
|
- **USDC** → **Polygon** — do **not** use Ethereum or other networks.
|
||||||
|
- Paste your **app deposit address** (no memo needed for these).
|
||||||
|
- Send a **small amount** first (e.g. minimum or a few dollars).
|
||||||
|
4. Wait for confirmations. The backend will credit your balance (usually within a few minutes for TRON; Polygon can take longer).
|
||||||
|
5. Check **Wallet** and **Transactions** in the app to confirm the deposit.
|
||||||
|
|
||||||
|
**Important:** Wrong network (e.g. USDT on ERC20 instead of TRC20) can lead to permanent loss. Always double-check network in the app and in Binance.
|
||||||
|
|
||||||
|
### 2.3 Withdraw real crypto (e.g. back to Binance)
|
||||||
|
|
||||||
|
1. In **Binance**: **Deposit** for the asset (e.g. TRX or USDT) → choose the **same network** (TRON / TRC20) → copy the **deposit address** (and memo if Binance shows one for that asset).
|
||||||
|
2. In the **app**: **Withdraw** → choose the same asset → paste the **Binance deposit address** → enter amount → enter **2FA** → confirm.
|
||||||
|
3. The backend sends from its hot wallet to that address. Check Binance deposit history and the app’s transaction list.
|
||||||
|
|
||||||
|
For production, withdrawals require the backend’s **hot wallet** to be funded and configured (see main [README](README.md#hot-wallet)).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Quick reference
|
||||||
|
|
||||||
|
| Goal | Backend env | Where to get funds | Where to send (deposit) / receive (withdraw) |
|
||||||
|
|-----------------------------|-----------------|---------------------------|----------------------------------------------|
|
||||||
|
| Test **no real coin** | Testnet URLs | Faucets (Shasta, Amoy) | App deposit address / your testnet wallet |
|
||||||
|
| Test **real crypto** | Mainnet URLs | Binance (or other exchange) | App deposit address / Binance deposit address |
|
||||||
|
|
||||||
|
Always match **asset + network** between the app and the exchange (TRX→TRON, USDT→TRC20, USDC→Polygon).
|
||||||
64
backend/.env
Normal file
64
backend/.env
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
# Server
|
||||||
|
NODE_ENV=development
|
||||||
|
PORT=4000
|
||||||
|
API_PREFIX=/api/v1
|
||||||
|
|
||||||
|
# Database (synced from repo root .env)
|
||||||
|
DATABASE_URL=postgresql://postgres@localhost:5432/crypto_wallet
|
||||||
|
DATABASE_PASSWORD=Japhni81!
|
||||||
|
|
||||||
|
# JWT
|
||||||
|
JWT_SECRET=36763979244226452948404D635166546A576D5A7134743777217A25432A462D
|
||||||
|
# One-time first-admin setup (used on /setup until an administrator exists)
|
||||||
|
INITIAL_SETUP_TOKEN=36763979244226452948404D635166546A576D5A7134743777217A25432A462ED
|
||||||
|
JWT_ACCESS_EXPIRY=15m
|
||||||
|
JWT_REFRESH_EXPIRY=7d
|
||||||
|
|
||||||
|
# Encryption (AES-256) - 32 bytes hex
|
||||||
|
ENCRYPTION_KEY=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
|
||||||
|
|
||||||
|
# HD Wallet - platform mnemonic (24 words). Keep secret.
|
||||||
|
PLATFORM_MNEMONIC=world access act denial panther slab target snap frequent loyal pigeon soldier angry vanish reduce tomato praise educate convince copper mistake truck ordinary pelican
|
||||||
|
|
||||||
|
# Blockchain — testnet (required in development; mainnet blocked by networkGuard)
|
||||||
|
TRON_NODE_URL=https://api.shasta.trongrid.io
|
||||||
|
TRON_API_KEY=
|
||||||
|
TRON_CONFIRMATIONS=3
|
||||||
|
USDT_TRC20_CONTRACT=TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs
|
||||||
|
|
||||||
|
POLYGON_RPC_URL=https://rpc-amoy.polygon.technology
|
||||||
|
USDC_POLYGON_CONTRACT=0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582
|
||||||
|
POLYGON_CONFIRMATIONS=8
|
||||||
|
|
||||||
|
# Safety (recommended for testing)
|
||||||
|
ALLOW_WITHDRAWALS=false
|
||||||
|
|
||||||
|
# Rate limiting
|
||||||
|
RATE_LIMIT_WINDOW_MS=900000
|
||||||
|
RATE_LIMIT_MAX=2000
|
||||||
|
LOGIN_RATE_LIMIT_MAX=20
|
||||||
|
# Withdrawal
|
||||||
|
DAILY_WITHDRAWAL_LIMIT_USD=10000
|
||||||
|
LARGE_WITHDRAWAL_THRESHOLD_USD=1000
|
||||||
|
|
||||||
|
# Email verification (dev: links logged to console unless SMTP is set in repo root .env)
|
||||||
|
# EMAIL_TRANSPORT=console
|
||||||
|
APP_PUBLIC_URL=https://prediqo.redirectme.net:9443
|
||||||
|
|
||||||
|
# Candle Predict engine (performance — lower = less DB load at scale)
|
||||||
|
# Real-time rounds still settle every ENGINE tick; backfill only fills historical gaps.
|
||||||
|
CANDLE_PREDICT_ENGINE_TICK_MS=3000
|
||||||
|
CANDLE_PREDICT_BACKFILL_MAX_PER_TICK=2
|
||||||
|
CANDLE_PREDICT_BACKFILL_INTERVAL_MS=60000
|
||||||
|
CANDLE_PREDICT_BACKFILL_SEED_MAX=15
|
||||||
|
|
||||||
|
# Phase B — Redis + realtime (local Node dev; Docker stack uses root .env)
|
||||||
|
REDIS_URL=redis://localhost:6379
|
||||||
|
REDIS_ENABLED=true
|
||||||
|
REDIS_ROUND_CACHE=true
|
||||||
|
BET_ASYNC=true
|
||||||
|
ENGINE_ENABLED=false
|
||||||
|
WS_ENABLED=false
|
||||||
|
WS_PORT=4001
|
||||||
|
WS_PATH=/ws/v1/games/candle-predict
|
||||||
|
WORKER_ID=worker-1
|
||||||
91
backend/.env.example
Normal file
91
backend/.env.example
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
# Server
|
||||||
|
NODE_ENV=development
|
||||||
|
PORT=4000
|
||||||
|
API_PREFIX=/api/v1
|
||||||
|
|
||||||
|
# Database
|
||||||
|
DATABASE_URL=postgresql://user:password@localhost:5432/crypto_wallet
|
||||||
|
|
||||||
|
# JWT
|
||||||
|
JWT_SECRET=your-super-secret-jwt-key-min-32-chars
|
||||||
|
# One-time first-admin setup (production). Min. 16 chars; use 32+ random characters.
|
||||||
|
# INITIAL_SETUP_TOKEN=your-random-setup-token-min-32-chars
|
||||||
|
JWT_ACCESS_EXPIRY=15m
|
||||||
|
JWT_REFRESH_EXPIRY=7d
|
||||||
|
|
||||||
|
# Encryption (AES-256) - 32 bytes hex
|
||||||
|
ENCRYPTION_KEY=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
|
||||||
|
|
||||||
|
# HD Wallet - platform mnemonic (24 words). Keep secret; used to derive user deposit addresses and hot wallet.
|
||||||
|
PLATFORM_MNEMONIC=word1 word2 ... word24
|
||||||
|
|
||||||
|
# Blockchain
|
||||||
|
TRON_NODE_URL=https://api.trongrid.io
|
||||||
|
TRON_API_KEY=
|
||||||
|
POLYGON_RPC_URL=https://polygon-rpc.com
|
||||||
|
USDC_POLYGON_CONTRACT=0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359
|
||||||
|
USDT_TRC20_CONTRACT=
|
||||||
|
|
||||||
|
# Safety (recommended for testing)
|
||||||
|
# NETWORK_MODE=testnet # default behavior in non-production is testnet safety
|
||||||
|
# ALLOW_WITHDRAWALS=false # withdrawals are disabled unless set to true
|
||||||
|
|
||||||
|
# Deposit confirmations
|
||||||
|
TRON_CONFIRMATIONS=20
|
||||||
|
POLYGON_CONFIRMATIONS=64
|
||||||
|
|
||||||
|
# Rate limiting
|
||||||
|
RATE_LIMIT_WINDOW_MS=900000
|
||||||
|
RATE_LIMIT_MAX=100
|
||||||
|
LOGIN_RATE_LIMIT_MAX=5
|
||||||
|
|
||||||
|
# Withdrawal
|
||||||
|
DAILY_WITHDRAWAL_LIMIT_USD=10000
|
||||||
|
LARGE_WITHDRAWAL_THRESHOLD_USD=1000
|
||||||
|
|
||||||
|
# Countries catalog (optional — without a key, sync uses ISO 3166 from GitHub)
|
||||||
|
# REST_COUNTRIES_API_KEY=
|
||||||
|
|
||||||
|
# App URLs (verification links in emails)
|
||||||
|
# SMTP settings can live here or in the repo root .env (root wins for mail vars).
|
||||||
|
APP_PUBLIC_URL=http://localhost:5173
|
||||||
|
# EMAIL_TRANSPORT=console # omit or set smtp when SMTP_* vars are configured
|
||||||
|
# SMTP_HOST=smtp.gmail.com
|
||||||
|
# SMTP_PORT=587
|
||||||
|
# SMTP_SECURE=false
|
||||||
|
# SMTP_USER=your@gmail.com
|
||||||
|
# SMTP_PASS=your-app-password
|
||||||
|
# EMAIL_FROM=your@gmail.com
|
||||||
|
VERIFY_EMAIL_PATH=/verify-email
|
||||||
|
RESET_PASSWORD_PATH=/reset-password
|
||||||
|
PASSWORD_RESET_EXPIRY_HOURS=1
|
||||||
|
|
||||||
|
# SMTP (required when EMAIL_TRANSPORT=smtp)
|
||||||
|
# SMTP_HOST=smtp.example.com
|
||||||
|
# SMTP_PORT=587
|
||||||
|
# SMTP_SECURE=false
|
||||||
|
# SMTP_USER=your-smtp-user
|
||||||
|
# SMTP_PASS=your-smtp-password
|
||||||
|
# EMAIL_FROM=Prediqo <noreply@yourdomain.com>
|
||||||
|
|
||||||
|
# Candle Predict engine (performance tuning for production scale)
|
||||||
|
# CANDLE_PREDICT_ENGINE_TICK_MS=3000 # main loop interval (ms)
|
||||||
|
# CANDLE_PREDICT_BACKFILL_MAX_PER_TICK=2 # candles per interval per backfill run
|
||||||
|
# CANDLE_PREDICT_BACKFILL_INTERVAL_MS=60000 # min delay between backfill runs (ms)
|
||||||
|
# CANDLE_PREDICT_BACKFILL_SEED_MAX=15 # initial chart history per interval
|
||||||
|
|
||||||
|
# Phase B — Redis + realtime (optional in local dev)
|
||||||
|
REDIS_URL=redis://localhost:6379
|
||||||
|
REDIS_ENABLED=true
|
||||||
|
REDIS_ROUND_CACHE=true
|
||||||
|
BET_ASYNC=true
|
||||||
|
ENGINE_ENABLED=false
|
||||||
|
WS_ENABLED=false
|
||||||
|
WS_PORT=4001
|
||||||
|
WS_PATH=/ws/v1/games/candle-predict
|
||||||
|
WORKER_ID=worker-1
|
||||||
|
|
||||||
|
# Slack alerts (optional — create one Incoming Webhook per channel in Slack)
|
||||||
|
# SLACK_SECURITY_WEBHOOK_URL=https://hooks.slack.com/services/... # #security
|
||||||
|
# SLACK_REFERRAL_WEBHOOK_URL=https://hooks.slack.com/services/... # #referral-fraud
|
||||||
|
# SLACK_WEBHOOK_URL=https://hooks.slack.com/services/... # legacy fallback for both
|
||||||
2
backend/.gitignore
vendored
Normal file
2
backend/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
data/exports/*
|
||||||
|
!data/exports/.gitkeep
|
||||||
32
backend/Dockerfile
Normal file
32
backend/Dockerfile
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# Build stage
|
||||||
|
FROM node:20-alpine AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
COPY tsconfig.json ./
|
||||||
|
COPY src ./src
|
||||||
|
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Production stage
|
||||||
|
FROM node:20-alpine
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
ENV PORT=4000
|
||||||
|
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm ci --omit=dev
|
||||||
|
|
||||||
|
COPY --from=builder /app/dist ./dist
|
||||||
|
# schema.sql is not compiled; needed at runtime for migrations
|
||||||
|
COPY --from=builder /app/src/db/schema.sql ./dist/db/
|
||||||
|
|
||||||
|
EXPOSE 4000
|
||||||
|
|
||||||
|
# Run migrations then start the server (migrate may fail if DB not ready; index.js will retry on first request)
|
||||||
|
CMD ["sh", "-c", "node dist/db/migrate.js 2>/dev/null || true && node dist/index.js"]
|
||||||
0
backend/data/exports/.gitkeep
Normal file
0
backend/data/exports/.gitkeep
Normal file
8
backend/dist/app.d.ts
vendored
Normal file
8
backend/dist/app.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* Express application setup.
|
||||||
|
* Configures security middleware, API routes, health checks, and global error handling.
|
||||||
|
*/
|
||||||
|
declare const app: import("express-serve-static-core").Express;
|
||||||
|
/** Configured Express application instance (not yet listening). */
|
||||||
|
export default app;
|
||||||
|
//# sourceMappingURL=app.d.ts.map
|
||||||
1
backend/dist/app.d.ts.map
vendored
Normal file
1
backend/dist/app.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,QAAA,MAAM,GAAG,6CAAY,CAAC;AA6DtB,mEAAmE;AACnE,eAAe,GAAG,CAAC"}
|
||||||
109
backend/dist/app.js
vendored
Normal file
109
backend/dist/app.js
vendored
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
"use strict";
|
||||||
|
/**
|
||||||
|
* Express application setup.
|
||||||
|
* Configures security middleware, API routes, health checks, and global error handling.
|
||||||
|
*/
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || (function () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const express_1 = __importDefault(require("express"));
|
||||||
|
const cors_1 = __importDefault(require("cors"));
|
||||||
|
const helmet_1 = __importDefault(require("helmet"));
|
||||||
|
const config_1 = require("./config");
|
||||||
|
const routes_1 = __importDefault(require("./routes"));
|
||||||
|
const settingsRepository = __importStar(require("./repositories/settingsRepository"));
|
||||||
|
const withdrawalFee_1 = require("./utils/withdrawalFee");
|
||||||
|
const app = (0, express_1.default)();
|
||||||
|
app.use((0, helmet_1.default)());
|
||||||
|
app.use((0, cors_1.default)({ origin: true, credentials: true }));
|
||||||
|
app.use(express_1.default.json());
|
||||||
|
app.use(config_1.config.apiPrefix, routes_1.default);
|
||||||
|
/**
|
||||||
|
* Infers TRON network label from the configured node URL for health reporting.
|
||||||
|
* @param url TRON node RPC URL
|
||||||
|
* @returns 'shasta', 'mainnet', or 'unknown'
|
||||||
|
*/
|
||||||
|
function labelTronNetwork(url) {
|
||||||
|
const u = (url || '').toLowerCase();
|
||||||
|
if (u.includes('shasta'))
|
||||||
|
return 'shasta';
|
||||||
|
if (u.includes('trongrid.io'))
|
||||||
|
return 'mainnet';
|
||||||
|
return 'unknown';
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Shortens a blockchain address for safe display in health/debug output.
|
||||||
|
* @param addr Full address or null/undefined
|
||||||
|
* @returns Masked address (first 6 + last 4 chars) or null when empty
|
||||||
|
*/
|
||||||
|
function maskAddress(addr) {
|
||||||
|
if (!addr)
|
||||||
|
return null;
|
||||||
|
const a = addr.trim();
|
||||||
|
if (a.length <= 12)
|
||||||
|
return a;
|
||||||
|
return `${a.slice(0, 6)}…${a.slice(-4)}`;
|
||||||
|
}
|
||||||
|
app.get('/health', async (_req, res) => {
|
||||||
|
const settings = await settingsRepository.getSettings();
|
||||||
|
const feeRaw = (0, withdrawalFee_1.getWithdrawalNetworkFeeRaw)(settings);
|
||||||
|
res.json({
|
||||||
|
status: 'ok',
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
env: config_1.config.env,
|
||||||
|
asset: 'USDT_TRC20',
|
||||||
|
network: labelTronNetwork(config_1.config.blockchain.tron.nodeUrl),
|
||||||
|
withdrawalsEnabled: settings.allow_withdrawals,
|
||||||
|
withdrawalNetworkFeeRaw: feeRaw.toString(),
|
||||||
|
rpc: {
|
||||||
|
tronNodeUrl: config_1.config.blockchain.tron.nodeUrl,
|
||||||
|
},
|
||||||
|
contracts: {
|
||||||
|
usdtTrc20: maskAddress(config_1.config.blockchain.tron.usdtTrc20Contract),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
app.use((_req, res) => {
|
||||||
|
res.status(404).json({ error: 'Not found' });
|
||||||
|
});
|
||||||
|
app.use((err, _req, res, _next) => {
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).json({ error: 'Internal server error' });
|
||||||
|
});
|
||||||
|
/** Configured Express application instance (not yet listening). */
|
||||||
|
exports.default = app;
|
||||||
|
//# sourceMappingURL=app.js.map
|
||||||
1
backend/dist/app.js.map
vendored
Normal file
1
backend/dist/app.js.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,sDAA8B;AAC9B,gDAAwB;AACxB,oDAA4B;AAC5B,qCAAkC;AAClC,sDAA8B;AAC9B,sFAAwE;AACxE,yDAAmE;AAEnE,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;AAEtB,GAAG,CAAC,GAAG,CAAC,IAAA,gBAAM,GAAE,CAAC,CAAC;AAClB,GAAG,CAAC,GAAG,CAAC,IAAA,cAAI,EAAC,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACnD,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AAExB,GAAG,CAAC,GAAG,CAAC,eAAM,CAAC,SAAS,EAAE,gBAAM,CAAC,CAAC;AAElC;;;;GAIG;AACH,SAAS,gBAAgB,CAAC,GAAW;IACnC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IACpC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC1C,IAAI,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC;QAAE,OAAO,SAAS,CAAC;IAChD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,SAAS,WAAW,CAAC,IAA+B;IAClD,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IACtB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AAqB,EAAE,KAA2B,EAAE,EAAE;IAChG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,uBAAuB,EAAE,CAAC,CAAC;AAC3D,CAAC,CAAC,CAAC;AAEH,mEAAmE;AACnE,kBAAe,GAAG,CAAC"}
|
||||||
5
backend/dist/apps/api.d.ts
vendored
Normal file
5
backend/dist/apps/api.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
/**
|
||||||
|
* HTTP API process — serves REST, optional WS disabled here by default.
|
||||||
|
*/
|
||||||
|
export {};
|
||||||
|
//# sourceMappingURL=api.d.ts.map
|
||||||
1
backend/dist/apps/api.d.ts.map
vendored
Normal file
1
backend/dist/apps/api.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/apps/api.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
||||||
34
backend/dist/apps/api.js
vendored
Normal file
34
backend/dist/apps/api.js
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
"use strict";
|
||||||
|
/**
|
||||||
|
* HTTP API process — serves REST, optional WS disabled here by default.
|
||||||
|
*/
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const app_1 = __importDefault(require("../app"));
|
||||||
|
const config_1 = require("../config");
|
||||||
|
const appBootstrap_1 = require("../bootstrap/appBootstrap");
|
||||||
|
async function main() {
|
||||||
|
await (0, appBootstrap_1.bootstrapCore)({
|
||||||
|
startEngines: config_1.config.engineEnabled,
|
||||||
|
startPlatformMonitors: true,
|
||||||
|
});
|
||||||
|
app_1.default.listen(config_1.config.port, () => {
|
||||||
|
console.log(`[api] listening on port ${config_1.config.port}`);
|
||||||
|
console.log(`[api] engine inline=${config_1.config.engineEnabled} redis=${config_1.config.redis.enabled}`);
|
||||||
|
console.log(`TRON node: ${config_1.config.blockchain.tron.nodeUrl}`);
|
||||||
|
console.log(`Withdrawals broadcasting enabled: ${config_1.config.withdrawal.allowWithdrawals}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
main().catch((e) => {
|
||||||
|
console.error(e);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
process.on('unhandledRejection', (reason) => {
|
||||||
|
console.error('[process] Unhandled promise rejection (continuing):', reason);
|
||||||
|
});
|
||||||
|
process.on('uncaughtException', (err) => {
|
||||||
|
console.error('[process] Uncaught exception (continuing):', err);
|
||||||
|
});
|
||||||
|
//# sourceMappingURL=api.js.map
|
||||||
1
backend/dist/apps/api.js.map
vendored
Normal file
1
backend/dist/apps/api.js.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/apps/api.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;AAEH,iDAAyB;AACzB,sCAAmC;AACnC,4DAA0D;AAE1D,KAAK,UAAU,IAAI;IACjB,MAAM,IAAA,4BAAa,EAAC;QAClB,YAAY,EAAE,eAAM,CAAC,aAAa;QAClC,qBAAqB,EAAE,IAAI;KAC5B,CAAC,CAAC;IAEH,aAAG,CAAC,MAAM,CAAC,eAAM,CAAC,IAAI,EAAE,GAAG,EAAE;QAC3B,OAAO,CAAC,GAAG,CAAC,2BAA2B,eAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QACtD,OAAO,CAAC,GAAG,CAAC,uBAAuB,eAAM,CAAC,aAAa,UAAU,eAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACzF,OAAO,CAAC,GAAG,CAAC,cAAc,eAAM,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5D,OAAO,CAAC,GAAG,CAAC,qCAAqC,eAAM,CAAC,UAAU,CAAC,gBAAgB,EAAE,CAAC,CAAC;IACzF,CAAC,CAAC,CAAC;AACL,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,EAAE;IAC1C,OAAO,CAAC,KAAK,CAAC,qDAAqD,EAAE,MAAM,CAAC,CAAC;AAC/E,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;IACtC,OAAO,CAAC,KAAK,CAAC,4CAA4C,EAAE,GAAG,CAAC,CAAC;AACnE,CAAC,CAAC,CAAC"}
|
||||||
5
backend/dist/apps/engine.d.ts
vendored
Normal file
5
backend/dist/apps/engine.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
/**
|
||||||
|
* Game engine process — runs Candle Predict tick loop without HTTP API.
|
||||||
|
*/
|
||||||
|
export {};
|
||||||
|
//# sourceMappingURL=engine.d.ts.map
|
||||||
1
backend/dist/apps/engine.d.ts.map
vendored
Normal file
1
backend/dist/apps/engine.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/apps/engine.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
||||||
24
backend/dist/apps/engine.js
vendored
Normal file
24
backend/dist/apps/engine.js
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
"use strict";
|
||||||
|
/**
|
||||||
|
* Game engine process — runs Candle Predict tick loop without HTTP API.
|
||||||
|
*/
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const appBootstrap_1 = require("../bootstrap/appBootstrap");
|
||||||
|
const config_1 = require("../config");
|
||||||
|
async function main() {
|
||||||
|
await (0, appBootstrap_1.bootstrapCore)({
|
||||||
|
startEngines: true,
|
||||||
|
startPlatformMonitors: false,
|
||||||
|
});
|
||||||
|
console.log('[engine] Candle Predict engine running');
|
||||||
|
console.log(`[engine] redis=${config_1.config.redis.enabled} roundCache=${config_1.config.redis.roundCacheEnabled}`);
|
||||||
|
console.log(`[engine] leader=${process.env.ENGINE_LEADER === '1' ? 'yes' : 'shared'}`);
|
||||||
|
}
|
||||||
|
main().catch((e) => {
|
||||||
|
console.error(e);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
process.on('unhandledRejection', (reason) => {
|
||||||
|
console.error('[engine] Unhandled promise rejection:', reason);
|
||||||
|
});
|
||||||
|
//# sourceMappingURL=engine.js.map
|
||||||
1
backend/dist/apps/engine.js.map
vendored
Normal file
1
backend/dist/apps/engine.js.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/apps/engine.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAEH,4DAA0D;AAC1D,sCAAmC;AAEnC,KAAK,UAAU,IAAI;IACjB,MAAM,IAAA,4BAAa,EAAC;QAClB,YAAY,EAAE,IAAI;QAClB,qBAAqB,EAAE,KAAK;KAC7B,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;IACtD,OAAO,CAAC,GAAG,CAAC,kBAAkB,eAAM,CAAC,KAAK,CAAC,OAAO,eAAe,eAAM,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC,CAAC;IACnG,OAAO,CAAC,GAAG,CAAC,mBAAmB,OAAO,CAAC,GAAG,CAAC,aAAa,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;AACzF,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,EAAE;IAC1C,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,MAAM,CAAC,CAAC;AACjE,CAAC,CAAC,CAAC"}
|
||||||
5
backend/dist/apps/worker-bets.d.ts
vendored
Normal file
5
backend/dist/apps/worker-bets.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
/**
|
||||||
|
* Bet queue worker — consumes Redis Stream jobs and executes placeBetInternal.
|
||||||
|
*/
|
||||||
|
export {};
|
||||||
|
//# sourceMappingURL=worker-bets.d.ts.map
|
||||||
1
backend/dist/apps/worker-bets.d.ts.map
vendored
Normal file
1
backend/dist/apps/worker-bets.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"worker-bets.d.ts","sourceRoot":"","sources":["../../src/apps/worker-bets.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
||||||
23
backend/dist/apps/worker-bets.js
vendored
Normal file
23
backend/dist/apps/worker-bets.js
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
"use strict";
|
||||||
|
/**
|
||||||
|
* Bet queue worker — consumes Redis Stream jobs and executes placeBetInternal.
|
||||||
|
*/
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const appBootstrap_1 = require("../bootstrap/appBootstrap");
|
||||||
|
const betConsumer_1 = require("../realtime/streams/betConsumer");
|
||||||
|
async function main() {
|
||||||
|
await (0, appBootstrap_1.bootstrapCore)({
|
||||||
|
startEngines: false,
|
||||||
|
startPlatformMonitors: false,
|
||||||
|
runDevMigrations: false,
|
||||||
|
});
|
||||||
|
await (0, betConsumer_1.startBetWorkerLoop)();
|
||||||
|
}
|
||||||
|
main().catch((e) => {
|
||||||
|
console.error(e);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
process.on('unhandledRejection', (reason) => {
|
||||||
|
console.error('[worker-bets] Unhandled promise rejection:', reason);
|
||||||
|
});
|
||||||
|
//# sourceMappingURL=worker-bets.js.map
|
||||||
1
backend/dist/apps/worker-bets.js.map
vendored
Normal file
1
backend/dist/apps/worker-bets.js.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"worker-bets.js","sourceRoot":"","sources":["../../src/apps/worker-bets.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAEH,4DAA0D;AAC1D,iEAAqE;AAErE,KAAK,UAAU,IAAI;IACjB,MAAM,IAAA,4BAAa,EAAC;QAClB,YAAY,EAAE,KAAK;QACnB,qBAAqB,EAAE,KAAK;QAC5B,gBAAgB,EAAE,KAAK;KACxB,CAAC,CAAC;IAEH,MAAM,IAAA,gCAAkB,GAAE,CAAC;AAC7B,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,EAAE;IAC1C,OAAO,CAAC,KAAK,CAAC,4CAA4C,EAAE,MAAM,CAAC,CAAC;AACtE,CAAC,CAAC,CAAC"}
|
||||||
7
backend/dist/apps/ws.d.ts
vendored
Normal file
7
backend/dist/apps/ws.d.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
/**
|
||||||
|
|
||||||
|
* WebSocket gateway — Candle Predict + Support messaging.
|
||||||
|
|
||||||
|
*/
|
||||||
|
export {};
|
||||||
|
//# sourceMappingURL=ws.d.ts.map
|
||||||
1
backend/dist/apps/ws.d.ts.map
vendored
Normal file
1
backend/dist/apps/ws.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../src/apps/ws.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
||||||
78
backend/dist/apps/ws.js
vendored
Normal file
78
backend/dist/apps/ws.js
vendored
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
"use strict";
|
||||||
|
/**
|
||||||
|
|
||||||
|
* WebSocket gateway — Candle Predict + Support messaging.
|
||||||
|
|
||||||
|
*/
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const http_1 = __importDefault(require("http"));
|
||||||
|
const ws_1 = require("ws");
|
||||||
|
const config_1 = require("../config");
|
||||||
|
const appBootstrap_1 = require("../bootstrap/appBootstrap");
|
||||||
|
const auth_1 = require("../realtime/ws/auth");
|
||||||
|
const hub_1 = require("../realtime/ws/hub");
|
||||||
|
const supportHub_1 = require("../realtime/ws/supportHub");
|
||||||
|
async function main() {
|
||||||
|
if (!config_1.config.ws.enabled) {
|
||||||
|
console.error('[ws] WS_ENABLED is not true — exiting');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
await (0, appBootstrap_1.bootstrapCore)({
|
||||||
|
startEngines: false,
|
||||||
|
startPlatformMonitors: false,
|
||||||
|
runDevMigrations: false,
|
||||||
|
});
|
||||||
|
await hub_1.gameWsHub.start();
|
||||||
|
await supportHub_1.supportWsHub.start();
|
||||||
|
const server = http_1.default.createServer((_req, res) => {
|
||||||
|
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
||||||
|
res.end('Prediqo WebSocket gateway');
|
||||||
|
});
|
||||||
|
const gameWss = new ws_1.WebSocketServer({ noServer: true });
|
||||||
|
const supportWss = new ws_1.WebSocketServer({ noServer: true });
|
||||||
|
gameWss.on('connection', (socket, req) => {
|
||||||
|
const url = new URL(req.url ?? '/', `http://${req.headers.host ?? 'localhost'}`);
|
||||||
|
const queryToken = url.searchParams.get('token') ?? undefined;
|
||||||
|
const headerToken = (0, auth_1.extractBearerToken)(req.headers.authorization);
|
||||||
|
const auth = (0, auth_1.authenticateWsToken)(headerToken ?? queryToken);
|
||||||
|
hub_1.gameWsHub.register(socket, auth);
|
||||||
|
socket.send(JSON.stringify({
|
||||||
|
type: 'connected',
|
||||||
|
authenticated: !!auth,
|
||||||
|
path: config_1.config.ws.path,
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
supportWss.on('connection', (socket, req) => {
|
||||||
|
supportHub_1.supportWsHub.register(socket, req.url ?? '/', req.headers.authorization);
|
||||||
|
});
|
||||||
|
server.on('upgrade', (req, socket, head) => {
|
||||||
|
const pathname = new URL(req.url ?? '/', `http://${req.headers.host ?? 'localhost'}`).pathname;
|
||||||
|
if (pathname === config_1.config.ws.path) {
|
||||||
|
gameWss.handleUpgrade(req, socket, head, (ws) => {
|
||||||
|
gameWss.emit('connection', ws, req);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (pathname === config_1.config.ws.supportPath) {
|
||||||
|
supportWss.handleUpgrade(req, socket, head, (ws) => {
|
||||||
|
supportWss.emit('connection', ws, req);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
socket.destroy();
|
||||||
|
});
|
||||||
|
server.listen(config_1.config.ws.port, () => {
|
||||||
|
console.log(`[ws] listening on port ${config_1.config.ws.port}`);
|
||||||
|
console.log(`[ws] game path=${config_1.config.ws.path}`);
|
||||||
|
console.log(`[ws] support path=${config_1.config.ws.supportPath}`);
|
||||||
|
console.log(`[ws] redis=${config_1.config.redis.enabled}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
main().catch((e) => {
|
||||||
|
console.error(e);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
//# sourceMappingURL=ws.js.map
|
||||||
1
backend/dist/apps/ws.js.map
vendored
Normal file
1
backend/dist/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/**
|
||||||
|
* Shared application bootstrap (migrations, background jobs, game registration).
|
||||||
|
*/
|
||||||
|
export type BootstrapOptions = {
|
||||||
|
/** Start Candle Predict / other game engines (disable on API-only process). */
|
||||||
|
startEngines?: boolean;
|
||||||
|
/** Start deposit, sweep, referral background monitors (disable on engine-only process). */
|
||||||
|
startPlatformMonitors?: boolean;
|
||||||
|
/** Run dev migrations on boot. */
|
||||||
|
runDevMigrations?: boolean;
|
||||||
|
};
|
||||||
|
/** Core bootstrap shared by API and engine processes. */
|
||||||
|
export declare function bootstrapCore(opts?: BootstrapOptions): Promise<void>;
|
||||||
|
//# sourceMappingURL=appBootstrap.d.ts.map
|
||||||
1
backend/dist/bootstrap/appBootstrap.d.ts.map
vendored
Normal file
1
backend/dist/bootstrap/appBootstrap.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"appBootstrap.d.ts","sourceRoot":"","sources":["../../src/bootstrap/appBootstrap.ts"],"names":[],"mappings":"AAAA;;GAEG;AAmGH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,+EAA+E;IAC/E,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,2FAA2F;IAC3F,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,kCAAkC;IAClC,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,yDAAyD;AACzD,wBAAsB,aAAa,CAAC,IAAI,GAAE,gBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CA6C9E"}
|
||||||
137
backend/dist/bootstrap/appBootstrap.js
vendored
Normal file
137
backend/dist/bootstrap/appBootstrap.js
vendored
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
"use strict";
|
||||||
|
/**
|
||||||
|
* Shared application bootstrap (migrations, background jobs, game registration).
|
||||||
|
*/
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.bootstrapCore = bootstrapCore;
|
||||||
|
const config_1 = require("../config");
|
||||||
|
const connection_1 = require("../db/connection");
|
||||||
|
const bootstrap_1 = require("../games/bootstrap");
|
||||||
|
const engineRunner_1 = require("../games/engineRunner");
|
||||||
|
const depositMonitorService_1 = require("../services/depositMonitorService");
|
||||||
|
const securityService_1 = require("../services/securityService");
|
||||||
|
const dbTamperService_1 = require("../services/dbTamperService");
|
||||||
|
const sweepService_1 = require("../services/sweepService");
|
||||||
|
const countryService_1 = require("../services/countryService");
|
||||||
|
const userAdminStatsService_1 = require("../services/userAdminStatsService");
|
||||||
|
const adminUserExportService_1 = require("../services/adminUserExportService");
|
||||||
|
const referralService_1 = require("../services/referralService");
|
||||||
|
const analyticsMaterializedViews_1 = require("../utils/analyticsMaterializedViews");
|
||||||
|
const networkGuard_1 = require("../safety/networkGuard");
|
||||||
|
const client_1 = require("../realtime/redis/client");
|
||||||
|
const DEPOSIT_POLL_INTERVAL_MS = 60 * 1000;
|
||||||
|
async function startDepositMonitor() {
|
||||||
|
const run = async () => {
|
||||||
|
try {
|
||||||
|
await (0, depositMonitorService_1.processTronDeposits)();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.error('Deposit monitor error:', e);
|
||||||
|
}
|
||||||
|
setTimeout(run, DEPOSIT_POLL_INTERVAL_MS);
|
||||||
|
};
|
||||||
|
setTimeout(run, 10 * 1000);
|
||||||
|
}
|
||||||
|
function startLedgerIntegrityMonitor() {
|
||||||
|
const intervalMs = (0, securityService_1.getIntegrityCheckIntervalMs)();
|
||||||
|
const run = async () => {
|
||||||
|
try {
|
||||||
|
const issues = await (0, securityService_1.runLedgerIntegrityCheck)();
|
||||||
|
if (issues.length > 0) {
|
||||||
|
console.warn(`[security] Ledger integrity check found ${issues.length} issue(s)`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.error('Ledger integrity check error:', e);
|
||||||
|
}
|
||||||
|
setTimeout(run, intervalMs);
|
||||||
|
};
|
||||||
|
setTimeout(run, 30000);
|
||||||
|
}
|
||||||
|
function startDbTamperMonitor() {
|
||||||
|
const intervalMs = (0, dbTamperService_1.getTamperCheckIntervalMs)();
|
||||||
|
const run = async () => {
|
||||||
|
try {
|
||||||
|
const n = await (0, dbTamperService_1.processDbTamperEvents)();
|
||||||
|
if (n > 0) {
|
||||||
|
console.warn(`[security] Processed ${n} unauthorized DB change event(s)`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.error('DB tamper monitor error:', e);
|
||||||
|
}
|
||||||
|
setTimeout(run, intervalMs);
|
||||||
|
};
|
||||||
|
setTimeout(run, 15000);
|
||||||
|
}
|
||||||
|
function startSweepMonitor() {
|
||||||
|
const intervalMs = (0, sweepService_1.getSweepPollIntervalMs)();
|
||||||
|
const run = async () => {
|
||||||
|
try {
|
||||||
|
const n = await (0, sweepService_1.processPendingSweeps)();
|
||||||
|
if (n > 0 && process.env.NODE_ENV !== 'production') {
|
||||||
|
console.log(`[sweep] Processed ${n} sweep(s)`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.error('Sweep monitor error:', e);
|
||||||
|
}
|
||||||
|
setTimeout(run, intervalMs);
|
||||||
|
};
|
||||||
|
setTimeout(run, 45000);
|
||||||
|
}
|
||||||
|
function startReferralCommissionMonitor() {
|
||||||
|
const intervalMs = (0, referralService_1.getReferralCommissionPollIntervalMs)();
|
||||||
|
const run = async () => {
|
||||||
|
try {
|
||||||
|
const n = await (0, referralService_1.processPendingReferralCommissions)();
|
||||||
|
if (n > 0 && process.env.NODE_ENV !== 'production') {
|
||||||
|
console.log(`[referral] Settled ${n} pending commission(s)`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.error('Referral commission monitor error:', e);
|
||||||
|
}
|
||||||
|
setTimeout(run, intervalMs);
|
||||||
|
};
|
||||||
|
setTimeout(run, 60000);
|
||||||
|
}
|
||||||
|
/** Core bootstrap shared by API and engine processes. */
|
||||||
|
async function bootstrapCore(opts = {}) {
|
||||||
|
const { startEngines = config_1.config.engineEnabled, startPlatformMonitors = true, runDevMigrations = config_1.config.env === 'development', } = opts;
|
||||||
|
(0, networkGuard_1.validateTestnetSafetyOrThrow)();
|
||||||
|
if (runDevMigrations) {
|
||||||
|
try {
|
||||||
|
await (0, connection_1.runMigrations)();
|
||||||
|
console.log('Migrations OK');
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.warn('Migrations warning:', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await (0, countryService_1.ensureCountriesSeeded)();
|
||||||
|
if (config_1.config.redis.enabled) {
|
||||||
|
try {
|
||||||
|
await (0, client_1.connectRedis)();
|
||||||
|
console.log('[redis] Connected');
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.warn('[redis] Connection failed (continuing without cache):', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(0, bootstrap_1.registerBuiltinGames)();
|
||||||
|
if (startPlatformMonitors) {
|
||||||
|
(0, userAdminStatsService_1.scheduleAdminStatsBackfill)();
|
||||||
|
(0, adminUserExportService_1.startAdminExportWorker)();
|
||||||
|
(0, analyticsMaterializedViews_1.scheduleAnalyticsMaterializedViewRefresh)();
|
||||||
|
startDepositMonitor();
|
||||||
|
startLedgerIntegrityMonitor();
|
||||||
|
startDbTamperMonitor();
|
||||||
|
startSweepMonitor();
|
||||||
|
startReferralCommissionMonitor();
|
||||||
|
}
|
||||||
|
if (startEngines) {
|
||||||
|
(0, engineRunner_1.startRegisteredGameEngines)();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=appBootstrap.js.map
|
||||||
1
backend/dist/bootstrap/appBootstrap.js.map
vendored
Normal file
1
backend/dist/bootstrap/appBootstrap.js.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"appBootstrap.js","sourceRoot":"","sources":["../../src/bootstrap/appBootstrap.ts"],"names":[],"mappings":";AAAA;;GAEG;;AA6GH,sCA6CC;AAxJD,sCAAmC;AACnC,iDAA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,CAAC,IAAI,CAAC,uDAAuD,EAAE,CAAC,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;IAED,IAAA,gCAAoB,GAAE,CAAC;IAEvB,IAAI,qBAAqB,EAAE,CAAC;QAC1B,IAAA,kDAA0B,GAAE,CAAC;QAC7B,IAAA,+CAAsB,GAAE,CAAC;QACzB,IAAA,qEAAwC,GAAE,CAAC;QAC3C,mBAAmB,EAAE,CAAC;QACtB,2BAA2B,EAAE,CAAC;QAC9B,oBAAoB,EAAE,CAAC;QACvB,iBAAiB,EAAE,CAAC;QACpB,8BAA8B,EAAE,CAAC;IACnC,CAAC;IAED,IAAI,YAAY,EAAE,CAAC;QACjB,IAAA,yCAA0B,GAAE,CAAC;IAC/B,CAAC;AACH,CAAC"}
|
||||||
131
backend/dist/config/index.d.ts
vendored
Normal file
131
backend/dist/config/index.d.ts
vendored
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
/**
|
||||||
|
* Application configuration loaded from environment variables.
|
||||||
|
* Centralizes defaults for server, database, JWT, encryption, blockchain, and safety settings.
|
||||||
|
*/
|
||||||
|
/** Resolved runtime configuration derived from process.env with safe defaults. */
|
||||||
|
export declare const config: {
|
||||||
|
env: string;
|
||||||
|
port: number;
|
||||||
|
apiPrefix: string;
|
||||||
|
database: {
|
||||||
|
url: string;
|
||||||
|
};
|
||||||
|
jwt: {
|
||||||
|
secret: string;
|
||||||
|
accessExpiry: string;
|
||||||
|
refreshExpiry: string;
|
||||||
|
};
|
||||||
|
encryption: {
|
||||||
|
key: string;
|
||||||
|
};
|
||||||
|
blockchain: {
|
||||||
|
tron: {
|
||||||
|
nodeUrl: string;
|
||||||
|
apiKey: string;
|
||||||
|
confirmations: number;
|
||||||
|
/** Optional override for USDT TRC20 contract (e.g. testnet token). When set, used instead of DB wallet_types.contract_address. */
|
||||||
|
usdtTrc20Contract: string | null;
|
||||||
|
};
|
||||||
|
polygon: {
|
||||||
|
rpcUrl: string;
|
||||||
|
usdcContract: string;
|
||||||
|
confirmations: number;
|
||||||
|
/** Max blocks per eth_getLogs call; Amoy public RPC rejects ~500-block ranges */
|
||||||
|
getLogsBlockRange: number;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
rateLimit: {
|
||||||
|
windowMs: number;
|
||||||
|
max: number;
|
||||||
|
loginMax: number;
|
||||||
|
};
|
||||||
|
withdrawal: {
|
||||||
|
dailyLimitUsd: number;
|
||||||
|
largeThresholdUsd: number;
|
||||||
|
/** Kill-switch: prevents broadcasting real chain txs unless explicitly enabled */
|
||||||
|
allowWithdrawals: boolean;
|
||||||
|
/** Default network fee in USDT micro-units (6 decimals); admin can override in Settings. */
|
||||||
|
networkFeeUsdtMicro: number;
|
||||||
|
};
|
||||||
|
security: {
|
||||||
|
integrityCheckIntervalMs: number;
|
||||||
|
};
|
||||||
|
treasury: {
|
||||||
|
/** Moves on-chain deposits from user addresses to cold storage */
|
||||||
|
sweepEnabled: boolean;
|
||||||
|
sweepPollIntervalMs: number;
|
||||||
|
/** Minimum token amount (raw units) to sweep */
|
||||||
|
sweepMinAmountRaw: string;
|
||||||
|
/** TRX sent from hot wallet to fund TRC20 sweeps (sun) */
|
||||||
|
tronGasTopUpSun: string;
|
||||||
|
/** MATIC sent from hot wallet to fund USDC sweeps (wei) */
|
||||||
|
polygonGasTopUpWei: string;
|
||||||
|
};
|
||||||
|
app: {
|
||||||
|
/** Public web app URL used in verification links (e.g. http://localhost:5173) */
|
||||||
|
publicUrl: string;
|
||||||
|
verifyEmailPath: string;
|
||||||
|
resetPasswordPath: string;
|
||||||
|
};
|
||||||
|
countries: {
|
||||||
|
/** Optional REST Countries v5 API key. When unset, sync uses the ISO 3166 public catalog. */
|
||||||
|
restCountriesApiKey: string;
|
||||||
|
};
|
||||||
|
deposit: {
|
||||||
|
/** Platform asset for deposits and predictions (USDT TRC20). */
|
||||||
|
walletTypeCode: string;
|
||||||
|
};
|
||||||
|
candlePredict: {
|
||||||
|
engineTickMs: number;
|
||||||
|
backfillMaxPerTick: number;
|
||||||
|
backfillIntervalMs: number;
|
||||||
|
backfillSeedMax: number;
|
||||||
|
};
|
||||||
|
email: {
|
||||||
|
/** smtp = send via SMTP; console = log link to stdout (dev) */
|
||||||
|
transport: "smtp" | "console";
|
||||||
|
host: string;
|
||||||
|
port: number;
|
||||||
|
secure: boolean;
|
||||||
|
user: string;
|
||||||
|
pass: string;
|
||||||
|
from: string;
|
||||||
|
verificationExpiryHours: number;
|
||||||
|
verificationSendMax: number;
|
||||||
|
passwordResetExpiryHours: number;
|
||||||
|
passwordResetSendMax: number;
|
||||||
|
};
|
||||||
|
slack: {
|
||||||
|
/** Legacy fallback when channel-specific webhooks are not set */
|
||||||
|
webhookUrl: string;
|
||||||
|
/** #security — withdrawals, auth, platform security alerts */
|
||||||
|
securityWebhookUrl: string;
|
||||||
|
/** #referral-fraud — cap blocks, clawbacks, Sybil review */
|
||||||
|
referralWebhookUrl: string;
|
||||||
|
};
|
||||||
|
redis: {
|
||||||
|
url: string;
|
||||||
|
/** Auto-enabled when REDIS_URL is set unless REDIS_ENABLED=false */
|
||||||
|
enabled: boolean;
|
||||||
|
/** Phase B: read round state from Redis before PostgreSQL */
|
||||||
|
roundCacheEnabled: boolean;
|
||||||
|
/** Phase B+: enqueue single bets to Redis Stream (requires worker-bets) */
|
||||||
|
betAsyncEnabled: boolean;
|
||||||
|
};
|
||||||
|
ws: {
|
||||||
|
enabled: boolean;
|
||||||
|
port: number;
|
||||||
|
path: string;
|
||||||
|
supportPath: string;
|
||||||
|
};
|
||||||
|
/** When false, API process skips starting game engines (use app-engine instead) */
|
||||||
|
engineEnabled: boolean;
|
||||||
|
setup: {
|
||||||
|
/**
|
||||||
|
* One-time secret for creating the first administrator on a fresh deployment.
|
||||||
|
* Set INITIAL_SETUP_TOKEN in production (min. 32 random characters).
|
||||||
|
*/
|
||||||
|
token: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
//# sourceMappingURL=index.d.ts.map
|
||||||
1
backend/dist/config/index.d.ts.map
vendored
Normal file
1
backend/dist/config/index.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkEH,kFAAkF;AAClF,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;YAoBb,kIAAkI;;;;;;;YAOlI,iFAAiF;;;;;;;;;;;;QAgBnF,kFAAkF;;QAElF,4FAA4F;;;;;;;QAU5F,kEAAkE;;;QAGlE,gDAAgD;;QAEhD,0DAA0D;;QAE1D,2DAA2D;;;;QAI3D,iFAAiF;;;;;;QAMjF,6FAA6F;;;;QAI7F,gEAAgE;;;;;;;;;;QAUhE,+DAA+D;;;;;;;;;;;;;;QAc/D,iEAAiE;;QAEjE,8DAA8D;;QAE9D,4DAA4D;;;;;QAK5D,oEAAoE;;QAIpE,6DAA6D;;QAE7D,2EAA2E;;;;;;;;;IAS7E,mFAAmF;;;QAGjF;;;WAGG;;;CAKN,CAAC"}
|
||||||
197
backend/dist/config/index.js
vendored
Normal file
197
backend/dist/config/index.js
vendored
Normal file
@ -0,0 +1,197 @@
|
|||||||
|
"use strict";
|
||||||
|
/**
|
||||||
|
* Application configuration loaded from environment variables.
|
||||||
|
* Centralizes defaults for server, database, JWT, encryption, blockchain, and safety settings.
|
||||||
|
*/
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.config = void 0;
|
||||||
|
const dotenv_1 = __importDefault(require("dotenv"));
|
||||||
|
const path_1 = __importDefault(require("path"));
|
||||||
|
const MAIL_ENV_KEYS = [
|
||||||
|
'EMAIL_TRANSPORT',
|
||||||
|
'SMTP_HOST',
|
||||||
|
'SMTP_PORT',
|
||||||
|
'SMTP_SECURE',
|
||||||
|
'SMTP_USER',
|
||||||
|
'SMTP_PASS',
|
||||||
|
'EMAIL_FROM',
|
||||||
|
'APP_PUBLIC_URL',
|
||||||
|
'VERIFY_EMAIL_PATH',
|
||||||
|
'RESET_PASSWORD_PATH',
|
||||||
|
'PASSWORD_RESET_EXPIRY_HOURS',
|
||||||
|
'EMAIL_VERIFICATION_EXPIRY_HOURS',
|
||||||
|
'EMAIL_VERIFICATION_SEND_MAX',
|
||||||
|
'PASSWORD_RESET_SEND_MAX',
|
||||||
|
];
|
||||||
|
function isSmtpEnvConfigured() {
|
||||||
|
return !!(process.env.SMTP_HOST &&
|
||||||
|
process.env.SMTP_USER &&
|
||||||
|
process.env.SMTP_PASS &&
|
||||||
|
process.env.EMAIL_FROM);
|
||||||
|
}
|
||||||
|
function resolveEmailTransport() {
|
||||||
|
const preferred = (process.env.EMAIL_TRANSPORT || '').toLowerCase();
|
||||||
|
if (preferred === 'console')
|
||||||
|
return 'console';
|
||||||
|
if (preferred === 'smtp')
|
||||||
|
return isSmtpEnvConfigured() ? 'smtp' : 'console';
|
||||||
|
return isSmtpEnvConfigured() ? 'smtp' : 'console';
|
||||||
|
}
|
||||||
|
function loadEnvFiles() {
|
||||||
|
const cwd = process.cwd();
|
||||||
|
const envFile = process.env.ENV_FILE || '.env';
|
||||||
|
dotenv_1.default.config({ path: path_1.default.resolve(cwd, envFile) });
|
||||||
|
// Repo-root .env often holds SMTP settings while backend/.env keeps local dev overrides.
|
||||||
|
const rootResult = dotenv_1.default.config({ path: path_1.default.resolve(cwd, '..', '.env') });
|
||||||
|
if (rootResult.parsed) {
|
||||||
|
for (const key of MAIL_ENV_KEYS) {
|
||||||
|
const value = rootResult.parsed[key];
|
||||||
|
if (value !== undefined && value !== '') {
|
||||||
|
process.env[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loadEnvFiles();
|
||||||
|
function readEnvInt(key, fallback, min, max) {
|
||||||
|
const raw = process.env[key];
|
||||||
|
if (!raw)
|
||||||
|
return fallback;
|
||||||
|
const n = parseInt(raw, 10);
|
||||||
|
if (!Number.isFinite(n))
|
||||||
|
return fallback;
|
||||||
|
return Math.min(max, Math.max(min, n));
|
||||||
|
}
|
||||||
|
/** Resolved runtime configuration derived from process.env with safe defaults. */
|
||||||
|
exports.config = {
|
||||||
|
env: process.env.NODE_ENV || 'development',
|
||||||
|
port: parseInt(process.env.PORT || '4000', 10),
|
||||||
|
apiPrefix: process.env.API_PREFIX || '/api/v1',
|
||||||
|
database: {
|
||||||
|
url: process.env.DATABASE_URL || '',
|
||||||
|
},
|
||||||
|
jwt: {
|
||||||
|
secret: process.env.JWT_SECRET || 'change-me-in-production',
|
||||||
|
accessExpiry: process.env.JWT_ACCESS_EXPIRY || '15m',
|
||||||
|
refreshExpiry: process.env.JWT_REFRESH_EXPIRY || '7d',
|
||||||
|
},
|
||||||
|
encryption: {
|
||||||
|
key: process.env.ENCRYPTION_KEY || '',
|
||||||
|
},
|
||||||
|
blockchain: {
|
||||||
|
tron: {
|
||||||
|
nodeUrl: process.env.TRON_NODE_URL || 'https://api.trongrid.io',
|
||||||
|
apiKey: process.env.TRON_API_KEY || '',
|
||||||
|
confirmations: parseInt(process.env.TRON_CONFIRMATIONS || '20', 10),
|
||||||
|
/** Optional override for USDT TRC20 contract (e.g. testnet token). When set, used instead of DB wallet_types.contract_address. */
|
||||||
|
usdtTrc20Contract: process.env.USDT_TRC20_CONTRACT || null,
|
||||||
|
},
|
||||||
|
polygon: {
|
||||||
|
rpcUrl: process.env.POLYGON_RPC_URL || 'https://polygon-rpc.com',
|
||||||
|
usdcContract: process.env.USDC_POLYGON_CONTRACT || '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359',
|
||||||
|
confirmations: parseInt(process.env.POLYGON_CONFIRMATIONS || '64', 10),
|
||||||
|
/** Max blocks per eth_getLogs call; Amoy public RPC rejects ~500-block ranges */
|
||||||
|
getLogsBlockRange: parseInt(process.env.POLYGON_GETLOGS_BLOCK_RANGE || '100', 10),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rateLimit: {
|
||||||
|
windowMs: parseInt(process.env.RATE_LIMIT_WINDOW_MS || '900000', 10),
|
||||||
|
max: parseInt(process.env.RATE_LIMIT_MAX ||
|
||||||
|
(process.env.NODE_ENV === 'development' ? '2000' : '100'), 10),
|
||||||
|
loginMax: parseInt(process.env.LOGIN_RATE_LIMIT_MAX || '5', 10),
|
||||||
|
},
|
||||||
|
withdrawal: {
|
||||||
|
dailyLimitUsd: parseInt(process.env.DAILY_WITHDRAWAL_LIMIT_USD || '10000', 10),
|
||||||
|
largeThresholdUsd: parseInt(process.env.LARGE_WITHDRAWAL_THRESHOLD_USD || '1000', 10),
|
||||||
|
/** Kill-switch: prevents broadcasting real chain txs unless explicitly enabled */
|
||||||
|
allowWithdrawals: process.env.ALLOW_WITHDRAWALS === 'true',
|
||||||
|
/** Default network fee in USDT micro-units (6 decimals); admin can override in Settings. */
|
||||||
|
networkFeeUsdtMicro: parseInt(process.env.WITHDRAWAL_NETWORK_FEE_USDT_MICRO || '2000000', 10),
|
||||||
|
},
|
||||||
|
security: {
|
||||||
|
integrityCheckIntervalMs: parseInt(process.env.SECURITY_INTEGRITY_CHECK_INTERVAL_MS || '300000', 10),
|
||||||
|
},
|
||||||
|
treasury: {
|
||||||
|
/** Moves on-chain deposits from user addresses to cold storage */
|
||||||
|
sweepEnabled: process.env.SWEEP_ENABLED === 'true',
|
||||||
|
sweepPollIntervalMs: parseInt(process.env.SWEEP_POLL_INTERVAL_MS || '120000', 10),
|
||||||
|
/** Minimum token amount (raw units) to sweep */
|
||||||
|
sweepMinAmountRaw: process.env.SWEEP_MIN_AMOUNT_RAW || '1000000',
|
||||||
|
/** TRX sent from hot wallet to fund TRC20 sweeps (sun) */
|
||||||
|
tronGasTopUpSun: process.env.SWEEP_TRON_GAS_TOPUP_SUN || '15000000',
|
||||||
|
/** MATIC sent from hot wallet to fund USDC sweeps (wei) */
|
||||||
|
polygonGasTopUpWei: process.env.SWEEP_POLYGON_GAS_TOPUP_WEI || '100000000000000000',
|
||||||
|
},
|
||||||
|
app: {
|
||||||
|
/** Public web app URL used in verification links (e.g. http://localhost:5173) */
|
||||||
|
publicUrl: process.env.APP_PUBLIC_URL || 'http://localhost:5173',
|
||||||
|
verifyEmailPath: process.env.VERIFY_EMAIL_PATH || '/verify-email',
|
||||||
|
resetPasswordPath: process.env.RESET_PASSWORD_PATH || '/reset-password',
|
||||||
|
},
|
||||||
|
countries: {
|
||||||
|
/** Optional REST Countries v5 API key. When unset, sync uses the ISO 3166 public catalog. */
|
||||||
|
restCountriesApiKey: process.env.REST_COUNTRIES_API_KEY || '',
|
||||||
|
},
|
||||||
|
deposit: {
|
||||||
|
/** Platform asset for deposits and predictions (USDT TRC20). */
|
||||||
|
walletTypeCode: process.env.PREDICTION_WALLET_TYPE || 'USDT_TRC20',
|
||||||
|
},
|
||||||
|
candlePredict: {
|
||||||
|
engineTickMs: readEnvInt('CANDLE_PREDICT_ENGINE_TICK_MS', 3000, 1000, 60000),
|
||||||
|
backfillMaxPerTick: readEnvInt('CANDLE_PREDICT_BACKFILL_MAX_PER_TICK', 2, 1, 50),
|
||||||
|
backfillIntervalMs: readEnvInt('CANDLE_PREDICT_BACKFILL_INTERVAL_MS', 60000, 10000, 600000),
|
||||||
|
backfillSeedMax: readEnvInt('CANDLE_PREDICT_BACKFILL_SEED_MAX', 15, 5, 120),
|
||||||
|
},
|
||||||
|
email: {
|
||||||
|
/** smtp = send via SMTP; console = log link to stdout (dev) */
|
||||||
|
transport: resolveEmailTransport(),
|
||||||
|
host: process.env.SMTP_HOST || '',
|
||||||
|
port: parseInt(process.env.SMTP_PORT || '587', 10),
|
||||||
|
secure: process.env.SMTP_SECURE === 'true',
|
||||||
|
user: process.env.SMTP_USER || '',
|
||||||
|
pass: process.env.SMTP_PASS || '',
|
||||||
|
from: process.env.EMAIL_FROM || '',
|
||||||
|
verificationExpiryHours: parseInt(process.env.EMAIL_VERIFICATION_EXPIRY_HOURS || '24', 10),
|
||||||
|
verificationSendMax: parseInt(process.env.EMAIL_VERIFICATION_SEND_MAX || '5', 10),
|
||||||
|
passwordResetExpiryHours: parseInt(process.env.PASSWORD_RESET_EXPIRY_HOURS || '1', 10),
|
||||||
|
passwordResetSendMax: parseInt(process.env.PASSWORD_RESET_SEND_MAX || '5', 10),
|
||||||
|
},
|
||||||
|
slack: {
|
||||||
|
/** Legacy fallback when channel-specific webhooks are not set */
|
||||||
|
webhookUrl: process.env.SLACK_WEBHOOK_URL || '',
|
||||||
|
/** #security — withdrawals, auth, platform security alerts */
|
||||||
|
securityWebhookUrl: process.env.SLACK_SECURITY_WEBHOOK_URL || '',
|
||||||
|
/** #referral-fraud — cap blocks, clawbacks, Sybil review */
|
||||||
|
referralWebhookUrl: process.env.SLACK_REFERRAL_WEBHOOK_URL || '',
|
||||||
|
},
|
||||||
|
redis: {
|
||||||
|
url: process.env.REDIS_URL || '',
|
||||||
|
/** Auto-enabled when REDIS_URL is set unless REDIS_ENABLED=false */
|
||||||
|
enabled: process.env.REDIS_ENABLED === 'true' ||
|
||||||
|
(!!process.env.REDIS_URL && process.env.REDIS_ENABLED !== 'false'),
|
||||||
|
/** Phase B: read round state from Redis before PostgreSQL */
|
||||||
|
roundCacheEnabled: process.env.REDIS_ROUND_CACHE === 'true',
|
||||||
|
/** Phase B+: enqueue single bets to Redis Stream (requires worker-bets) */
|
||||||
|
betAsyncEnabled: process.env.BET_ASYNC === 'true',
|
||||||
|
},
|
||||||
|
ws: {
|
||||||
|
enabled: process.env.WS_ENABLED === 'true',
|
||||||
|
port: parseInt(process.env.WS_PORT || '4001', 10),
|
||||||
|
path: process.env.WS_PATH || '/ws/v1/games/candle-predict',
|
||||||
|
supportPath: process.env.WS_SUPPORT_PATH || '/ws/v1/support',
|
||||||
|
},
|
||||||
|
/** When false, API process skips starting game engines (use app-engine instead) */
|
||||||
|
engineEnabled: process.env.ENGINE_ENABLED !== 'false',
|
||||||
|
setup: {
|
||||||
|
/**
|
||||||
|
* One-time secret for creating the first administrator on a fresh deployment.
|
||||||
|
* Set INITIAL_SETUP_TOKEN in production (min. 32 random characters).
|
||||||
|
*/
|
||||||
|
token: process.env.INITIAL_SETUP_TOKEN ||
|
||||||
|
(process.env.NODE_ENV === 'development' ? 'dev-setup-change-me' : ''),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
//# sourceMappingURL=index.js.map
|
||||||
1
backend/dist/config/index.js.map
vendored
Normal file
1
backend/dist/config/index.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
21
backend/dist/controllers/adminController.d.ts
vendored
Normal file
21
backend/dist/controllers/adminController.d.ts
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* Admin controller — HTTP handlers for admin user management endpoints.
|
||||||
|
* Delegates all business logic to adminService.
|
||||||
|
*/
|
||||||
|
import { Response } from 'express';
|
||||||
|
import { AuthRequest } from '../middleware/auth';
|
||||||
|
/**
|
||||||
|
* Lists users for the admin panel with optional search, filters, sorting, and pagination.
|
||||||
|
*/
|
||||||
|
export declare function listUsers(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function startUsersExport(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function getUsersExportStatus(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function downloadUsersExport(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function updateUserFlags(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function batchUpdateUserFlags(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function batchUpdateUserSecurity(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function batchGrantLedgerCredit(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function verifyUserEmail(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function getUserDetails(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function updateUserRole(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
//# sourceMappingURL=adminController.d.ts.map
|
||||||
1
backend/dist/controllers/adminController.d.ts.map
vendored
Normal file
1
backend/dist/controllers/adminController.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"adminController.d.ts","sourceRoot":"","sources":["../../src/controllers/adminController.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AASjD;;GAEG;AACH,wBAAsB,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAiB9E;AAED,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAkCrF;AAED,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAYzF;AAED,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAmBxF;AAED,wBAAsB,eAAe,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBpF;AAED,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAmBzF;AAED,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAyB5F;AAED,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CA6B3F;AAED,wBAAsB,eAAe,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAWpF;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAUnF;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAenF"}
|
||||||
252
backend/dist/controllers/adminController.js
vendored
Normal file
252
backend/dist/controllers/adminController.js
vendored
Normal file
@ -0,0 +1,252 @@
|
|||||||
|
"use strict";
|
||||||
|
/**
|
||||||
|
* Admin controller — HTTP handlers for admin user management endpoints.
|
||||||
|
* Delegates all business logic to adminService.
|
||||||
|
*/
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || (function () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.listUsers = listUsers;
|
||||||
|
exports.startUsersExport = startUsersExport;
|
||||||
|
exports.getUsersExportStatus = getUsersExportStatus;
|
||||||
|
exports.downloadUsersExport = downloadUsersExport;
|
||||||
|
exports.updateUserFlags = updateUserFlags;
|
||||||
|
exports.batchUpdateUserFlags = batchUpdateUserFlags;
|
||||||
|
exports.batchUpdateUserSecurity = batchUpdateUserSecurity;
|
||||||
|
exports.batchGrantLedgerCredit = batchGrantLedgerCredit;
|
||||||
|
exports.verifyUserEmail = verifyUserEmail;
|
||||||
|
exports.getUserDetails = getUserDetails;
|
||||||
|
exports.updateUserRole = updateUserRole;
|
||||||
|
const adminService = __importStar(require("../services/adminService"));
|
||||||
|
const adminUserExportService = __importStar(require("../services/adminUserExportService"));
|
||||||
|
const adminUserListQuery_1 = require("../utils/adminUserListQuery");
|
||||||
|
/**
|
||||||
|
* Lists users for the admin panel with optional search, filters, sorting, and pagination.
|
||||||
|
*/
|
||||||
|
async function listUsers(req, res) {
|
||||||
|
try {
|
||||||
|
const options = (0, adminUserListQuery_1.parseAdminUserListOptions)(req.query);
|
||||||
|
const minAge = options.minAge;
|
||||||
|
const maxAge = options.maxAge;
|
||||||
|
if (minAge !== undefined && maxAge !== undefined && minAge > maxAge) {
|
||||||
|
res.status(400).json({ error: 'minAge cannot be greater than maxAge' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await adminService.listUsers(options);
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to list users';
|
||||||
|
res.status(500).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function startUsersExport(req, res) {
|
||||||
|
try {
|
||||||
|
const body = req.body ?? {};
|
||||||
|
const minAge = (0, adminUserListQuery_1.parseAgeQuery)(body.minAge);
|
||||||
|
const maxAge = (0, adminUserListQuery_1.parseAgeQuery)(body.maxAge);
|
||||||
|
if (minAge !== undefined && maxAge !== undefined && minAge > maxAge) {
|
||||||
|
res.status(400).json({ error: 'minAge cannot be greater than maxAge' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const listOptions = (0, adminUserListQuery_1.parseAdminUserListOptions)(body, { limit: 100, includeTotal: false });
|
||||||
|
const userIds = Array.isArray(body.userIds)
|
||||||
|
? body.userIds.filter((id) => typeof id === 'string' && id.trim()).map((id) => id.trim())
|
||||||
|
: undefined;
|
||||||
|
const maxRowsRaw = body.maxRows;
|
||||||
|
const maxRows = maxRowsRaw === undefined || maxRowsRaw === null || String(maxRowsRaw).trim() === ''
|
||||||
|
? undefined
|
||||||
|
: parseInt(String(maxRowsRaw), 10);
|
||||||
|
const job = await adminUserExportService.startAdminUserExport(req.user.userId, {
|
||||||
|
...listOptions,
|
||||||
|
columns: (0, adminUserListQuery_1.sanitizeExportColumns)(body.columns),
|
||||||
|
maxRows: Number.isFinite(maxRows) && (maxRows ?? 0) > 0 ? maxRows : undefined,
|
||||||
|
userIds: userIds?.length ? userIds : undefined,
|
||||||
|
format: body.format === 'csv' ? 'csv' : 'xlsx',
|
||||||
|
});
|
||||||
|
res.status(202).json(job);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to start export';
|
||||||
|
res.status(500).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function getUsersExportStatus(req, res) {
|
||||||
|
try {
|
||||||
|
const job = await adminUserExportService.getAdminUserExportJob(req.params.jobId, req.user.userId);
|
||||||
|
if (!job) {
|
||||||
|
res.status(404).json({ error: 'Export job not found' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res.json(job);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to get export status';
|
||||||
|
res.status(500).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function downloadUsersExport(req, res) {
|
||||||
|
try {
|
||||||
|
const file = await adminUserExportService.getAdminUserExportFilePath(req.params.jobId, req.user.userId);
|
||||||
|
if (!file) {
|
||||||
|
res.status(404).json({ error: 'Export file not ready' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const mime = file.fileName.endsWith('.csv') ?
|
||||||
|
'text/csv; charset=utf-8'
|
||||||
|
: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
||||||
|
res.download(file.filePath, file.fileName, { headers: { 'Content-Type': mime } });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to download export';
|
||||||
|
res.status(500).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function updateUserFlags(req, res) {
|
||||||
|
try {
|
||||||
|
const userId = req.params.userId;
|
||||||
|
const { isEnabled, isAccountNonExpired, isAccountNonLocked, isCredentialsNonExpired } = req.body;
|
||||||
|
await adminService.updateUserAccountFlags(userId, {
|
||||||
|
isEnabled,
|
||||||
|
isAccountNonExpired,
|
||||||
|
isAccountNonLocked,
|
||||||
|
isCredentialsNonExpired,
|
||||||
|
});
|
||||||
|
res.json({ message: 'Updated' });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Update failed';
|
||||||
|
const status = msg === 'User not found' ? 404 : 400;
|
||||||
|
res.status(status).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function batchUpdateUserFlags(req, res) {
|
||||||
|
try {
|
||||||
|
const { userIds, ...flags } = req.body;
|
||||||
|
if (!Array.isArray(userIds) || userIds.length === 0) {
|
||||||
|
res.status(400).json({ error: 'userIds array is required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await adminService.batchUpdateUserAccountFlags(userIds, flags);
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Batch update failed';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function batchUpdateUserSecurity(req, res) {
|
||||||
|
try {
|
||||||
|
const { userIds, withdrawalsSuspended, underSurveillance, reactivateWithdrawals, reason } = req.body;
|
||||||
|
if (!Array.isArray(userIds) || userIds.length === 0) {
|
||||||
|
res.status(400).json({ error: 'userIds array is required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await adminService.batchUpdateUserSecurity(userIds, {
|
||||||
|
withdrawalsSuspended,
|
||||||
|
underSurveillance,
|
||||||
|
reactivateWithdrawals,
|
||||||
|
reason,
|
||||||
|
});
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Batch security update failed';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function batchGrantLedgerCredit(req, res) {
|
||||||
|
try {
|
||||||
|
const { userIds, walletTypeId, adjustmentType, amountRaw, reason } = req.body;
|
||||||
|
if (!Array.isArray(userIds) || userIds.length === 0) {
|
||||||
|
res.status(400).json({ error: 'userIds array is required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!walletTypeId || !adjustmentType || !amountRaw || !reason) {
|
||||||
|
res.status(400).json({
|
||||||
|
error: 'walletTypeId, adjustmentType, amountRaw, and reason are required',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await adminService.batchGrantLedgerCredit(userIds, { walletTypeId, adjustmentType, amountRaw, reason }, req.user.userId);
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Batch credit failed';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function verifyUserEmail(req, res) {
|
||||||
|
try {
|
||||||
|
const userId = req.params.userId;
|
||||||
|
const adminUserId = req.user.userId;
|
||||||
|
const result = await adminService.markUserEmailVerified(userId, adminUserId);
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Verification failed';
|
||||||
|
const status = msg === 'User not found' ? 404 : 400;
|
||||||
|
res.status(status).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function getUserDetails(req, res) {
|
||||||
|
try {
|
||||||
|
const userId = req.params.userId;
|
||||||
|
const details = await adminService.getUserDetails(userId);
|
||||||
|
res.json(details);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to load user details';
|
||||||
|
const status = msg === 'User not found' ? 404 : 500;
|
||||||
|
res.status(status).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function updateUserRole(req, res) {
|
||||||
|
try {
|
||||||
|
const userId = req.params.userId;
|
||||||
|
const { role } = req.body;
|
||||||
|
if (!role) {
|
||||||
|
res.status(400).json({ error: 'role is required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await adminService.updateUserRole(userId, role, req.user.userId);
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to update role';
|
||||||
|
const status = msg === 'User not found' ? 404 : 400;
|
||||||
|
res.status(status).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=adminController.js.map
|
||||||
1
backend/dist/controllers/adminController.js.map
vendored
Normal file
1
backend/dist/controllers/adminController.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
5
backend/dist/controllers/adminCreditController.d.ts
vendored
Normal file
5
backend/dist/controllers/adminCreditController.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { Response } from 'express';
|
||||||
|
import { AuthRequest } from '../middleware/auth';
|
||||||
|
export declare function grantCredit(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function listCredits(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
//# sourceMappingURL=adminCreditController.d.ts.map
|
||||||
1
backend/dist/controllers/adminCreditController.d.ts.map
vendored
Normal file
1
backend/dist/controllers/adminCreditController.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"adminCreditController.d.ts","sourceRoot":"","sources":["../../src/controllers/adminCreditController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,wBAAsB,WAAW,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CA+BhF;AAED,wBAAsB,WAAW,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAWhF"}
|
||||||
77
backend/dist/controllers/adminCreditController.js
vendored
Normal file
77
backend/dist/controllers/adminCreditController.js
vendored
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
"use strict";
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || (function () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.grantCredit = grantCredit;
|
||||||
|
exports.listCredits = listCredits;
|
||||||
|
const adminCreditService = __importStar(require("../services/adminCreditService"));
|
||||||
|
async function grantCredit(req, res) {
|
||||||
|
try {
|
||||||
|
const userId = req.params.userId;
|
||||||
|
const { walletTypeId, adjustmentType, amountRaw, reason } = req.body;
|
||||||
|
if (!walletTypeId || !adjustmentType || !amountRaw || !reason) {
|
||||||
|
res.status(400).json({
|
||||||
|
error: 'walletTypeId, adjustmentType, amountRaw, and reason are required',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await adminCreditService.grantLedgerCredit({
|
||||||
|
userId,
|
||||||
|
walletTypeId,
|
||||||
|
adjustmentType,
|
||||||
|
amountRaw,
|
||||||
|
reason,
|
||||||
|
approvedBy: req.user.userId,
|
||||||
|
});
|
||||||
|
res.status(201).json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Credit failed';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function listCredits(req, res) {
|
||||||
|
try {
|
||||||
|
const userId = req.query.userId || undefined;
|
||||||
|
const limit = parseInt(req.query.limit || '50', 10);
|
||||||
|
const offset = parseInt(req.query.offset || '0', 10);
|
||||||
|
const result = await adminCreditService.listLedgerCredits({ userId, limit, offset });
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to list credits';
|
||||||
|
res.status(500).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=adminCreditController.js.map
|
||||||
1
backend/dist/controllers/adminCreditController.js.map
vendored
Normal file
1
backend/dist/controllers/adminCreditController.js.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"adminCreditController.js","sourceRoot":"","sources":["../../src/controllers/adminCreditController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,kCA+BC;AAED,kCAWC;AA9CD,mFAAqE;AAE9D,KAAK,UAAU,WAAW,CAAC,GAAgB,EAAE,GAAa;IAC/D,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;QACjC,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,IAK/D,CAAC;QAEF,IAAI,CAAC,YAAY,IAAI,CAAC,cAAc,IAAI,CAAC,SAAS,IAAI,CAAC,MAAM,EAAE,CAAC;YAC9D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACnB,KAAK,EAAE,kEAAkE;aAC1E,CAAC,CAAC;YACH,OAAO;QACT,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,iBAAiB,CAAC;YACx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,CAAC;IACvC,CAAC;AACH,CAAC"}
|
||||||
8
backend/dist/controllers/advertisementController.d.ts
vendored
Normal file
8
backend/dist/controllers/advertisementController.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { Response } from 'express';
|
||||||
|
import { AuthRequest } from '../middleware/auth';
|
||||||
|
export declare function listAdvertisements(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function listAdvertisementsAdmin(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function createAdvertisement(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function updateAdvertisement(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function deleteAdvertisement(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
//# sourceMappingURL=advertisementController.d.ts.map
|
||||||
1
backend/dist/controllers/advertisementController.d.ts.map
vendored
Normal file
1
backend/dist/controllers/advertisementController.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"advertisementController.d.ts","sourceRoot":"","sources":["../../src/controllers/advertisementController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CASvF;AAED,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ5F;AAED,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAQxF;AAED,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAYxF;AAED,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAQxF"}
|
||||||
94
backend/dist/controllers/advertisementController.js
vendored
Normal file
94
backend/dist/controllers/advertisementController.js
vendored
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
"use strict";
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || (function () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.listAdvertisements = listAdvertisements;
|
||||||
|
exports.listAdvertisementsAdmin = listAdvertisementsAdmin;
|
||||||
|
exports.createAdvertisement = createAdvertisement;
|
||||||
|
exports.updateAdvertisement = updateAdvertisement;
|
||||||
|
exports.deleteAdvertisement = deleteAdvertisement;
|
||||||
|
const advertisementService = __importStar(require("../services/advertisementService"));
|
||||||
|
async function listAdvertisements(req, res) {
|
||||||
|
try {
|
||||||
|
const placement = req.query.placement || undefined;
|
||||||
|
const ads = await advertisementService.listAdvertisements(placement);
|
||||||
|
res.json(ads);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to load advertisements';
|
||||||
|
res.status(500).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function listAdvertisementsAdmin(req, res) {
|
||||||
|
try {
|
||||||
|
const ads = await advertisementService.listAllAdvertisementsAdmin();
|
||||||
|
res.json(ads);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to load advertisements';
|
||||||
|
res.status(500).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function createAdvertisement(req, res) {
|
||||||
|
try {
|
||||||
|
const ad = await advertisementService.createAdvertisement(req.body);
|
||||||
|
res.status(201).json(ad);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to create advertisement';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function updateAdvertisement(req, res) {
|
||||||
|
try {
|
||||||
|
const ad = await advertisementService.updateAdvertisement(req.params.id, req.body);
|
||||||
|
res.json(ad);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to update advertisement';
|
||||||
|
const status = msg === 'Advertisement not found' ? 404 : 400;
|
||||||
|
res.status(status).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function deleteAdvertisement(req, res) {
|
||||||
|
try {
|
||||||
|
await advertisementService.deleteAdvertisement(req.params.id);
|
||||||
|
res.status(204).send();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to delete advertisement';
|
||||||
|
res.status(msg === 'Advertisement not found' ? 404 : 400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=advertisementController.js.map
|
||||||
1
backend/dist/controllers/advertisementController.js.map
vendored
Normal file
1
backend/dist/controllers/advertisementController.js.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"advertisementController.js","sourceRoot":"","sources":["../../src/controllers/advertisementController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,gDASC;AAED,0DAQC;AAED,kDAQC;AAED,kDAYC;AAED,kDAQC;AAvDD,uFAAyE;AAElE,KAAK,UAAU,kBAAkB,CAAC,GAAgB,EAAE,GAAa;IACtE,IAAI,CAAC;QACH,MAAM,SAAS,GAAI,GAAG,CAAC,KAAK,CAAC,SAAoB,IAAI,SAAS,CAAC;QAC/D,MAAM,GAAG,GAAG,MAAM,oBAAoB,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;QACrE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,GAAG,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,+BAA+B,CAAC;QAC7E,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IACvC,CAAC;AACH,CAAC;AAEM,KAAK,UAAU,uBAAuB,CAAC,GAAgB,EAAE,GAAa;IAC3E,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MA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C,OAAO,CAAC,CAAC,CAAC,gCAAgC,CAAC;QAC9E,MAAM,MAAM,GAAG,GAAG,KAAK,yBAAyB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;QAC7D,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC;AAEM,KAAK,UAAU,mBAAmB,CAAC,GAAgB,EAAE,GAAa;IACvE,IAAI,CAAC;QACH,MAAM,oBAAoB,CAAC,mBAAmB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC9D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,GAAG,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,gCAAgC,CAAC;QAC9E,GAAG,CAAC,MAAM,CAAC,GAAG,KAAK,yBAAyB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IACjF,CAAC;AACH,CAAC"}
|
||||||
5
backend/dist/controllers/analyticsController.d.ts
vendored
Normal file
5
backend/dist/controllers/analyticsController.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { Response } from 'express';
|
||||||
|
import { AuthRequest } from '../middleware/auth';
|
||||||
|
/** Returns full admin dashboard analytics for the selected filters. */
|
||||||
|
export declare function getDashboardAnalytics(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
//# sourceMappingURL=analyticsController.d.ts.map
|
||||||
1
backend/dist/controllers/analyticsController.d.ts.map
vendored
Normal file
1
backend/dist/controllers/analyticsController.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"analyticsController.d.ts","sourceRoot":"","sources":["../../src/controllers/analyticsController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,uEAAuE;AACvE,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAY1F"}
|
||||||
53
backend/dist/controllers/analyticsController.js
vendored
Normal file
53
backend/dist/controllers/analyticsController.js
vendored
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
"use strict";
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || (function () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.getDashboardAnalytics = getDashboardAnalytics;
|
||||||
|
const analyticsService = __importStar(require("../services/analyticsService"));
|
||||||
|
/** Returns full admin dashboard analytics for the selected filters. */
|
||||||
|
async function getDashboardAnalytics(req, res) {
|
||||||
|
try {
|
||||||
|
const preset = typeof req.query.preset === 'string' ? req.query.preset : undefined;
|
||||||
|
const from = typeof req.query.from === 'string' ? req.query.from : undefined;
|
||||||
|
const to = typeof req.query.to === 'string' ? req.query.to : undefined;
|
||||||
|
const gameKey = typeof req.query.gameKey === 'string' ? req.query.gameKey : undefined;
|
||||||
|
const data = await analyticsService.getAdminDashboardAnalytics({ preset, from, to, gameKey });
|
||||||
|
res.json(data);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to load dashboard analytics';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=analyticsController.js.map
|
||||||
1
backend/dist/controllers/analyticsController.js.map
vendored
Normal file
1
backend/dist/controllers/analyticsController.js.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"analyticsController.js","sourceRoot":"","sources":["../../src/controllers/analyticsController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,sDAYC;AAfD,+EAAiE;AAEjE,uEAAuE;AAChE,KAAK,UAAU,qBAAqB,CAAC,GAAgB,EAAE,GAAa;IACzE,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,OAAO,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;QACnF,MAAM,IAAI,GAAG,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;QAC7E,MAAM,EAAE,GAAG,OAAO,GAAG,CAAC,KAAK,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QACvE,MAAM,OAAO,GAAG,OAAO,GAAG,CAAC,KAAK,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;QACtF,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,0BAA0B,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAC9F,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,GAAG,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,oCAAoC,CAAC;QAClF,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
|
||||||
59
backend/dist/controllers/authController.d.ts
vendored
Normal file
59
backend/dist/controllers/authController.d.ts
vendored
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/**
|
||||||
|
* Auth controller — HTTP handlers for registration, login, token refresh, 2FA, and password changes.
|
||||||
|
*/
|
||||||
|
import { Request, Response } from 'express';
|
||||||
|
import { AuthRequest } from '../middleware/auth';
|
||||||
|
/**
|
||||||
|
* Registers a new user with email and password.
|
||||||
|
* @param req - Request body: `email`, `password`.
|
||||||
|
* @param res - 201 with `{ message, userId }` on success, 400 on validation or registration failure.
|
||||||
|
*/
|
||||||
|
export declare function register(req: Request, res: Response): Promise<void>;
|
||||||
|
export declare function validateReferralCode(req: Request, res: Response): Promise<void>;
|
||||||
|
/**
|
||||||
|
* Authenticates a user with email and password, optionally requiring a TOTP code when 2FA is enabled.
|
||||||
|
* @param req - Request body: `email`, `password`, optional `totpCode`. IP and user-agent are forwarded for audit.
|
||||||
|
* @param res - JSON with access/refresh tokens on success, 401 on invalid credentials.
|
||||||
|
*/
|
||||||
|
export declare function login(req: Request, res: Response): Promise<void>;
|
||||||
|
/**
|
||||||
|
* Issues a new access/refresh token pair using a valid refresh token.
|
||||||
|
* @param req - Request body: `refreshToken`.
|
||||||
|
* @param res - JSON with new tokens on success, 401 if the refresh token is invalid or expired.
|
||||||
|
*/
|
||||||
|
export declare function refresh(req: Request, res: Response): Promise<void>;
|
||||||
|
/**
|
||||||
|
* Starts TOTP 2FA setup for the authenticated user and returns the secret and QR code data.
|
||||||
|
* @param req - Authenticated request; user ID is taken from the JWT.
|
||||||
|
* @param res - JSON with TOTP setup details on success, 400 on failure.
|
||||||
|
*/
|
||||||
|
export declare function setup2FA(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
/**
|
||||||
|
* Confirms and enables TOTP 2FA for the authenticated user using a verification code.
|
||||||
|
* @param req - Authenticated request. Body: `code` (TOTP verification code).
|
||||||
|
* @param res - JSON `{ message: '2FA enabled' }` on success, 400 if the code is missing or invalid.
|
||||||
|
*/
|
||||||
|
export declare function enable2FA(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
/**
|
||||||
|
* Changes the authenticated user's password after verifying the current password.
|
||||||
|
* @param req - Authenticated request. Body: `currentPassword`, `newPassword`.
|
||||||
|
* @param res - JSON `{ message: 'Password updated' }` on success, 400 on validation or auth failure.
|
||||||
|
*/
|
||||||
|
export declare function changePassword(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
/**
|
||||||
|
* Sends a verification email to the authenticated user's address on file.
|
||||||
|
* @param req - Authenticated request
|
||||||
|
* @param res - JSON with success message; includes devVerifyUrl in non-production console mode
|
||||||
|
*/
|
||||||
|
export declare function sendVerificationEmail(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
/**
|
||||||
|
* Confirms email ownership using a single-use token from the verification link.
|
||||||
|
* @param req - Body or query: `token`
|
||||||
|
* @param res - JSON success message on valid token
|
||||||
|
*/
|
||||||
|
export declare function verifyEmail(req: Request, res: Response): Promise<void>;
|
||||||
|
export declare function resendVerificationEmail(req: Request, res: Response): Promise<void>;
|
||||||
|
export declare function forgotPassword(req: Request, res: Response): Promise<void>;
|
||||||
|
export declare function resetPassword(req: Request, res: Response): Promise<void>;
|
||||||
|
export declare function validateResetToken(req: Request, res: Response): Promise<void>;
|
||||||
|
//# sourceMappingURL=authController.d.ts.map
|
||||||
1
backend/dist/controllers/authController.d.ts.map
vendored
Normal file
1
backend/dist/controllers/authController.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"authController.d.ts","sourceRoot":"","sources":["../../src/controllers/authController.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD;;;;GAIG;AACH,wBAAsB,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CA0CzE;AAED,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAcrF;AAED;;;;GAIG;AACH,wBAAsB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAmB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-0,0 +1,305 @@
|
|||||||
|
"use strict";
|
||||||
|
/**
|
||||||
|
* Auth controller — HTTP handlers for registration, login, token refresh, 2FA, and password changes.
|
||||||
|
*/
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || (function () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.register = register;
|
||||||
|
exports.validateReferralCode = validateReferralCode;
|
||||||
|
exports.login = login;
|
||||||
|
exports.refresh = refresh;
|
||||||
|
exports.setup2FA = setup2FA;
|
||||||
|
exports.enable2FA = enable2FA;
|
||||||
|
exports.changePassword = changePassword;
|
||||||
|
exports.sendVerificationEmail = sendVerificationEmail;
|
||||||
|
exports.verifyEmail = verifyEmail;
|
||||||
|
exports.resendVerificationEmail = resendVerificationEmail;
|
||||||
|
exports.forgotPassword = forgotPassword;
|
||||||
|
exports.resetPassword = resetPassword;
|
||||||
|
exports.validateResetToken = validateResetToken;
|
||||||
|
const authService = __importStar(require("../services/authService"));
|
||||||
|
const emailVerificationService = __importStar(require("../services/emailVerificationService"));
|
||||||
|
const passwordResetService = __importStar(require("../services/passwordResetService"));
|
||||||
|
const optionalAuth_1 = require("../middleware/optionalAuth");
|
||||||
|
/**
|
||||||
|
* Registers a new user with email and password.
|
||||||
|
* @param req - Request body: `email`, `password`.
|
||||||
|
* @param res - 201 with `{ message, userId }` on success, 400 on validation or registration failure.
|
||||||
|
*/
|
||||||
|
async function register(req, res) {
|
||||||
|
try {
|
||||||
|
const { email, password, fullName, phone, countryOfResidence, nationality, referralCode, gender, } = req.body;
|
||||||
|
if (!email || !password || !fullName || !countryOfResidence || !gender) {
|
||||||
|
res.status(400).json({
|
||||||
|
error: 'email, password, fullName, countryOfResidence, and gender are required',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await authService.register({
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
fullName,
|
||||||
|
phone,
|
||||||
|
countryOfResidence,
|
||||||
|
nationality,
|
||||||
|
gender,
|
||||||
|
referralCode,
|
||||||
|
registrationIp: req.ip || undefined,
|
||||||
|
userAgent: req.get('user-agent') || undefined,
|
||||||
|
visitorSupportToken: (0, optionalAuth_1.readVisitorToken)(req),
|
||||||
|
});
|
||||||
|
res.status(201).json({
|
||||||
|
message: 'Registered. Please check your email and click the verification link before signing in.',
|
||||||
|
userId: result.userId,
|
||||||
|
referralCode: result.referralCode,
|
||||||
|
emailVerificationRequired: result.emailVerificationRequired,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Registration failed';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function validateReferralCode(req, res) {
|
||||||
|
try {
|
||||||
|
const code = (req.params.code || req.query.code);
|
||||||
|
if (!code) {
|
||||||
|
res.status(400).json({ error: 'Referral code required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { validateReferralCode: validate } = await Promise.resolve().then(() => __importStar(require('../services/referralService')));
|
||||||
|
const result = await validate(code);
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Validation failed';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Authenticates a user with email and password, optionally requiring a TOTP code when 2FA is enabled.
|
||||||
|
* @param req - Request body: `email`, `password`, optional `totpCode`. IP and user-agent are forwarded for audit.
|
||||||
|
* @param res - JSON with access/refresh tokens on success, 401 on invalid credentials.
|
||||||
|
*/
|
||||||
|
async function login(req, res) {
|
||||||
|
try {
|
||||||
|
const { email, password, totpCode } = req.body;
|
||||||
|
if (!email || !password) {
|
||||||
|
res.status(400).json({ error: 'Email and password required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await authService.login(email, password, totpCode, {
|
||||||
|
ipAddress: req.ip || undefined,
|
||||||
|
userAgent: req.get('user-agent') || undefined,
|
||||||
|
visitorSupportToken: (0, optionalAuth_1.readVisitorToken)(req),
|
||||||
|
});
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Login failed';
|
||||||
|
const code = e.code;
|
||||||
|
const status = code === 'EMAIL_NOT_VERIFIED' ? 403 : 401;
|
||||||
|
res.status(status).json(code ? { error: msg, code } : { error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Issues a new access/refresh token pair using a valid refresh token.
|
||||||
|
* @param req - Request body: `refreshToken`.
|
||||||
|
* @param res - JSON with new tokens on success, 401 if the refresh token is invalid or expired.
|
||||||
|
*/
|
||||||
|
async function refresh(req, res) {
|
||||||
|
try {
|
||||||
|
const { refreshToken } = req.body;
|
||||||
|
if (!refreshToken) {
|
||||||
|
res.status(400).json({ error: 'Refresh token required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await authService.refreshTokens(refreshToken);
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Invalid refresh token';
|
||||||
|
res.status(401).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Starts TOTP 2FA setup for the authenticated user and returns the secret and QR code data.
|
||||||
|
* @param req - Authenticated request; user ID is taken from the JWT.
|
||||||
|
* @param res - JSON with TOTP setup details on success, 400 on failure.
|
||||||
|
*/
|
||||||
|
async function setup2FA(req, res) {
|
||||||
|
try {
|
||||||
|
const userId = req.user.userId;
|
||||||
|
const result = await authService.setupTotp(userId);
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Setup failed';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Confirms and enables TOTP 2FA for the authenticated user using a verification code.
|
||||||
|
* @param req - Authenticated request. Body: `code` (TOTP verification code).
|
||||||
|
* @param res - JSON `{ message: '2FA enabled' }` on success, 400 if the code is missing or invalid.
|
||||||
|
*/
|
||||||
|
async function enable2FA(req, res) {
|
||||||
|
try {
|
||||||
|
const userId = req.user.userId;
|
||||||
|
const { code } = req.body;
|
||||||
|
if (!code) {
|
||||||
|
res.status(400).json({ error: 'Code required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await authService.enableTotp(userId, code);
|
||||||
|
res.json({ message: '2FA enabled' });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Invalid code';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Changes the authenticated user's password after verifying the current password.
|
||||||
|
* @param req - Authenticated request. Body: `currentPassword`, `newPassword`.
|
||||||
|
* @param res - JSON `{ message: 'Password updated' }` on success, 400 on validation or auth failure.
|
||||||
|
*/
|
||||||
|
async function changePassword(req, res) {
|
||||||
|
try {
|
||||||
|
const userId = req.user.userId;
|
||||||
|
const { currentPassword, newPassword } = req.body;
|
||||||
|
if (!currentPassword || !newPassword) {
|
||||||
|
res.status(400).json({ error: 'Current password and new password required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await authService.changePassword(userId, currentPassword, newPassword);
|
||||||
|
res.json({ message: 'Password updated' });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Password change failed';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Sends a verification email to the authenticated user's address on file.
|
||||||
|
* @param req - Authenticated request
|
||||||
|
* @param res - JSON with success message; includes devVerifyUrl in non-production console mode
|
||||||
|
*/
|
||||||
|
async function sendVerificationEmail(req, res) {
|
||||||
|
try {
|
||||||
|
const userId = req.user.userId;
|
||||||
|
const result = await emailVerificationService.sendVerificationEmailForUser(userId);
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to send verification email';
|
||||||
|
const status = msg === 'Email is already verified' ? 400 : 400;
|
||||||
|
res.status(status).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Confirms email ownership using a single-use token from the verification link.
|
||||||
|
* @param req - Body or query: `token`
|
||||||
|
* @param res - JSON success message on valid token
|
||||||
|
*/
|
||||||
|
async function verifyEmail(req, res) {
|
||||||
|
try {
|
||||||
|
const token = (typeof req.body?.token === 'string' ? req.body.token : null) ||
|
||||||
|
(typeof req.query.token === 'string' ? req.query.token : null);
|
||||||
|
const result = await emailVerificationService.verifyEmailToken(token || '');
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Verification failed';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function resendVerificationEmail(req, res) {
|
||||||
|
try {
|
||||||
|
const { email } = req.body;
|
||||||
|
if (!email?.trim()) {
|
||||||
|
res.status(400).json({ error: 'Email is required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await emailVerificationService.requestVerificationResendByEmail(email);
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Request failed';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function forgotPassword(req, res) {
|
||||||
|
try {
|
||||||
|
const { email } = req.body;
|
||||||
|
if (!email?.trim()) {
|
||||||
|
res.status(400).json({ error: 'Email is required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await passwordResetService.requestPasswordReset(email);
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Request failed';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function resetPassword(req, res) {
|
||||||
|
try {
|
||||||
|
const { token, newPassword } = req.body;
|
||||||
|
if (!token || !newPassword) {
|
||||||
|
res.status(400).json({ error: 'token and newPassword are required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await passwordResetService.resetPasswordWithToken(token, newPassword);
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Reset failed';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function validateResetToken(req, res) {
|
||||||
|
try {
|
||||||
|
const token = req.params.token ||
|
||||||
|
(typeof req.query.token === 'string' ? req.query.token : '');
|
||||||
|
const result = await passwordResetService.validateResetToken(token);
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(400).json({ error: e instanceof Error ? e.message : 'Invalid token' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=authController.js.map
|
||||||
1
backend/dist/controllers/authController.js.map
vendored
Normal file
1
backend/dist/controllers/authController.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
18
backend/dist/controllers/candlePredictController.d.ts
vendored
Normal file
18
backend/dist/controllers/candlePredictController.d.ts
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { Response } from 'express';
|
||||||
|
import { AuthRequest } from '../middleware/auth';
|
||||||
|
export declare function getState(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function getCandles(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function placeBet(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function getMyBets(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function getAutoSettings(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function updateAutoSettings(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function getAdminConfig(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function updateAdminConfig(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function listAdminIntervals(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function createAdminInterval(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function updateAdminInterval(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function deleteAdminInterval(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function placeMultiBet(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function listAdminMultiLevels(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function updateAdminMultiLevels(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
//# sourceMappingURL=candlePredictController.d.ts.map
|
||||||
1
backend/dist/controllers/candlePredictController.d.ts.map
vendored
Normal file
1
backend/dist/controllers/candlePredictController.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"candlePredictController.d.ts","sourceRoot":"","sources":["../../src/controllers/candlePredictController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAoBjD,wBAAsB,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAsB7E;AAID,wBAAsB,UAAU,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAwC/E;AAID,wBAAsB,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAwD7E;AAID,wBAAsB,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAwC9E;AAID,wBAAsB,eAAe,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAwBpF;AAID,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CA8BvF;AAID,wBAAsB,cAAc,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBnF;AAID,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBtF;AAID,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBvF;AAID,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAoBxF;AAID,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAgCxF;AAID,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BxF;AAID,wBAAsB,aAAa,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAkFlF;AAID,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBzF;AAID,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAoB3F"}
|
||||||
288
backend/dist/controllers/candlePredictController.js
vendored
Normal file
288
backend/dist/controllers/candlePredictController.js
vendored
Normal file
@ -0,0 +1,288 @@
|
|||||||
|
"use strict";
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || (function () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.getState = getState;
|
||||||
|
exports.getCandles = getCandles;
|
||||||
|
exports.placeBet = placeBet;
|
||||||
|
exports.getMyBets = getMyBets;
|
||||||
|
exports.getAutoSettings = getAutoSettings;
|
||||||
|
exports.updateAutoSettings = updateAutoSettings;
|
||||||
|
exports.getAdminConfig = getAdminConfig;
|
||||||
|
exports.updateAdminConfig = updateAdminConfig;
|
||||||
|
exports.listAdminIntervals = listAdminIntervals;
|
||||||
|
exports.createAdminInterval = createAdminInterval;
|
||||||
|
exports.updateAdminInterval = updateAdminInterval;
|
||||||
|
exports.deleteAdminInterval = deleteAdminInterval;
|
||||||
|
exports.placeMultiBet = placeMultiBet;
|
||||||
|
exports.listAdminMultiLevels = listAdminMultiLevels;
|
||||||
|
exports.updateAdminMultiLevels = updateAdminMultiLevels;
|
||||||
|
const candlePredictService = __importStar(require("../services/candlePredictService"));
|
||||||
|
const stakeAmountValidation_1 = require("../utils/stakeAmountValidation");
|
||||||
|
const placeBetResponse_1 = require("../utils/placeBetResponse");
|
||||||
|
function parseIntervalMinutes(value) {
|
||||||
|
if (value == null || value === '')
|
||||||
|
return undefined;
|
||||||
|
const n = Number(value);
|
||||||
|
return Number.isFinite(n) ? n : undefined;
|
||||||
|
}
|
||||||
|
async function getState(req, res) {
|
||||||
|
try {
|
||||||
|
const intervalMinutes = parseIntervalMinutes(req.query.intervalMinutes);
|
||||||
|
const includeInternal = req.user?.role === 'admin';
|
||||||
|
const state = await candlePredictService.getGameState(req.user?.userId, intervalMinutes, {
|
||||||
|
includeInternal,
|
||||||
|
});
|
||||||
|
res.json(state);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to load game state';
|
||||||
|
res.status(500).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function getCandles(req, res) {
|
||||||
|
try {
|
||||||
|
const limit = parseInt(req.query.limit || '0', 10);
|
||||||
|
const intervalMinutes = parseIntervalMinutes(req.query.intervalMinutes);
|
||||||
|
const beforeRaw = req.query.beforeOpenMs;
|
||||||
|
const beforeOpenMs = beforeRaw != null && beforeRaw !== '' && Number.isFinite(Number(beforeRaw))
|
||||||
|
? Number(beforeRaw)
|
||||||
|
: undefined;
|
||||||
|
const page = await candlePredictService.getCandlesPage({
|
||||||
|
limit: limit > 0 ? limit : undefined,
|
||||||
|
intervalMinutes,
|
||||||
|
beforeOpenMs,
|
||||||
|
includeInternal: req.user?.role === 'admin',
|
||||||
|
});
|
||||||
|
res.json(page);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to load candles';
|
||||||
|
res.status(500).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function placeBet(req, res) {
|
||||||
|
try {
|
||||||
|
if (!req.user?.userId) {
|
||||||
|
res.status(401).json({ error: 'Unauthorized' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { direction, stakeAmount, intervalMinutes, stakeAccountKind } = req.body;
|
||||||
|
if (stakeAmount === undefined || stakeAmount === null) {
|
||||||
|
res.status(400).json({ error: 'stakeAmount is required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const parsedStake = (0, stakeAmountValidation_1.parseStakeAmountFromBody)(stakeAmount);
|
||||||
|
const result = await candlePredictService.placeBet(req.user.userId, direction ?? '', parsedStake, intervalMinutes, stakeAccountKind, {
|
||||||
|
idempotencyKey: (0, placeBetResponse_1.readIdempotencyKey)(req, req.body),
|
||||||
|
source: 'http',
|
||||||
|
});
|
||||||
|
(0, placeBetResponse_1.sendPlaceBetResult)(res, result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to place prediction';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function getMyBets(req, res) {
|
||||||
|
try {
|
||||||
|
if (!req.user?.userId) {
|
||||||
|
res.status(401).json({ error: 'Unauthorized' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const page = Math.max(1, parseInt(req.query.page || '1', 10));
|
||||||
|
const pageSize = Math.min(50, Math.max(1, parseInt(req.query.pageSize || '10', 10)));
|
||||||
|
const intervalMinutes = parseIntervalMinutes(req.query.intervalMinutes);
|
||||||
|
const predictions = await candlePredictService.getRecentPredictions(req.user.userId, page, pageSize, intervalMinutes);
|
||||||
|
res.json(predictions);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to load predictions';
|
||||||
|
res.status(500).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function getAutoSettings(req, res) {
|
||||||
|
try {
|
||||||
|
if (!req.user?.userId) {
|
||||||
|
res.status(401).json({ error: 'Unauthorized' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const settings = await candlePredictService.getAutoSettings(req.user.userId);
|
||||||
|
res.json(settings);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to load auto settings';
|
||||||
|
res.status(500).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function updateAutoSettings(req, res) {
|
||||||
|
try {
|
||||||
|
if (!req.user?.userId) {
|
||||||
|
res.status(401).json({ error: 'Unauthorized' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const settings = await candlePredictService.saveAutoSettings(req.user.userId, req.body);
|
||||||
|
res.json(settings);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to update auto settings';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function getAdminConfig(req, res) {
|
||||||
|
try {
|
||||||
|
const config = await candlePredictService.getPublicConfig();
|
||||||
|
res.json(config);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to load config';
|
||||||
|
res.status(500).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function updateAdminConfig(req, res) {
|
||||||
|
try {
|
||||||
|
const config = await candlePredictService.updateAdminConfig(req.body);
|
||||||
|
res.json(config);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to update config';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function listAdminIntervals(req, res) {
|
||||||
|
try {
|
||||||
|
const intervals = await candlePredictService.listAdminIntervals();
|
||||||
|
res.json(intervals);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to load intervals';
|
||||||
|
res.status(500).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function createAdminInterval(req, res) {
|
||||||
|
try {
|
||||||
|
const interval = await candlePredictService.createAdminInterval(req.body);
|
||||||
|
res.status(201).json(interval);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to create interval';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function updateAdminInterval(req, res) {
|
||||||
|
try {
|
||||||
|
const id = Number(req.params.id);
|
||||||
|
if (!Number.isFinite(id)) {
|
||||||
|
res.status(400).json({ error: 'Invalid interval id' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const interval = await candlePredictService.updateAdminInterval(id, req.body);
|
||||||
|
res.json(interval);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to update interval';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function deleteAdminInterval(req, res) {
|
||||||
|
try {
|
||||||
|
const id = Number(req.params.id);
|
||||||
|
if (!Number.isFinite(id)) {
|
||||||
|
res.status(400).json({ error: 'Invalid interval id' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await candlePredictService.deleteAdminInterval(id);
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to delete interval';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function placeMultiBet(req, res) {
|
||||||
|
try {
|
||||||
|
if (!req.user?.userId) {
|
||||||
|
res.status(401).json({ error: 'Unauthorized' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { level, sequence, stakeAmount, intervalMinutes, stakeAccountKind } = req.body;
|
||||||
|
if (stakeAmount === undefined || stakeAmount === null) {
|
||||||
|
res.status(400).json({ error: 'stakeAmount is required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (level == null || !Number.isFinite(Number(level))) {
|
||||||
|
res.status(400).json({ error: 'level is required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!Array.isArray(sequence) || sequence.length === 0) {
|
||||||
|
res.status(400).json({ error: 'sequence is required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const parsedStake = (0, stakeAmountValidation_1.parseStakeAmountFromBody)(stakeAmount);
|
||||||
|
const directions = sequence.filter((d) => d === 'short' || d === 'long');
|
||||||
|
const bet = await candlePredictService.placeMultiCandleBet(req.user.userId, {
|
||||||
|
level: Number(level),
|
||||||
|
sequence: directions,
|
||||||
|
stakeDisplay: parsedStake,
|
||||||
|
intervalMinutes,
|
||||||
|
stakeAccountKind,
|
||||||
|
});
|
||||||
|
res.status(201).json(bet);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to place multi-candle prediction';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function listAdminMultiLevels(req, res) {
|
||||||
|
try {
|
||||||
|
const levels = await candlePredictService.listAdminMultiLevels();
|
||||||
|
res.json(levels);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to load multi levels';
|
||||||
|
res.status(500).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function updateAdminMultiLevels(req, res) {
|
||||||
|
try {
|
||||||
|
const levels = await candlePredictService.updateAdminMultiLevels(req.body);
|
||||||
|
res.json(levels);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to update multi levels';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=candlePredictController.js.map
|
||||||
1
backend/dist/controllers/candlePredictController.js.map
vendored
Normal file
1
backend/dist/controllers/candlePredictController.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
8
backend/dist/controllers/countryController.d.ts
vendored
Normal file
8
backend/dist/controllers/countryController.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { Response } from 'express';
|
||||||
|
import { Request } from 'express';
|
||||||
|
import { AuthRequest } from '../middleware/auth';
|
||||||
|
export declare function listRegistrationCountries(_req: Request, res: Response): Promise<void>;
|
||||||
|
export declare function listCountriesAdmin(_req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function syncCountriesAdmin(_req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function updateCountryRegistration(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
//# sourceMappingURL=countryController.d.ts.map
|
||||||
1
backend/dist/controllers/countryController.d.ts.map
vendored
Normal file
1
backend/dist/controllers/countryController.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"countryController.d.ts","sourceRoot":"","sources":["../../src/controllers/countryController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAO3F;AAED,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAOxF;AAED,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAQxF;AAED,wBAAsB,yBAAyB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAa9F"}
|
||||||
84
backend/dist/controllers/countryController.js
vendored
Normal file
84
backend/dist/controllers/countryController.js
vendored
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
"use strict";
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || (function () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.listRegistrationCountries = listRegistrationCountries;
|
||||||
|
exports.listCountriesAdmin = listCountriesAdmin;
|
||||||
|
exports.syncCountriesAdmin = syncCountriesAdmin;
|
||||||
|
exports.updateCountryRegistration = updateCountryRegistration;
|
||||||
|
const countryService = __importStar(require("../services/countryService"));
|
||||||
|
async function listRegistrationCountries(_req, res) {
|
||||||
|
try {
|
||||||
|
const countries = await countryService.listRegistrationCountries();
|
||||||
|
res.json(countries);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(500).json({ error: e instanceof Error ? e.message : 'Failed to load countries' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function listCountriesAdmin(_req, res) {
|
||||||
|
try {
|
||||||
|
const countries = await countryService.listAllCountriesAdmin();
|
||||||
|
res.json({ items: countries, total: countries.length });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(500).json({ error: e instanceof Error ? e.message : 'Failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function syncCountriesAdmin(_req, res) {
|
||||||
|
try {
|
||||||
|
const result = await countryService.syncCountriesFromApi();
|
||||||
|
const countries = await countryService.listAllCountriesAdmin();
|
||||||
|
res.json({ ...result, total: countries.length });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(400).json({ error: e instanceof Error ? e.message : 'Sync failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function updateCountryRegistration(req, res) {
|
||||||
|
try {
|
||||||
|
const code = req.params.code;
|
||||||
|
const { registrationAllowed } = req.body;
|
||||||
|
if (typeof registrationAllowed !== 'boolean') {
|
||||||
|
res.status(400).json({ error: 'registrationAllowed boolean is required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await countryService.setCountryRegistrationAllowed(code, registrationAllowed);
|
||||||
|
res.json({ message: 'Updated', code, registrationAllowed });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(400).json({ error: e instanceof Error ? e.message : 'Update failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=countryController.js.map
|
||||||
1
backend/dist/controllers/countryController.js.map
vendored
Normal file
1
backend/dist/controllers/countryController.js.map
vendored
Normal file
@ -0,0 +1 @@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dist/controllers/faqController.d.ts
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { Request, Response } from 'express';
|
||||||
|
import { AuthRequest } from '../middleware/auth';
|
||||||
|
export declare function listPublicCategories(_req: Request, res: Response): Promise<void>;
|
||||||
|
export declare function listPublicFaqs(req: Request, res: Response): Promise<void>;
|
||||||
|
export declare function listPopularFaqs(req: Request, res: Response): Promise<void>;
|
||||||
|
export declare function getPublicFaq(req: Request, res: Response): Promise<void>;
|
||||||
|
export declare function recordView(req: Request, res: Response): Promise<void>;
|
||||||
|
export declare function recordHelpful(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function getFaqFile(req: Request, res: Response): Promise<void>;
|
||||||
|
export declare function adminListCategories(_req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function adminCreateCategory(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function adminUpdateCategory(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function adminDeleteCategory(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function adminListFaqs(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function adminCreateFaq(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function adminUpdateFaq(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function adminDeleteFaq(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function adminUploadMedia(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
//# sourceMappingURL=faqController.d.ts.map
|
||||||
1
backend/dist/controllers/faqController.d.ts.map
vendored
Normal file
1
backend/dist/controllers/faqController.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"faqController.d.ts","sourceRoot":"","sources":["../../src/controllers/faqController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AA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AAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAclF;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAUnF;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAWnF;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAMnF;AAED,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBrF"}
|
||||||
233
backend/dist/controllers/faqController.js
vendored
Normal file
233
backend/dist/controllers/faqController.js
vendored
Normal file
@ -0,0 +1,233 @@
|
|||||||
|
"use strict";
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || (function () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.listPublicCategories = listPublicCategories;
|
||||||
|
exports.listPublicFaqs = listPublicFaqs;
|
||||||
|
exports.listPopularFaqs = listPopularFaqs;
|
||||||
|
exports.getPublicFaq = getPublicFaq;
|
||||||
|
exports.recordView = recordView;
|
||||||
|
exports.recordHelpful = recordHelpful;
|
||||||
|
exports.getFaqFile = getFaqFile;
|
||||||
|
exports.adminListCategories = adminListCategories;
|
||||||
|
exports.adminCreateCategory = adminCreateCategory;
|
||||||
|
exports.adminUpdateCategory = adminUpdateCategory;
|
||||||
|
exports.adminDeleteCategory = adminDeleteCategory;
|
||||||
|
exports.adminListFaqs = adminListFaqs;
|
||||||
|
exports.adminCreateFaq = adminCreateFaq;
|
||||||
|
exports.adminUpdateFaq = adminUpdateFaq;
|
||||||
|
exports.adminDeleteFaq = adminDeleteFaq;
|
||||||
|
exports.adminUploadMedia = adminUploadMedia;
|
||||||
|
const faqService = __importStar(require("../services/faqService"));
|
||||||
|
function handleError(res, e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Request failed';
|
||||||
|
if (msg.includes('not found') || msg === 'FAQ not found' || msg === 'Category not found') {
|
||||||
|
res.status(404).json({ error: msg });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
async function listPublicCategories(_req, res) {
|
||||||
|
try {
|
||||||
|
res.json({ items: await faqService.listPublicCategories() });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
handleError(res, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function listPublicFaqs(req, res) {
|
||||||
|
try {
|
||||||
|
res.json({
|
||||||
|
items: await faqService.listPublicFaqs({
|
||||||
|
category: typeof req.query.category === 'string' ? req.query.category : undefined,
|
||||||
|
search: typeof req.query.search === 'string' ? req.query.search : undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
handleError(res, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function listPopularFaqs(req, res) {
|
||||||
|
try {
|
||||||
|
const limit = req.query.limit ? Number(req.query.limit) : 5;
|
||||||
|
res.json({ items: await faqService.listPopularFaqs(limit) });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
handleError(res, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function getPublicFaq(req, res) {
|
||||||
|
try {
|
||||||
|
res.json(await faqService.getPublicFaq(req.params.id));
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
handleError(res, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function recordView(req, res) {
|
||||||
|
try {
|
||||||
|
res.json(await faqService.recordFaqView(req.params.id));
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
handleError(res, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function recordHelpful(req, res) {
|
||||||
|
try {
|
||||||
|
const helpful = req.body?.helpful === true;
|
||||||
|
const voterKey = faqService.buildVoterKey(req, req.user?.userId);
|
||||||
|
const result = await faqService.recordFaqHelpful(req.params.id, helpful, voterKey);
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
handleError(res, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function getFaqFile(req, res) {
|
||||||
|
try {
|
||||||
|
const filePath = faqService.readFaqFile(req.params.filename);
|
||||||
|
if (!filePath) {
|
||||||
|
res.status(404).json({ error: 'File not found' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res.sendFile(filePath);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
handleError(res, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function adminListCategories(_req, res) {
|
||||||
|
try {
|
||||||
|
res.json({ items: await faqService.listAdminCategories() });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
handleError(res, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function adminCreateCategory(req, res) {
|
||||||
|
try {
|
||||||
|
const item = await faqService.createAdminCategory(req.body);
|
||||||
|
res.status(201).json(item);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
handleError(res, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function adminUpdateCategory(req, res) {
|
||||||
|
try {
|
||||||
|
const id = Number(req.params.id);
|
||||||
|
if (!Number.isFinite(id)) {
|
||||||
|
res.status(400).json({ error: 'Invalid category id' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res.json(await faqService.updateAdminCategory(id, req.body));
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
handleError(res, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function adminDeleteCategory(req, res) {
|
||||||
|
try {
|
||||||
|
const id = Number(req.params.id);
|
||||||
|
if (!Number.isFinite(id)) {
|
||||||
|
res.status(400).json({ error: 'Invalid category id' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res.json(await faqService.deleteAdminCategory(id));
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
handleError(res, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function adminListFaqs(req, res) {
|
||||||
|
try {
|
||||||
|
const isActive = req.query.isActive === 'true' ? true : req.query.isActive === 'false' ? false : undefined;
|
||||||
|
res.json({
|
||||||
|
items: await faqService.listAdminFaqs({
|
||||||
|
categoryId: req.query.categoryId ? Number(req.query.categoryId) : undefined,
|
||||||
|
search: typeof req.query.search === 'string' ? req.query.search : undefined,
|
||||||
|
isActive,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
handleError(res, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function adminCreateFaq(req, res) {
|
||||||
|
try {
|
||||||
|
const item = await faqService.createAdminFaq(req.user.userId, req.body);
|
||||||
|
res.status(201).json(item);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
handleError(res, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function adminUpdateFaq(req, res) {
|
||||||
|
try {
|
||||||
|
const item = await faqService.updateAdminFaq(req.params.id, req.user.userId, req.body);
|
||||||
|
res.json(item);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
handleError(res, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function adminDeleteFaq(req, res) {
|
||||||
|
try {
|
||||||
|
res.json(await faqService.deleteAdminFaq(req.params.id));
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
handleError(res, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function adminUploadMedia(req, res) {
|
||||||
|
try {
|
||||||
|
if (!req.file) {
|
||||||
|
res.status(400).json({ error: 'No file uploaded' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const url = faqService.publicFaqFileUrl(req.file.filename);
|
||||||
|
res.status(201).json({
|
||||||
|
url,
|
||||||
|
filename: req.file.filename,
|
||||||
|
mimeType: req.file.mimetype,
|
||||||
|
originalName: req.file.originalname,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
handleError(res, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=faqController.js.map
|
||||||
1
backend/dist/controllers/faqController.js.map
vendored
Normal file
1
backend/dist/controllers/faqController.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
10
backend/dist/controllers/gameController.d.ts
vendored
Normal file
10
backend/dist/controllers/gameController.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { Response } from 'express';
|
||||||
|
import { AuthRequest } from '../middleware/auth';
|
||||||
|
export declare function listGames(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function getGame(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function listGamesAdmin(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function listImplementationsAdmin(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function createGame(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function updateGame(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function deleteGame(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
//# sourceMappingURL=gameController.d.ts.map
|
||||||
1
backend/dist/controllers/gameController.d.ts.map
vendored
Normal file
1
backend/dist/controllers/gameController.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"gameController.d.ts","sourceRoot":"","sources":["../../src/controllers/gameController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,wBAAsB,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAS9E;AAED,wBAAsB,OAAO,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAY5E;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAQnF;AAED,wBAAsB,wBAAwB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ7F;AAED,wBAAsB,UAAU,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ/E;AAED,wBAAsB,UAAU,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAS/E;AAED,wBAAsB,UAAU,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ/E"}
|
||||||
120
backend/dist/controllers/gameController.js
vendored
Normal file
120
backend/dist/controllers/gameController.js
vendored
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
"use strict";
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || (function () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.listGames = listGames;
|
||||||
|
exports.getGame = getGame;
|
||||||
|
exports.listGamesAdmin = listGamesAdmin;
|
||||||
|
exports.listImplementationsAdmin = listImplementationsAdmin;
|
||||||
|
exports.createGame = createGame;
|
||||||
|
exports.updateGame = updateGame;
|
||||||
|
exports.deleteGame = deleteGame;
|
||||||
|
const gameService = __importStar(require("../services/gameService"));
|
||||||
|
async function listGames(req, res) {
|
||||||
|
try {
|
||||||
|
const featured = req.query.featured === 'true';
|
||||||
|
const games = await gameService.listGames({ featured });
|
||||||
|
res.json(games);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to load games';
|
||||||
|
res.status(500).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function getGame(req, res) {
|
||||||
|
try {
|
||||||
|
const game = await gameService.getGame(req.params.slug);
|
||||||
|
if (!game) {
|
||||||
|
res.status(404).json({ error: 'Game not found' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res.json(game);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to load game';
|
||||||
|
res.status(500).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function listGamesAdmin(req, res) {
|
||||||
|
try {
|
||||||
|
const games = await gameService.listAllGamesAdmin();
|
||||||
|
res.json(games);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to load games';
|
||||||
|
res.status(500).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function listImplementationsAdmin(req, res) {
|
||||||
|
try {
|
||||||
|
const items = await gameService.listImplementationsAdmin();
|
||||||
|
res.json(items);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to load implementations';
|
||||||
|
res.status(500).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function createGame(req, res) {
|
||||||
|
try {
|
||||||
|
const game = await gameService.createGame(req.body);
|
||||||
|
res.status(201).json(game);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to create game';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function updateGame(req, res) {
|
||||||
|
try {
|
||||||
|
const game = await gameService.updateGame(req.params.id, req.body);
|
||||||
|
res.json(game);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to update game';
|
||||||
|
const status = msg === 'Game not found' ? 404 : 400;
|
||||||
|
res.status(status).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function deleteGame(req, res) {
|
||||||
|
try {
|
||||||
|
await gameService.deleteGame(req.params.id);
|
||||||
|
res.status(204).send();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to delete game';
|
||||||
|
res.status(msg === 'Game not found' ? 404 : 400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=gameController.js.map
|
||||||
1
backend/dist/controllers/gameController.js.map
vendored
Normal file
1
backend/dist/controllers/gameController.js.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"gameController.js","sourceRoot":"","sources":["../../src/controllers/gameController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,8BASC;AAED,0BAYC;AAED,wCAQC;AAED,4DAQC;AAED,gCAQC;AAED,gCASC;AAED,gCAQC;AA5ED,qEAAuD;AAEhD,KAAK,UAAU,SAAS,CA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CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IACxE,CAAC;AACH,CAAC"}
|
||||||
9
backend/dist/controllers/gamePlayController.d.ts
vendored
Normal file
9
backend/dist/controllers/gamePlayController.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { Response } from 'express';
|
||||||
|
import { AuthRequest } from '../middleware/auth';
|
||||||
|
export declare function getState(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function placeBet(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function getMyBets(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function getAutoSettings(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function updateAutoSettings(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function customGet(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
//# sourceMappingURL=gamePlayController.d.ts.map
|
||||||
1
backend/dist/controllers/gamePlayController.d.ts.map
vendored
Normal file
1
backend/dist/controllers/gamePlayController.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"gamePlayController.d.ts","sourceRoot":"","sources":["../../src/controllers/gamePlayController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AASnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAyCjD,wBAAsB,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAS7E;AAED,wBAAsB,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAqC7E;AAED,wBAAsB,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAa9E;AAED,wBAAsB,eAAe,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBpF;AAED,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBvF;AAED,wBAAsB,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAe9E"}
|
||||||
160
backend/dist/controllers/gamePlayController.js
vendored
Normal file
160
backend/dist/controllers/gamePlayController.js
vendored
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.getState = getState;
|
||||||
|
exports.placeBet = placeBet;
|
||||||
|
exports.getMyBets = getMyBets;
|
||||||
|
exports.getAutoSettings = getAutoSettings;
|
||||||
|
exports.updateAutoSettings = updateAutoSettings;
|
||||||
|
exports.customGet = customGet;
|
||||||
|
const errors_1 = require("../games/errors");
|
||||||
|
const gamePlayService_1 = require("../services/gamePlayService");
|
||||||
|
const placeBetResponse_1 = require("../utils/placeBetResponse");
|
||||||
|
function buildCtx(req) {
|
||||||
|
return {
|
||||||
|
userId: req.user?.userId,
|
||||||
|
role: req.user?.role,
|
||||||
|
query: req.query,
|
||||||
|
body: (req.body ?? {}),
|
||||||
|
params: req.params,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function sendGameError(res, e, fallbackStatus = 500) {
|
||||||
|
if (e instanceof errors_1.GameNotFoundError) {
|
||||||
|
res.status(404).json({ error: e.message });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (e instanceof errors_1.GameNotImplementedError || e instanceof errors_1.GameNotRegisteredError) {
|
||||||
|
res.status(501).json({ error: e.message });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (e instanceof errors_1.UnsupportedGameActionError) {
|
||||||
|
res.status(404).json({ error: e.message });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (e instanceof Error && e.message === 'Unauthorized') {
|
||||||
|
res.status(401).json({ error: 'Unauthorized' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const msg = e instanceof Error ? e.message : 'Request failed';
|
||||||
|
res.status(fallbackStatus).json({ error: msg });
|
||||||
|
}
|
||||||
|
function assertAction(mod, action) {
|
||||||
|
if (!mod.capabilities.actions.includes(action)) {
|
||||||
|
throw new errors_1.UnsupportedGameActionError(action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function getState(req, res) {
|
||||||
|
try {
|
||||||
|
const { mod } = await (0, gamePlayService_1.resolveModuleBySlug)(req.params.slug);
|
||||||
|
assertAction(mod, 'state');
|
||||||
|
const state = await mod.getState(buildCtx(req));
|
||||||
|
res.json(state);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
sendGameError(res, e, 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function placeBet(req, res) {
|
||||||
|
try {
|
||||||
|
if (!req.user?.userId) {
|
||||||
|
res.status(401).json({ error: 'Unauthorized' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { mod } = await (0, gamePlayService_1.resolveModuleBySlug)(req.params.slug);
|
||||||
|
assertAction(mod, 'placeBet');
|
||||||
|
const body = (req.body ?? {});
|
||||||
|
const ctx = buildCtx(req);
|
||||||
|
ctx.body = {
|
||||||
|
...body,
|
||||||
|
idempotencyKey: (0, placeBetResponse_1.readIdempotencyKey)(req, body) ?? body.idempotencyKey,
|
||||||
|
};
|
||||||
|
const bet = await mod.placeBet(ctx);
|
||||||
|
if (bet &&
|
||||||
|
typeof bet === 'object' &&
|
||||||
|
'status' in bet &&
|
||||||
|
bet.status === 'queued') {
|
||||||
|
(0, placeBetResponse_1.sendPlaceBetResult)(res, bet);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (bet &&
|
||||||
|
typeof bet === 'object' &&
|
||||||
|
'status' in bet &&
|
||||||
|
bet.status === 'accepted') {
|
||||||
|
(0, placeBetResponse_1.sendPlaceBetResult)(res, bet);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res.status(201).json(bet);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
sendGameError(res, e, 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function getMyBets(req, res) {
|
||||||
|
try {
|
||||||
|
if (!req.user?.userId) {
|
||||||
|
res.status(401).json({ error: 'Unauthorized' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { mod } = await (0, gamePlayService_1.resolveModuleBySlug)(req.params.slug);
|
||||||
|
assertAction(mod, 'myBets');
|
||||||
|
const bets = await mod.getMyBets(buildCtx(req));
|
||||||
|
res.json(bets);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
sendGameError(res, e, 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function getAutoSettings(req, res) {
|
||||||
|
try {
|
||||||
|
if (!req.user?.userId) {
|
||||||
|
res.status(401).json({ error: 'Unauthorized' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { mod } = await (0, gamePlayService_1.resolveModuleBySlug)(req.params.slug);
|
||||||
|
assertAction(mod, 'auto.get');
|
||||||
|
if (!mod.getAutoSettings) {
|
||||||
|
throw new errors_1.UnsupportedGameActionError('auto.get');
|
||||||
|
}
|
||||||
|
const settings = await mod.getAutoSettings(buildCtx(req));
|
||||||
|
res.json(settings);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
sendGameError(res, e, 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function updateAutoSettings(req, res) {
|
||||||
|
try {
|
||||||
|
if (!req.user?.userId) {
|
||||||
|
res.status(401).json({ error: 'Unauthorized' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { mod } = await (0, gamePlayService_1.resolveModuleBySlug)(req.params.slug);
|
||||||
|
assertAction(mod, 'auto.update');
|
||||||
|
if (!mod.updateAutoSettings) {
|
||||||
|
throw new errors_1.UnsupportedGameActionError('auto.update');
|
||||||
|
}
|
||||||
|
const settings = await mod.updateAutoSettings(buildCtx(req));
|
||||||
|
res.json(settings);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
sendGameError(res, e, 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function customGet(req, res) {
|
||||||
|
try {
|
||||||
|
const action = req.params.customAction;
|
||||||
|
const { mod } = await (0, gamePlayService_1.resolveModuleBySlug)(req.params.slug);
|
||||||
|
if (!mod.capabilities.customGet?.includes(action)) {
|
||||||
|
throw new errors_1.UnsupportedGameActionError(action);
|
||||||
|
}
|
||||||
|
if (!mod.handleCustom) {
|
||||||
|
throw new errors_1.UnsupportedGameActionError(action);
|
||||||
|
}
|
||||||
|
const result = await mod.handleCustom(action, 'GET', buildCtx(req));
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
sendGameError(res, e, 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=gamePlayController.js.map
|
||||||
1
backend/dist/controllers/gamePlayController.js.map
vendored
Normal file
1
backend/dist/controllers/gamePlayController.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
6
backend/dist/controllers/notificationController.d.ts
vendored
Normal file
6
backend/dist/controllers/notificationController.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { Response } from 'express';
|
||||||
|
import { AuthRequest } from '../middleware/auth';
|
||||||
|
export declare function listNotifications(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function markNotificationRead(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function markAllNotificationsRead(_req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
//# sourceMappingURL=notificationController.d.ts.map
|
||||||
1
backend/dist/controllers/notificationController.d.ts.map
vendored
Normal file
1
backend/dist/controllers/notificationController.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"notificationController.d.ts","sourceRoot":"","sources":["../../src/controllers/notificationController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAIjD,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBtF;AAED,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAQzF;AAED,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ9F"}
|
||||||
86
backend/dist/controllers/notificationController.js
vendored
Normal file
86
backend/dist/controllers/notificationController.js
vendored
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
"use strict";
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || (function () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.listNotifications = listNotifications;
|
||||||
|
exports.markNotificationRead = markNotificationRead;
|
||||||
|
exports.markAllNotificationsRead = markAllNotificationsRead;
|
||||||
|
const adminNotificationRepository = __importStar(require("../repositories/adminNotificationRepository"));
|
||||||
|
const crypto_1 = require("../utils/crypto");
|
||||||
|
async function listNotifications(req, res) {
|
||||||
|
try {
|
||||||
|
const unreadOnly = req.query.unreadOnly === 'true';
|
||||||
|
const limit = parseInt(req.query.limit || '50', 10);
|
||||||
|
const offset = parseInt(req.query.offset || '0', 10);
|
||||||
|
const result = await adminNotificationRepository.listNotifications({ unreadOnly, limit, offset });
|
||||||
|
res.json({
|
||||||
|
items: result.items.map((n) => ({
|
||||||
|
id: n.id,
|
||||||
|
title: n.title,
|
||||||
|
body: n.body_encrypted ? (0, crypto_1.decryptSensitive)(n.body_encrypted) : null,
|
||||||
|
severity: n.severity,
|
||||||
|
alertId: n.alert_id,
|
||||||
|
readAt: n.read_at,
|
||||||
|
createdAt: n.created_at,
|
||||||
|
})),
|
||||||
|
total: result.total,
|
||||||
|
unreadCount: result.unreadCount,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to list notifications';
|
||||||
|
res.status(500).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function markNotificationRead(req, res) {
|
||||||
|
try {
|
||||||
|
await adminNotificationRepository.markRead(req.params.notificationId);
|
||||||
|
res.json({ message: 'Marked as read' });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to mark notification';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function markAllNotificationsRead(_req, res) {
|
||||||
|
try {
|
||||||
|
await adminNotificationRepository.markAllRead();
|
||||||
|
res.json({ message: 'All marked as read' });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to mark notifications';
|
||||||
|
res.status(400).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=notificationController.js.map
|
||||||
1
backend/dist/controllers/notificationController.js.map
vendored
Normal file
1
backend/dist/controllers/notificationController.js.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"notificationController.js","sourceRoot":"","sources":["../../src/controllers/notificationController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,8CAuBC;AAED,oDAQC;AAED,4DAQC;AA9CD,yGAA2F;AAC3F,4CAAmD;AAE5C,KAAK,UAAU,iBAAiB,CAAC,GAAgB,EAAE,GAAa;IACrE,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,UAAU,KAAK,MAAM,CAAC;QACnD,MAAM,KAAK,GAAG,QAAQ,CAAE,GAAG,CAAC,KAAK,CAAC,KAAgB,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;QAChE,MAAM,MAAM,GAAG,QAAQ,CAAE,GAAG,CAAC,KAAK,CAAC,MAAiB,IAAI,GAAG,EAAE,EAAE,CAAC,CAAC;QACjE,MAAM,MAAM,GAAG,MAAM,2BAA2B,CAAC,iBAAiB,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QAClG,GAAG,CAAC,IAAI,CAAC;YACP,KAAK,EAAE,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,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IACvC,CAAC;AACH,CAAC;AAEM,KAAK,UAAU,wBAAwB,CAAC,IAAiB,EAAE,GAAa;IAC7E,IAAI,CAAC;QACH,MAAM,2BAA2B,CAAC,WAAW,EAAE,CAAC;QAChD,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,oBAAoB,EAAE,CAAC,CAAC;IAC9C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,GAAG,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,8BAA8B,CAAC;QAC5E,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
|
||||||
20
backend/dist/controllers/overviewController.d.ts
vendored
Normal file
20
backend/dist/controllers/overviewController.d.ts
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
|
||||||
|
* Overview controller — HTTP handler for the admin dashboard aggregate statistics.
|
||||||
|
|
||||||
|
* Delegates to [overviewService].
|
||||||
|
|
||||||
|
*/
|
||||||
|
import { Response } from 'express';
|
||||||
|
import { AuthRequest } from '../middleware/auth';
|
||||||
|
/**
|
||||||
|
|
||||||
|
* Returns aggregate user counts and platform flags for the admin overview dashboard.
|
||||||
|
|
||||||
|
* @param req - Authenticated admin request.
|
||||||
|
|
||||||
|
* @param res - JSON overview object on success, 500 on failure.
|
||||||
|
|
||||||
|
*/
|
||||||
|
export declare function getAdminOverview(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
//# sourceMappingURL=overviewController.d.ts.map
|
||||||
1
backend/dist/controllers/overviewController.d.ts.map
vendored
Normal file
1
backend/dist/controllers/overviewController.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"overviewController.d.ts","sourceRoot":"","sources":["../../src/controllers/overviewController.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAMjD;;;;;;;;GAQG;AAEH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBrF"}
|
||||||
64
backend/dist/controllers/overviewController.js
vendored
Normal file
64
backend/dist/controllers/overviewController.js
vendored
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
"use strict";
|
||||||
|
/**
|
||||||
|
|
||||||
|
* Overview controller — HTTP handler for the admin dashboard aggregate statistics.
|
||||||
|
|
||||||
|
* Delegates to [overviewService].
|
||||||
|
|
||||||
|
*/
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || (function () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.getAdminOverview = getAdminOverview;
|
||||||
|
const overviewService = __importStar(require("../services/overviewService"));
|
||||||
|
/**
|
||||||
|
|
||||||
|
* Returns aggregate user counts and platform flags for the admin overview dashboard.
|
||||||
|
|
||||||
|
* @param req - Authenticated admin request.
|
||||||
|
|
||||||
|
* @param res - JSON overview object on success, 500 on failure.
|
||||||
|
|
||||||
|
*/
|
||||||
|
async function getAdminOverview(req, res) {
|
||||||
|
try {
|
||||||
|
const overview = await overviewService.getAdminOverview();
|
||||||
|
res.json(overview);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : 'Failed to load overview';
|
||||||
|
res.status(500).json({ error: msg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=overviewController.js.map
|
||||||
1
backend/dist/controllers/overviewController.js.map
vendored
Normal file
1
backend/dist/controllers/overviewController.js.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"overviewController.js","sourceRoot":"","sources":["../../src/controllers/overviewController.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBH,4CAgBC;AA9BD,6EAA+D;AAI/D;;;;;;;;GAQG;AAEI,KAAK,UAAU,gBAAgB,CAAC,GAAgB,EAAE,GAAa;IAEpE,IAAI,CAAC;QAEH,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC,gBAAgB,EAAE,CAAC;QAE1D,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAErB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QAEX,MAAM,GAAG,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,yBAAyB,CAAC;QAEvE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IAEvC,CAAC;AAEH,CAAC"}
|
||||||
5
backend/dist/controllers/presenceController.d.ts
vendored
Normal file
5
backend/dist/controllers/presenceController.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { Response } from 'express';
|
||||||
|
import type { AuthRequest } from '../middleware/auth';
|
||||||
|
/** Lightweight heartbeat so idle browsers stay in the app presence set. */
|
||||||
|
export declare function pingPresence(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
//# sourceMappingURL=presenceController.d.ts.map
|
||||||
1
backend/dist/controllers/presenceController.d.ts.map
vendored
Normal file
1
backend/dist/controllers/presenceController.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"presenceController.d.ts","sourceRoot":"","sources":["../../src/controllers/presenceController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,2EAA2E;AAC3E,wBAAsB,YAAY,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAIjF"}
|
||||||
12
backend/dist/controllers/presenceController.js
vendored
Normal file
12
backend/dist/controllers/presenceController.js
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.pingPresence = pingPresence;
|
||||||
|
const onlinePresence_1 = require("../realtime/redis/onlinePresence");
|
||||||
|
/** Lightweight heartbeat so idle browsers stay in the app presence set. */
|
||||||
|
async function pingPresence(req, res) {
|
||||||
|
const userId = req.user?.userId;
|
||||||
|
if (userId)
|
||||||
|
await (0, onlinePresence_1.touchAppPresence)(userId);
|
||||||
|
res.json({ ok: true });
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=presenceController.js.map
|
||||||
1
backend/dist/controllers/presenceController.js.map
vendored
Normal file
1
backend/dist/controllers/presenceController.js.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"presenceController.js","sourceRoot":"","sources":["../../src/controllers/presenceController.ts"],"names":[],"mappings":";;AAKA,oCAIC;AARD,qEAAoE;AAGpE,2EAA2E;AACpE,KAAK,UAAU,YAAY,CAAC,GAAgB,EAAE,GAAa;IAChE,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC;IAChC,IAAI,MAAM;QAAE,MAAM,IAAA,iCAAgB,EAAC,MAAM,CAAC,CAAC;IAC3C,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AACzB,CAAC"}
|
||||||
20
backend/dist/controllers/referralController.d.ts
vendored
Normal file
20
backend/dist/controllers/referralController.d.ts
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { Response } from 'express';
|
||||||
|
import { AuthRequest } from '../middleware/auth';
|
||||||
|
export declare function getMyReferralInfo(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function getMyReferralDashboard(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function getMyReferralCommissions(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function getBonusBalances(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function transferBonusToMain(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function getAdminReferralConfig(_req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function updateAdminReferralSettings(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function upsertReferralLevel(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function deleteReferralLevel(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function getReferralStats(_req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function fundBonusPool(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function getReferralReviewQueue(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function approveReferralCommission(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function rejectReferralCommission(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function getReferralFraudDashboard(_req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function clawbackReferralCommission(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function exportReferralClawbacksCsv(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
//# sourceMappingURL=referralController.d.ts.map
|
||||||
1
backend/dist/controllers/referralController.d.ts.map
vendored
Normal file
1
backend/dist/controllers/referralController.d.ts.map
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"referralController.d.ts","sourceRoot":"","sources":["../../src/controllers/referralController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAOjD,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAOtF;AAED,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAW3F;AAED,wBAAsB,wBAAwB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAY7F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AE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAO/F;AAED,wBAAsB,0BAA0B,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAiB/F;AAED,wBAAsB,0BAA0B,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAwB/F"}
|
||||||
314
backend/dist/controllers/referralController.js
vendored
Normal file
314
backend/dist/controllers/referralController.js
vendored
Normal file
@ -0,0 +1,314 @@
|
|||||||
|
"use strict";
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || (function () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.getMyReferralInfo = getMyReferralInfo;
|
||||||
|
exports.getMyReferralDashboard = getMyReferralDashboard;
|
||||||
|
exports.getMyReferralCommissions = getMyReferralCommissions;
|
||||||
|
exports.getBonusBalances = getBonusBalances;
|
||||||
|
exports.transferBonusToMain = transferBonusToMain;
|
||||||
|
exports.getAdminReferralConfig = getAdminReferralConfig;
|
||||||
|
exports.updateAdminReferralSettings = updateAdminReferralSettings;
|
||||||
|
exports.upsertReferralLevel = upsertReferralLevel;
|
||||||
|
exports.deleteReferralLevel = deleteReferralLevel;
|
||||||
|
exports.getReferralStats = getReferralStats;
|
||||||
|
exports.fundBonusPool = fundBonusPool;
|
||||||
|
exports.getReferralReviewQueue = getReferralReviewQueue;
|
||||||
|
exports.approveReferralCommission = approveReferralCommission;
|
||||||
|
exports.rejectReferralCommission = rejectReferralCommission;
|
||||||
|
exports.getReferralFraudDashboard = getReferralFraudDashboard;
|
||||||
|
exports.clawbackReferralCommission = clawbackReferralCommission;
|
||||||
|
exports.exportReferralClawbacksCsv = exportReferralClawbacksCsv;
|
||||||
|
const referralService = __importStar(require("../services/referralService"));
|
||||||
|
const bonusService = __importStar(require("../services/bonusService"));
|
||||||
|
const referralRepository = __importStar(require("../repositories/referralRepository"));
|
||||||
|
const bonusPoolRepository = __importStar(require("../repositories/bonusPoolRepository"));
|
||||||
|
const referralExportService_1 = require("../services/referralExportService");
|
||||||
|
async function getMyReferralInfo(req, res) {
|
||||||
|
try {
|
||||||
|
const info = await referralService.getUserReferralInfo(req.user.userId);
|
||||||
|
res.json(info);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(500).json({ error: e instanceof Error ? e.message : 'Failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function getMyReferralDashboard(req, res) {
|
||||||
|
try {
|
||||||
|
const maxDepth = req.query.maxDepth ? Number(req.query.maxDepth) : 5;
|
||||||
|
const dashboard = await referralService.getUserReferralDashboard(req.user.userId, Number.isFinite(maxDepth) ? maxDepth : 5);
|
||||||
|
res.json(dashboard);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(500).json({ error: e instanceof Error ? e.message : 'Failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function getMyReferralCommissions(req, res) {
|
||||||
|
try {
|
||||||
|
const limit = req.query.limit ? Number(req.query.limit) : 25;
|
||||||
|
const offset = req.query.offset ? Number(req.query.offset) : 0;
|
||||||
|
const result = await referralService.getUserReferralCommissions(req.user.userId, {
|
||||||
|
limit: Number.isFinite(limit) ? limit : 25,
|
||||||
|
offset: Number.isFinite(offset) ? offset : 0,
|
||||||
|
});
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(500).json({ error: e instanceof Error ? e.message : 'Failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function getBonusBalances(req, res) {
|
||||||
|
try {
|
||||||
|
const balances = await bonusService.getUserBonusBalances(req.user.userId);
|
||||||
|
const bonusWithdrawable = await bonusService.isBonusWithdrawable();
|
||||||
|
res.json({ balances, bonusWithdrawable });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(500).json({ error: e instanceof Error ? e.message : 'Failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function transferBonusToMain(req, res) {
|
||||||
|
try {
|
||||||
|
const { walletTypeId, amountRaw } = req.body;
|
||||||
|
if (!walletTypeId || !amountRaw) {
|
||||||
|
res.status(400).json({ error: 'walletTypeId and amountRaw are required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await bonusService.transferBonusToMain({
|
||||||
|
userId: req.user.userId,
|
||||||
|
walletTypeId,
|
||||||
|
amountRaw,
|
||||||
|
});
|
||||||
|
res.json({ message: 'Bonus transferred to main account' });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(400).json({ error: e instanceof Error ? e.message : 'Transfer failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function getAdminReferralConfig(_req, res) {
|
||||||
|
try {
|
||||||
|
const config = await referralService.getProgramSettingsForAdmin();
|
||||||
|
res.json(config);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(500).json({ error: e instanceof Error ? e.message : 'Failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function updateAdminReferralSettings(req, res) {
|
||||||
|
try {
|
||||||
|
const body = req.body;
|
||||||
|
await referralRepository.updateSettings({
|
||||||
|
enabled: body.enabled,
|
||||||
|
defaultReferrerUserId: body.defaultReferrerUserId,
|
||||||
|
bonusWithdrawable: body.bonusWithdrawable,
|
||||||
|
referrerMustBeVerified: body.referrerMustBeVerified,
|
||||||
|
referrerMustHaveDeposited: body.referrerMustHaveDeposited,
|
||||||
|
referredMustBeVerified: body.referredMustBeVerified,
|
||||||
|
commissionHoldDays: body.commissionHoldDays,
|
||||||
|
minReferredPredictions: body.minReferredPredictions,
|
||||||
|
commissionMaxPendingDays: body.commissionMaxPendingDays,
|
||||||
|
sybilDetectionEnabled: body.sybilDetectionEnabled,
|
||||||
|
sybilReviewThreshold: body.sybilReviewThreshold,
|
||||||
|
sybilBlockThreshold: body.sybilBlockThreshold,
|
||||||
|
maxReferralsPerDay: body.maxReferralsPerDay,
|
||||||
|
maxCommissionAmountPerReferrerMonthRaw: body.maxCommissionAmountPerReferrerMonthRaw,
|
||||||
|
maxCommissionsPerReferrerMonth: body.maxCommissionsPerReferrerMonth,
|
||||||
|
slackAlertsEnabled: body.slackAlertsEnabled,
|
||||||
|
depositCommissionsEnabled: body.depositCommissionsEnabled,
|
||||||
|
withdrawalCommissionsEnabled: body.withdrawalCommissionsEnabled,
|
||||||
|
minFirstDepositRaw: body.minFirstDepositRaw,
|
||||||
|
commissionWalletTypeId: body.commissionWalletTypeId,
|
||||||
|
});
|
||||||
|
const config = await referralService.getProgramSettingsForAdmin();
|
||||||
|
res.json(config);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(400).json({ error: e instanceof Error ? e.message : 'Update failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function upsertReferralLevel(req, res) {
|
||||||
|
try {
|
||||||
|
const { levelNumber, commissionPercent, isActive, monthlyMaxAmountRaw, monthlyMaxCount, } = req.body;
|
||||||
|
if (!levelNumber || commissionPercent == null) {
|
||||||
|
res.status(400).json({ error: 'levelNumber and commissionPercent are required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await referralRepository.upsertLevel(levelNumber, commissionPercent, isActive ?? true, monthlyMaxAmountRaw ?? '0', monthlyMaxCount ?? 0);
|
||||||
|
res.json({ message: 'Level saved' });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(400).json({ error: e instanceof Error ? e.message : 'Failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function deleteReferralLevel(req, res) {
|
||||||
|
try {
|
||||||
|
const levelNumber = parseInt(req.params.levelNumber, 10);
|
||||||
|
if (!levelNumber) {
|
||||||
|
res.status(400).json({ error: 'Invalid level number' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await referralRepository.deleteLevel(levelNumber);
|
||||||
|
res.json({ message: 'Level deleted' });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(400).json({ error: e instanceof Error ? e.message : 'Failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function getReferralStats(_req, res) {
|
||||||
|
try {
|
||||||
|
const stats = await referralRepository.getAdminStats();
|
||||||
|
res.json(stats);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(500).json({ error: e instanceof Error ? e.message : 'Failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function fundBonusPool(req, res) {
|
||||||
|
try {
|
||||||
|
const { walletTypeId, amountRaw } = req.body;
|
||||||
|
if (!walletTypeId || !amountRaw) {
|
||||||
|
res.status(400).json({ error: 'walletTypeId and amountRaw are required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const amount = BigInt(amountRaw);
|
||||||
|
if (amount <= 0n) {
|
||||||
|
res.status(400).json({ error: 'Amount must be positive' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await bonusPoolRepository.fundPool(walletTypeId, amount);
|
||||||
|
const pools = await bonusPoolRepository.listPools();
|
||||||
|
res.json({ message: 'Pool funded', pools });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(400).json({ error: e instanceof Error ? e.message : 'Failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function getReferralReviewQueue(req, res) {
|
||||||
|
try {
|
||||||
|
const limit = req.query.limit ? Number(req.query.limit) : 50;
|
||||||
|
const offset = req.query.offset ? Number(req.query.offset) : 0;
|
||||||
|
const queue = await referralService.listReferralReviewQueue({ limit, offset });
|
||||||
|
res.json(queue);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(500).json({ error: e instanceof Error ? e.message : 'Failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function approveReferralCommission(req, res) {
|
||||||
|
try {
|
||||||
|
const payoutId = req.params.payoutId;
|
||||||
|
const { note } = req.body;
|
||||||
|
await referralService.approveReferralCommissionReview({
|
||||||
|
payoutId,
|
||||||
|
reviewerId: req.user.userId,
|
||||||
|
note,
|
||||||
|
});
|
||||||
|
res.json({ message: 'Commission approved and paid' });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(400).json({ error: e instanceof Error ? e.message : 'Approval failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function rejectReferralCommission(req, res) {
|
||||||
|
try {
|
||||||
|
const payoutId = req.params.payoutId;
|
||||||
|
const { reason } = req.body;
|
||||||
|
if (!reason?.trim()) {
|
||||||
|
res.status(400).json({ error: 'reason is required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await referralService.rejectReferralCommissionReview({
|
||||||
|
payoutId,
|
||||||
|
reviewerId: req.user.userId,
|
||||||
|
reason: reason.trim(),
|
||||||
|
});
|
||||||
|
res.json({ message: 'Commission rejected' });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(400).json({ error: e instanceof Error ? e.message : 'Rejection failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function getReferralFraudDashboard(_req, res) {
|
||||||
|
try {
|
||||||
|
const dashboard = await referralService.getReferralFraudDashboard();
|
||||||
|
res.json(dashboard);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(500).json({ error: e instanceof Error ? e.message : 'Failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function clawbackReferralCommission(req, res) {
|
||||||
|
try {
|
||||||
|
const payoutId = req.params.payoutId;
|
||||||
|
const { reason } = req.body;
|
||||||
|
if (!reason?.trim()) {
|
||||||
|
res.status(400).json({ error: 'reason is required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await referralService.clawbackReferralCommission({
|
||||||
|
payoutId,
|
||||||
|
adminId: req.user.userId,
|
||||||
|
reason: reason.trim(),
|
||||||
|
});
|
||||||
|
res.json(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(400).json({ error: e instanceof Error ? e.message : 'Clawback failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function exportReferralClawbacksCsv(req, res) {
|
||||||
|
try {
|
||||||
|
const fromRaw = req.query.from ? String(req.query.from) : undefined;
|
||||||
|
const toRaw = req.query.to ? String(req.query.to) : undefined;
|
||||||
|
const from = fromRaw ? new Date(fromRaw) : undefined;
|
||||||
|
const to = toRaw ? new Date(toRaw) : undefined;
|
||||||
|
if (from && Number.isNaN(from.getTime())) {
|
||||||
|
res.status(400).json({ error: 'Invalid from date (use ISO 8601)' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (to && Number.isNaN(to.getTime())) {
|
||||||
|
res.status(400).json({ error: 'Invalid to date (use ISO 8601)' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const csv = await (0, referralExportService_1.buildClawbacksCsv)({ from, to });
|
||||||
|
const filename = `referral-clawbacks-${new Date().toISOString().slice(0, 10)}.csv`;
|
||||||
|
res.setHeader('Content-Type', 'text/csv; charset=utf-8');
|
||||||
|
res.setHeader('Content-Disposition', `attachment; filename="${filename}"`);
|
||||||
|
res.send(csv);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
res.status(500).json({ error: e instanceof Error ? e.message : 'Export failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=referralController.js.map
|
||||||
1
backend/dist/controllers/referralController.js.map
vendored
Normal file
1
backend/dist/controllers/referralController.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
11
backend/dist/controllers/reportsController.d.ts
vendored
Normal file
11
backend/dist/controllers/reportsController.d.ts
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { Response } from 'express';
|
||||||
|
import { AuthRequest } from '../middleware/auth';
|
||||||
|
export declare function getCatalog(_req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function getReport(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function exportReport(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function exportReportPost(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function startReportExportAsync(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function getReportExportJobStatus(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function downloadReportExportJob(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
export declare function runBulkAction(req: AuthRequest, res: Response): Promise<void>;
|
||||||
|
//# sourceMappingURL=reportsController.d.ts.map
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user