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