Skip to content

Commit 0fa7eac

Browse files
committed
format pre es6 to es6
1 parent 5488f96 commit 0fa7eac

File tree

19 files changed

+70
-54
lines changed

19 files changed

+70
-54
lines changed

src/app.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import cors from 'cors';
55
import { corsUrl, environment } from './config';
66
import './database'; // initialize database
77
import { NotFoundError, ApiError, InternalError } from './core/ApiError';
8+
import routesV1 from './routes/v1';
89

910
const app = express();
1011

@@ -13,7 +14,7 @@ app.use(bodyParser.urlencoded({ limit: '10mb', extended: true, parameterLimit: 5
1314
app.use(cors({ origin: corsUrl, optionsSuccessStatus: 200 }));
1415

1516
// Routes
16-
app.use('/v1', require('./routes/v1'));
17+
app.use('/v1', routesV1);
1718

1819
// catch 404 and forward to error handler
1920
app.use((req, res, next) => next(new NotFoundError()));

src/auth/apikey.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import asyncHandler from '../helpers/asyncHandler';
99

1010
const router = express.Router();
1111

12-
router.use(validator(schema.apiKey, ValidationSource.HEADER),
12+
export default router.use(validator(schema.apiKey, ValidationSource.HEADER),
1313
asyncHandler(async (req: PublicRequest, res, next) => {
1414

1515
req.apiKey = req.headers['x-api-key'].toString();
@@ -19,7 +19,4 @@ router.use(validator(schema.apiKey, ValidationSource.HEADER),
1919

2020
if (!apiKey) throw new ForbiddenError();
2121
return next();
22-
}
23-
));
24-
25-
module.exports = router;
22+
}));

src/auth/authentication.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import asyncHandler from '../helpers/asyncHandler';
1313

1414
const router = express.Router();
1515

16-
router.use(validator(schema.auth, ValidationSource.HEADER),
16+
export default router.use(validator(schema.auth, ValidationSource.HEADER),
1717
asyncHandler(async (req: ProtectedRequest, res, next) => {
1818
req.accessToken = req.headers['x-access-token'].toString();
1919

@@ -39,7 +39,4 @@ router.use(validator(schema.auth, ValidationSource.HEADER),
3939
if (e instanceof TokenExpiredError) throw new AccessTokenError(e.message);
4040
throw e;
4141
}
42-
}
43-
));
44-
45-
module.exports = router;
42+
}));

src/auth/authorization.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import asyncHandler from '../helpers/asyncHandler';
66

77
const router = express.Router();
88

9-
router.use(
9+
export default router.use(
1010
asyncHandler(async (req: ProtectedRequest, res, next) => {
1111
if (!req.user || !req.user.roles || !req.currentRoleCode)
1212
throw new AuthFailureError('Permission denied');
@@ -21,6 +21,4 @@ router.use(
2121
throw new AuthFailureError('Permission denied');
2222

2323
return next();
24-
}));
25-
26-
module.exports = router;
24+
}));

src/helpers/role.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { RoleCode } from '../database/model/Role';
2+
import { RoleRequest } from 'app-request';
3+
import { Response, NextFunction } from 'express';
4+
5+
export default (roleCode: RoleCode) =>
6+
(req: RoleRequest, res: Response, next: NextFunction) => {
7+
req.currentRoleCode = roleCode;
8+
next();
9+
};

src/routes/v1/access/login.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import _ from 'lodash';
1313

1414
const router = express.Router();
1515

16-
router.post('/basic', validator(schema.userCredential),
16+
export default router.post('/basic', validator(schema.userCredential),
1717
asyncHandler(async (req, res, next) => {
1818
const user = await UserRepo.findByEmail(req.body.email);
1919
if (!user) throw new BadRequestError('User not registered');
@@ -32,6 +32,4 @@ router.post('/basic', validator(schema.userCredential),
3232
user: _.pick(user, ['_id', 'name', 'roles', 'profilePicUrl']),
3333
tokens: tokens
3434
}).send(res);
35-
}));
36-
37-
module.exports = router;
35+
}));

src/routes/v1/access/logout.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import KeystoreRepo from '../../../database/Repository/KeystoreRepo';
33
import { ProtectedRequest } from 'app-request';
44
import { SuccessMsgResponse } from '../../../core/ApiResponse';
55
import asyncHandler from '../../../helpers/asyncHandler';
6+
import authentication from '../../../auth/authentication';
67

78
const router = express.Router();
89

910
/*-------------------------------------------------------------------------*/
1011
// Below all APIs are private APIs protected for Access Token
11-
router.use('/', require('../../../auth/authentication'));
12+
router.use('/', authentication);
1213
/*-------------------------------------------------------------------------*/
1314

1415
router.delete('/',
@@ -17,4 +18,4 @@ router.delete('/',
1718
new SuccessMsgResponse('Logout success').send(res);
1819
}));
1920

20-
module.exports = router;
21+
export default router;

src/routes/v1/access/signup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ router.post('/basic', validator(schema.signup),
3838
}).send(res);
3939
}));
4040

41-
module.exports = router;
41+
export default router;

src/routes/v1/access/token.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ router.post('/refresh',
6060
new TokenRefreshResponse('Token Issued', tokens.accessToken, tokens.refreshToken).send(res);
6161
}));
6262

63-
module.exports = router;
63+
export default router;

src/routes/v1/blog/blogDetail.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ router.get('/id/:id', validator(schema.blogId, ValidationSource.PARAM),
2323
return new SuccessResponse('success', blog).send(res);
2424
}));
2525

26-
module.exports = router;
26+
export default router;

0 commit comments

Comments
 (0)