API Functions for communities and product offers added
This commit is contained in:
18
routes/communities.js
Normal file
18
routes/communities.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import {Router} from 'express';
|
||||
import { createCommunity, 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, createCommunity);
|
||||
router.get('/', getAllCommunities);
|
||||
router.get('/:id_comunidad', getCommunityById);
|
||||
router.put('/:id_comunidad', validateCommunityPayload, editCommunity);
|
||||
router.delete('/:id_comunidad', deleteCommunity);
|
||||
Reference in New Issue
Block a user