File tree Expand file tree Collapse file tree 9 files changed +54
-31
lines changed Expand file tree Collapse file tree 9 files changed +54
-31
lines changed Original file line number Diff line number Diff line change @@ -109,6 +109,30 @@ $ yarn migrate # to migrate
109109$ yarn seed # to seed
110110```
111111
112+ ## Setting up REST Client
113+
114+ Create a file or add ` .vscode > settings.json ` and switch an environment ` Cmd/Ctrl + Shift + P ` > ` REST Client: Switch Environment ` . Then, you can request APIs from ` api.rest ` file.
115+
116+ ```
117+ {
118+ "rest-client.environmentVariables": {
119+ "$shared": {
120+ "refreshToken": "foo",
121+ "accessToken": "bar",
122+ "email": "sgr.raee@gmail.com",
123+ "password": "secret"
124+ },
125+ "local": {
126+ "host": "localhost",
127+ "refreshToken": "{{$shared refreshToken}}",
128+ "accessToken": "{{$shared accessToken}}",
129+ "email": "{{$shared email}}",
130+ "password": "{{$shared password}}"
131+ }
132+ }
133+ }
134+ ```
135+
112136## Contributing
113137
114138Feel free to send pull requests.
Original file line number Diff line number Diff line change 1+ GET {{host}} HTTP/1.1
2+
3+ ###
4+
5+ POST {{host}}/login HTTP/1.1
6+ Content-Type: application/json
7+
8+ {
9+ "email": "{{email}}",
10+ "password": "{{password}}"
11+ }
12+
13+ ###
14+
15+ POST {{host}}/refresh HTTP/1.1
16+ Authorization: {{refreshToken}}
17+
18+ ###
Original file line number Diff line number Diff line change 9191 "@typescript-eslint/eslint-plugin" : " ^5.30.0" ,
9292 "@typescript-eslint/parser" : " ^5.30.0" ,
9393 "babel-jest" : " ^27.0.6" ,
94- "chalk" : " ^5.0 .1" ,
94+ "chalk" : " ^4.1 .1" ,
9595 "concurrently" : " ^7.2.2" ,
9696 "eslint" : " ^8.18.0" ,
9797 "eslint-plugin-security" : " ^1.4.0" ,
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ function print<T>(data: T): void {
2020 print ( await fake . generate ( factoryCallback , total ) ) ;
2121
2222 process . exit ( 0 ) ;
23- } catch ( err ) {
23+ } catch ( err : any ) {
2424 info ( chalk `{red ${ err . message } }` ) ;
2525
2626 process . exit ( 1 ) ;
Original file line number Diff line number Diff line change @@ -2,14 +2,13 @@ import Joi from 'joi';
22import { Request , Response , NextFunction } from 'express' ;
33
44import logger from '../utils/logger' ;
5- import validate from '../utils/validate' ;
65
76/**
87 * A middleware to validate schema.
98 *
10- * @param {Joi.Schema } params
9+ * @param {Joi.Schema } schema
1110 */
12- export function schema ( params : Joi . Schema ) {
11+ export default function validate ( schema : Joi . Schema ) {
1312 return async (
1413 req : Request ,
1514 _ : Response ,
@@ -18,7 +17,9 @@ export function schema(params: Joi.Schema) {
1817 try {
1918 logger . log ( 'info' , 'Validating schema' ) ;
2019
21- await validate ( req . body , params ) ;
20+ logger . log ( 'debug' , 'Validation Payload' , req . body ) ;
21+ const value = await schema . validateAsync ( req . body ) ;
22+ logger . log ( 'debug' , 'Validation Response:' , value ) ;
2223
2324 next ( ) ;
2425 } catch ( err ) {
Original file line number Diff line number Diff line change 11import { Router } from 'express' ;
22
3- import * as validate from './middlewares/validate' ;
3+ import validate from './middlewares/validate' ;
44import * as homeController from './controllers/home' ;
55import * as userController from './controllers/user' ;
66import * as authController from './controllers/auth' ;
@@ -13,15 +13,15 @@ const router: Router = Router();
1313
1414router . get ( '/' , homeController . index ) ;
1515
16- router . post ( '/login' , validate . schema ( loginSchema ) , authController . login ) ;
16+ router . post ( '/login' , validate ( loginSchema ) , authController . login ) ;
1717router . post ( '/refresh' , validateRefreshToken , authController . refresh ) ;
1818router . post ( '/logout' , validateRefreshToken , authController . logout ) ;
1919
2020router . get ( '/users' , authenticate , userController . index ) ;
2121router . post (
2222 '/users' ,
2323 authenticate ,
24- validate . schema ( userPOSTSchema ) ,
24+ validate ( userPOSTSchema ) ,
2525 userController . store
2626) ;
2727
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -3,6 +3,6 @@ import Joi from 'joi';
33export const loginSchema = Joi . object ( )
44 . options ( { abortEarly : false } )
55 . keys ( {
6- email : Joi . string ( ) . min ( 10 ) . max ( 100 ) . label ( 'Email' ) . required ( ) ,
6+ email : Joi . string ( ) . max ( 100 ) . label ( 'Email' ) . required ( ) ,
77 password : Joi . string ( ) . min ( 6 ) . max ( 100 ) . label ( 'Password' ) . required ( )
88 } ) ;
Original file line number Diff line number Diff line change @@ -2302,19 +2302,14 @@ chalk@^2.0.0:
23022302 escape-string-regexp "^1.0.5"
23032303 supports-color "^5.3.0"
23042304
2305- chalk@^4.0.0, chalk@^4.1.0 :
2305+ chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.1 :
23062306 version "4.1.2"
23072307 resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
23082308 integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
23092309 dependencies :
23102310 ansi-styles "^4.1.0"
23112311 supports-color "^7.1.0"
23122312
2313- chalk@^5.0.1 :
2314- version "5.0.1"
2315- resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.0.1.tgz#ca57d71e82bb534a296df63bbacc4a1c22b2a4b6"
2316- integrity sha512-Fo07WOYGqMfCWHOzSXOt2CxDbC6skS/jO9ynEcmpANMoPrD+W1r1K6Vx7iNm+AQmETU1Xr2t+n8nzkV9t6xh3w==
2317-
23182313char-regex@^1.0.2 :
23192314 version "1.0.2"
23202315 resolved "https://registry.yarnpkg.com/char-regex/-/char-regex-1.0.2.tgz#d744358226217f981ed58f479b1d6bcc29545dcf"
You can’t perform that action at this time.
0 commit comments