After improving the faq fonctionality management in adding the pdf upload
This commit is contained in:
parent
46a062fcb8
commit
d272c49f46
8
backend/dist-test-faq/app.d.ts
vendored
Normal file
8
backend/dist-test-faq/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-test-faq/app.d.ts.map
Normal file
1
backend/dist-test-faq/app.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAuBH,QAAA,MAAM,GAAG,6CAAY,CAAC;AA2FtB,mEAAmE;AACnE,eAAe,GAAG,CAAC"}
|
||||
150
backend/dist-test-faq/app.js
Normal file
150
backend/dist-test-faq/app.js
Normal file
@ -0,0 +1,150 @@
|
||||
"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 errorHandler_1 = require("./middleware/errorHandler");
|
||||
const settingsRepository = __importStar(require("./repositories/settingsRepository"));
|
||||
const withdrawalFee_1 = require("./utils/withdrawalFee");
|
||||
const emailService_1 = require("./services/emailService");
|
||||
function resolveCorsOrigin() {
|
||||
const configured = config_1.config.app.corsOrigins;
|
||||
if (configured.length > 0)
|
||||
return configured;
|
||||
if (config_1.config.env !== 'production')
|
||||
return true;
|
||||
if (config_1.config.app.publicUrl)
|
||||
return [config_1.config.app.publicUrl];
|
||||
console.error('[cors] CORS_ORIGINS is not set in production — denying cross-origin requests (fail-closed)');
|
||||
return (_origin, callback) => callback(null, false);
|
||||
}
|
||||
const app = (0, express_1.default)();
|
||||
// Behind nginx / Docker reverse proxy (required for rate-limit + req.ip).
|
||||
if (process.env.TRUST_PROXY === 'true' || process.env.TRUST_PROXY === '1') {
|
||||
app.set('trust proxy', 1);
|
||||
}
|
||||
else if (process.env.NODE_ENV === 'production') {
|
||||
app.set('trust proxy', 1);
|
||||
}
|
||||
app.use((0, helmet_1.default)());
|
||||
app.use((0, cors_1.default)({ origin: resolveCorsOrigin(), 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();
|
||||
/** Fee in 6-decimal micro-USDT; clients scale to wallet decimals (e.g. BEP20 18). */
|
||||
const feeRaw = (0, withdrawalFee_1.getWithdrawalNetworkFeeRaw)(settings, 6);
|
||||
res.json({
|
||||
status: 'ok',
|
||||
timestamp: new Date().toISOString(),
|
||||
env: config_1.config.env,
|
||||
emailTransport: config_1.config.email.transport,
|
||||
emailConsoleMode: (0, emailService_1.usesConsoleEmailTransport)(),
|
||||
/** @deprecated Prefer `assets` — primary prediction ledger remains TRC20. */
|
||||
asset: 'USDT_TRC20',
|
||||
network: labelTronNetwork(config_1.config.blockchain.tron.nodeUrl),
|
||||
assets: ['USDT_TRC20', 'USDT_BEP20'],
|
||||
networks: {
|
||||
USDT_TRC20: {
|
||||
depositEnabled: settings.network_usdt_trc20_deposit_enabled,
|
||||
withdrawEnabled: settings.network_usdt_trc20_withdraw_enabled,
|
||||
label: labelTronNetwork(config_1.config.blockchain.tron.nodeUrl),
|
||||
},
|
||||
USDT_BEP20: {
|
||||
depositEnabled: settings.network_usdt_bep20_deposit_enabled,
|
||||
withdrawEnabled: settings.network_usdt_bep20_withdraw_enabled,
|
||||
label: 'bsc',
|
||||
},
|
||||
},
|
||||
withdrawalsEnabled: settings.allow_withdrawals,
|
||||
requireWithdrawal2fa: settings.require_withdrawal_2fa,
|
||||
withdrawalNetworkFeeRaw: feeRaw.toString(),
|
||||
/** Min remaining after peer transfer (6-decimal micro-USDT; 0 = disabled). */
|
||||
transferMinRemainingRaw: String(Math.max(0, Math.floor(settings.transfer_min_remaining_usdt_micro || 0))),
|
||||
rpc: {
|
||||
tronNodeUrl: config_1.config.blockchain.tron.nodeUrl,
|
||||
bscRpcUrl: config_1.config.blockchain.bsc.rpcUrl,
|
||||
},
|
||||
contracts: {
|
||||
usdtTrc20: maskAddress(config_1.config.blockchain.tron.usdtTrc20Contract),
|
||||
usdtBep20: maskAddress(config_1.config.blockchain.bsc.usdtBep20Contract),
|
||||
},
|
||||
});
|
||||
});
|
||||
app.use((_req, res) => {
|
||||
res.status(404).json({ error: 'Not found' });
|
||||
});
|
||||
app.use((err, req, res, next) => {
|
||||
(0, errorHandler_1.errorHandler)(err, req, res, next);
|
||||
});
|
||||
/** Configured Express application instance (not yet listening). */
|
||||
exports.default = app;
|
||||
//# sourceMappingURL=app.js.map
|
||||
1
backend/dist-test-faq/app.js.map
Normal file
1
backend/dist-test-faq/app.js.map
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,4DAAyD;AACzD,sFAAwE;AACxE,yDAAmE;AAC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AAC,CAAC,CAAC;AAEH,GAAG,CAAC,GAAG,CAAC,CAAC,GAAU,EAAE,GAAoB,EAAE,GAAqB,EAAE,IAA0B,EAAE,EAAE;IAC9F,IAAA,2BAAY,EAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AACpC,CAAC,CAAC,CAAC;AAEH,mEAAmE;AACnE,kBAAe,GAAG,CAAC"}
|
||||
5
backend/dist-test-faq/apps/api.d.ts
vendored
Normal file
5
backend/dist-test-faq/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-test-faq/apps/api.d.ts.map
Normal file
1
backend/dist-test-faq/apps/api.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/apps/api.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
||||
39
backend/dist-test-faq/apps/api.js
Normal file
39
backend/dist-test-faq/apps/api.js
Normal file
@ -0,0 +1,39 @@
|
||||
"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");
|
||||
const sentry_1 = require("../observability/sentry");
|
||||
(0, sentry_1.initSentry)('api');
|
||||
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) => {
|
||||
(0, sentry_1.captureException)(e);
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
process.on('unhandledRejection', (reason) => {
|
||||
(0, sentry_1.captureException)(reason);
|
||||
console.error('[process] Unhandled promise rejection (continuing):', reason);
|
||||
});
|
||||
process.on('uncaughtException', (err) => {
|
||||
(0, sentry_1.captureException)(err);
|
||||
console.error('[process] Uncaught exception (continuing):', err);
|
||||
});
|
||||
//# sourceMappingURL=api.js.map
|
||||
1
backend/dist-test-faq/apps/api.js.map
Normal file
1
backend/dist-test-faq/apps/api.js.map
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;AAC1D,oDAAuE;AAEvE,IAAA,mBAAU,EAAC,KAAK,CAAC,CAAC;AAElB,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,IAAA,yBAAgB,EAAC,CAAC,CAAC,CAAC;IACpB,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,IAAA,yBAAgB,EAAC,MAAM,CAAC,CAAC;IACzB,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,IAAA,yBAAgB,EAAC,GAAG,CAAC,CAAC;IACtB,OAAO,CAAC,KAAK,CAAC,4CAA4C,EAAE,GAAG,CAAC,CAAC;AACnE,CAAC,CAAC,CAAC"}
|
||||
5
backend/dist-test-faq/apps/engine.d.ts
vendored
Normal file
5
backend/dist-test-faq/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-test-faq/apps/engine.d.ts.map
Normal file
1
backend/dist-test-faq/apps/engine.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/apps/engine.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
||||
24
backend/dist-test-faq/apps/engine.js
Normal file
24
backend/dist-test-faq/apps/engine.js
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-test-faq/apps/engine.js.map
Normal file
1
backend/dist-test-faq/apps/engine.js.map
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-test-faq/apps/worker-bets.d.ts
vendored
Normal file
5
backend/dist-test-faq/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-test-faq/apps/worker-bets.d.ts.map
Normal file
1
backend/dist-test-faq/apps/worker-bets.d.ts.map
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-test-faq/apps/worker-bets.js
Normal file
23
backend/dist-test-faq/apps/worker-bets.js
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-test-faq/apps/worker-bets.js.map
Normal file
1
backend/dist-test-faq/apps/worker-bets.js.map
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"}
|
||||
5
backend/dist-test-faq/apps/ws.d.ts
vendored
Normal file
5
backend/dist-test-faq/apps/ws.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
/**
|
||||
* WebSocket gateway — Candle Predict + Support messaging.
|
||||
*/
|
||||
export {};
|
||||
//# sourceMappingURL=ws.d.ts.map
|
||||
1
backend/dist-test-faq/apps/ws.d.ts.map
Normal file
1
backend/dist-test-faq/apps/ws.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../src/apps/ws.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
||||
92
backend/dist-test-faq/apps/ws.js
Normal file
92
backend/dist-test-faq/apps/ws.js
Normal file
@ -0,0 +1,92 @@
|
||||
"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 sentry_1 = require("../observability/sentry");
|
||||
const auth_1 = require("../realtime/ws/auth");
|
||||
const hub_1 = require("../realtime/ws/hub");
|
||||
const supportHub_1 = require("../realtime/ws/supportHub");
|
||||
const securityHub_1 = require("../realtime/ws/securityHub");
|
||||
async function main() {
|
||||
(0, sentry_1.initSentry)('ws');
|
||||
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();
|
||||
await securityHub_1.securityWsHub.start();
|
||||
const server = http_1.default.createServer((_req, res) => {
|
||||
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
||||
res.end('Tloto WebSocket gateway');
|
||||
});
|
||||
const gameWss = new ws_1.WebSocketServer({ noServer: true });
|
||||
const supportWss = new ws_1.WebSocketServer({ noServer: true });
|
||||
const securityWss = 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);
|
||||
});
|
||||
securityWss.on('connection', (socket, req) => {
|
||||
securityHub_1.securityWsHub.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;
|
||||
}
|
||||
if (pathname === config_1.config.ws.securityPath) {
|
||||
securityWss.handleUpgrade(req, socket, head, (ws) => {
|
||||
securityWss.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] security path=${config_1.config.ws.securityPath}`);
|
||||
console.log(`[ws] redis=${config_1.config.redis.enabled}`);
|
||||
});
|
||||
}
|
||||
main().catch((e) => {
|
||||
(0, sentry_1.captureException)(e);
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
//# sourceMappingURL=ws.js.map
|
||||
1
backend/dist-test-faq/apps/ws.js.map
Normal file
1
backend/dist-test-faq/apps/ws.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"ws.js","sourceRoot":"","sources":["../../src/apps/ws.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;AAEH,gDAAwB;AACxB,2BAAqC;AAErC,sCAAmC;AACnC,4DAA0D;AAC1D,oDAAuE;AACvE,8CAA8E;AAC9E,4CAA+C;AAC/C,0DAAyD;AACzD,4DAA2D;AAE3D,KAAK,UAAU,IAAI;IACjB,IAAA,mBAAU,EAAC,IAAI,CAAC,CAAC;IAEjB,IAAI,CAAC,eAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;QACvB,OAAO,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;QACvD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,IAAA,4BAAa,EAAC;QAClB,YAAY,EAAE,KAAK;QACnB,qBAAqB,EAAE,KAAK;QAC5B,gBAAgB,EAAE,KAAK;KACxB,CAAC,CAAC;IAEH,MAAM,eAAS,CAAC,KAAK,EAAE,CAAC;IACxB,MAAM,yBAAY,CAAC,KAAK,EAAE,CAAC;IAC3B,MAAM,2BAAa,CAAC,KAAK,EAAE,CAAC;IAE5B,MAAM,MAAM,GAAG,cAAI,CAAC,YAAY,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;QAC7C,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC,CAAC;QACrD,GAAG,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,IAAI,oBAAe,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACxD,MAAM,UAAU,GAAG,IAAI,o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B,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,MAAM,CAAC,eAAM,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE;QACjC,OAAO,CAAC,GAAG,CAAC,0BAA0B,eAAM,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QACxD,OAAO,CAAC,GAAG,CAAC,kBAAkB,eAAM,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QAChD,OAAO,CAAC,GAAG,CAAC,qBAAqB,eAAM,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;QAC1D,OAAO,CAAC,GAAG,CAAC,sBAAsB,eAAM,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,CAAC;QAC5D,OAAO,CAAC,GAAG,CAAC,cAAc,eAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;IACjB,IAAA,yBAAgB,EAAC,CAAC,CAAC,CAAC;IACpB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
||||
14
backend/dist-test-faq/bootstrap/appBootstrap.d.ts
vendored
Normal file
14
backend/dist-test-faq/bootstrap/appBootstrap.d.ts
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* 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-test-faq/bootstrap/appBootstrap.d.ts.map
Normal file
1
backend/dist-test-faq/bootstrap/appBootstrap.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"appBootstrap.d.ts","sourceRoot":"","sources":["../../src/bootstrap/appBootstrap.ts"],"names":[],"mappings":"AAAA;;GAEG;AA8IH,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,CAiD9E"}
|
||||
176
backend/dist-test-faq/bootstrap/appBootstrap.js
Normal file
176
backend/dist-test-faq/bootstrap/appBootstrap.js
Normal file
@ -0,0 +1,176 @@
|
||||
"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 fileIntegrityService_1 = require("../services/fileIntegrityService");
|
||||
const dbTamperService_1 = require("../services/dbTamperService");
|
||||
const sweepBatchService_1 = require("../services/sweepBatchService");
|
||||
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 encryptionRotationReminderService_1 = require("../services/encryptionRotationReminderService");
|
||||
const networkGuard_1 = require("../safety/networkGuard");
|
||||
const productionSecretsGuard_1 = require("../safety/productionSecretsGuard");
|
||||
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.processAllDeposits)();
|
||||
}
|
||||
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 startFileIntegrityMonitor() {
|
||||
const intervalMs = (0, securityService_1.getIntegrityCheckIntervalMs)();
|
||||
const run = async () => {
|
||||
try {
|
||||
const issues = await (0, fileIntegrityService_1.runFileIntegrityCheck)();
|
||||
if (issues.length > 0) {
|
||||
console.warn(`[security] File integrity check found ${issues.length} issue(s)`);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error('File integrity check error:', e);
|
||||
}
|
||||
setTimeout(run, intervalMs);
|
||||
};
|
||||
setTimeout(run, 45000);
|
||||
}
|
||||
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 startSweepBatchMonitor() {
|
||||
const auto = config_1.config.treasury.sweepEnabled && config_1.config.treasury.sweepAutoExecute;
|
||||
console.log(`[sweep] monitor start: SWEEP_ENABLED=${config_1.config.treasury.sweepEnabled} ` +
|
||||
`SWEEP_AUTO_EXECUTE=${config_1.config.treasury.sweepAutoExecute} ` +
|
||||
`allowlist=${config_1.config.treasury.sweepColdAllowlist.length} addr(s) ` +
|
||||
`maxRaw=${config_1.config.treasury.sweepAutoMaxAmountRaw || '(none)'}`);
|
||||
const run = async () => {
|
||||
try {
|
||||
if (config_1.config.treasury.sweepEnabled && config_1.config.treasury.sweepAutoExecute) {
|
||||
const nAuto = await (0, sweepService_1.processAutoEligibleSweeps)();
|
||||
if (nAuto > 0) {
|
||||
console.log(`[sweep] auto-executed ${nAuto} sweep(s)`);
|
||||
}
|
||||
}
|
||||
// Creates Approvals only when needed; also cancels orphan batches already auto-swept.
|
||||
const n = await (0, sweepBatchService_1.createSweepBatchApprovalRequests)();
|
||||
if (n > 0) {
|
||||
console.log(`[sweep-batch] Enqueued ${n} batch approval request(s)`);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error('Sweep batch job error:', e);
|
||||
}
|
||||
const nextMs = auto
|
||||
? Math.min(sweepBatchService_1.SWEEP_BATCH_INTERVAL_MS, (0, sweepService_1.getSweepPollIntervalMs)())
|
||||
: sweepBatchService_1.SWEEP_BATCH_INTERVAL_MS;
|
||||
setTimeout(run, nextMs);
|
||||
};
|
||||
// First pass quickly so a pending sweep after deploy does not wait a full minute
|
||||
setTimeout(run, auto ? 10000 : 60000);
|
||||
}
|
||||
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)();
|
||||
(0, networkGuard_1.validateProductionMainnetOrThrow)();
|
||||
(0, productionSecretsGuard_1.validateProductionSecretsOrThrow)();
|
||||
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();
|
||||
startFileIntegrityMonitor();
|
||||
startDbTamperMonitor();
|
||||
startSweepBatchMonitor();
|
||||
startReferralCommissionMonitor();
|
||||
(0, encryptionRotationReminderService_1.scheduleEncryptionKeyRotationReminder)();
|
||||
}
|
||||
if (startEngines) {
|
||||
(0, engineRunner_1.startRegisteredGameEngines)();
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=appBootstrap.js.map
|
||||
1
backend/dist-test-faq/bootstrap/appBootstrap.js.map
Normal file
1
backend/dist-test-faq/bootstrap/appBootstrap.js.map
Normal file
File diff suppressed because one or more lines are too long
5
backend/dist-test-faq/brand/platformName.d.ts
vendored
Normal file
5
backend/dist-test-faq/brand/platformName.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
/** Official platform name shown in emails, 2FA issuers, and user-facing copy. */
|
||||
export declare const PLATFORM_NAME = "Tloto";
|
||||
/** Wordmark spelling used in branded email headers. */
|
||||
export declare const PLATFORM_WORDMARK = "TLOTO";
|
||||
//# sourceMappingURL=platformName.d.ts.map
|
||||
1
backend/dist-test-faq/brand/platformName.d.ts.map
Normal file
1
backend/dist-test-faq/brand/platformName.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"platformName.d.ts","sourceRoot":"","sources":["../../src/brand/platformName.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,eAAO,MAAM,aAAa,UAAU,CAAC;AAErC,uDAAuD;AACvD,eAAO,MAAM,iBAAiB,UAAU,CAAC"}
|
||||
8
backend/dist-test-faq/brand/platformName.js
Normal file
8
backend/dist-test-faq/brand/platformName.js
Normal file
@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PLATFORM_WORDMARK = exports.PLATFORM_NAME = void 0;
|
||||
/** Official platform name shown in emails, 2FA issuers, and user-facing copy. */
|
||||
exports.PLATFORM_NAME = 'Tloto';
|
||||
/** Wordmark spelling used in branded email headers. */
|
||||
exports.PLATFORM_WORDMARK = 'TLOTO';
|
||||
//# sourceMappingURL=platformName.js.map
|
||||
1
backend/dist-test-faq/brand/platformName.js.map
Normal file
1
backend/dist-test-faq/brand/platformName.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"platformName.js","sourceRoot":"","sources":["../../src/brand/platformName.ts"],"names":[],"mappings":";;;AAAA,iFAAiF;AACpE,QAAA,aAAa,GAAG,OAAO,CAAC;AAErC,uDAAuD;AAC1C,QAAA,iBAAiB,GAAG,OAAO,CAAC"}
|
||||
240
backend/dist-test-faq/config/index.d.ts
vendored
Normal file
240
backend/dist-test-faq/config/index.d.ts
vendored
Normal file
@ -0,0 +1,240 @@
|
||||
/**
|
||||
* 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;
|
||||
};
|
||||
bsc: {
|
||||
rpcUrl: string;
|
||||
/**
|
||||
* Extra RPCs tried for eth_getLogs when the primary returns -32005 / limit exceeded.
|
||||
* Public Binance dataseeds often ban getLogs; rpc-bsc.48.club is the reliable free fallback.
|
||||
* (1rpc.io often returns 403 from datacenter / VPS IPs — do not list it by default.)
|
||||
*/
|
||||
rpcFallbacks: string[];
|
||||
/** Optional override; otherwise DB wallet_types.contract_address for USDT_BEP20 */
|
||||
usdtBep20Contract: string | null;
|
||||
confirmations: number;
|
||||
getLogsBlockRange: number;
|
||||
/**
|
||||
* First-scan / balance catch-up lookback (~3s/block → 200k ≈ 7 days).
|
||||
* Missed deposits older than this need manual creditByTx.
|
||||
*/
|
||||
depositInitialLookbackBlocks: number;
|
||||
/** Re-scan overlap each poll to survive empty eth_getLogs / late indexing. */
|
||||
depositOverlapLookbackBlocks: number;
|
||||
/**
|
||||
* When HD still holds USDT (missed credit), rescan this many recent blocks via getLogs.
|
||||
* Must be wide enough for deposits missed while public RPCs were rate-limiting
|
||||
* (≈3s/block → 200000 ≈ 7 days). Used as floor with depositInitialLookbackBlocks.
|
||||
*/
|
||||
unpaidLookbackBlocks: number;
|
||||
/** Optional Etherscan V2 / BscScan key for unpaid deposit fallback. */
|
||||
explorerApiKey: string;
|
||||
/**
|
||||
* Optional Etherscan-compatible tokentx API. Default empty: Blockscout BSC host is often 404;
|
||||
* deposit recovery relies on RPC fallbacks (+ BSCSCAN_API_KEY when set).
|
||||
*/
|
||||
explorerApiUrl: string;
|
||||
/** Native BNB top-up for sweeps (wei); default 0.001 BNB */
|
||||
gasTopUpWei: string;
|
||||
};
|
||||
};
|
||||
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;
|
||||
/** When set, overrides DB setting `require_admin_2fa` (use `false` for local Docker dev). */
|
||||
requireAdmin2faEnv: string | null;
|
||||
/** Skips JWT token_version check (enabled automatically in NODE_ENV=test). */
|
||||
skipAccessTokenVersionCheck: boolean;
|
||||
};
|
||||
treasury: {
|
||||
/** Moves on-chain deposits from user addresses to cold storage */
|
||||
sweepEnabled: boolean;
|
||||
/**
|
||||
* When true, pending sweeps execute on-chain without Approvals (after safety checks).
|
||||
* Default false — keep human approval for cold destination / amount review.
|
||||
*/
|
||||
sweepAutoExecute: boolean;
|
||||
/**
|
||||
* Optional raw-unit cap for auto-execute. Above this amount, sweep stays pending
|
||||
* for Submit sweeps → Approvals. Empty = no cap when SWEEP_AUTO_EXECUTE=true.
|
||||
*/
|
||||
sweepAutoMaxAmountRaw: string;
|
||||
/**
|
||||
* Optional comma-separated cold addresses allowed as sweep destinations (EVM lowercased).
|
||||
* When set, active cold must match; blocks sweeps if DB cold was changed to an unknown address.
|
||||
*/
|
||||
sweepColdAllowlist: string[];
|
||||
sweepPollIntervalMs: number;
|
||||
/** Minimum token amount (raw units) to sweep */
|
||||
sweepMinAmountRaw: string;
|
||||
/** TRX sent from hot wallet to fund TRC20 sweeps (sun) */
|
||||
tronGasTopUpSun: string;
|
||||
/**
|
||||
* Min USDT (chain raw units) to leave on hot after Hot→Cold USDT transfer.
|
||||
* Default 0 = no USDT floor (native withdrawal gas reserve still enforced).
|
||||
*/
|
||||
hotUsdtMinReserveRaw: 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;
|
||||
/** Comma-separated allowed CORS origins in production */
|
||||
corsOrigins: 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;
|
||||
/** Visible From (can be an alias, e.g. info@ while SMTP_USER is admin@). */
|
||||
from: string;
|
||||
/** Optional Reply-To (defaults to the address inside EMAIL_FROM). */
|
||||
replyTo: 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;
|
||||
securityPath: 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;
|
||||
};
|
||||
turnstile: {
|
||||
siteKey: string;
|
||||
secretKey: string;
|
||||
};
|
||||
sentry: {
|
||||
dsn: string;
|
||||
tracesSampleRate: number;
|
||||
};
|
||||
clamav: {
|
||||
enabled: boolean;
|
||||
host: string;
|
||||
port: number;
|
||||
timeoutMs: number;
|
||||
};
|
||||
mobileReleases: {
|
||||
/** Expected Android signing certificate SHA-256 (hex, no colons). Empty = skip cert check (dev only). */
|
||||
expectedCertSha256: string;
|
||||
expectedPackage: string;
|
||||
maxUploadBytes: number;
|
||||
/** HMAC secret for short-lived download tokens (falls back to JWT secret). */
|
||||
downloadTokenSecret: string;
|
||||
downloadTokenTtlSeconds: number;
|
||||
};
|
||||
/** Live TLS probes for admin SSL expiry page (defaults from APP_PUBLIC_URL + www). */
|
||||
sslStatus: {
|
||||
warnDays: number;
|
||||
criticalDays: number;
|
||||
timeoutMs: number;
|
||||
};
|
||||
/** Admin VPS monitor — Prometheus HTTP only (allowlisted PromQL). */
|
||||
vpsMonitor: {
|
||||
prometheusUrl: string;
|
||||
timeoutMs: number;
|
||||
thresholds: {
|
||||
cpuWarn: number;
|
||||
cpuCritical: number;
|
||||
memWarn: number;
|
||||
memCritical: number;
|
||||
diskWarn: number;
|
||||
diskCritical: number;
|
||||
loadWarn: number;
|
||||
loadCritical: number;
|
||||
};
|
||||
};
|
||||
};
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
1
backend/dist-test-faq/config/index.d.ts.map
Normal file
1
backend/dist-test-faq/config/index.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoEH,kFAAkF;AAClF,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;YAoBb,kIAAkI;;;;;;;YAOlI,iFAAiF;;;;;YAKjF;;;;eAIG;;YAKH,mFAAmF;;;;YAInF;;;eAGG;;YAKH,8EAA8E;;YAK9E;;;;eAIG;;YAEH,uEAAuE;;YAEvE;;;eAGG;;YAEH,4DAA4D;;;;;;;;;;;;QAgB9D,kFAAkF;;QAElF,4FAA4F;;;;;QAQ5F,6FAA6F;;QAE7F,8EAA8E;;;;QAI9E,kEAAkE;;QAElE;;;WAGG;;QAEH;;;WAGG;;QAEH;;;WAGG;;;QAMH,gDAAgD;;QAEhD,0DAA0D;;QAE1D;;;WAGG;;QAEH,2DAA2D;;;;QAI3D,iFAAiF;;;;QAIjF,yDAAyD;;;;QAOzD,6FAA6F;;;;QAI7F,gEAAgE;;;;;;;;;;QAUhE,+DAA+D;;;;;;;QAO/D,4EAA4E;;QAE5E,qEAAqE;;;;;;;;QAQrE,iEAAiE;;QAEjE,8DAA8D;;QAE9D,4DAA4D;;;;;QAK5D,oEAAoE;;QAIpE,6DAA6D;;QAE7D,2EAA2E;;;;;;;;;;IAU7E,mFAAmF;;;QAGjF;;;WAGG;;;;;;;;;;;;;;;;;;QAuBH,yGAAyG;;;;QAIzG,8EAA8E;;;;IAOhF,sFAAsF;;;;;;IAMtF,qEAAqE;;;;;;;;;;;;;;;CAetE,CAAC"}
|
||||
319
backend/dist-test-faq/config/index.js
Normal file
319
backend/dist-test-faq/config/index.js
Normal file
@ -0,0 +1,319 @@
|
||||
"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',
|
||||
'EMAIL_REPLY_TO',
|
||||
'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];
|
||||
// Docker Compose / ENV_FILE values take precedence over repo-root .env
|
||||
if (value !== undefined && value !== '' && process.env[key] === undefined) {
|
||||
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),
|
||||
},
|
||||
bsc: {
|
||||
rpcUrl: process.env.BSC_RPC_URL || 'https://bsc-dataseed.binance.org',
|
||||
/**
|
||||
* Extra RPCs tried for eth_getLogs when the primary returns -32005 / limit exceeded.
|
||||
* Public Binance dataseeds often ban getLogs; rpc-bsc.48.club is the reliable free fallback.
|
||||
* (1rpc.io often returns 403 from datacenter / VPS IPs — do not list it by default.)
|
||||
*/
|
||||
rpcFallbacks: (process.env.BSC_RPC_FALLBACKS || 'https://rpc-bsc.48.club')
|
||||
.split(',')
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean),
|
||||
/** Optional override; otherwise DB wallet_types.contract_address for USDT_BEP20 */
|
||||
usdtBep20Contract: process.env.USDT_BEP20_CONTRACT || null,
|
||||
confirmations: parseInt(process.env.BSC_CONFIRMATIONS || '15', 10),
|
||||
getLogsBlockRange: parseInt(process.env.BSC_GETLOGS_BLOCK_RANGE || '2000', 10),
|
||||
/**
|
||||
* First-scan / balance catch-up lookback (~3s/block → 200k ≈ 7 days).
|
||||
* Missed deposits older than this need manual creditByTx.
|
||||
*/
|
||||
depositInitialLookbackBlocks: parseInt(process.env.BSC_DEPOSIT_INITIAL_LOOKBACK_BLOCKS || '200000', 10),
|
||||
/** Re-scan overlap each poll to survive empty eth_getLogs / late indexing. */
|
||||
depositOverlapLookbackBlocks: parseInt(process.env.BSC_DEPOSIT_OVERLAP_LOOKBACK_BLOCKS || '5000', 10),
|
||||
/**
|
||||
* When HD still holds USDT (missed credit), rescan this many recent blocks via getLogs.
|
||||
* Must be wide enough for deposits missed while public RPCs were rate-limiting
|
||||
* (≈3s/block → 200000 ≈ 7 days). Used as floor with depositInitialLookbackBlocks.
|
||||
*/
|
||||
unpaidLookbackBlocks: parseInt(process.env.BSC_UNPAID_LOOKBACK_BLOCKS || '200000', 10),
|
||||
/** Optional Etherscan V2 / BscScan key for unpaid deposit fallback. */
|
||||
explorerApiKey: process.env.BSCSCAN_API_KEY || process.env.ETHERSCAN_API_KEY || '',
|
||||
/**
|
||||
* Optional Etherscan-compatible tokentx API. Default empty: Blockscout BSC host is often 404;
|
||||
* deposit recovery relies on RPC fallbacks (+ BSCSCAN_API_KEY when set).
|
||||
*/
|
||||
explorerApiUrl: process.env.BSC_EXPLORER_API_URL || '',
|
||||
/** Native BNB top-up for sweeps (wei); default 0.001 BNB */
|
||||
gasTopUpWei: process.env.SWEEP_BSC_GAS_TOPUP_WEI || '1000000000000000',
|
||||
},
|
||||
},
|
||||
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),
|
||||
/** When set, overrides DB setting `require_admin_2fa` (use `false` for local Docker dev). */
|
||||
requireAdmin2faEnv: process.env.REQUIRE_ADMIN_2FA?.trim().toLowerCase() || null,
|
||||
/** Skips JWT token_version check (enabled automatically in NODE_ENV=test). */
|
||||
skipAccessTokenVersionCheck: process.env.NODE_ENV === 'test',
|
||||
},
|
||||
treasury: {
|
||||
/** Moves on-chain deposits from user addresses to cold storage */
|
||||
sweepEnabled: process.env.SWEEP_ENABLED === 'true',
|
||||
/**
|
||||
* When true, pending sweeps execute on-chain without Approvals (after safety checks).
|
||||
* Default false — keep human approval for cold destination / amount review.
|
||||
*/
|
||||
sweepAutoExecute: process.env.SWEEP_AUTO_EXECUTE === 'true',
|
||||
/**
|
||||
* Optional raw-unit cap for auto-execute. Above this amount, sweep stays pending
|
||||
* for Submit sweeps → Approvals. Empty = no cap when SWEEP_AUTO_EXECUTE=true.
|
||||
*/
|
||||
sweepAutoMaxAmountRaw: (process.env.SWEEP_AUTO_MAX_AMOUNT_RAW || '').trim(),
|
||||
/**
|
||||
* Optional comma-separated cold addresses allowed as sweep destinations (EVM lowercased).
|
||||
* When set, active cold must match; blocks sweeps if DB cold was changed to an unknown address.
|
||||
*/
|
||||
sweepColdAllowlist: (process.env.SWEEP_COLD_ALLOWLIST || '')
|
||||
.split(',')
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean),
|
||||
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',
|
||||
/**
|
||||
* Min USDT (chain raw units) to leave on hot after Hot→Cold USDT transfer.
|
||||
* Default 0 = no USDT floor (native withdrawal gas reserve still enforced).
|
||||
*/
|
||||
hotUsdtMinReserveRaw: (process.env.HOT_USDT_MIN_RESERVE_RAW || '0').trim() || '0',
|
||||
/** 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',
|
||||
/** Comma-separated allowed CORS origins in production */
|
||||
corsOrigins: (process.env.CORS_ORIGINS || '')
|
||||
.split(',')
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean),
|
||||
},
|
||||
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 || '').trim(),
|
||||
pass: (process.env.SMTP_PASS || '').replace(/\s+/g, ''),
|
||||
/** Visible From (can be an alias, e.g. info@ while SMTP_USER is admin@). */
|
||||
from: process.env.EMAIL_FROM || '',
|
||||
/** Optional Reply-To (defaults to the address inside EMAIL_FROM). */
|
||||
replyTo: (process.env.EMAIL_REPLY_TO || '').trim(),
|
||||
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',
|
||||
securityPath: process.env.WS_SECURITY_PATH || '/ws/v1/security',
|
||||
},
|
||||
/** 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' : ''),
|
||||
},
|
||||
turnstile: {
|
||||
siteKey: process.env.TURNSTILE_SITE_KEY || '',
|
||||
secretKey: process.env.TURNSTILE_SECRET_KEY || '',
|
||||
},
|
||||
sentry: {
|
||||
dsn: process.env.SENTRY_DSN || '',
|
||||
tracesSampleRate: Math.min(1, Math.max(0, parseFloat(process.env.SENTRY_TRACES_SAMPLE_RATE || '0.1'))),
|
||||
},
|
||||
clamav: {
|
||||
enabled: process.env.CLAMAV_ENABLED === 'true',
|
||||
host: process.env.CLAMAV_HOST || '127.0.0.1',
|
||||
port: parseInt(process.env.CLAMAV_PORT || '3310', 10),
|
||||
timeoutMs: readEnvInt('CLAMAV_TIMEOUT_MS', 30000, 5000, 120000),
|
||||
},
|
||||
mobileReleases: {
|
||||
/** Expected Android signing certificate SHA-256 (hex, no colons). Empty = skip cert check (dev only). */
|
||||
expectedCertSha256: (process.env.ANDROID_APK_EXPECTED_CERT_SHA256 || '').trim().toLowerCase().replace(/:/g, ''),
|
||||
expectedPackage: (process.env.ANDROID_APK_EXPECTED_PACKAGE || 'com.prediqo.mobile').trim(),
|
||||
maxUploadBytes: readEnvInt('APK_MAX_UPLOAD_BYTES', 120 * 1024 * 1024, 1000000, 300 * 1024 * 1024),
|
||||
/** HMAC secret for short-lived download tokens (falls back to JWT secret). */
|
||||
downloadTokenSecret: process.env.APK_DOWNLOAD_TOKEN_SECRET ||
|
||||
process.env.JWT_SECRET ||
|
||||
'change-me-in-production',
|
||||
downloadTokenTtlSeconds: readEnvInt('APK_DOWNLOAD_TOKEN_TTL_SECONDS', 3600, 60, 86400),
|
||||
},
|
||||
/** Live TLS probes for admin SSL expiry page (defaults from APP_PUBLIC_URL + www). */
|
||||
sslStatus: {
|
||||
warnDays: readEnvInt('SSL_STATUS_WARN_DAYS', 30, 1, 90),
|
||||
criticalDays: readEnvInt('SSL_STATUS_CRITICAL_DAYS', 7, 1, 30),
|
||||
timeoutMs: readEnvInt('SSL_STATUS_TIMEOUT_MS', 8000, 1000, 60000),
|
||||
},
|
||||
/** Admin VPS monitor — Prometheus HTTP only (allowlisted PromQL). */
|
||||
vpsMonitor: {
|
||||
prometheusUrl: (process.env.PROMETHEUS_URL || 'http://prometheus:9090').trim(),
|
||||
timeoutMs: readEnvInt('VPS_MONITOR_TIMEOUT_MS', 8000, 1000, 30000),
|
||||
thresholds: {
|
||||
cpuWarn: readEnvInt('VPS_MONITOR_CPU_WARN', 70, 1, 100),
|
||||
cpuCritical: readEnvInt('VPS_MONITOR_CPU_CRITICAL', 90, 1, 100),
|
||||
memWarn: readEnvInt('VPS_MONITOR_MEM_WARN', 75, 1, 100),
|
||||
memCritical: readEnvInt('VPS_MONITOR_MEM_CRITICAL', 90, 1, 100),
|
||||
diskWarn: readEnvInt('VPS_MONITOR_DISK_WARN', 75, 1, 100),
|
||||
diskCritical: readEnvInt('VPS_MONITOR_DISK_CRITICAL', 90, 1, 100),
|
||||
loadWarn: readEnvInt('VPS_MONITOR_LOAD_WARN', 4, 1, 256),
|
||||
loadCritical: readEnvInt('VPS_MONITOR_LOAD_CRITICAL', 8, 1, 256),
|
||||
},
|
||||
},
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
backend/dist-test-faq/config/index.js.map
Normal file
1
backend/dist-test-faq/config/index.js.map
Normal file
File diff suppressed because one or more lines are too long
23
backend/dist-test-faq/controllers/adminController.d.ts
vendored
Normal file
23
backend/dist-test-faq/controllers/adminController.d.ts
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* 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>;
|
||||
export declare function updateUserRoles(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function deleteUser(req: AuthRequest, res: Response): Promise<void>;
|
||||
//# sourceMappingURL=adminController.d.ts.map
|
||||
@ -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;AAUjD;;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,CAsBpF;AAED,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAwBzF;AAED,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CA8B5F;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,CAgBnF;AAED,wBAAsB,eAAe,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAepF;AAED,wBAAsB,UAAU,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAiB/E"}
|
||||
302
backend/dist-test-faq/controllers/adminController.js
Normal file
302
backend/dist-test-faq/controllers/adminController.js
Normal file
@ -0,0 +1,302 @@
|
||||
"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;
|
||||
exports.updateUserRoles = updateUserRoles;
|
||||
exports.deleteUser = deleteUser;
|
||||
const securityAudit_1 = require("../utils/securityAudit");
|
||||
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;
|
||||
const ctx = (0, securityAudit_1.auditContextFromRequest)(req);
|
||||
await adminService.updateUserAccountFlags(userId, {
|
||||
isEnabled,
|
||||
isAccountNonExpired,
|
||||
isAccountNonLocked,
|
||||
isCredentialsNonExpired,
|
||||
}, { adminUserId: req.user.userId, ipAddress: ctx.ipAddress, userAgent: ctx.userAgent });
|
||||
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 ctx = (0, securityAudit_1.auditContextFromRequest)(req);
|
||||
const result = await adminService.batchUpdateUserAccountFlags(userIds, flags, {
|
||||
adminUserId: req.user.userId,
|
||||
ipAddress: ctx.ipAddress,
|
||||
userAgent: ctx.userAgent,
|
||||
});
|
||||
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 ctx = (0, securityAudit_1.auditContextFromRequest)(req);
|
||||
const result = await adminService.batchUpdateUserSecurity(userIds, {
|
||||
withdrawalsSuspended,
|
||||
underSurveillance,
|
||||
reactivateWithdrawals,
|
||||
reason,
|
||||
}, {
|
||||
adminUserId: req.user.userId,
|
||||
ipAddress: ctx.ipAddress,
|
||||
userAgent: ctx.userAgent,
|
||||
});
|
||||
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 ctx = (0, securityAudit_1.auditContextFromRequest)(req);
|
||||
const result = await adminService.updateUserRole(userId, role, req.user.userId, ctx);
|
||||
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 });
|
||||
}
|
||||
}
|
||||
async function updateUserRoles(req, res) {
|
||||
try {
|
||||
const userId = req.params.userId;
|
||||
const { roles } = req.body;
|
||||
if (!roles?.length) {
|
||||
res.status(400).json({ error: 'roles array is required' });
|
||||
return;
|
||||
}
|
||||
const ctx = (0, securityAudit_1.auditContextFromRequest)(req);
|
||||
const result = await adminService.updateUserRoles(userId, roles, req.user.userId, ctx);
|
||||
res.json(result);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to update roles';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function deleteUser(req, res) {
|
||||
try {
|
||||
const userId = req.params.userId;
|
||||
const { reason } = (req.body ?? {});
|
||||
const ctx = (0, securityAudit_1.auditContextFromRequest)(req);
|
||||
const result = await adminService.deleteUser(userId, req.user.userId, {
|
||||
reason,
|
||||
ipAddress: ctx.ipAddress,
|
||||
userAgent: ctx.userAgent,
|
||||
});
|
||||
res.json(result);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Delete failed';
|
||||
const status = msg === 'User not found' ? 404 : msg.includes('cannot delete') || msg.includes('must remain') ? 403 : 400;
|
||||
res.status(status).json({ error: msg });
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=adminController.js.map
|
||||
1
backend/dist-test-faq/controllers/adminController.js.map
Normal file
1
backend/dist-test-faq/controllers/adminController.js.map
Normal file
File diff suppressed because one or more lines are too long
5
backend/dist-test-faq/controllers/adminCreditController.d.ts
vendored
Normal file
5
backend/dist-test-faq/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
|
||||
@ -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,CAgChF;AAED,wBAAsB,WAAW,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAYhF"}
|
||||
79
backend/dist-test-faq/controllers/adminCreditController.js
Normal file
79
backend/dist-test-faq/controllers/adminCreditController.js
Normal file
@ -0,0 +1,79 @@
|
||||
"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 fundApprovalService = __importStar(require("../services/fundApprovalService"));
|
||||
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 fundApprovalService.createFundRequest({
|
||||
operationType: 'ledger_credit',
|
||||
payload: { userId, walletTypeId, adjustmentType, amountRaw, reason },
|
||||
requestedBy: req.user.userId,
|
||||
});
|
||||
res.status(202).json({
|
||||
requestId: result.id,
|
||||
status: result.status,
|
||||
message: 'Credit request submitted — pending super-admin approval',
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Credit request 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 { listLedgerCredits } = await Promise.resolve().then(() => __importStar(require('../services/adminCreditService')));
|
||||
const result = await 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
|
||||
@ -0,0 +1 @@
|
||||
{"version":3,"file":"adminCreditController.js","sourceRoot":"","sources":["../../src/controllers/adminCreditController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,kCAgCC;AAED,kCAYC;AAhDD,qFAAuE;AAEhE,KAAK,UAAU,WAAW,CAAC,GAAgB,EAAE,GAA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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,EAAE,iBAAiB,EAAE,GAAG,wDAAa,gCAAgC,GAAC,CAAC;QAC7E,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QAClE,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,GAAG,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,wBAAwB,CAAC;QACtE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
|
||||
8
backend/dist-test-faq/controllers/advertisementController.d.ts
vendored
Normal file
8
backend/dist-test-faq/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
|
||||
@ -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-test-faq/controllers/advertisementController.js
Normal file
94
backend/dist-test-faq/controllers/advertisementController.js
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
|
||||
@ -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,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AI,CAAC,EAAE,CAAC,CAAC;IACf,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,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-test-faq/controllers/analyticsController.d.ts
vendored
Normal file
5
backend/dist-test-faq/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
|
||||
@ -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-test-faq/controllers/analyticsController.js
Normal file
53
backend/dist-test-faq/controllers/analyticsController.js
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
|
||||
@ -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"}
|
||||
77
backend/dist-test-faq/controllers/authController.d.ts
vendored
Normal file
77
backend/dist-test-faq/controllers/authController.d.ts
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
/**
|
||||
* 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>;
|
||||
/**
|
||||
* Public captcha configuration for the login form (Turnstile or built-in math).
|
||||
*/
|
||||
export declare function getCaptchaConfig(_req: Request, res: Response): Promise<void>;
|
||||
/**
|
||||
* Issues a fresh captcha challenge (math prompt, or Turnstile site key hint).
|
||||
*/
|
||||
export declare function getCaptchaChallenge(_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>;
|
||||
/**
|
||||
* Revokes the refresh token in the request body (logout).
|
||||
*/
|
||||
export declare function logout(req: Request, res: Response): Promise<void>;
|
||||
/**
|
||||
* Revokes all refresh tokens for the authenticated user.
|
||||
*/
|
||||
export declare function logoutAll(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function disable2FA(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function regenerateRecoveryCodes(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
|
||||
@ -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;AAOjD;;;;GAIG;AACH,wBAAsB,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CA8CzE;AAED,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAcrF;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAUlF;AAED;;GAEG;AACH,wBAAs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AAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAU1F;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAW5E;AAED,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAaxF;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAa/E;AAED,wBAAsB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAa9E;AAED,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAUnF"}
|
||||
447
backend/dist-test-faq/controllers/authController.js
Normal file
447
backend/dist-test-faq/controllers/authController.js
Normal file
@ -0,0 +1,447 @@
|
||||
"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.getCaptchaConfig = getCaptchaConfig;
|
||||
exports.getCaptchaChallenge = getCaptchaChallenge;
|
||||
exports.login = login;
|
||||
exports.refresh = refresh;
|
||||
exports.setup2FA = setup2FA;
|
||||
exports.enable2FA = enable2FA;
|
||||
exports.logout = logout;
|
||||
exports.logoutAll = logoutAll;
|
||||
exports.disable2FA = disable2FA;
|
||||
exports.regenerateRecoveryCodes = regenerateRecoveryCodes;
|
||||
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");
|
||||
const safeError_1 = require("../utils/safeError");
|
||||
const clientDevice_1 = require("../utils/clientDevice");
|
||||
const captchaService = __importStar(require("../services/captchaService"));
|
||||
const settingsRepository = __importStar(require("../repositories/settingsRepository"));
|
||||
/**
|
||||
* 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 = (0, safeError_1.clientErrorMessage)(e, 'Registration failed');
|
||||
const status = msg === 'Email is already registered' || msg === 'Phone number already registered'
|
||||
? 409
|
||||
: 400;
|
||||
res.status(status).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 });
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Public captcha configuration for the login form (Turnstile or built-in math).
|
||||
*/
|
||||
async function getCaptchaConfig(_req, res) {
|
||||
const settings = await settingsRepository.getSettings();
|
||||
const afterFailures = settings.login_captcha_after_failures;
|
||||
const provider = captchaService.getCaptchaProvider();
|
||||
res.json({
|
||||
enabled: captchaService.isCaptchaAvailable(afterFailures),
|
||||
provider,
|
||||
siteKey: provider === 'turnstile' ? captchaService.getCaptchaSiteKey() : null,
|
||||
afterFailures,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Issues a fresh captcha challenge (math prompt, or Turnstile site key hint).
|
||||
*/
|
||||
async function getCaptchaChallenge(_req, res) {
|
||||
const settings = await settingsRepository.getSettings();
|
||||
if (!captchaService.isCaptchaAvailable(settings.login_captcha_after_failures)) {
|
||||
res.status(404).json({ error: 'Captcha is disabled' });
|
||||
return;
|
||||
}
|
||||
res.json(captchaService.createLoginCaptchaChallenge());
|
||||
}
|
||||
/**
|
||||
* 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, captchaToken } = 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: (0, clientDevice_1.resolveClientUserAgent)(req),
|
||||
visitorSupportToken: (0, optionalAuth_1.readVisitorToken)(req),
|
||||
}, captchaToken);
|
||||
res.json(result);
|
||||
}
|
||||
catch (e) {
|
||||
const code = e.code;
|
||||
const status = code === 'EMAIL_NOT_VERIFIED' ? 403
|
||||
: code === 'ACCOUNT_LOCKED' ? 429
|
||||
: code === 'CAPTCHA_REQUIRED' || code === 'CAPTCHA_INVALID' ? 400
|
||||
: 401;
|
||||
res.status(status).json({
|
||||
error: (0, safeError_1.clientErrorMessage)(e, 'Login failed'),
|
||||
...(code ? { code } : {}),
|
||||
...(e.lockedUntil
|
||||
? { lockedUntil: e.lockedUntil }
|
||||
: {}),
|
||||
...(e.retryAfterMinutes != null
|
||||
? { retryAfterMinutes: e.retryAfterMinutes }
|
||||
: {}),
|
||||
...(e.captcha
|
||||
? { captcha: e.captcha }
|
||||
: {}),
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 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 { password, totpCode } = req.body;
|
||||
const result = await authService.setupTotp(userId, {
|
||||
password,
|
||||
totpCode,
|
||||
auditContext: {
|
||||
ipAddress: req.ip || undefined,
|
||||
userAgent: req.get('user-agent') || undefined,
|
||||
},
|
||||
});
|
||||
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;
|
||||
}
|
||||
const result = await authService.enableTotp(userId, code, {
|
||||
ipAddress: req.ip || undefined,
|
||||
userAgent: req.get('user-agent') || undefined,
|
||||
});
|
||||
res.json({ message: '2FA enabled', recoveryCodes: result.recoveryCodes });
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Invalid code';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revokes the refresh token in the request body (logout).
|
||||
*/
|
||||
async function logout(req, res) {
|
||||
try {
|
||||
const { refreshToken } = req.body;
|
||||
if (!refreshToken) {
|
||||
res.status(400).json({ error: 'Refresh token required' });
|
||||
return;
|
||||
}
|
||||
await authService.logout(refreshToken, {
|
||||
ipAddress: req.ip || undefined,
|
||||
userAgent: req.get('user-agent') || undefined,
|
||||
});
|
||||
res.json({ message: 'Logged out' });
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Logout failed';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revokes all refresh tokens for the authenticated user.
|
||||
*/
|
||||
async function logoutAll(req, res) {
|
||||
try {
|
||||
const userId = req.user.userId;
|
||||
await authService.logoutAll(userId, {
|
||||
ipAddress: req.ip || undefined,
|
||||
userAgent: req.get('user-agent') || undefined,
|
||||
});
|
||||
res.json({ message: 'Logged out from all devices' });
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Logout failed';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function disable2FA(req, res) {
|
||||
try {
|
||||
const userId = req.user.userId;
|
||||
const { password, code } = req.body;
|
||||
if (!password || !code) {
|
||||
res.status(400).json({ error: 'password and code are required' });
|
||||
return;
|
||||
}
|
||||
await authService.disableTotp(userId, password, code, {
|
||||
ipAddress: req.ip || undefined,
|
||||
userAgent: req.get('user-agent') || undefined,
|
||||
});
|
||||
res.json({ message: '2FA disabled' });
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Disable failed';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function regenerateRecoveryCodes(req, res) {
|
||||
try {
|
||||
const userId = req.user.userId;
|
||||
const { code } = req.body;
|
||||
if (!code) {
|
||||
res.status(400).json({ error: 'TOTP code required' });
|
||||
return;
|
||||
}
|
||||
const result = await authService.regenerateRecoveryCodes(userId, code, {
|
||||
ipAddress: req.ip || undefined,
|
||||
userAgent: req.get('user-agent') || undefined,
|
||||
});
|
||||
res.json({ recoveryCodes: result.recoveryCodes });
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Regeneration failed';
|
||||
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, {
|
||||
ipAddress: req.ip || undefined,
|
||||
userAgent: req.get('user-agent') || undefined,
|
||||
});
|
||||
res.json({ message: 'Password updated. Please sign in again.' });
|
||||
}
|
||||
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-test-faq/controllers/authController.js.map
Normal file
1
backend/dist-test-faq/controllers/authController.js.map
Normal file
File diff suppressed because one or more lines are too long
19
backend/dist-test-faq/controllers/candlePredictController.d.ts
vendored
Normal file
19
backend/dist-test-faq/controllers/candlePredictController.d.ts
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
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 getBetOutcome(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
|
||||
@ -0,0 +1 @@
|
||||
{"version":3,"file":"candlePredictController.d.ts","sourceRoot":"","sources":["../../src/controllers/candlePredictController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AA6JjD,wBAAsB,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CA2G7E;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,CA2D7E;AAID,wBAAsB,aAAa,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAuClF;AAED,wBAAsB,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CA+C9E;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,CAgFlF;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"}
|
||||
534
backend/dist-test-faq/controllers/candlePredictController.js
Normal file
534
backend/dist-test-faq/controllers/candlePredictController.js
Normal file
@ -0,0 +1,534 @@
|
||||
"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.getBetOutcome = getBetOutcome;
|
||||
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 crypto_1 = require("crypto");
|
||||
const roleAccess_1 = require("../utils/roleAccess");
|
||||
const candlePredictService = __importStar(require("../services/candlePredictService"));
|
||||
const testWalletService_1 = require("../services/testWalletService");
|
||||
const stakeAmountValidation_1 = require("../utils/stakeAmountValidation");
|
||||
const placeBetResponse_1 = require("../utils/placeBetResponse");
|
||||
const stateVersions_1 = require("../realtime/redis/stateVersions");
|
||||
function placeBetErrorBody(e, fallback) {
|
||||
if (e instanceof testWalletService_1.TestWalletError) {
|
||||
return {
|
||||
error: e.message,
|
||||
...(e.code ? { code: e.code } : {}),
|
||||
...(e.waitLabel ? { wait: e.waitLabel } : {}),
|
||||
};
|
||||
}
|
||||
return { error: e instanceof Error ? e.message : fallback };
|
||||
}
|
||||
const STATE_CACHE_TTL_MS = 1200;
|
||||
const STATE_CACHE_MAX_ENTRIES = 500;
|
||||
const stateResponseCache = new Map();
|
||||
function compactPart(value) {
|
||||
if (value == null)
|
||||
return '';
|
||||
if (Array.isArray(value))
|
||||
return value.map(compactPart).join(',');
|
||||
if (typeof value === 'object')
|
||||
return JSON.stringify(value);
|
||||
return String(value);
|
||||
}
|
||||
function businessFingerprint(state) {
|
||||
const config = state?.config ?? {};
|
||||
const interval = state?.interval ?? {};
|
||||
const round = state?.round ?? {};
|
||||
const userBet = state?.userBet ?? {};
|
||||
const userMultiBet = state?.userMultiBet ?? {};
|
||||
const autoSettings = state?.autoSettings ?? {};
|
||||
const intervals = Array.isArray(state?.intervals) ? state.intervals : [];
|
||||
const multiLevels = Array.isArray(state?.multiLevels) ? state.multiLevels : [];
|
||||
const intervalFingerprint = intervals
|
||||
.map((item) => [
|
||||
item?.id,
|
||||
item?.intervalMinutes,
|
||||
item?.isActive,
|
||||
item?.isDefault,
|
||||
item?.predictionWindowSeconds,
|
||||
item?.chartCandleLimit,
|
||||
].map(compactPart).join(':'))
|
||||
.join('|');
|
||||
const multiLevelFingerprint = multiLevels
|
||||
.map((item) => [
|
||||
item?.level,
|
||||
item?.candleCount,
|
||||
item?.enabled,
|
||||
item?.payoutMultiplier,
|
||||
item?.poolMultiplier,
|
||||
item?.sortOrder,
|
||||
].map(compactPart).join(':'))
|
||||
.join('|');
|
||||
return [
|
||||
config?.updatedAt,
|
||||
config?.isActive,
|
||||
config?.walletTypeCode,
|
||||
config?.predictionTypes ? JSON.stringify(config.predictionTypes) : '',
|
||||
config?.dailyRevenueNetToday,
|
||||
interval?.id,
|
||||
interval?.intervalMinutes,
|
||||
interval?.predictionWindowSeconds,
|
||||
interval?.chartCandleLimit,
|
||||
state?.selectedIntervalMinutes,
|
||||
intervalFingerprint,
|
||||
round?.id,
|
||||
round?.status,
|
||||
round?.outcome,
|
||||
round?.settledAt,
|
||||
round?.openPrice,
|
||||
round?.highPrice,
|
||||
round?.lowPrice,
|
||||
round?.closePrice,
|
||||
round?.shortPool,
|
||||
round?.longPool,
|
||||
round?.shortPoolPercent,
|
||||
round?.longPoolPercent,
|
||||
userBet?.id,
|
||||
userBet?.roundId,
|
||||
userBet?.status,
|
||||
userBet?.payoutDisplay,
|
||||
userBet?.stakeDisplay,
|
||||
userBet?.candleOpenMs,
|
||||
userMultiBet?.id,
|
||||
userMultiBet?.status,
|
||||
userMultiBet?.sequenceStep,
|
||||
userMultiBet?.currentCandleOpenMs,
|
||||
userMultiBet?.payoutDisplay,
|
||||
userMultiBet?.stakeDisplay,
|
||||
multiLevelFingerprint,
|
||||
autoSettings?.enabled,
|
||||
autoSettings?.direction,
|
||||
autoSettings?.stakeDisplay,
|
||||
autoSettings?.mode,
|
||||
autoSettings?.periodMinutes,
|
||||
autoSettings?.intervalSeconds,
|
||||
autoSettings?.stakeAccountKind,
|
||||
autoSettings?.lastAutoBetAt,
|
||||
autoSettings?.autoBetError,
|
||||
]
|
||||
.map(compactPart)
|
||||
.join('||');
|
||||
}
|
||||
function parseIntervalMinutes(value) {
|
||||
if (value == null || value === '')
|
||||
return undefined;
|
||||
const n = Number(value);
|
||||
return Number.isFinite(n) ? n : undefined;
|
||||
}
|
||||
function rememberStateCache(cacheKey, etag, body, now) {
|
||||
stateResponseCache.set(cacheKey, {
|
||||
etag,
|
||||
body,
|
||||
expiresAt: now + STATE_CACHE_TTL_MS,
|
||||
});
|
||||
if (stateResponseCache.size <= STATE_CACHE_MAX_ENTRIES)
|
||||
return;
|
||||
for (const [key, entry] of stateResponseCache) {
|
||||
if (entry.expiresAt <= now)
|
||||
stateResponseCache.delete(key);
|
||||
}
|
||||
if (stateResponseCache.size > STATE_CACHE_MAX_ENTRIES) {
|
||||
const oldestKey = stateResponseCache.keys().next().value;
|
||||
if (oldestKey)
|
||||
stateResponseCache.delete(oldestKey);
|
||||
}
|
||||
}
|
||||
async function getState(req, res) {
|
||||
try {
|
||||
const intervalMinutes = parseIntervalMinutes(req.query.intervalMinutes);
|
||||
const includeInternal = req.user ? (0, roleAccess_1.hasAdminAccess)(req.user) : false;
|
||||
const cacheKey = JSON.stringify({
|
||||
userId: req.user?.userId ?? 'anon',
|
||||
intervalMinutes: intervalMinutes ?? null,
|
||||
includeInternal,
|
||||
});
|
||||
const ifNoneMatch = String(req.header('if-none-match') ?? '').trim();
|
||||
const now = Date.now();
|
||||
const cached = stateResponseCache.get(cacheKey);
|
||||
res.setHeader('Cache-Control', 'private, max-age=0, must-revalidate');
|
||||
res.setHeader('Vary', 'Authorization');
|
||||
if (cached && cached.expiresAt > now) {
|
||||
res.setHeader('ETag', cached.etag);
|
||||
if (ifNoneMatch && ifNoneMatch === cached.etag) {
|
||||
res.status(304).end();
|
||||
return;
|
||||
}
|
||||
res.json(cached.body);
|
||||
return;
|
||||
}
|
||||
// Cheap path: Redis business versions → 304 before getGameState.
|
||||
// Requires an explicit interval so we do not resolve defaults from DB first.
|
||||
// Any Redis failure falls through to full getGameState + fingerprint ETag.
|
||||
if (intervalMinutes != null) {
|
||||
try {
|
||||
const versions = await (0, stateVersions_1.getStateVersions)({
|
||||
userId: req.user?.userId,
|
||||
intervalMinutes,
|
||||
});
|
||||
if (versions) {
|
||||
const versionEtag = (0, stateVersions_1.buildVersionEtag)({
|
||||
versions,
|
||||
intervalMinutes,
|
||||
includeInternal,
|
||||
});
|
||||
res.setHeader('X-Prediqo-State-Versions', `${versions.config}.${versions.round}.${versions.bet}.${versions.auto}`);
|
||||
if (ifNoneMatch && ifNoneMatch === versionEtag) {
|
||||
res.setHeader('ETag', versionEtag);
|
||||
res.status(304).end();
|
||||
return;
|
||||
}
|
||||
const state = await candlePredictService.getGameState(req.user?.userId, intervalMinutes, {
|
||||
includeInternal,
|
||||
});
|
||||
rememberStateCache(cacheKey, versionEtag, state, now);
|
||||
res.setHeader('ETag', versionEtag);
|
||||
res.json(state);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error('[getState] version short-circuit failed, falling back:', e);
|
||||
}
|
||||
}
|
||||
const state = await candlePredictService.getGameState(req.user?.userId, intervalMinutes, {
|
||||
includeInternal,
|
||||
});
|
||||
// Prefer version ETag when Redis answers; otherwise fingerprint (no Redis required).
|
||||
const resolvedInterval = intervalMinutes ??
|
||||
(typeof state.selectedIntervalMinutes === 'number'
|
||||
? state.selectedIntervalMinutes
|
||||
: undefined);
|
||||
let etag = null;
|
||||
if (resolvedInterval != null) {
|
||||
const versions = await (0, stateVersions_1.getStateVersions)({
|
||||
userId: req.user?.userId,
|
||||
intervalMinutes: resolvedInterval,
|
||||
}).catch(() => null);
|
||||
if (versions) {
|
||||
etag = (0, stateVersions_1.buildVersionEtag)({
|
||||
versions,
|
||||
intervalMinutes: resolvedInterval,
|
||||
includeInternal,
|
||||
});
|
||||
res.setHeader('X-Prediqo-State-Versions', `${versions.config}.${versions.round}.${versions.bet}.${versions.auto}`);
|
||||
}
|
||||
}
|
||||
if (!etag) {
|
||||
etag = `"cp-state-${(0, crypto_1.createHash)('sha1').update(businessFingerprint(state)).digest('hex')}"`;
|
||||
}
|
||||
rememberStateCache(cacheKey, etag, state, now);
|
||||
res.setHeader('ETag', etag);
|
||||
if (ifNoneMatch && ifNoneMatch === etag) {
|
||||
res.status(304).end();
|
||||
return;
|
||||
}
|
||||
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 ? (0, roleAccess_1.hasAdminAccess)(req.user) : false,
|
||||
});
|
||||
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 body = placeBetErrorBody(e, 'Failed to place prediction');
|
||||
console.warn('[candle-predict] placeBet rejected:', body.error, {
|
||||
userId: req.user?.userId,
|
||||
});
|
||||
res.status(400).json(body);
|
||||
}
|
||||
}
|
||||
async function getBetOutcome(req, res) {
|
||||
try {
|
||||
if (!req.user?.userId) {
|
||||
res.status(401).json({ error: 'Unauthorized' });
|
||||
return;
|
||||
}
|
||||
const idempotencyKey = String(req.params.idempotencyKey ?? '').trim();
|
||||
if (!idempotencyKey) {
|
||||
res.status(400).json({ error: 'idempotencyKey is required' });
|
||||
return;
|
||||
}
|
||||
const record = await candlePredictService.getBetIdempotency(idempotencyKey);
|
||||
if (!record) {
|
||||
res.status(404).json({ error: 'Bet outcome not found' });
|
||||
return;
|
||||
}
|
||||
if (record.status === 'accepted') {
|
||||
const betUserId = String(record.bet.user_id ?? record.bet.userId ?? '').trim();
|
||||
if (betUserId && betUserId !== req.user.userId) {
|
||||
res.status(403).json({ error: 'Forbidden' });
|
||||
return;
|
||||
}
|
||||
res.json({ status: 'accepted', bet: record.bet });
|
||||
return;
|
||||
}
|
||||
if (record.status === 'rejected') {
|
||||
res.json({ status: 'rejected', error: record.error });
|
||||
return;
|
||||
}
|
||||
res.json({ status: 'processing' });
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to load bet outcome';
|
||||
res.status(500).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 stakeAccountKind = typeof req.query.stakeAccountKind === 'string' ? req.query.stakeAccountKind : undefined;
|
||||
const status = typeof req.query.status === 'string' ? req.query.status : undefined;
|
||||
const predictions = await candlePredictService.getRecentPredictions(req.user.userId, page, pageSize, intervalMinutes, { stakeAccountKind, status });
|
||||
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) {
|
||||
res.status(400).json(placeBetErrorBody(e, 'Failed to place multi-candle prediction'));
|
||||
}
|
||||
}
|
||||
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
|
||||
File diff suppressed because one or more lines are too long
8
backend/dist-test-faq/controllers/countryController.d.ts
vendored
Normal file
8
backend/dist-test-faq/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
|
||||
@ -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-test-faq/controllers/countryController.js
Normal file
84
backend/dist-test-faq/controllers/countryController.js
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
|
||||
@ -0,0 +1 @@
|
||||
{"version":3,"file":"countryController.js","sourceRoot":"","sources":["../../src/controllers/countryController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,8DAOC;AAED,gDAOC;AAED,gDAQC;AAED,8DAaC;AA3CD,2EAA6D;AAEtD,KAAK,UAAU,yBAAyB,CAAC,IAAa,EAAE,GAAa;IAC1E,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,MAAM,cAAc,CAAC,yBAAyB,EAAE,CAAC;QACnE,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACtB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,0BAA0B,EAAE,CAAC,CAAC;IAC/F,CAAC;AACH,CAAC;AAEM,KAAK,UAAU,kBAAkB,CAAC,IAAiB,EAAE,GAAa;IACvE,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,MAAM,cAAc,CAAC,qBAAqB,EAAE,CAAC;QAC/D,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,CAAC,MAAM,EA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C,CAAC;QAC9E,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC,CAAC;IAC9D,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC;IACpF,CAAC;AACH,CAAC"}
|
||||
23
backend/dist-test-faq/controllers/faqController.d.ts
vendored
Normal file
23
backend/dist-test-faq/controllers/faqController.d.ts
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
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>;
|
||||
/** Public download of a category PDF (active categories only). */
|
||||
export declare function downloadCategoryDocument(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>;
|
||||
export declare function adminUploadCategoryDocument(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function adminDeleteCategoryDocument(req: AuthRequest, res: Response): Promise<void>;
|
||||
//# sourceMappingURL=faqController.d.ts.map
|
||||
1
backend/dist-test-faq/controllers/faqController.d.ts.map
Normal file
1
backend/dist-test-faq/controllers/faqController.d.ts.map
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;AAG5C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAgBjD,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAMtF;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAW/E;AAED,wBAAsB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAOhF;AAED,wBAAsB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAM7E;AAED,wBAAsB,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAM3E;AAED,wBAAsB,aAAa,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CASlF;AAED,wBAAsB,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,O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,wBAAsB,2BAA2B,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAYhG"}
|
||||
318
backend/dist-test-faq/controllers/faqController.js
Normal file
318
backend/dist-test-faq/controllers/faqController.js
Normal file
@ -0,0 +1,318 @@
|
||||
"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;
|
||||
};
|
||||
})();
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
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.downloadCategoryDocument = downloadCategoryDocument;
|
||||
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;
|
||||
exports.adminUploadCategoryDocument = adminUploadCategoryDocument;
|
||||
exports.adminDeleteCategoryDocument = adminDeleteCategoryDocument;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const faqUpload_1 = require("../middleware/faqUpload");
|
||||
const fileIntegrityService_1 = require("../services/fileIntegrityService");
|
||||
const fileMagic_1 = require("../utils/fileMagic");
|
||||
const uploadValidation_1 = require("../utils/uploadValidation");
|
||||
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.setHeader('Cross-Origin-Resource-Policy', 'cross-origin');
|
||||
res.sendFile(filePath);
|
||||
}
|
||||
catch (e) {
|
||||
handleError(res, e);
|
||||
}
|
||||
}
|
||||
/** Public download of a category PDF (active categories only). */
|
||||
async function downloadCategoryDocument(req, res) {
|
||||
try {
|
||||
const lang = faqService.parseFaqDocumentLang(req.params.lang);
|
||||
const resolved = await faqService.resolvePublicCategoryDocument(req.params.slug, lang);
|
||||
if (!resolved) {
|
||||
res.status(404).json({ error: 'Document not found' });
|
||||
return;
|
||||
}
|
||||
res.setHeader('Content-Type', 'application/pdf');
|
||||
res.setHeader('Content-Disposition', `attachment; filename="${resolved.downloadName.replace(/"/g, '')}"`);
|
||||
res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin');
|
||||
res.sendFile(resolved.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 filePath = path_1.default.join((0, faqUpload_1.ensureFaqUploadDir)(), req.file.filename);
|
||||
try {
|
||||
await (0, uploadValidation_1.validateUploadedFile)(filePath, faqUpload_1.FAQ_ALLOWED_MIMES);
|
||||
}
|
||||
catch (e) {
|
||||
(0, fileMagic_1.removeUploadedFile)(filePath);
|
||||
const msg = e instanceof Error ? e.message : 'File validation failed';
|
||||
res.status(msg.includes('virus') ? 422 : 400).json({ error: msg });
|
||||
return;
|
||||
}
|
||||
const url = faqService.publicFaqFileUrl(req.file.filename);
|
||||
await (0, fileIntegrityService_1.recordUploadedFile)(fileIntegrityService_1.FILE_INTEGRITY_ROOTS.faq, 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);
|
||||
}
|
||||
}
|
||||
async function adminUploadCategoryDocument(req, res) {
|
||||
try {
|
||||
const id = Number(req.params.id);
|
||||
if (!Number.isFinite(id)) {
|
||||
res.status(400).json({ error: 'Invalid category id' });
|
||||
return;
|
||||
}
|
||||
if (!req.file) {
|
||||
res.status(400).json({ error: 'No file uploaded' });
|
||||
return;
|
||||
}
|
||||
const lang = faqService.parseFaqDocumentLang(req.params.lang);
|
||||
const item = await faqService.uploadCategoryDocument({
|
||||
categoryId: id,
|
||||
lang,
|
||||
storedFilename: req.file.filename,
|
||||
originalName: req.file.originalname,
|
||||
byteSize: req.file.size,
|
||||
});
|
||||
res.status(201).json(item);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Upload failed';
|
||||
if (msg.includes('virus')) {
|
||||
res.status(422).json({ error: msg });
|
||||
return;
|
||||
}
|
||||
handleError(res, e);
|
||||
}
|
||||
}
|
||||
async function adminDeleteCategoryDocument(req, res) {
|
||||
try {
|
||||
const id = Number(req.params.id);
|
||||
if (!Number.isFinite(id)) {
|
||||
res.status(400).json({ error: 'Invalid category id' });
|
||||
return;
|
||||
}
|
||||
const lang = faqService.parseFaqDocumentLang(req.params.lang);
|
||||
res.json(await faqService.deleteCategoryDocument(id, lang));
|
||||
}
|
||||
catch (e) {
|
||||
handleError(res, e);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=faqController.js.map
|
||||
1
backend/dist-test-faq/controllers/faqController.js.map
Normal file
1
backend/dist-test-faq/controllers/faqController.js.map
Normal file
File diff suppressed because one or more lines are too long
12
backend/dist-test-faq/controllers/fundApprovalController.d.ts
vendored
Normal file
12
backend/dist-test-faq/controllers/fundApprovalController.d.ts
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
import { Response } from 'express';
|
||||
import { AuthRequest } from '../middleware/auth';
|
||||
export declare function createFundRequest(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function listFundRequests(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function getFundRequest(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function approveFundRequest(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function rejectFundRequest(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function cancelFundRequest(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function listApprovalPolicies(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function listPolicyRevisions(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function draftPolicyChange(req: AuthRequest, res: Response): Promise<void>;
|
||||
//# sourceMappingURL=fundApprovalController.d.ts.map
|
||||
@ -0,0 +1 @@
|
||||
{"version":3,"file":"fundApprovalController.d.ts","sourceRoot":"","sources":["../../src/controllers/fundApprovalController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAKjD,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAoBtF;AAED,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAcrF;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAWnF;AAED,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAQvF;AAED,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBtF;AAED,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAQtF;AAED,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAQzF;AAED,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CASxF;AAED,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBtF"}
|
||||
171
backend/dist-test-faq/controllers/fundApprovalController.js
Normal file
171
backend/dist-test-faq/controllers/fundApprovalController.js
Normal file
@ -0,0 +1,171 @@
|
||||
"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.createFundRequest = createFundRequest;
|
||||
exports.listFundRequests = listFundRequests;
|
||||
exports.getFundRequest = getFundRequest;
|
||||
exports.approveFundRequest = approveFundRequest;
|
||||
exports.rejectFundRequest = rejectFundRequest;
|
||||
exports.cancelFundRequest = cancelFundRequest;
|
||||
exports.listApprovalPolicies = listApprovalPolicies;
|
||||
exports.listPolicyRevisions = listPolicyRevisions;
|
||||
exports.draftPolicyChange = draftPolicyChange;
|
||||
const fundApprovalService = __importStar(require("../services/fundApprovalService"));
|
||||
async function createFundRequest(req, res) {
|
||||
try {
|
||||
const { operationType, payload } = req.body;
|
||||
if (!operationType || !payload) {
|
||||
res.status(400).json({ error: 'operationType and payload are required' });
|
||||
return;
|
||||
}
|
||||
const result = await fundApprovalService.createFundRequest({
|
||||
operationType,
|
||||
payload,
|
||||
requestedBy: req.user.userId,
|
||||
});
|
||||
res.status(202).json({ requestId: result.id, status: result.status, request: result });
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to create request';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function listFundRequests(req, res) {
|
||||
try {
|
||||
const status = req.query.status || undefined;
|
||||
const operationType = req.query.operationType || undefined;
|
||||
const limit = parseInt(req.query.limit || '50', 10);
|
||||
const offset = parseInt(req.query.offset || '0', 10);
|
||||
const result = await fundApprovalService.listFundRequests({ status, operationType, limit, offset }, req.user.userId);
|
||||
res.json(result);
|
||||
}
|
||||
catch (e) {
|
||||
res.status(500).json({ error: e instanceof Error ? e.message : 'Failed to list requests' });
|
||||
}
|
||||
}
|
||||
async function getFundRequest(req, res) {
|
||||
try {
|
||||
const result = await fundApprovalService.getFundRequest(req.params.id, req.user.userId);
|
||||
if (!result) {
|
||||
res.status(404).json({ error: 'Request not found' });
|
||||
return;
|
||||
}
|
||||
res.json(result);
|
||||
}
|
||||
catch (e) {
|
||||
res.status(500).json({ error: e instanceof Error ? e.message : 'Failed to load request' });
|
||||
}
|
||||
}
|
||||
async function approveFundRequest(req, res) {
|
||||
try {
|
||||
const result = await fundApprovalService.approveFundRequest(req.params.id, req.user.userId);
|
||||
res.json(result);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Approval failed';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function rejectFundRequest(req, res) {
|
||||
try {
|
||||
const { reason } = req.body;
|
||||
if (!reason?.trim()) {
|
||||
res.status(400).json({ error: 'reason is required' });
|
||||
return;
|
||||
}
|
||||
const result = await fundApprovalService.rejectFundRequest(req.params.id, req.user.userId, reason);
|
||||
res.json(result);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Rejection failed';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function cancelFundRequest(req, res) {
|
||||
try {
|
||||
const result = await fundApprovalService.cancelFundRequest(req.params.id, req.user.userId);
|
||||
res.json(result);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Cancel failed';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function listApprovalPolicies(req, res) {
|
||||
try {
|
||||
const items = await fundApprovalService.listApprovalPolicies(req.user.userId);
|
||||
res.json({ items });
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to list policies';
|
||||
res.status(msg.includes('Permission') ? 403 : 500).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function listPolicyRevisions(req, res) {
|
||||
try {
|
||||
const limit = parseInt(req.query.limit || '50', 10);
|
||||
const items = await fundApprovalService.listPolicyRevisions(req.user.userId, limit);
|
||||
res.json({ items });
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to list revisions';
|
||||
res.status(msg.includes('Permission') ? 403 : 500).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function draftPolicyChange(req, res) {
|
||||
try {
|
||||
const { after, note } = req.body;
|
||||
if (!Array.isArray(after)) {
|
||||
res.status(400).json({ error: 'after (policies array) is required' });
|
||||
return;
|
||||
}
|
||||
const result = await fundApprovalService.draftPolicyChange({
|
||||
after,
|
||||
note,
|
||||
requestedBy: req.user.userId,
|
||||
});
|
||||
res.status(202).json({
|
||||
requestId: result.id,
|
||||
status: result.status,
|
||||
message: 'Policy change submitted — approve under Approvals to apply',
|
||||
request: result,
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to draft policy change';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=fundApprovalController.js.map
|
||||
File diff suppressed because one or more lines are too long
10
backend/dist-test-faq/controllers/gameController.d.ts
vendored
Normal file
10
backend/dist-test-faq/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
|
||||
@ -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-test-faq/controllers/gameController.js
Normal file
120
backend/dist-test-faq/controllers/gameController.js
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-test-faq/controllers/gameController.js.map
Normal file
1
backend/dist-test-faq/controllers/gameController.js.map
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,CAAC,GAAgB,EAAE,GAAa;IAC7D,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,KAAK,MAAM,CAAC;QAC/C,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file
9
backend/dist-test-faq/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
|
||||
@ -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;AA0CjD,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"}
|
||||
161
backend/dist-test-faq/controllers/gamePlayController.js
Normal file
161
backend/dist-test-faq/controllers/gamePlayController.js
Normal file
@ -0,0 +1,161 @@
|
||||
"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,
|
||||
roles: req.user?.roles,
|
||||
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
|
||||
File diff suppressed because one or more lines are too long
12
backend/dist-test-faq/controllers/marketingController.d.ts
vendored
Normal file
12
backend/dist-test-faq/controllers/marketingController.d.ts
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
import { Response } from 'express';
|
||||
import { AuthRequest } from '../middleware/auth';
|
||||
export declare function getDailyStats(_req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function getActivityFeed(_req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function getWithdrawalFeed(_req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function getLiveActivitySettings(_req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function updateLiveActivitySettings(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function listPersonas(_req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function createPersona(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function updatePersona(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function deletePersona(req: AuthRequest, res: Response): Promise<void>;
|
||||
//# sourceMappingURL=marketingController.d.ts.map
|
||||
@ -0,0 +1 @@
|
||||
{"version":3,"file":"marketingController.d.ts","sourceRoot":"","sources":["../../src/controllers/marketingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,wBAAsB,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAQnF;AAED,wBAAsB,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAQrF;AAED,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAQvF;AAED,wBAAsB,uBAAuB,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ7F;AAED,wBAAsB,0BAA0B,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAU/F;AAED,wBAAsB,YAAY,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAQlF;AAED,wBAAsB,aAAa,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAUlF;AAED,wBAAsB,aAAa,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAYlF;AAED,wBAAsB,aAAa,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAQlF"}
|
||||
137
backend/dist-test-faq/controllers/marketingController.js
Normal file
137
backend/dist-test-faq/controllers/marketingController.js
Normal file
@ -0,0 +1,137 @@
|
||||
"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.getDailyStats = getDailyStats;
|
||||
exports.getActivityFeed = getActivityFeed;
|
||||
exports.getWithdrawalFeed = getWithdrawalFeed;
|
||||
exports.getLiveActivitySettings = getLiveActivitySettings;
|
||||
exports.updateLiveActivitySettings = updateLiveActivitySettings;
|
||||
exports.listPersonas = listPersonas;
|
||||
exports.createPersona = createPersona;
|
||||
exports.updatePersona = updatePersona;
|
||||
exports.deletePersona = deletePersona;
|
||||
const marketingService = __importStar(require("../services/marketingService"));
|
||||
async function getDailyStats(_req, res) {
|
||||
try {
|
||||
const stats = await marketingService.getDailyStats();
|
||||
res.json(stats);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to load daily stats';
|
||||
res.status(500).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function getActivityFeed(_req, res) {
|
||||
try {
|
||||
const feed = await marketingService.getActivityFeed();
|
||||
res.json(feed);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to load activity feed';
|
||||
res.status(500).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function getWithdrawalFeed(_req, res) {
|
||||
try {
|
||||
const feed = await marketingService.getWithdrawalFeed();
|
||||
res.json(feed);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to load withdrawal feed';
|
||||
res.status(500).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function getLiveActivitySettings(_req, res) {
|
||||
try {
|
||||
const settings = await marketingService.getLiveActivitySettingsAdmin();
|
||||
res.json(settings);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to load marketing settings';
|
||||
res.status(500).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function updateLiveActivitySettings(req, res) {
|
||||
try {
|
||||
const settings = await marketingService.updateLiveActivitySettingsAdmin(req.body);
|
||||
res.json(settings);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to update marketing settings';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function listPersonas(_req, res) {
|
||||
try {
|
||||
const personas = await marketingService.listPersonasAdmin();
|
||||
res.json(personas);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to load personas';
|
||||
res.status(500).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function createPersona(req, res) {
|
||||
try {
|
||||
const persona = await marketingService.createPersonaAdmin(req.body);
|
||||
res.status(201).json(persona);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to create persona';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function updatePersona(req, res) {
|
||||
try {
|
||||
const persona = await marketingService.updatePersonaAdmin(req.params.id, req.body);
|
||||
res.json(persona);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to update persona';
|
||||
const status = msg === 'Persona not found' ? 404 : 400;
|
||||
res.status(status).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function deletePersona(req, res) {
|
||||
try {
|
||||
await marketingService.deletePersonaAdmin(req.params.id);
|
||||
res.status(204).send();
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to delete persona';
|
||||
res.status(msg === 'Persona not found' ? 404 : 400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=marketingController.js.map
|
||||
@ -0,0 +1 @@
|
||||
{"version":3,"file":"marketingController.js","sourceRoot":"","sources":["../../src/controllers/marketingController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,sCAQC;AAED,0CAQC;AAED,8CAQ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AAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,0BAA0B,CAAC;QACxE,MAAM,MAAM,GAAG,GAAG,KAAK,mBAAmB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;QACvD,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC;AAEM,KAAK,UAAU,aAAa,CAAC,GAAgB,EAAE,GAAa;IACjE,IAAI,CAAC;QACH,MAAM,gBAAgB,CAAC,kBAAkB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACzD,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,0BAA0B,CAAC;QACxE,GAAG,CAAC,MAAM,CAAC,GAAG,KAAK,mBAAmB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC"}
|
||||
24
backend/dist-test-faq/controllers/mobileAppReleaseController.d.ts
vendored
Normal file
24
backend/dist-test-faq/controllers/mobileAppReleaseController.d.ts
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* HTTP handlers for mobile app release admin + public update check/download.
|
||||
*/
|
||||
import { Response } from 'express';
|
||||
import { AuthRequest } from '../middleware/auth';
|
||||
export declare function checkAndroid(req: AuthRequest, res: Response): Promise<void>;
|
||||
/** Public metadata + download link for the website APK button (no auth). */
|
||||
export declare function latestAndroid(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function downloadAndroid(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function postEvent(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function adminList(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function adminGet(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function adminCreate(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function adminUpdate(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function adminUploadApk(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function adminSubmit(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function adminPublish(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function adminSuspend(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function adminRetire(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function adminDelete(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function adminStats(_req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function adminGetSettings(_req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function adminUpdateSettings(req: AuthRequest, res: Response): Promise<void>;
|
||||
//# sourceMappingURL=mobileAppReleaseController.d.ts.map
|
||||
@ -0,0 +1 @@
|
||||
{"version":3,"file":"mobileAppReleaseController.d.ts","sourceRoot":"","sources":["../../src/controllers/mobileAppReleaseController.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAcjD,wBAAsB,YAAY,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBjF;AAED,4EAA4E;AAC5E,wBAAsB,aAAa,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CASlF;AAED,wBAAsB,eAAe,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,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AAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAMhF;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAMtF;AAED,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAMxF"}
|
||||
274
backend/dist-test-faq/controllers/mobileAppReleaseController.js
Normal file
274
backend/dist-test-faq/controllers/mobileAppReleaseController.js
Normal file
@ -0,0 +1,274 @@
|
||||
"use strict";
|
||||
/**
|
||||
* HTTP handlers for mobile app release admin + public update check/download.
|
||||
*/
|
||||
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 });
|
||||
exports.checkAndroid = checkAndroid;
|
||||
exports.latestAndroid = latestAndroid;
|
||||
exports.downloadAndroid = downloadAndroid;
|
||||
exports.postEvent = postEvent;
|
||||
exports.adminList = adminList;
|
||||
exports.adminGet = adminGet;
|
||||
exports.adminCreate = adminCreate;
|
||||
exports.adminUpdate = adminUpdate;
|
||||
exports.adminUploadApk = adminUploadApk;
|
||||
exports.adminSubmit = adminSubmit;
|
||||
exports.adminPublish = adminPublish;
|
||||
exports.adminSuspend = adminSuspend;
|
||||
exports.adminRetire = adminRetire;
|
||||
exports.adminDelete = adminDelete;
|
||||
exports.adminStats = adminStats;
|
||||
exports.adminGetSettings = adminGetSettings;
|
||||
exports.adminUpdateSettings = adminUpdateSettings;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const mobileAppReleaseService = __importStar(require("../services/mobileAppReleaseService"));
|
||||
const mobileAppReleaseService_1 = require("../services/mobileAppReleaseService");
|
||||
function sendError(res, e, fallback) {
|
||||
if (e instanceof mobileAppReleaseService_1.MobileReleaseError || (e instanceof Error && 'statusCode' in e)) {
|
||||
const err = e;
|
||||
res.status(err.statusCode ?? 400).json({ error: err.message, ...(err.code ? { code: err.code } : {}) });
|
||||
return;
|
||||
}
|
||||
console.error(e);
|
||||
res.status(500).json({ error: e instanceof Error ? e.message : fallback });
|
||||
}
|
||||
async function checkAndroid(req, res) {
|
||||
try {
|
||||
const q = req.query;
|
||||
const result = await mobileAppReleaseService.checkAndroidUpdate({
|
||||
versionCode: Number(q.versionCode),
|
||||
versionName: q.versionName,
|
||||
channel: q.channel,
|
||||
deviceId: q.deviceId,
|
||||
});
|
||||
res.json(result);
|
||||
}
|
||||
catch (e) {
|
||||
sendError(res, e, 'Update check failed');
|
||||
}
|
||||
}
|
||||
/** Public metadata + download link for the website APK button (no auth). */
|
||||
async function latestAndroid(req, res) {
|
||||
try {
|
||||
const channel = String(req.query.channel || 'production');
|
||||
const result = await mobileAppReleaseService.getLatestPublicAndroidApk(channel);
|
||||
res.setHeader('Cache-Control', 'no-store');
|
||||
res.json(result);
|
||||
}
|
||||
catch (e) {
|
||||
sendError(res, e, 'Latest APK lookup failed');
|
||||
}
|
||||
}
|
||||
async function downloadAndroid(req, res) {
|
||||
try {
|
||||
const id = String(req.params.id || '');
|
||||
const token = String(req.query.token || '');
|
||||
const { release, absolutePath } = await mobileAppReleaseService.openDownloadStream(id, token);
|
||||
const stat = fs_1.default.statSync(absolutePath);
|
||||
res.setHeader('Content-Type', 'application/vnd.android.package-archive');
|
||||
res.setHeader('Content-Length', String(stat.size));
|
||||
res.setHeader('Content-Disposition', `attachment; filename="tloto-${release.versionName}.apk"`);
|
||||
res.setHeader('X-Content-SHA256', release.sha256 || '');
|
||||
res.setHeader('Accept-Ranges', 'bytes');
|
||||
res.setHeader('Cache-Control', 'no-store');
|
||||
res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin');
|
||||
const range = req.headers.range;
|
||||
if (range) {
|
||||
const match = /^bytes=(\d+)-(\d*)$/.exec(range);
|
||||
if (match) {
|
||||
const start = parseInt(match[1], 10);
|
||||
const end = match[2] ? parseInt(match[2], 10) : stat.size - 1;
|
||||
if (start >= 0 && end < stat.size && start <= end) {
|
||||
res.status(206);
|
||||
res.setHeader('Content-Range', `bytes ${start}-${end}/${stat.size}`);
|
||||
res.setHeader('Content-Length', String(end - start + 1));
|
||||
fs_1.default.createReadStream(absolutePath, { start, end }).pipe(res);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
fs_1.default.createReadStream(absolutePath).pipe(res);
|
||||
}
|
||||
catch (e) {
|
||||
sendError(res, e, 'Download failed');
|
||||
}
|
||||
}
|
||||
async function postEvent(req, res) {
|
||||
try {
|
||||
const body = req.body;
|
||||
await mobileAppReleaseService.recordClientEvent({
|
||||
...body,
|
||||
userId: req.user?.userId ?? null,
|
||||
});
|
||||
res.json({ ok: true });
|
||||
}
|
||||
catch (e) {
|
||||
sendError(res, e, 'Event failed');
|
||||
}
|
||||
}
|
||||
async function adminList(req, res) {
|
||||
try {
|
||||
const q = req.query;
|
||||
const result = await mobileAppReleaseService.listReleases({
|
||||
platform: q.platform,
|
||||
channel: q.channel,
|
||||
status: q.status,
|
||||
search: q.search,
|
||||
limit: q.limit ? Number(q.limit) : undefined,
|
||||
offset: q.offset ? Number(q.offset) : undefined,
|
||||
});
|
||||
res.json(result);
|
||||
}
|
||||
catch (e) {
|
||||
sendError(res, e, 'List failed');
|
||||
}
|
||||
}
|
||||
async function adminGet(req, res) {
|
||||
try {
|
||||
const release = await mobileAppReleaseService.getRelease(String(req.params.id));
|
||||
res.json(release);
|
||||
}
|
||||
catch (e) {
|
||||
sendError(res, e, 'Get failed');
|
||||
}
|
||||
}
|
||||
async function adminCreate(req, res) {
|
||||
try {
|
||||
const release = await mobileAppReleaseService.createRelease({
|
||||
...req.body,
|
||||
createdBy: req.user?.userId ?? null,
|
||||
});
|
||||
res.status(201).json(release);
|
||||
}
|
||||
catch (e) {
|
||||
sendError(res, e, 'Create failed');
|
||||
}
|
||||
}
|
||||
async function adminUpdate(req, res) {
|
||||
try {
|
||||
const release = await mobileAppReleaseService.updateReleaseMeta(String(req.params.id), req.body);
|
||||
res.json(release);
|
||||
}
|
||||
catch (e) {
|
||||
sendError(res, e, 'Update failed');
|
||||
}
|
||||
}
|
||||
async function adminUploadApk(req, res) {
|
||||
try {
|
||||
const file = req.file;
|
||||
if (!file?.path) {
|
||||
res.status(400).json({ error: 'APK file is required (field name: file)' });
|
||||
return;
|
||||
}
|
||||
const release = await mobileAppReleaseService.attachApk(String(req.params.id), file.path);
|
||||
res.json(release);
|
||||
}
|
||||
catch (e) {
|
||||
sendError(res, e, 'Upload failed');
|
||||
}
|
||||
}
|
||||
async function adminSubmit(req, res) {
|
||||
try {
|
||||
res.json(await mobileAppReleaseService.submitForValidation(String(req.params.id)));
|
||||
}
|
||||
catch (e) {
|
||||
sendError(res, e, 'Submit failed');
|
||||
}
|
||||
}
|
||||
async function adminPublish(req, res) {
|
||||
try {
|
||||
res.json(await mobileAppReleaseService.publish(String(req.params.id)));
|
||||
}
|
||||
catch (e) {
|
||||
sendError(res, e, 'Publish failed');
|
||||
}
|
||||
}
|
||||
async function adminSuspend(req, res) {
|
||||
try {
|
||||
res.json(await mobileAppReleaseService.suspend(String(req.params.id)));
|
||||
}
|
||||
catch (e) {
|
||||
sendError(res, e, 'Suspend failed');
|
||||
}
|
||||
}
|
||||
async function adminRetire(req, res) {
|
||||
try {
|
||||
res.json(await mobileAppReleaseService.retire(String(req.params.id)));
|
||||
}
|
||||
catch (e) {
|
||||
sendError(res, e, 'Retire failed');
|
||||
}
|
||||
}
|
||||
async function adminDelete(req, res) {
|
||||
try {
|
||||
res.json(await mobileAppReleaseService.hardDelete(String(req.params.id), {
|
||||
userId: req.user.userId,
|
||||
ipAddress: req.ip || undefined,
|
||||
userAgent: req.get('user-agent') || undefined,
|
||||
}));
|
||||
}
|
||||
catch (e) {
|
||||
sendError(res, e, 'Delete failed');
|
||||
}
|
||||
}
|
||||
async function adminStats(_req, res) {
|
||||
try {
|
||||
res.json(await mobileAppReleaseService.getStats());
|
||||
}
|
||||
catch (e) {
|
||||
sendError(res, e, 'Stats failed');
|
||||
}
|
||||
}
|
||||
async function adminGetSettings(_req, res) {
|
||||
try {
|
||||
res.json(await mobileAppReleaseService.getSettings());
|
||||
}
|
||||
catch (e) {
|
||||
sendError(res, e, 'Settings failed');
|
||||
}
|
||||
}
|
||||
async function adminUpdateSettings(req, res) {
|
||||
try {
|
||||
res.json(await mobileAppReleaseService.updateSettings(req.body));
|
||||
}
|
||||
catch (e) {
|
||||
sendError(res, e, 'Settings update failed');
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=mobileAppReleaseController.js.map
|
||||
File diff suppressed because one or more lines are too long
6
backend/dist-test-faq/controllers/notificationController.d.ts
vendored
Normal file
6
backend/dist-test-faq/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
|
||||
@ -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-test-faq/controllers/notificationController.js
Normal file
86
backend/dist-test-faq/controllers/notificationController.js
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
|
||||
@ -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,iBA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,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,6BAA6B,CAAC;QAC3E,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,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-test-faq/controllers/overviewController.d.ts
vendored
Normal file
20
backend/dist-test-faq/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
|
||||
@ -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-test-faq/controllers/overviewController.js
Normal file
64
backend/dist-test-faq/controllers/overviewController.js
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
|
||||
@ -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-test-faq/controllers/presenceController.d.ts
vendored
Normal file
5
backend/dist-test-faq/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
|
||||
@ -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-test-faq/controllers/presenceController.js
Normal file
12
backend/dist-test-faq/controllers/presenceController.js
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
|
||||
@ -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"}
|
||||
17
backend/dist-test-faq/controllers/rbacController.d.ts
vendored
Normal file
17
backend/dist-test-faq/controllers/rbacController.d.ts
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* RBAC HTTP handlers — roles and permissions management.
|
||||
*/
|
||||
import { Response } from 'express';
|
||||
import { AuthRequest } from '../middleware/auth';
|
||||
export declare function listPermissions(_req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function listRoles(_req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function getRole(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function createRole(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function updateRole(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function deleteRole(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function getMyPermissions(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function listAdminUsers(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function getAdminUser(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function getAdminUserPermissions(req: AuthRequest, res: Response): Promise<void>;
|
||||
export declare function updateAdminUserPermissions(req: AuthRequest, res: Response): Promise<void>;
|
||||
//# sourceMappingURL=rbacController.d.ts.map
|
||||
@ -0,0 +1 @@
|
||||
{"version":3,"file":"rbacController.d.ts","sourceRoot":"","sources":["../../src/controllers/rbacController.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,wBAAsB,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,G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||
* RBAC HTTP handlers — roles and permissions management.
|
||||
*/
|
||||
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.listPermissions = listPermissions;
|
||||
exports.listRoles = listRoles;
|
||||
exports.getRole = getRole;
|
||||
exports.createRole = createRole;
|
||||
exports.updateRole = updateRole;
|
||||
exports.deleteRole = deleteRole;
|
||||
exports.getMyPermissions = getMyPermissions;
|
||||
exports.listAdminUsers = listAdminUsers;
|
||||
exports.getAdminUser = getAdminUser;
|
||||
exports.getAdminUserPermissions = getAdminUserPermissions;
|
||||
exports.updateAdminUserPermissions = updateAdminUserPermissions;
|
||||
const rbacService = __importStar(require("../services/rbacService"));
|
||||
async function listPermissions(_req, res) {
|
||||
try {
|
||||
const data = await rbacService.listPermissions();
|
||||
res.json(data);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to list permissions';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function listRoles(_req, res) {
|
||||
try {
|
||||
const roles = await rbacService.listRoles();
|
||||
res.json({ roles });
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to list roles';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function getRole(req, res) {
|
||||
try {
|
||||
const roleId = parseInt(req.params.roleId, 10);
|
||||
const role = await rbacService.getRole(roleId);
|
||||
if (!role) {
|
||||
res.status(404).json({ error: 'Role not found' });
|
||||
return;
|
||||
}
|
||||
res.json(role);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to load role';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function createRole(req, res) {
|
||||
try {
|
||||
const { name, description, permissionKeys } = req.body;
|
||||
if (!name?.trim()) {
|
||||
res.status(400).json({ error: 'Role name is required' });
|
||||
return;
|
||||
}
|
||||
const role = await rbacService.createRole({ name, description, permissionKeys: permissionKeys ?? [] }, req.user.userId);
|
||||
res.status(201).json(role);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to create role';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function updateRole(req, res) {
|
||||
try {
|
||||
const roleId = parseInt(req.params.roleId, 10);
|
||||
const { name, description, permissionKeys } = req.body;
|
||||
const role = await rbacService.updateRole(roleId, { name, description, permissionKeys }, req.user.userId);
|
||||
res.json(role);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to update role';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function deleteRole(req, res) {
|
||||
try {
|
||||
const roleId = parseInt(req.params.roleId, 10);
|
||||
await rbacService.deleteRole(roleId, req.user.userId);
|
||||
res.json({ message: 'Role deleted' });
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to delete role';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function getMyPermissions(req, res) {
|
||||
try {
|
||||
const userId = req.user.userId;
|
||||
const roleRepository = await Promise.resolve().then(() => __importStar(require('../repositories/roleRepository')));
|
||||
const [roles, permissions] = await Promise.all([
|
||||
roleRepository.getUserRoleNames(userId),
|
||||
roleRepository.getUserPermissions(userId),
|
||||
]);
|
||||
res.json({
|
||||
roles,
|
||||
permissions,
|
||||
primaryRole: roleRepository.resolvePrimaryRole(roles),
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to load permissions';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function listAdminUsers(req, res) {
|
||||
try {
|
||||
const q = req.query;
|
||||
const exceptionRaw = q.exception ?? 'all';
|
||||
const exception = exceptionRaw === 'any' ||
|
||||
exceptionRaw === 'allow' ||
|
||||
exceptionRaw === 'deny' ||
|
||||
exceptionRaw === 'none' ||
|
||||
exceptionRaw === 'all'
|
||||
? exceptionRaw
|
||||
: 'all';
|
||||
const data = await rbacService.listAdminUsers({
|
||||
search: q.search,
|
||||
role: q.role,
|
||||
exception,
|
||||
permission: q.permission,
|
||||
limit: q.limit ? parseInt(q.limit, 10) : 50,
|
||||
offset: q.offset ? parseInt(q.offset, 10) : 0,
|
||||
});
|
||||
res.json(data);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to list admin users';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function getAdminUser(req, res) {
|
||||
try {
|
||||
const userId = req.params.userId;
|
||||
const data = await rbacService.getAdminUser(userId);
|
||||
if (!data) {
|
||||
res.status(404).json({ error: 'User not found' });
|
||||
return;
|
||||
}
|
||||
res.json(data);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to load admin user';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function getAdminUserPermissions(req, res) {
|
||||
try {
|
||||
const userId = req.params.userId;
|
||||
const data = await rbacService.getAdminUser(userId);
|
||||
if (!data) {
|
||||
res.status(404).json({ error: 'User not found' });
|
||||
return;
|
||||
}
|
||||
res.json({
|
||||
user: data.user,
|
||||
permissions: data.permissions,
|
||||
categories: data.categories,
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to load permissions';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
async function updateAdminUserPermissions(req, res) {
|
||||
try {
|
||||
const userId = req.params.userId;
|
||||
const body = req.body;
|
||||
const changes = body.changes ??
|
||||
(body.permissionKey && body.action
|
||||
? [{ key: body.permissionKey, action: body.action }]
|
||||
: []);
|
||||
const data = await rbacService.applyUserPermissionChanges(userId, changes, req.user.userId);
|
||||
res.json(data);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to update permissions';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=rbacController.js.map
|
||||
1
backend/dist-test-faq/controllers/rbacController.js.map
Normal file
1
backend/dist-test-faq/controllers/rbacController.js.map
Normal file
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user