Files
gameno-api/components/notifications/notificationController.js
T
kavehhn f04c797be6 Initial commit: teaching institution management API.
Express/MongoDB backend with JWT auth, RBAC, S3 uploads, notifications, and scheduled jobs.
2026-08-09 04:18:08 +02:00

46 lines
1.9 KiB
JavaScript

// /components/notifications/notificationController.js
const catchAsync = require('../../utils/catchAsync');
const notificationService = require('./notificationService');
const { successResponse, listResponse } = require('../../utils/apiResponse');
exports.create = catchAsync(async (req, res, next) => {
const notification = await notificationService.createNotification(req.body);
return successResponse(res, 201, 'Notification created successfully', notification);
});
exports.getOne = catchAsync(async (req, res, next) => {
const notification = await notificationService.getNotificationById(req.params.id);
return successResponse(res, 200, 'Notification retrieved successfully', notification);
});
exports.getAll = catchAsync(async (req, res, next) => {
const { data, meta } = await notificationService.getAllNotifications(req.query);
return listResponse(res, 200, data, meta);
});
exports.update = catchAsync(async (req, res, next) => {
const notification = await notificationService.updateNotification(req.params.id, req.body);
return successResponse(res, 200, 'Notification updated successfully', notification);
});
exports.delete = catchAsync(async (req, res, next) => {
await notificationService.deleteNotification(req.params.id);
return successResponse(res, 200, 'Notification deleted successfully');
});
exports.search = catchAsync(async (req, res, next) => {
const { data, meta } = await notificationService.searchNotifications(req.query);
return listResponse(res, 200, data, meta);
});
exports.retry = catchAsync(async (req, res, next) => {
const result = await notificationService.retryNotification(req.params.id);
return successResponse(res, 200, 'Notification retried successfully', result);
});
exports.getMyNotifications = catchAsync(async (req, res, next) => {
const { data, meta } = await notificationService.getMyNotifications(req.user._id, req.query);
return listResponse(res, 200, data, meta);
});