Skip to content

Commit

Permalink
Update route file, Improve test and implement swagger documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
higustave12 committed Dec 24, 2019
1 parent ff152f8 commit 7ba3629
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 153 deletions.
4 changes: 2 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import express from 'express';
import AuthRoute from './routes/auth/auth.route';
import authRoute from './routes/auth.route';

const app = express();

app.use(express.urlencoded({ extended: false }));
app.use(express.json());

app.use('/api/auth', AuthRoute);
app.use('/api/auth', authRoute);

export default app;
11 changes: 11 additions & 0 deletions src/routes/auth.route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import express from 'express';
import UsersController from '../controllers/user.controller';
import { signupValidator, sendVerificationLinkValidator } from '../validations/auth.validation';
import Validations from '../middlewares/route-access.middleware';

const router = express.Router();

router.post('/signup', signupValidator, UsersController.signUp);
router.patch('/user/verify', Validations.checkRouteAccess, UsersController.verifyAccount);
router.get('/user/resendLink', sendVerificationLinkValidator, UsersController.resendAccVerificationLink);
export default router;
143 changes: 0 additions & 143 deletions src/routes/auth/auth.route.js

This file was deleted.

217 changes: 217 additions & 0 deletions src/swagger/auth.swagger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
/**
* @swagger
* definitions:
* Signup:
* type: object
* properties:
* firstName:
* type: string
* lastName:
* type: string
* email:
* type: string
* format: email
* password:
* type: string
* format: password
* required:
* - firstName
* - lastName
* - email
* - password
* Login:
* type: object
* properties:
* email:
* type: string
* password:
* type: string
* format: password
* required:
* - email
* - password
* Resend Account Verification Link:
* type: object
* properties:
* email:
* type: string
* required:
* - email
*/

/**
* @swagger
* /api/auth/signup:
* post:
* tags:
* - User
* name: Signup
* summary: Signup a user in a system
* produces:
* - application/json
* consumes:
* - application/json
* parameters:
* - name: body
* in: body
* schema:
* $ref: '#/definitions/Signup'
* type: object
* properties:
* firstName:
* type: string
* lastName:
* type: string
* email:
* type: string
* password:
* type: string
* format: password
* required:
* - firstName
* - lastName
* - email
* - password
* responses:
* '201':
* description: User created.
* '400':
* description: Bad request.
* '409':
* description: User already exist.
*
* /api/auth/login:
* post:
* tags:
* - User
* name: Login
* summary: Log a user in a system
* produces:
* - application/json
* consumes:
* - application/json
* parameters:
* - name: body
* in: body
* schema:
* $ref: '#/definitions/Login'
* type: object
* properties:
* email:
* type: string
* password:
* type: string
* format: password
* required:
* - email
* - password
* responses:
* '200':
* description: User logged in successfully
* '401':
* description: Incorrect credentials.
*/
/**
* @swagger
* /api/auth/logout:
* post:
* tags:
* - User
* name: Logout
* summary: Logs out a user from system
* parameters:
* - name: authorization
* in: header
* schema:
* type: string
* produces:
* - application/json
* consumes:
* - application/json
* responses:
* '200':
* description: Succesful
* '401':
* description: No Token supplied
*/
/**
* @swagger
* /api/auth/protected:
* get:
* tags:
* - User
* name: Protected
* summary: Protected route that can be accessed only by logged in user
* parameters:
* - name: authorization
* in: header
* schema:
* type: string
* produces:
* - application/json
* consumes:
* - application/json
* responses:
* '200':
* description: Succesful
* '401':
* description: No Token supplied
*
*/
/**
* @swagger
* /api/auth/user/verify:
* patch:
* tags:
* - User
* name: Verify Account
* summary: Verify Newly Created User's Account
* parameters:
* - name: authorization
* in: header
* schema:
* type: string
* produces:
* - application/json
* consumes:
* - application/json
* responses:
* '200':
* description: Account verified successfully. You can proceed to login
* '400':
* description: Bad Request
* '403':
* description: Forbiden
*/
/**
* @swagger
* /api/auth/user/resendLink:
* get:
* tags:
* - User
* name: Resend Verification Link
* summary: Resend Account Verification Link
* produces:
* - application/json
* consumes:
* - application/json
* parameters:
* - name: body
* in: body
* schema:
* $ref: '#/definitions/Resend Account Verification Link'
* type: object
* properties:
* email:
* type: string
* required:
* - email
* responses:
* '200':
* description: Verification Link Successfully Sent,
* Visit Your Email To Activate Account
* '400':
* description: Bad request.
* '404':
* description: Email Not Found in The Database. To Get a Link You Must Register
*/
2 changes: 1 addition & 1 deletion src/swagger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const swaggerDefinition = {
};
const options = {
swaggerDefinition,
apis: ['./src/routes/*.js']
apis: ['./src/swagger/*.swagger.js']
};
const swaggerSpec = swaggerJSDoc(options);

Expand Down
Loading

0 comments on commit 7ba3629

Please sign in to comment.