Files
hope-events/backend/src/controllers/sectionController.js
T

46 lines
1.5 KiB
JavaScript

// Scanning sections: which ticket types may come in at which door. Shared with
// /api/v2/sections (services/setup.ts, 1.51.8).
const setup = require('../services/setup');
const { listWhere } = require('../utils/campusScope');
const fail = (res, error) => res.status(error.statusCode || 400).json({ message: error.message });
// @desc Get sections (optionally by event)
// @route GET /api/sections?eventId=xxx
// @access Private/Staff
const getSections = async (req, res) => {
try {
res.json(await setup.listSections(req.query.eventId, await listWhere(req, 'event')));
} catch (error) { fail(res, error); }
};
// @desc Create section
// @route POST /api/sections
// @access Private/Admin/Supervisor
const createSection = async (req, res) => {
try {
res.status(201).json(await setup.createSection(req.body || {}));
} catch (error) { fail(res, error); }
};
// @desc Update section
// @route PUT /api/sections/:id
// @access Private/Admin/Supervisor
const updateSection = async (req, res) => {
try {
res.json(await setup.updateSection(req.params.id, req.body || {}));
} catch (error) { fail(res, error); }
};
// @desc Delete section
// @route DELETE /api/sections/:id
// @access Private/Admin
const deleteSection = async (req, res) => {
try {
await setup.deleteSection(req.params.id);
res.json({ message: 'Section deleted' });
} catch (error) { fail(res, error); }
};
module.exports = { getSections, createSection, updateSection, deleteSection };