Skip to content

Commit

Permalink
Integrate swagger Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ejiro-Edwin committed Aug 30, 2019
1 parent fb2d98e commit 1d8b53c
Show file tree
Hide file tree
Showing 11 changed files with 429 additions and 91 deletions.
Binary file added API_INT.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Send-AM
SendAM is a courier service that helps users deliver parcels to different destinations. SendIT provides courier quotes based on weight categories.

![Test Image 1](https://github.com/Ejiro-Edwin/SendAm/tree/master/Server/API_INT.png)

## Feature
* There are two types of users admin and regular user
* Users can Register if they have no account or login otherwise
Expand Down
16 changes: 6 additions & 10 deletions Server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@ const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const cors = require('cors');
const mysql=require('mysql');
const db = require('./config/db');

// const swagger = require("swagger-ui-express");
// import swaggerDocument from "../swagger.js";
const swagger = require("swagger-ui-express");
const swaggerDocument = require("../Swagger.js");

let app = express();


const parcelRoute = require('./routes/parcels');
const userRoute = require('./routes/users');
const authRoute = require('./routes/auth');
app.use("/docs", swagger.serve, swagger.setup(swaggerDocument));

app.set('views', path.join(__dirname, 'views'));

// app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

Expand All @@ -40,15 +37,14 @@ app.all('/*', function(req, res, next) {
app.use('/api/v1/auth', authRoute)
app.use('/api/v1/parcels', parcelRoute)
app.use('/api/v1/users', userRoute)
// app.use("/docs", swagger.serve, swagger.setup(swaggerDocument));

app.get('/', (req, res) => {
return res.status(200).json({ msg: 'Welcome to new SendAM API.'});
});

// app.use(function (err, req, res, next) {
// res.status(500).send('Something wrong broke!');
// })
app.use(function (err, req, res, next) {
res.status(500).send('Something wrong broke!');
})

const port = process.env.PORT || 10000;

Expand Down
12 changes: 12 additions & 0 deletions Server/config/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ const sequelize = new Sequelize('sendit', 'root', '', {
idle: 10000
}
})
// const sequelize = new Sequelize(process.env.DATABASE, process.env.USER, '', {
// host: process.env.DATABASE || 'localhost',
// dialect: 'mysql',
// operatorsAliases: false,

// pool: {
// max: 5,
// min: 0,
// acquire: 30000,
// idle: 10000
// }
// })

db.sequelize = sequelize
db.Sequelize = Sequelize
Expand Down
8 changes: 4 additions & 4 deletions Server/controllers/ParcelsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Parcels {

static cancel(req, res) {
const newStatus = 'canceled';
Parcel.update(
parcel.update(
{status:newStatus},
{where : {
id : req.params.id,
Expand Down Expand Up @@ -149,7 +149,7 @@ class Parcels {

const newDestination = req.body.toAddress

Parcel.update(
parcel.update(
{toAddress:newDestination},
{where : {
id : req.params.id,
Expand Down Expand Up @@ -180,7 +180,7 @@ class Parcels {

const currentLocation = req.body.currentLocation

Parcel.update(
parcel.update(
{toAddress:currentLocation},
{where : {
id : req.params.id
Expand Down Expand Up @@ -212,7 +212,7 @@ static changeStatus(req, res) {
if (fieldError.error) return res.status(400).send(fieldError.error.details[0].message);

const status = req.body.status
Parcel.update(
parcel.update(
{status:status},
{where : {
id : req.params.id,
Expand Down
1 change: 0 additions & 1 deletion Server/controllers/UsersController.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const moment = require ('moment');
// const db = require('../config/db');
const dotenv = require('dotenv');
const helper = require ('../helpers/helper');
const Users = require('../models/users');
Expand Down
5 changes: 3 additions & 2 deletions Server/helpers/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const bcrypt = require('bcryptjs');
const jwt = require('jsonwebtoken');
const dotenv = require('dotenv');
const sgMail = require('@sendgrid/mail');
const config = require('config');

dotenv.config();

Expand All @@ -17,7 +18,7 @@ const helper = {
generateToken(payload) {
const token = jwt.sign(
payload,
"secret", { expiresIn: '20d' }
config.get('SECRET'), { expiresIn: '20d' }
);
return token;
},
Expand All @@ -32,7 +33,7 @@ const helper = {
html: "Your PDO has been updated",
};
sgMail.send(mail);
}
},
}

module.exports = helper;
28 changes: 2 additions & 26 deletions Server/middleware/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,7 @@ class Auth {
res.status(400).send('Invalid Token');
}

// jwt.verify(req.token, process.env.SECRET , (err, data) => {
// if (err) {
// res.status(403).send("You cannot access this page because you require a token to access it");
// } else {
// req.user = data.userId,
// req.adminStatus = data.isAdmin
// next()
// }
// })
}
}
}


module.exports = Auth;

// module.exports = function(req,res,next){
// const token = req.header('x-auth-token');
// if(!token) return res.status(401).send('Access Denied. No token provided');

// try {
// const decoded = jwt.verify(token, config.get('JwtPrivateKey'));
// req.user = decoded;
// next();
// } catch (ex) {
// res.status(400).send('Invalid Token');
// }

// }
module.exports = Auth;
Loading

0 comments on commit 1d8b53c

Please sign in to comment.