Skip to content

Commit ed08204

Browse files
committed
Move rotas para diretorio routes
1 parent 2de8c36 commit ed08204

File tree

6 files changed

+52
-27
lines changed

6 files changed

+52
-27
lines changed

gulpfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ gulp.task('scripts', () => {
99
return tsResult.js.pipe(gulp.dest('dist'));
1010
});
1111

12-
gulp.task('watch', ['scripts', 'cp'], () => {
12+
gulp.task('watch', ['scripts'], () => {
1313
gulp.watch('**/*.ts', ['scripts']);
1414
});
1515

server/api/api.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
"use strict";
22
var express = require('express');
33
var logger = require('morgan');
4-
var routes_1 = require('../modules/User/routes');
5-
var routes_2 = require('../modules/auth/routes');
64
var auth_1 = require('../auth');
5+
var routes_1 = require('./routes/routes');
76
var bodyParser = require('body-parser');
87
var Api = (function () {
98
function Api() {
109
this.express = express();
1110
this.middleware();
12-
this.router = new routes_1["default"]();
13-
this.routes();
11+
this.router(this.express);
1412
}
1513
Api.prototype.middleware = function () {
1614
this.express.use(logger('dev'));
@@ -19,13 +17,8 @@ var Api = (function () {
1917
this.auth = auth_1["default"]();
2018
this.express.use(this.auth.initialize());
2119
};
22-
Api.prototype.routes = function () {
23-
this.express.route('/api/users/all').get(this.router.index);
24-
this.express.route('/api/users/create').post(this.router.create);
25-
this.express.route('/api/users/:id').get(this.router.findOne);
26-
this.express.route('/api/users/:id/update').put(this.router.update);
27-
this.express.route('/api/users/:id/destroy').delete(this.router.destroy);
28-
this.express.use('/token', routes_2["default"](this.auth));
20+
Api.prototype.router = function (app) {
21+
new routes_1["default"](app);
2922
};
3023
return Api;
3124
}());

server/api/api.ts

+5-14
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
import * as express from 'express';
22
import * as path from 'path';
33
import * as logger from 'morgan';
4-
import UserRoutes from '../modules/User/routes';
5-
import tokenRoute from '../modules/auth/routes';
64
import authConfig from '../auth';
5+
import Routes from './routes/routes';
76

87
const bodyParser = require('body-parser');
98

109
class Api {
1110

1211
public express: express.Application;
1312
public auth;
14-
public router: UserRoutes;
15-
13+
1614
constructor(){
1715
this.express = express();
1816
this.middleware();
19-
this.router = new UserRoutes();
20-
this.routes();
17+
this.router(this.express);
2118
}
2219

2320
middleware(): void {
@@ -28,15 +25,9 @@ class Api {
2825
this.express.use(this.auth.initialize());
2926
}
3027

31-
private routes(): void {
32-
this.express.route('/api/users/all').get(this.router.index);
33-
this.express.route('/api/users/create').post(this.router.create);
34-
this.express.route('/api/users/:id').get(this.router.findOne);
35-
this.express.route('/api/users/:id/update').put(this.router.update);
36-
this.express.route('/api/users/:id/destroy').delete(this.router.destroy);
37-
this.express.use('/token', tokenRoute(this.auth));
28+
private router(app: express.Application): void {
29+
new Routes(app);
3830
}
39-
4031
}
4132

4233
export default new Api().express;

server/api/routes/routes.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"use strict";
2+
var routes_1 = require('../../modules/User/routes');
3+
var Routes = (function () {
4+
function Routes(app) {
5+
this.router = new routes_1["default"]();
6+
this.getRoutes(app);
7+
}
8+
Routes.prototype.getRoutes = function (app) {
9+
app.route('/api/users/all').get(this.router.index);
10+
app.route('/api/users/create').post(this.router.create);
11+
app.route('/api/users/:id').get(this.router.findOne);
12+
app.route('/api/users/:id/update').put(this.router.update);
13+
app.route('/api/users/:id/destroy').delete(this.router.destroy);
14+
};
15+
return Routes;
16+
}());
17+
exports.__esModule = true;
18+
exports["default"] = Routes;

server/api/routes/routes.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {Application} from 'express';
2+
import UserRoutes from '../../modules/User/routes';
3+
import tokenRoute from '../../modules/auth/routes';
4+
5+
class Routes {
6+
7+
private router: UserRoutes;
8+
9+
constructor(app: Application){
10+
this.router = new UserRoutes();
11+
this.getRoutes(app);
12+
}
13+
14+
getRoutes(app: Application): void {
15+
app.route('/api/users/all').get(this.router.index);
16+
app.route('/api/users/create').post(this.router.create);
17+
app.route('/api/users/:id').get(this.router.findOne);
18+
app.route('/api/users/:id/update').put(this.router.update);
19+
app.route('/api/users/:id/destroy').delete(this.router.destroy);
20+
}
21+
}
22+
23+
export default Routes;

server/modules/User/test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {app, req, expect, Chai} from '../../config/tests/functional/helpers';
22
import * as jwt from 'jwt-simple';
33
import * as _ from 'lodash';
4-
const config = require('../../config/config');
4+
const config = require('../../config/env/config');
55
let id;
66
const userDefault = {
77
id: 1,

0 commit comments

Comments
 (0)