Files
crosscode-platform/apps/events/backend/src/controllers/costController.js
T

45 lines
1.4 KiB
JavaScript

// Planned event costs (cashup and the profit report). Shared with /api/v2 (services/setup.ts, 1.51.8).
const setup = require('../services/setup');
const { safeErrorMessage } = require('../utils/errorUtils');
const fail = (res, error) => res.status(error.statusCode || 400).json({ message: safeErrorMessage(error) });
// @desc List costs for an event
// @route GET /api/events/:eventId/costs
// @access Private/Supervisor
const getEventCosts = async (req, res) => {
try {
res.json(await setup.listCosts(req.params.eventId));
} catch (error) { fail(res, error); }
};
// @desc Create a cost for an event
// @route POST /api/events/:eventId/costs
// @access Private/Admin
const createEventCost = async (req, res) => {
try {
res.status(201).json(await setup.createCost(req.params.eventId, req.body || {}));
} catch (error) { fail(res, error); }
};
// @desc Update a cost
// @route PUT /api/costs/:id
// @access Private/Admin
const updateEventCost = async (req, res) => {
try {
res.json(await setup.updateCost(req.params.id, req.body || {}));
} catch (error) { fail(res, error); }
};
// @desc Delete a cost
// @route DELETE /api/costs/:id
// @access Private/Admin
const deleteEventCost = async (req, res) => {
try {
await setup.deleteCost(req.params.id);
res.json({ message: 'Cost deleted' });
} catch (error) { fail(res, error); }
};
module.exports = { getEventCosts, createEventCost, updateEventCost, deleteEventCost };