update swagger docs
This commit is contained in:
Generated
+375
-6487
File diff suppressed because it is too large
Load Diff
+4
-1
@@ -28,7 +28,9 @@
|
|||||||
"pg-promise": "^10.11.1",
|
"pg-promise": "^10.11.1",
|
||||||
"postgres": "^1.0.2",
|
"postgres": "^1.0.2",
|
||||||
"sequelize": "^6.17.0",
|
"sequelize": "^6.17.0",
|
||||||
"sequelize-cli": "^6.4.1"
|
"sequelize-cli": "^6.4.1",
|
||||||
|
"swagger-jsdoc": "^6.1.0",
|
||||||
|
"swagger-ui-express": "^4.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "4.2.0",
|
"chai": "4.2.0",
|
||||||
@@ -38,6 +40,7 @@
|
|||||||
"eslint-plugin-import": "2.18.2",
|
"eslint-plugin-import": "2.18.2",
|
||||||
"eslint-plugin-jsx-a11y": "6.2.3",
|
"eslint-plugin-jsx-a11y": "6.2.3",
|
||||||
"eslint-plugin-react": "7.16.0",
|
"eslint-plugin-react": "7.16.0",
|
||||||
|
"express-swagger-generator": "^1.1.17",
|
||||||
"mocha": "^6.2.3"
|
"mocha": "^6.2.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+36
-1
@@ -6,7 +6,7 @@ var cors = require('cors')
|
|||||||
const app = express();
|
const app = express();
|
||||||
app.use(cors({
|
app.use(cors({
|
||||||
origin: '*',
|
origin: '*',
|
||||||
methods: ['GET','POST','DELETE','UPDATE','PUT','PATCH']
|
methods: ['GET', 'POST', 'DELETE', 'UPDATE', 'PUT', 'PATCH']
|
||||||
}));
|
}));
|
||||||
|
|
||||||
app.use(logger("dev"));
|
app.use(logger("dev"));
|
||||||
@@ -14,6 +14,41 @@ app.use(bodyParser.json());
|
|||||||
app.use(bodyParser.urlencoded({ extended: false }));
|
app.use(bodyParser.urlencoded({ extended: false }));
|
||||||
|
|
||||||
require("./server/routes")(app);
|
require("./server/routes")(app);
|
||||||
|
|
||||||
|
const swaggerJSDoc = require('swagger-jsdoc');
|
||||||
|
|
||||||
|
const swaggerUi = require('swagger-ui-express');
|
||||||
|
|
||||||
|
|
||||||
|
const swaggerDefinition = {
|
||||||
|
openapi: '3.0.1',
|
||||||
|
info: {
|
||||||
|
title: 'Float API',
|
||||||
|
version: '1.0.0',
|
||||||
|
},
|
||||||
|
host: "localhost:8000/v1/",
|
||||||
|
components: {
|
||||||
|
securitySchemes: {
|
||||||
|
bearerAuth: {
|
||||||
|
type: 'http',
|
||||||
|
scheme: 'bearer',
|
||||||
|
bearerFormat: 'JWT',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
security: [{
|
||||||
|
bearerAuth: []
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
swaggerDefinition,
|
||||||
|
apis: ['./src/server/models/*.js','./src/server/routes/*.js'],
|
||||||
|
};
|
||||||
|
|
||||||
|
const swaggerSpec = swaggerJSDoc(options);
|
||||||
|
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
|
||||||
|
|
||||||
app.get("/api", (req, res) =>
|
app.get("/api", (req, res) =>
|
||||||
res.status(200).send({
|
res.status(200).send({
|
||||||
message: "Welcome to Float API"
|
message: "Welcome to Float API"
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ var Sequelize = require('sequelize');
|
|||||||
const nodemailer = require('nodemailer');
|
const nodemailer = require('nodemailer');
|
||||||
const { body, validationResult } = require('express-validator');
|
const { body, validationResult } = require('express-validator');
|
||||||
const memberServices = require("../services").member;
|
const memberServices = require("../services").member;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
validate(method) {
|
validate(method) {
|
||||||
switch (method) {
|
switch (method) {
|
||||||
@@ -51,27 +52,35 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
resetPassword(req, res) {
|
resetPassword(req, res) {
|
||||||
memberServices.resetPassword(req)
|
const mode = req.body.mode;
|
||||||
.then(result => {
|
switch (mode) {
|
||||||
res.status(200).send(result)
|
case memberServices.RESET_START:
|
||||||
})
|
memberServices.resetPassword(req)
|
||||||
.catch(error => res.status(400).send(error.errors));
|
.then(result => {
|
||||||
},
|
res.status(200).send(result)
|
||||||
|
})
|
||||||
|
.catch(error => res.status(400).send(error.errors));
|
||||||
|
break;
|
||||||
|
case memberServices.RESET_CONFIRM:
|
||||||
|
memberServices.confirmResetPassword(req)
|
||||||
|
.then(result => {
|
||||||
|
res.status(200).send(result)
|
||||||
|
})
|
||||||
|
.catch(error => res.status(400).send(error.errors));
|
||||||
|
break;
|
||||||
|
|
||||||
confirmResetPassword(req, res) {
|
case memberServices.RESET_COMPLETE:
|
||||||
memberServices.confirmResetPassword(req)
|
memberServices.completeResetPassword(req)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
res.status(200).send(result)
|
res.status(200).send(result)
|
||||||
})
|
})
|
||||||
.catch(error => res.status(400).send(error.errors));
|
.catch(error => res.status(400).send(error.errors));
|
||||||
},
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
res.status(400).send("Invalid mode")
|
||||||
|
}
|
||||||
|
|
||||||
completeResetPassword(req, res) {
|
|
||||||
memberServices.completeResetPassword(req)
|
|
||||||
.then(result => {
|
|
||||||
res.status(200).send(result)
|
|
||||||
})
|
|
||||||
.catch(error => res.status(400).send(error.errors));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
updateProfile(req, res) {
|
updateProfile(req, res) {
|
||||||
@@ -99,7 +108,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
deactivate(req, res) {
|
deactivate(req, res) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -1,4 +1,32 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* components:
|
||||||
|
* schemas:
|
||||||
|
* Member:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* username:
|
||||||
|
* type: string
|
||||||
|
* description: username
|
||||||
|
* example: float
|
||||||
|
* email:
|
||||||
|
* type: string
|
||||||
|
* description: The user's email.
|
||||||
|
* example: support@float.sg
|
||||||
|
* firstname:
|
||||||
|
* type: string
|
||||||
|
* description: The user's firstname.
|
||||||
|
* example: Float
|
||||||
|
* lastname:
|
||||||
|
* type: string
|
||||||
|
* description: The user's lastname.
|
||||||
|
* example: Mobility
|
||||||
|
* phone:
|
||||||
|
* type: string
|
||||||
|
* description: The user's phone.
|
||||||
|
* example: 0123456789
|
||||||
|
*/
|
||||||
module.exports = (sequelize, DataTypes) => {
|
module.exports = (sequelize, DataTypes) => {
|
||||||
const Member = sequelize.define('Member', {
|
const Member = sequelize.define('Member', {
|
||||||
username: {
|
username: {
|
||||||
|
|||||||
+216
-2
@@ -2,12 +2,226 @@ const memberController = require("../controllers").member;
|
|||||||
const auth = require("../middleware/auth");
|
const auth = require("../middleware/auth");
|
||||||
|
|
||||||
module.exports = app => {
|
module.exports = app => {
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /v1/user/register:
|
||||||
|
* post:
|
||||||
|
* tags:
|
||||||
|
* - Users
|
||||||
|
* summary: Create a JSONPlaceholder user.
|
||||||
|
* requestBody:
|
||||||
|
* required: true
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* username:
|
||||||
|
* type: string
|
||||||
|
* description: The user's username.
|
||||||
|
* example: test@float.sg
|
||||||
|
* email:
|
||||||
|
* type: string
|
||||||
|
* description: The user's email.
|
||||||
|
* example: test@float.sg
|
||||||
|
* password:
|
||||||
|
* type: string
|
||||||
|
* description: The user's password.
|
||||||
|
* example: test@float.sg
|
||||||
|
* firstname:
|
||||||
|
* type: string
|
||||||
|
* description: The user's firstname.
|
||||||
|
* example: Float
|
||||||
|
* lastname:
|
||||||
|
* type: string
|
||||||
|
* description: The user's lastname.
|
||||||
|
* example: Mobility
|
||||||
|
* phone:
|
||||||
|
* type: string
|
||||||
|
* description: The user's phone.
|
||||||
|
* example: 123456789
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Created
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* message:
|
||||||
|
* type: striing
|
||||||
|
* description: Message
|
||||||
|
* example: Register successfully
|
||||||
|
* 400:
|
||||||
|
* description: Invalid
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* message:
|
||||||
|
* type: striing
|
||||||
|
* description: Message
|
||||||
|
* example: Failed
|
||||||
|
*/
|
||||||
app.post("/api/v1/user/register", memberController.validate('register'), memberController.register);
|
app.post("/api/v1/user/register", memberController.validate('register'), memberController.register);
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /v1/user/login:
|
||||||
|
* post:
|
||||||
|
* tags:
|
||||||
|
* - Users
|
||||||
|
* summary: Create a JSONPlaceholder user.
|
||||||
|
* requestBody:
|
||||||
|
* required: true
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* username:
|
||||||
|
* type: string
|
||||||
|
* description: The user's username.
|
||||||
|
* example: test@float.sg
|
||||||
|
* password:
|
||||||
|
* type: string
|
||||||
|
* description: The user's password.
|
||||||
|
* example: test@float.sg
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Login success
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* accessToken:
|
||||||
|
* type: string
|
||||||
|
* description: Message
|
||||||
|
* example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3RAZmxvYXQuc2ciLCJpYXQiOjE2NDcwODIxNDIsImV4cCI6MTY0NzA4Mzk0Mn0.fMQYB4ielKPh21QcZFwOJSjlGNCAg8rkvEcKWctxdX8
|
||||||
|
* 400:
|
||||||
|
* description: Invalid
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* message:
|
||||||
|
* type: string
|
||||||
|
* description: Message
|
||||||
|
* example: Wrong username or password
|
||||||
|
*/
|
||||||
app.post("/api/v1/user/login", memberController.login);
|
app.post("/api/v1/user/login", memberController.login);
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /v1/user/forgot-password:
|
||||||
|
* post:
|
||||||
|
* tags:
|
||||||
|
* - Users
|
||||||
|
* summary: Create a JSONPlaceholder user.
|
||||||
|
* requestBody:
|
||||||
|
* required: true
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* email:
|
||||||
|
* type: string
|
||||||
|
* description: The user's username.
|
||||||
|
* example: test@float.sg
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Login success
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* message:
|
||||||
|
* type: string
|
||||||
|
* description: Message
|
||||||
|
* example: Email has been sent
|
||||||
|
* 400:
|
||||||
|
* description: Invalid
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* message:
|
||||||
|
* type: string
|
||||||
|
* description: Message
|
||||||
|
* example: Wrong email
|
||||||
|
*/
|
||||||
app.post("/api/v1/user/forgot-password", memberController.forgotPassword);
|
app.post("/api/v1/user/forgot-password", memberController.forgotPassword);
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /v1/user/reset-password:
|
||||||
|
* post:
|
||||||
|
* tags:
|
||||||
|
* - Users
|
||||||
|
* summary: Create a JSONPlaceholder user.
|
||||||
|
* requestBody:
|
||||||
|
* required: true
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* email:
|
||||||
|
* type: string
|
||||||
|
* description: The user's username.
|
||||||
|
* example: test@float.sg
|
||||||
|
* mode:
|
||||||
|
* type: integer
|
||||||
|
* description: The reset mode (100: start, 200:confirm, 300:complete)
|
||||||
|
* example: 100
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Login success
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* accessToken:
|
||||||
|
* type: string
|
||||||
|
* description: Message
|
||||||
|
* example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3RAZmxvYXQuc2ciLCJpYXQiOjE2NDcwODIxNDIsImV4cCI6MTY0NzA4Mzk0Mn0.fMQYB4ielKPh21QcZFwOJSjlGNCAg8rkvEcKWctxdX8
|
||||||
|
* 400:
|
||||||
|
* description: Invalid
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* message:
|
||||||
|
* type: string
|
||||||
|
* description: Message
|
||||||
|
* example: Wrong username or password
|
||||||
|
*/
|
||||||
app.post("/api/v1/user/reset-password", memberController.resetPassword);
|
app.post("/api/v1/user/reset-password", memberController.resetPassword);
|
||||||
app.post("/api/v1/user/confirm-reset-password", memberController.confirmResetPassword);
|
/**
|
||||||
app.post("/api/v1/user/complete-reset-password", memberController.completeResetPassword);
|
* @swagger
|
||||||
|
* /v1/user/profile:
|
||||||
|
* get:
|
||||||
|
* tags:
|
||||||
|
* - Users
|
||||||
|
* summary: Retrieve a single JSONPlaceholder user.
|
||||||
|
* description: Retrieve a single JSONPlaceholder user. Can be used to populate a user profile when prototyping or testing an API.
|
||||||
|
* security: # <--- ADD THIS
|
||||||
|
* - bearerAuth: [] # <--- ADD THIS
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: A single user.
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* $ref: '#/components/schemas/Member'
|
||||||
|
*/
|
||||||
|
|
||||||
app.get("/api/v1/user/profile", auth, memberController.profile);
|
app.get("/api/v1/user/profile", auth, memberController.profile);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const member = require("./user/member");
|
const member = require("./member/member");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
member
|
member
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ const Member = require("../../models").Member;
|
|||||||
const resetPasswordService = require("./resetPassword");
|
const resetPasswordService = require("./resetPassword");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
RESET_START: 100,
|
||||||
|
RESET_CONFIRM: 200,
|
||||||
|
RESET_COMPLETE: 300,
|
||||||
async create(req) {
|
async create(req) {
|
||||||
const { username, password, firstname, lastname, phone, email } = req.body;
|
const { username, password, firstname, lastname, phone, email } = req.body;
|
||||||
const salt = bcrypt.genSaltSync(10);
|
const salt = bcrypt.genSaltSync(10);
|
||||||
Reference in New Issue
Block a user