36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
const express = require('express');
|
|
const router = express.Router();
|
|
const { isAuthenticated } = require('../middleware/auth');
|
|
const Company = require('../models/Company');
|
|
const User = require('../models/User');
|
|
|
|
router.get('/', isAuthenticated, async (req, res) => {
|
|
try {
|
|
const company = await Company.findById(req.session.user.company_id);
|
|
const userCount = await Company.countUsers(company.id);
|
|
const ticketCount = await Company.countTickets(company.id);
|
|
res.render('company/settings', { company, userCount, ticketCount });
|
|
} catch (error) {
|
|
console.error(error);
|
|
req.flash('error_msg', 'Error al cargar configuración');
|
|
res.redirect('/');
|
|
}
|
|
});
|
|
|
|
router.post('/update', isAuthenticated, async (req, res) => {
|
|
const { name } = req.body;
|
|
try {
|
|
if (name) {
|
|
await Company.update(req.session.user.company_id, { name });
|
|
}
|
|
req.flash('success_msg', 'Empresa actualizada');
|
|
res.redirect('/company');
|
|
} catch (error) {
|
|
console.error(error);
|
|
req.flash('error_msg', 'Error al actualizar');
|
|
res.redirect('/company');
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|