Fixed a lot of stuff
This commit is contained in:
5
app.js
5
app.js
@@ -5,6 +5,8 @@ import apiRoutes from './routes/api.js';
|
||||
import userRoutes from './routes/user.js';
|
||||
import postRoutes from './routes/posts.js';
|
||||
import commentRoutes from './routes/comments.js';
|
||||
import communityRoutes from './routes/communities.js';
|
||||
import offerRoutes from './routes/offers.js';
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
@@ -39,6 +41,9 @@ app.use('/api/user', userRoutes); // Rutas de usuarios
|
||||
app.use('/api/post', postRoutes); // Rutas de posts
|
||||
app.use('/api/comments', commentRoutes); // Rutas de comentarios
|
||||
app.use('/uploads', express.static('uploads'));
|
||||
app.use('/api/offers', express.static('uploads'));
|
||||
app.use('/api/offers', offerRoutes); // Rutas de ofertas
|
||||
app.use('/api/communities', communityRoutes); // Rutas de comunidades
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Example app listening on port ${port}`);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {pool} from '../db.js';
|
||||
import { pool } from '../lib/database.js';
|
||||
|
||||
export const createNewCommunity = async (req, res) => {
|
||||
try {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {pool} from '../db.js';
|
||||
import {pool} from '../lib/database.js';
|
||||
|
||||
export const createNewOffer = async (req, res) => {
|
||||
try {
|
||||
@@ -84,4 +84,24 @@ export const deleteOffer = async (req, res) => {
|
||||
res.status(500).json({ error: err.message });
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
export const getOffersByUserId = async (req, res) => {
|
||||
try {
|
||||
const { id_usuario } = req.params;
|
||||
const query = await pool.query(
|
||||
`SELECT usuarios.nombre, usuarios.apellido_pa, usuarios.apellido_ma, oferta.*
|
||||
FROM oferta
|
||||
JOIN usuarios ON oferta.id_usuario = usuarios.id_usuario
|
||||
WHERE usuarios.id_usuario = $1
|
||||
ORDER BY oferta.fecha_publicacion DESC`,
|
||||
[id_usuario]
|
||||
);
|
||||
res.json(query.rows);
|
||||
}
|
||||
catch (err) {
|
||||
console.error(err);
|
||||
res.status(500).json({ error: err.message });
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ export const getPostById = async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
getPostByComunityId = async (req, res) => {
|
||||
export const getPostByComunityId = async (req, res) => {
|
||||
try {
|
||||
const { comunidad } = req.params;
|
||||
const query = await pool.query(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {Router} from 'express';
|
||||
import { createCommunity, getCommunityById, getAllCommunities, deleteCommunity, editCommunity } from '../functions/communityFunctions.js';
|
||||
import { createNewCommunity, getCommunityById, getAllCommunities, deleteCommunity, editCommunity } from '../functions/communityFunctions.js';
|
||||
const router = Router();
|
||||
|
||||
// Validate create community payload
|
||||
@@ -11,8 +11,10 @@ const validateCommunityPayload = (req, res, next) => {
|
||||
next();
|
||||
};
|
||||
|
||||
router.post('/', validateCommunityPayload, createCommunity);
|
||||
router.post('/', validateCommunityPayload, createNewCommunity);
|
||||
router.get('/', getAllCommunities);
|
||||
router.get('/:id_comunidad', getCommunityById);
|
||||
router.put('/:id_comunidad', validateCommunityPayload, editCommunity);
|
||||
router.delete('/:id_comunidad', deleteCommunity);
|
||||
router.delete('/:id_comunidad', deleteCommunity);
|
||||
|
||||
export default router;
|
||||
@@ -1,4 +1,10 @@
|
||||
import { Router } from "express";
|
||||
import path from 'path';
|
||||
import multer from 'multer';
|
||||
import fs from 'fs/promises';
|
||||
import sharp from 'sharp';
|
||||
import crypto from 'crypto';
|
||||
import { fileTypeFromBuffer } from 'file-type';
|
||||
import { createNewOffer, getOfferById, deleteOffer, getAllOffers, getOffersByUserId, editOffer } from "../functions/offerFunctions.js";
|
||||
const router = Router();
|
||||
|
||||
@@ -78,4 +84,6 @@ router.get('/', getAllOffers);
|
||||
router.get('/:id_oferta', getOfferById);
|
||||
router.put('/:id_oferta', upload.single('imagen'), validateOfferPayload, processUploadedImage, editOffer);
|
||||
router.delete('/:id_oferta', deleteOffer);
|
||||
router.get('/user/:id_usuario', getOffersByUserId);
|
||||
router.get('/user/:id_usuario', getOffersByUserId);
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user