games_app/backend/dist/controllers/notificationController.js
2026-06-29 15:01:23 +02:00

86 lines
3.4 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.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