Skip to content

Commit

Permalink
category fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vabatista committed Mar 13, 2024
1 parent bbf3158 commit d0448cb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
coverage/
.idea/
.env
github_token.txt
github_token.txt
google_oauth_client.json
4 changes: 2 additions & 2 deletions config/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import mongoose from 'mongoose';
dotenv.config();
export default function connectDB() {
const url = process.env.MONGODB_URI;
console.log(url)

try {
mongoose.connect(url);
} catch (err) {
Expand All @@ -14,7 +14,7 @@ export default function connectDB() {
const dbConnection = mongoose.connection;

dbConnection.once('open', () => {
console.log(`Database connected: ${url}`);
console.log(`Database connected`);
});

dbConnection.on('error', (err) => {
Expand Down
1 change: 1 addition & 0 deletions controllers/posts-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const getPostByCategoryHandler = async (req, res) => {
const category = req.params.category;
try {
// Validation - check if category is valid
console.log(validCategories, category)
if (!validCategories.includes(category)) {
return res.status(HTTP_STATUS.BAD_REQUEST).json({ message: RESPONSE_MESSAGES.POSTS.INVALID_CATEGORY });
}
Expand Down
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import connectDB from './config/db.js';
import cors from 'cors';
import compression from 'compression';
const app = express();
const port = process.env.PORT || 5000;
const port = process.env.PORT || 5050;

app.use(express.json());
app.use(express.urlencoded({ extended: true }));
Expand Down
18 changes: 11 additions & 7 deletions utils/constants.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
export const validCategories = [
'Travel',
'Nature',
'City',
'Adventure',
'Beaches',
'Landmarks',
'Mountains',
'Roteiro',
'Europa',
'Brasil',
'Dicas',
'Gastronomia',
'Destino',
'Nordeste',
'Eventos',
'América do Sul',
'África',
'Ásia'
];
export const HTTP_STATUS = {
OK: 200,
Expand Down

0 comments on commit d0448cb

Please sign in to comment.