games_app/backend/dist/games/modules/candle-predict/candlePredictModule.js
2026-07-07 15:03:17 +02:00

114 lines
5.0 KiB
JavaScript

"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.candlePredictModule = void 0;
const candlePredictService = __importStar(require("../../../services/candlePredictService"));
const stakeAmountValidation_1 = require("../../../utils/stakeAmountValidation");
const errors_1 = require("../../errors");
const roleAccess_1 = require("../../../utils/roleAccess");
function parseIntervalMinutes(value) {
if (value == null || value === '')
return undefined;
const n = Number(value);
return Number.isFinite(n) ? n : undefined;
}
function parsePage(value, fallback) {
const n = parseInt(String(value ?? ''), 10);
return Number.isFinite(n) ? Math.max(1, n) : fallback;
}
function parsePageSize(value, fallback) {
const n = parseInt(String(value ?? ''), 10);
return Number.isFinite(n) ? Math.min(50, Math.max(1, n)) : fallback;
}
exports.candlePredictModule = {
implementationKey: 'candle-predict',
displayName: 'Candle Predict',
slug: 'candle-predict',
capabilities: {
actions: ['state', 'placeBet', 'myBets', 'auto.get', 'auto.update'],
customGet: ['candles'],
hasBackgroundEngine: true,
adminConfigPath: '/admin/candle-predict/config',
},
startEngine: () => candlePredictService.startCandlePredictEngine(),
getState: ({ userId, query, role, roles }) => candlePredictService.getGameState(userId, parseIntervalMinutes(query.intervalMinutes), {
includeInternal: (0, roleAccess_1.hasAdminAccess)({ role, roles }),
}),
placeBet: ({ userId, body }) => {
if (!userId)
throw new Error('Unauthorized');
const { direction, stakeAmount, intervalMinutes, stakeAccountKind, idempotencyKey } = body;
if (stakeAmount === undefined || stakeAmount === null) {
throw new Error('stakeAmount is required');
}
const parsedStake = (0, stakeAmountValidation_1.parseStakeAmountFromBody)(stakeAmount);
return candlePredictService.placeBet(userId, direction ?? '', parsedStake, intervalMinutes, stakeAccountKind, {
idempotencyKey: typeof idempotencyKey === 'string' ? idempotencyKey : undefined,
source: 'http',
});
},
getMyBets: ({ userId, query }) => {
if (!userId)
throw new Error('Unauthorized');
return candlePredictService.getRecentPredictions(userId, parsePage(query.page, 1), parsePageSize(query.pageSize, 10), parseIntervalMinutes(query.intervalMinutes));
},
getAutoSettings: ({ userId }) => {
if (!userId)
throw new Error('Unauthorized');
return candlePredictService.getAutoSettings(userId);
},
updateAutoSettings: ({ userId, body }) => {
if (!userId)
throw new Error('Unauthorized');
return candlePredictService.saveAutoSettings(userId, body);
},
handleCustom: (action, method, ctx) => {
if (action === 'candles' && method === 'GET') {
const limit = parseInt(String(ctx.query.limit ?? '0'), 10);
const beforeRaw = ctx.query.beforeOpenMs;
const beforeOpenMs = beforeRaw != null && beforeRaw !== '' && Number.isFinite(Number(beforeRaw))
? Number(beforeRaw)
: undefined;
return candlePredictService.getCandlesPage({
limit: limit > 0 ? limit : undefined,
intervalMinutes: parseIntervalMinutes(ctx.query.intervalMinutes),
beforeOpenMs,
includeInternal: (0, roleAccess_1.hasAdminAccess)(ctx),
});
}
throw new errors_1.UnsupportedGameActionError(action);
},
};
//# sourceMappingURL=candlePredictModule.js.map