Skip to content
New issue

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

No operations defined in spec! #365

Open
devmbilal opened this issue Dec 30, 2023 · 0 comments
Open

No operations defined in spec! #365

devmbilal opened this issue Dec 30, 2023 · 0 comments

Comments

@devmbilal
Copy link

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');

/**

  • @Swagger
  • /api/stops:
  • post:
  • summary: Add a new stop
    
  • requestBody:
    
  •   required: true
    
  •   content:
    
  •     application/json:
    
  •       schema:
    
  •         type: object
    
  •         properties:
    
  •           stopName:
    
  •             type: string
    
  •           latitude:
    
  •             type: number
    
  •           longitude:
    
  •             type: number
    
  • 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' });
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant