82 lines
3.1 KiB
JavaScript
82 lines
3.1 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.listActiveGames = listActiveGames;
|
|
exports.listAllGames = listAllGames;
|
|
exports.getGameById = getGameById;
|
|
exports.getGameBySlug = getGameBySlug;
|
|
exports.createGame = createGame;
|
|
exports.updateGame = updateGame;
|
|
exports.deleteGame = deleteGame;
|
|
const connection_1 = require("../db/connection");
|
|
async function listActiveGames(featuredOnly = false) {
|
|
const featuredClause = featuredOnly ? 'AND is_featured = TRUE' : '';
|
|
return (0, connection_1.query)(`SELECT * FROM games
|
|
WHERE status IN ('active', 'coming_soon', 'maintenance')
|
|
${featuredClause}
|
|
ORDER BY sort_order ASC, title ASC`);
|
|
}
|
|
async function listAllGames() {
|
|
return (0, connection_1.query)('SELECT * FROM games ORDER BY sort_order ASC, title ASC');
|
|
}
|
|
async function getGameById(id) {
|
|
const rows = await (0, connection_1.query)('SELECT * FROM games WHERE id = $1', [id]);
|
|
return rows[0] ?? null;
|
|
}
|
|
async function getGameBySlug(slug) {
|
|
const rows = await (0, connection_1.query)('SELECT * FROM games WHERE slug = $1', [slug]);
|
|
return rows[0] ?? null;
|
|
}
|
|
async function createGame(input) {
|
|
const rows = await (0, connection_1.query)(`INSERT INTO games (slug, title, description, category, thumbnail_url, accent_color, status, sort_order, is_featured, implementation_key)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
|
RETURNING *`, [
|
|
input.slug,
|
|
input.title,
|
|
input.description ?? null,
|
|
input.category ?? 'prediction',
|
|
input.thumbnailUrl ?? null,
|
|
input.accentColor ?? '#D6B25E',
|
|
input.status ?? 'active',
|
|
input.sortOrder ?? 0,
|
|
input.isFeatured ?? false,
|
|
input.implementationKey ?? null,
|
|
]);
|
|
return rows[0];
|
|
}
|
|
async function updateGame(id, input) {
|
|
const existing = await getGameById(id);
|
|
if (!existing)
|
|
return null;
|
|
const rows = await (0, connection_1.query)(`UPDATE games SET
|
|
slug = $2,
|
|
title = $3,
|
|
description = $4,
|
|
category = $5,
|
|
thumbnail_url = $6,
|
|
accent_color = $7,
|
|
status = $8,
|
|
sort_order = $9,
|
|
is_featured = $10,
|
|
implementation_key = $11,
|
|
updated_at = NOW()
|
|
WHERE id = $1
|
|
RETURNING *`, [
|
|
id,
|
|
input.slug ?? existing.slug,
|
|
input.title ?? existing.title,
|
|
input.description !== undefined ? input.description : existing.description,
|
|
input.category ?? existing.category,
|
|
input.thumbnailUrl !== undefined ? input.thumbnailUrl : existing.thumbnail_url,
|
|
input.accentColor ?? existing.accent_color ?? '#D6B25E',
|
|
input.status ?? existing.status,
|
|
input.sortOrder ?? existing.sort_order,
|
|
input.isFeatured ?? existing.is_featured,
|
|
input.implementationKey !== undefined ? input.implementationKey : existing.implementation_key,
|
|
]);
|
|
return rows[0] ?? null;
|
|
}
|
|
async function deleteGame(id) {
|
|
const rows = await (0, connection_1.query)('DELETE FROM games WHERE id = $1 RETURNING id', [id]);
|
|
return rows.length > 0;
|
|
}
|
|
//# sourceMappingURL=gameRepository.js.map
|