OwlCyberSecurity - MANAGER
Edit File: section.controller.js
// controllers/sectionController.js import { Section, Department } from '../models/index.js'; export const getSections = async (req, res) => { try { const sections = await Section.findAll({ include: [{ model: Department, attributes: ['id', 'dept_name'] }], }); res.json(sections); } catch (error) { console.error('Error fetching sections:', error); res.status(500).json({ message: 'Internal server error' }); } }; export const createSection = async (req, res) => { try { const section = await Section.create(req.body); res.status(201).json(section); } catch (error) { console.error('Error creating section:', error); res.status(500).json({ error: 'Failed to create section' }); } };