20 lines
774 B
JavaScript
20 lines
774 B
JavaScript
import {Router} from 'express';
|
|
import { createNewCommunity, getCommunityById, getAllCommunities, deleteCommunity, editCommunity } from '../functions/communityFunctions.js';
|
|
const router = Router();
|
|
|
|
// Validate create community payload
|
|
const validateCommunityPayload = (req, res, next) => {
|
|
const { nombre, descripcion } = req.body;
|
|
if (!nombre || !descripcion) {
|
|
return res.status(400).json({ error: 'nombre and descripcion are required' });
|
|
}
|
|
next();
|
|
};
|
|
|
|
router.post('/', validateCommunityPayload, createNewCommunity);
|
|
router.get('/', getAllCommunities);
|
|
router.get('/:id_comunidad', getCommunityById);
|
|
router.put('/:id_comunidad', validateCommunityPayload, editCommunity);
|
|
router.delete('/:id_comunidad', deleteCommunity);
|
|
|
|
export default router; |