games_app/backend/dist-test-faq/controllers/countryController.js

84 lines
3.3 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.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