We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
App.JS
app.js require('dotenv').config();
const express = require('express'); const connectDB = require('./server/config/db'); const swaggerJsDoc = require('swagger-jsdoc'); const swaggerUi = require('swagger-ui-express');
const app = express(); const port = process.env.PORT || 5000; connectDB();
const swaggerOptions = { swaggerDefinition: { info: { title: 'SJP App API', version: '1.0.0', description: 'Smart Journey Planner App API Information', }, servers: ['http://localhost:5000'], }, apis: ['./server/routes/routes.js'], };
const swaggerDocs = swaggerJsDoc(swaggerOptions); app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocs));
ROUTES.JS const express = require('express'); const router = express.Router();
const stopController = require('../controllers/stops/stopController');
// Stops router.post('/addstop', stopController.postStop);
module.exports = router;
const Stop = require('../../models/stop/Stop'); const mongoose = require('mongoose');
/**
summary: Add a new stop
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
stopName:
type: string
latitude:
type: number
longitude:
responses:
200:
description: Stop added successfully
500:
description: Error adding stop
*/
exports.postStop = async (req, res) => { try { const highestStop = await Stop.findOne().sort({ stopId: -1 });
let nextStopId; if (highestStop) { const match = highestStop.stopId.match(/\d+/); const highestStopId = match ? parseInt(match[0]) : 0; nextStopId = `STP-${highestStopId + 1}`; } else { nextStopId = "STP-1"; } const newStop = new Stop({ stopId: nextStopId, stopName: req.body.stopName, latitude: req.body.latitude, longitude: req.body.longitude }); await Stop.create(newStop); res.status(200).json({ message: 'Stop added successfully', stop: newStop }); } catch (err) { console.error(err); res.status(500).json({ error: 'Error adding stop' }); }
}
The text was updated successfully, but these errors were encountered:
No branches or pull requests
App.JS
app.js
require('dotenv').config();
const express = require('express');
const connectDB = require('./server/config/db');
const swaggerJsDoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
const app = express();
const port = process.env.PORT || 5000;
connectDB();
const swaggerOptions = {
swaggerDefinition: {
info: {
title: 'SJP App API',
version: '1.0.0',
description: 'Smart Journey Planner App API Information',
},
servers: ['http://localhost:5000'],
},
apis: ['./server/routes/routes.js'],
};
const swaggerDocs = swaggerJsDoc(swaggerOptions);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocs));
ROUTES.JS
const express = require('express');
const router = express.Router();
const stopController = require('../controllers/stops/stopController');
// Stops
router.post('/addstop', stopController.postStop);
module.exports = router;
const Stop = require('../../models/stop/Stop');
const mongoose = require('mongoose');
/**
*/
exports.postStop = async (req, res) => {
try
{
const highestStop = await Stop.findOne().sort({ stopId: -1 });
}
The text was updated successfully, but these errors were encountered: