Skip to content

Commit c070aa6

Browse files
author
hirsch88
committed
Merge branch 'feature/upgrade-versions' into develop
2 parents f94afeb + becf33a commit c070aa6

File tree

13 files changed

+192
-339
lines changed

13 files changed

+192
-339
lines changed

package.json

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,23 @@
7575
"@types/helmet": "0.0.35",
7676
"@types/inquirer": "^0.0.35",
7777
"@types/jest": "^20.0.2",
78-
"@types/jsonwebtoken": "^7.2.1",
78+
"@types/jsonwebtoken": "^7.2.2",
7979
"@types/knex": "0.0.52",
80-
"@types/lodash": "^4.14.67",
81-
"@types/mkdirp": "^0.3.29",
80+
"@types/lodash": "^4.14.68",
8281
"@types/morgan": "^1.7.32",
8382
"@types/pluralize": "^0.0.27",
8483
"@types/reflect-metadata": "0.0.5",
8584
"@types/request": "^0.0.45",
86-
"@types/request-promise": "^4.1.35",
85+
"@types/request-promise": "^4.1.36",
8786
"@types/serve-favicon": "^2.2.28",
8887
"@types/winston": "^2.3.3",
8988
"body-parser": "^1.17.2",
9089
"bookshelf": "^0.10.3",
9190
"bookshelf-camelcase": "^1.1.4",
92-
"chalk": "^1.1.3",
91+
"chalk": "^2.0.1",
9392
"class-validator": "^0.7.2",
94-
"commander": "^2.10.0",
95-
"compression": "^1.6.2",
93+
"commander": "^2.11.0",
94+
"compression": "^1.7.0",
9695
"copyfiles": "^1.2.0",
9796
"cors": "^2.8.1",
9897
"dotenv": "^4.0.0",
@@ -103,14 +102,12 @@
103102
"glob": "^7.1.2",
104103
"handlebars": "^4.0.10",
105104
"helmet": "^3.6.1",
106-
"inquirer": "^3.1.1",
107-
"inversify": "^4.1.1",
108-
"inversify-express-utils": "^3.5.1",
109-
"jest": "^20.0.3",
105+
"inquirer": "^3.2.0",
106+
"inversify": "^4.2.0",
107+
"inversify-express-utils": "^4.0.0",
110108
"jsonwebtoken": "^7.4.1",
111109
"knex": "^0.12.0",
112110
"lodash": "^4.17.4",
113-
"mkdirp": "^0.5.1",
114111
"morgan": "^1.7.0",
115112
"mysql": "^2.13.0",
116113
"nodemon": "^1.11.0",
@@ -119,16 +116,12 @@
119116
"reflect-metadata": "^0.1.10",
120117
"request": "^2.81.0",
121118
"request-promise": "^4.2.1",
122-
"require-dir": "^0.3.2",
123-
"rimraf": "^2.6.1",
124-
"run-sequence": "^1.2.2",
125119
"serve-favicon": "^2.4.3",
126-
"swagger-jsdoc": "^1.9.5",
127-
"swagger-ui-express": "^2.0.0",
120+
"swagger-jsdoc": "^1.9.6",
121+
"swagger-ui-express": "^2.0.1",
128122
"trash-cli": "^1.4.0",
129-
"ts-jest": "^20.0.6",
130-
"ts-node": "^3.1.0",
131-
"tslint": "^5.4.3",
123+
"ts-node": "^3.2.0",
124+
"tslint": "^5.5.0",
132125
"typescript": "^2.4.1",
133126
"winston": "^2.3.1"
134127
},
@@ -148,6 +141,8 @@
148141
},
149142
"license": "MIT",
150143
"devDependencies": {
151-
"cross-env": "^5.0.1"
144+
"cross-env": "^5.0.1",
145+
"jest": "^20.0.3",
146+
"ts-jest": "^20.0.7"
152147
}
153148
}

src/api/controllers/UserController.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { inject, named } from 'inversify';
10-
import { Controller, Get, Post, Put, Delete, RequestParam, RequestBody, Response, Request } from 'inversify-express-utils';
10+
import { controller, httpGet, httpPost, httpPut, httpDelete, response, request, requestBody, requestParam } from 'inversify-express-utils';
1111
import { app } from '../../app';
1212
import { Types, Targets } from '../../constants';
1313
import { UserService } from '../services/UserService';
@@ -17,42 +17,42 @@ const populateUser = app.IoC.getNamed<interfaces.Middleware>(Types.Middleware, T
1717
const authenticate = app.IoC.getNamed<interfaces.Middleware>(Types.Middleware, Targets.Middleware.AuthenticateMiddleware);
1818

1919

20-
@Controller('/users', authenticate.use)
20+
@controller('/users', authenticate.use)
2121
export class UserController {
2222

2323
constructor( @inject(Types.Service) @named(Targets.Service.UserService) private userService: UserService) { }
2424

25-
@Get('/')
26-
public async findAll( @Response() res: myExpress.Response): Promise<any> {
25+
@httpGet('/')
26+
public async findAll( @response() res: myExpress.Response): Promise<any> {
2727
const users = await this.userService.findAll();
2828
return res.found(users.toJSON());
2929
}
3030

31-
@Post('/')
32-
public async create( @Response() res: myExpress.Response, @RequestBody() body: any): Promise<any> {
31+
@httpPost('/')
32+
public async create( @response() res: myExpress.Response, @requestBody() body: any): Promise<any> {
3333
const user = await this.userService.create(body);
3434
return res.created(user.toJSON());
3535
}
3636

37-
@Get('/me', populateUser.use)
38-
public async findMe( @Request() req: myExpress.Request, @Response() res: myExpress.Response): Promise<any> {
37+
@httpGet('/me', populateUser.use)
38+
public async findMe( @request() req: myExpress.Request, @response() res: myExpress.Response): Promise<any> {
3939
return res.found(req.user);
4040
}
4141

42-
@Get('/:id')
43-
public async findOne( @Response() res: myExpress.Response, @RequestParam('id') id: string): Promise<any> {
42+
@httpGet('/:id')
43+
public async findOne( @response() res: myExpress.Response, @requestParam('id') id: string): Promise<any> {
4444
const user = await this.userService.findOne(parseInt(id, 10));
4545
return res.found(user.toJSON());
4646
}
4747

48-
@Put('/:id')
49-
public async update( @Response() res: myExpress.Response, @RequestParam('id') id: string, @RequestBody() body: any): Promise<any> {
48+
@httpPut('/:id')
49+
public async update( @response() res: myExpress.Response, @requestParam('id') id: string, @requestBody() body: any): Promise<any> {
5050
const user = await this.userService.update(parseInt(id, 10), body);
5151
return res.updated(user.toJSON());
5252
}
5353

54-
@Delete('/:id')
55-
public async destroy( @Response() res: myExpress.Response, @RequestParam('id') id: string): Promise<any> {
54+
@httpDelete('/:id')
55+
public async destroy( @response() res: myExpress.Response, @requestParam('id') id: string): Promise<any> {
5656
await this.userService.destroy(parseInt(id, 10));
5757
return res.destroyed();
5858
}

src/api/services/UserService.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { inject, named } from 'inversify';
1212
import { Types, Core, Targets } from '../../constants';
1313
import { Logger as LoggerType } from '../../core/Logger';
1414
import { EventEmitter } from '../../core/api/events';
15-
import { Validate, Request } from '../../core/api/Validate';
15+
import { validate, request } from '../../core/api/Validate';
1616
import { NotFoundException } from '../exceptions/NotFoundException';
1717
import { UserCreateRequest } from '../requests/user/UserCreateRequest';
1818
import { UserUpdateRequest } from '../requests/user/UserUpdateRequest';
@@ -77,8 +77,8 @@ export class UserService {
7777
* @param {*} data is the json body of the request
7878
* @returns {Promise<User>}
7979
*/
80-
@Validate()
81-
public async create( @Request(UserCreateRequest) data: any): Promise<User> {
80+
@validate()
81+
public async create( @request(UserCreateRequest) data: any): Promise<User> {
8282
// If the request body was valid we will create the user
8383
const user = await this.userRepo.create(data);
8484
this.events.emit(UserCreatedListener.Event, user.toJSON());
@@ -93,8 +93,8 @@ export class UserService {
9393
* @param {*} newUser is the json body of the request
9494
* @returns {Promise<User>}
9595
*/
96-
@Validate()
97-
public async update(id: number, @Request(UserUpdateRequest) newUser: any): Promise<User> {
96+
@validate()
97+
public async update(id: number, @request(UserUpdateRequest) newUser: any): Promise<User> {
9898
// Find or fail
9999
const user = await this.findOne(id);
100100
// Set new values

src/console/lib/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ export const buildFilePath = (targetPath: string, fileName: string, isTest = fal
4040

4141
export const inputIsRequired = (value: any) => !!value;
4242

43-
export const existsFile = async (path: string, stop: boolean = false, isTest = false) => {
43+
export const existsFile = async (filePath: string, stop: boolean = false, isTest = false) => {
4444
const prompt = inquirer.createPromptModule();
4545
return new Promise((resolve, reject) => {
46-
fs.exists(path, async (exists) => {
46+
fs.exists(filePath, async (exists) => {
4747

4848
if (exists) {
49-
let fileName = path.split('/src/')[1];
49+
let fileName = filePath.split('/src/')[1];
5050
if (isTest) {
51-
fileName = path.split('/test/')[1];
51+
fileName = filePath.split('/test/')[1];
5252
}
5353
const answer = await prompt([
5454
{

src/console/templates/controller.hbs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{{#if isResourceTemplate}}
22
import { inject, named } from 'inversify';
3-
import { Controller, Get, Post, Put, Delete, RequestParam, RequestBody, Response } from 'inversify-express-utils';
3+
import { controller, httpGet, httpPost, httpPut, httpDelete, response, request, requestBody, requestParam } from 'inversify-express-utils';
44
import { Types, Targets } from '../../{{deepness}}constants';
55
import { app } from '../../{{deepness}}app';
66
import { {{name.capitalize}}Service } from '../{{deepness}}services/{{name.capitalize}}Service';
77
{{else}}
8-
import { Controller } from 'inversify-express-utils';
8+
import { controller } from 'inversify-express-utils';
99
import { app } from '../../{{deepness}}app';
1010
import { Types, Targets } from '../../{{deepness}}constants';
1111
{{/if}}
@@ -14,37 +14,37 @@ import { Types, Targets } from '../../{{deepness}}constants';
1414
const authenticate = app.IoC.getNamed<interfaces.Middleware>(Types.Middleware, Targets.Middleware.AuthenticateMiddleware);
1515

1616

17-
@Controller('/{{name.pluralize}}', authenticate.use)
17+
@controller('/{{name.pluralize}}', authenticate.use)
1818
export class {{name.capitalize}}Controller {
1919

2020
{{#if isResourceTemplate}}constructor( @inject(Types.Service) @named(Targets.Service.{{name.capitalize}}Service) private {{name.camelCase}}Service: {{name.capitalize}}Service) { }
2121

22-
@Get('/')
23-
public async findAll( @Response() res: myExpress.Response): Promise<any> {
22+
@httpGet('/')
23+
public async findAll( @response() res: myExpress.Response): Promise<any> {
2424
const {{name.camelCase}}s = await this.{{name.camelCase}}Service.findAll();
2525
return res.found({{name.camelCase}}s.toJSON());
2626
}
2727

28-
@Post('/')
29-
public async create( @Response() res: myExpress.Response, @RequestBody() body: any): Promise<any> {
28+
@httpPost('/')
29+
public async create( @response() res: myExpress.Response, @requestBody() body: any): Promise<any> {
3030
const {{name.camelCase}} = await this.{{name.camelCase}}Service.create(body);
3131
return res.created({{name.camelCase}}.toJSON());
3232
}
3333

34-
@Get('/:id')
35-
public async findOne( @Response() res: myExpress.Response, @RequestParam('id') id: string): Promise<any> {
34+
@httpGet('/:id')
35+
public async findOne( @response() res: myExpress.Response, @requestParam('id') id: string): Promise<any> {
3636
const {{name.camelCase}} = await this.{{name.camelCase}}Service.findOne(parseInt(id, 10));
3737
return res.found({{name.camelCase}}.toJSON());
3838
}
3939

40-
@Put('/:id')
41-
public async update( @Response() res: myExpress.Response, @RequestParam('id') id: string, @RequestBody() body: any): Promise<any> {
40+
@httpPut('/:id')
41+
public async update( @response() res: myExpress.Response, @requestParam('id') id: string, @requestBody() body: any): Promise<any> {
4242
const {{name.camelCase}} = await this.{{name.camelCase}}Service.update(parseInt(id, 10), body);
4343
return res.updated({{name.camelCase}}.toJSON());
4444
}
4545

46-
@Delete('/:id')
47-
public async destroy( @Response() res: myExpress.Response, @RequestParam('id') id: string): Promise<any> {
46+
@httpDelete('/:id')
47+
public async destroy( @response() res: myExpress.Response, @requestParam('id') id: string): Promise<any> {
4848
await this.{{name.camelCase}}Service.destroy(parseInt(id, 10));
4949
return res.destroyed();
5050
}{{/if}}

src/core/IoC.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Types, Core, Targets } from '../constants';
1313
import { events, EventEmitter } from './api/events';
1414
import { Logger } from './Logger';
1515
import { IocConfig } from '../config/IocConfig';
16-
import { getFolderwrapping } from './helpers/Path';
16+
import { getFolderWrapping } from './helpers/Path';
1717

1818

1919
export class IoC {
@@ -122,16 +122,16 @@ export class IoC {
122122
.whenTargetNamed(name);
123123
}
124124

125-
private bindFiles(path: string, target: any, callback: (name: any, value: any) => void): Promise<void> {
125+
private bindFiles(filePath: string, target: any, callback: (name: any, value: any) => void): Promise<void> {
126126
return new Promise<void>((resolve) => {
127-
this.getFiles(path, (files: string[]) => {
127+
this.getFiles(filePath, (files: string[]) => {
128128
files.forEach((file: any) => {
129129
let fileExport;
130130
let fileClass;
131131
let fileTarget;
132132
const isRecursive = file.name.indexOf('.') > 0;
133133
try {
134-
fileExport = require(`${file.path}`);
134+
fileExport = require(`${file.filePath}`);
135135
} catch (e) {
136136
this.log.warn(e.message);
137137
return;
@@ -185,32 +185,31 @@ export class IoC {
185185
}
186186

187187
private getBasePath(): string {
188-
const baseFolder = __dirname.indexOf(getFolderwrapping('src')) >= 0 ? getFolderwrapping('src') : getFolderwrapping('dist');
188+
const baseFolder = __dirname.indexOf(getFolderWrapping('src')) >= 0 ? getFolderWrapping('src') : getFolderWrapping('dist');
189189
const baseRoot = __dirname.substring(0, __dirname.indexOf(baseFolder));
190190
return path.join(baseRoot, baseFolder, 'api');
191191
}
192192

193-
private getFiles(path: string, done: (files: any[]) => void): void {
194-
const isTypeScript = __dirname.indexOf(getFolderwrapping('src')) >= 0;
193+
private getFiles(filePath: string, done: (files: any[]) => void): void {
194+
const isTypeScript = __dirname.indexOf(getFolderWrapping('src')) >= 0;
195195
if (!isTypeScript) {
196-
path = path.replace('.ts', '.js');
196+
filePath = filePath.replace('.ts', '.js');
197197
}
198-
glob(this.getBasePath() + path, (err: any, files: string[]) => {
198+
glob(this.getBasePath() + filePath, (err: any, files: string[]) => {
199199
if (err) {
200-
this.log.warn(`Could not read the folder ${path}!`);
200+
this.log.warn(`Could not read the folder ${filePath}!`);
201201
return;
202202
}
203203
done(files.map((p: string) => this.parseFilePath(p)));
204204
});
205205
}
206206

207-
private parseFilePath(path: string): any {
208-
const filePath = path.substring(this.getBasePath().length + 1);
209-
const dir = filePath.split('/')[0];
210-
const file = filePath.substr(dir.length + 1);
207+
private parseFilePath(filePath: string): any {
208+
const p = filePath.substring(this.getBasePath().length + 1);
209+
const dir = p.split('/')[0];
210+
const file = p.substr(dir.length + 1);
211211
const name = file.replace('/', '.').substring(0, file.length - 3);
212212
return {
213-
path,
214213
filePath,
215214
dir,
216215
file,

src/core/Logger.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getFolderwrapping, isWindows } from './helpers/Path';
1+
import { getFolderWrapping, isWindows } from './helpers/Path';
22

33
/**
44
* core.log.Log
@@ -35,8 +35,8 @@ export class Logger {
3535
const pathDelimiter = isWindows() ? '\\' : '/';
3636
if (path.indexOf(pathDelimiter) >= 0) {
3737
path = path.replace(process.cwd(), '');
38-
path = path.replace(getFolderwrapping('src'), '');
39-
path = path.replace(getFolderwrapping('dist'), '');
38+
path = path.replace(getFolderWrapping('src'), '');
39+
path = path.replace(getFolderWrapping('dist'), '');
4040
path = path.replace('.ts', '');
4141
path = path.replace('.js', '');
4242
path = path.replace(/\//g, ':');

src/core/SwaggerUI.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as express from 'express';
22
import * as path from 'path';
33
import * as swaggerUi from 'swagger-ui-express';
44
import { Environment } from './helpers/Environment';
5-
import { getFolderwrapping } from './helpers/Path';
5+
import { getFolderWrapping } from './helpers/Path';
66

77

88
export class SwaggerUI {
@@ -13,7 +13,7 @@ export class SwaggerUI {
1313

1414
public setup(app: express.Application): void {
1515
if (Environment.isTruthy(process.env.SWAGGER_ENABLED)) {
16-
const baseFolder = __dirname.indexOf(getFolderwrapping('src')) >= 0 ? getFolderwrapping('src') : getFolderwrapping('dist');
16+
const baseFolder = __dirname.indexOf(getFolderWrapping('src')) >= 0 ? getFolderWrapping('src') : getFolderWrapping('dist');
1717
const basePath = __dirname.substring(0, __dirname.indexOf(baseFolder));
1818
const swaggerFile = require(path.join(basePath, process.env.SWAGGER_FILE));
1919
const packageJson = require(path.join(basePath, 'package.json'));

src/core/api/Validate.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ interface RequestParameter {
2424
*
2525
* @param request
2626
*/
27-
export const Request = (request: typeof RequestBody) => (target: object, propertyKey: string | symbol, parameterIndex: number): any => {
27+
export const request = (requestBody: typeof RequestBody) => (target: object, propertyKey: string | symbol, parameterIndex: number): any => {
2828
const existingRequestParameters: RequestParameter[] = Reflect.getOwnMetadata(requestMetadataKey, target, propertyKey) || [];
2929
existingRequestParameters.push({
30-
request,
30+
request: requestBody,
3131
index: parameterIndex
3232
});
3333
Reflect.defineMetadata(requestMetadataKey, existingRequestParameters, target, propertyKey);
@@ -40,14 +40,14 @@ export const Request = (request: typeof RequestBody) => (target: object, propert
4040
* @param propertyName
4141
* @param descriptor
4242
*/
43-
export const Validate = () => (target: any, propertyName: string, descriptor: TypedPropertyDescriptor<any>): any => {
43+
export const validate = () => (target: any, propertyName: string, descriptor: TypedPropertyDescriptor<any>): any => {
4444
const method = descriptor.value;
4545
descriptor.value = async function(...args: any[]): Promise<any> {
4646
const requestParameters: RequestParameter[] = Reflect.getOwnMetadata(requestMetadataKey, target, propertyName);
4747
if (requestParameters.length > 0) {
4848
for (const requestParameter of requestParameters) {
49-
const request = new requestParameter.request(args[requestParameter.index]);
50-
await request.validate();
49+
const requestBody = new requestParameter.request(args[requestParameter.index]);
50+
await requestBody.validate();
5151
}
5252
}
5353
return method && method.apply(this, args);

0 commit comments

Comments
 (0)