Skip to content

Commit 6d99b92

Browse files
author
hirsch88
committed
rename my to myExpress
1 parent eb7ac89 commit 6d99b92

File tree

9 files changed

+58
-55
lines changed

9 files changed

+58
-55
lines changed

src/api/controllers/UserController.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import { inject, named } from 'inversify';
1010
import { Controller, Get, Post, Put, Delete, RequestParam, RequestBody, Response, Request } from 'inversify-express-utils';
11-
import { my } from 'my-express';
11+
import { myExpress } from 'my-express';
1212
import { UserService } from '../services/UserService';
1313
import { Types } from '../../constants/Types';
1414
import { Service, Middleware } from '../../constants/Targets';
@@ -27,36 +27,36 @@ export class UserController {
2727
constructor( @inject(Types.Service) @named(Service.UserService) private userService: UserService) { }
2828

2929
@Get('/')
30-
public async findAll( @Response() res: my.Response): Promise<any> {
30+
public async findAll( @Response() res: myExpress.Response): Promise<any> {
3131
const users = await this.userService.findAll();
3232
return res.found(users.toJSON());
3333
}
3434

3535
@Post('/')
36-
public async create( @Response() res: my.Response, @RequestBody() body: any): Promise<any> {
36+
public async create( @Response() res: myExpress.Response, @RequestBody() body: any): Promise<any> {
3737
const user = await this.userService.create(body);
3838
return res.created(user.toJSON());
3939
}
4040

4141
@Get('/me', populateUser.use)
42-
public async findMe( @Request() req: my.Request, @Response() res: my.Response): Promise<any> {
42+
public async findMe( @Request() req: myExpress.Request, @Response() res: myExpress.Response): Promise<any> {
4343
return res.found(req.user);
4444
}
4545

4646
@Get('/:id')
47-
public async findOne( @Response() res: my.Response, @RequestParam('id') id: string): Promise<any> {
47+
public async findOne( @Response() res: myExpress.Response, @RequestParam('id') id: string): Promise<any> {
4848
const user = await this.userService.findOne(parseInt(id, 10));
4949
return res.found(user.toJSON());
5050
}
5151

5252
@Put('/:id')
53-
public async update( @Response() res: my.Response, @RequestParam('id') id: string, @RequestBody() body: any): Promise<any> {
53+
public async update( @Response() res: myExpress.Response, @RequestParam('id') id: string, @RequestBody() body: any): Promise<any> {
5454
const user = await this.userService.update(parseInt(id, 10), body);
5555
return res.updated(user.toJSON());
5656
}
5757

5858
@Delete('/:id')
59-
public async destroy( @Response() res: my.Response, @RequestParam('id') id: string): Promise<any> {
59+
public async destroy( @Response() res: myExpress.Response, @RequestParam('id') id: string): Promise<any> {
6060
await this.userService.destroy(parseInt(id, 10));
6161
return res.destroyed();
6262
}

src/api/middlewares/AuthenticateMiddleware.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { inject, named } from 'inversify';
22
import * as Request from 'request';
3-
import { my } from 'my-express';
3+
import { myExpress } from 'my-express';
44
import { Log } from '../../core/log';
55
import { Types } from '../../constants/Types';
66
import { Core } from '../../core/Targets';
@@ -20,7 +20,7 @@ export class AuthenticateMiddleware {
2020
}
2121

2222

23-
public use = (req: my.Request, res: my.Response, next: my.NextFunction): void => {
23+
public use = (req: myExpress.Request, res: myExpress.Response, next: myExpress.NextFunction): void => {
2424
const token = this.getToken(req);
2525

2626
if (token === null) {
@@ -59,7 +59,7 @@ export class AuthenticateMiddleware {
5959
});
6060
}
6161

62-
private getToken(req: my.Request): string | null {
62+
private getToken(req: myExpress.Request): string | null {
6363
const authorization = req.headers.authorization;
6464

6565
// Retrieve the token form the Authorization header

src/api/middlewares/PopulateUserMiddleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { inject, named } from 'inversify';
2-
import { my } from 'my-express';
2+
import { myExpress } from 'my-express';
33
import { Log } from '../../core/log';
44
import { UserService } from '../services/UserService';
55
import { Types } from '../../constants/Types';
@@ -19,7 +19,7 @@ export class PopulateUserMiddleware {
1919
}
2020

2121

22-
public use = (req: my.Request, res: my.Response, next: my.NextFunction): void => {
22+
public use = (req: myExpress.Request, res: myExpress.Response, next: myExpress.NextFunction): void => {
2323
// Check if the authenticate middleware was successful
2424
if (!req.tokeninfo || !req.tokeninfo.user_id) {
2525
return res.failed(400, 'Missing token information!');

src/console/templates/controller.hbs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{#if isResourceTemplate}}
22
import { inject, named } from 'inversify';
33
import { Controller, Get, Post, Put, Delete, RequestParam, RequestBody, Response } from 'inversify-express-utils';
4-
import { my } from 'my-express';
4+
import { myExpress } from 'my-express';
55
import { Types } from '../../{{deepness}}constants/Types';
66
import { Service, Middleware } from '../../{{deepness}}constants/Targets';
77
import { ioc } from '../../{{deepness}}core/IoC';
@@ -27,31 +27,31 @@ export class {{name.capitalize}}Controller {
2727
constructor( @inject(Types.Service) @named(Service.{{name.capitalize}}Service) private {{name.camelCase}}Service: {{name.capitalize}}Service) { }
2828

2929
@Get('/')
30-
public async findAll( @Response() res: my.Response): Promise<any> {
30+
public async findAll( @Response() res: myExpress.Response): Promise<any> {
3131
const {{name.camelCase}}s = await this.{{name.camelCase}}Service.findAll();
3232
return res.found({{name.camelCase}}s.toJSON());
3333
}
3434

3535
@Post('/')
36-
public async create( @Response() res: my.Response, @RequestBody() body: any): Promise<any> {
36+
public async create( @Response() res: myExpress.Response, @RequestBody() body: any): Promise<any> {
3737
const {{name.camelCase}} = await this.{{name.camelCase}}Service.create(body);
3838
return res.created({{name.camelCase}}.toJSON());
3939
}
4040

4141
@Get('/:id')
42-
public async findOne( @Response() res: my.Response, @RequestParam('id') id: string): Promise<any> {
42+
public async findOne( @Response() res: myExpress.Response, @RequestParam('id') id: string): Promise<any> {
4343
const {{name.camelCase}} = await this.{{name.camelCase}}Service.findOne(parseInt(id, 10));
4444
return res.found({{name.camelCase}}.toJSON());
4545
}
4646

4747
@Put('/:id')
48-
public async update( @Response() res: my.Response, @RequestParam('id') id: string, @RequestBody() body: any): Promise<any> {
48+
public async update( @Response() res: myExpress.Response, @RequestParam('id') id: string, @RequestBody() body: any): Promise<any> {
4949
const {{name.camelCase}} = await this.{{name.camelCase}}Service.update(parseInt(id, 10), body);
5050
return res.updated({{name.camelCase}}.toJSON());
5151
}
5252

5353
@Delete('/:id')
54-
public async destroy( @Response() res: my.Response, @RequestParam('id') id: string): Promise<any> {
54+
public async destroy( @Response() res: myExpress.Response, @RequestParam('id') id: string): Promise<any> {
5555
await this.{{name.camelCase}}Service.destroy(parseInt(id, 10));
5656
return res.destroyed();
5757
}{{/if}}

src/console/templates/middleware.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { inject, named } from 'inversify';
2-
import { my } from 'my-express';
2+
import { myExpress } from 'my-express';
33
import { Log } from '../../{{deepness}}core/log';
44
import { Types } from '../../{{deepness}}constants/Types';
55
import { Core } from '../../{{deepness}}core/Targets';
@@ -16,7 +16,7 @@ export class {{name.capitalize}}Middleware {
1616
}
1717

1818

19-
public use = (req: my.Request, res: my.Response, next: my.NextFunction): void => {
19+
public use = (req: myExpress.Request, res: myExpress.Response, next: myExpress.NextFunction): void => {
2020
// TODO add your middleware logic here
2121
next();
2222
}

src/core/ApiInfo.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as express from 'express';
2-
import { my } from 'my-express';
2+
import * as path from 'path';
3+
import { myExpress } from 'my-express';
34
import { Environment } from './Environment';
45

56

@@ -9,24 +10,26 @@ export class ApiInfo {
910

1011
public setup(): void {
1112
if (Environment.get<string>('API_INFO_ENABLED').toLowerCase() === 'true') {
12-
this.app.get(Environment.get<string>('APP_URL_PREFIX') + Environment.get<string>('API_INFO_ROUTE'), (req: my.Request, res: my.Response) => {
13-
const pkg = Environment.getPkg();
14-
const links = {
15-
links: {}
16-
};
17-
if (Environment.get<string>('SWAGGER_ENABLED').toLowerCase() === 'true') {
18-
links.links['swagger'] = `${this.app.get('host')}:${this.app.get('port')}${process.env.APP_URL_PREFIX}${process.env.SWAGGER_ROUTE}`;
19-
}
20-
if (Environment.get<string>('MONITOR_ENABLED').toLowerCase() === 'true') {
21-
links.links['monitor'] = `${this.app.get('host')}:${this.app.get('port')}${process.env.APP_URL_PREFIX}${process.env.MONITOR_ROUTE}`;
22-
}
23-
return res.json({
24-
name: pkg.name,
25-
version: pkg.version,
26-
description: pkg.description,
27-
...links
13+
this.app.get(
14+
path.join(Environment.get<string>('APP_URL_PREFIX'), Environment.get<string>('API_INFO_ROUTE')),
15+
(req: myExpress.Request, res: myExpress.Response) => {
16+
const pkg = Environment.getPkg();
17+
const links = {
18+
links: {}
19+
};
20+
if (Environment.get<string>('SWAGGER_ENABLED').toLowerCase() === 'true') {
21+
links.links['swagger'] = `${this.app.get('host')}:${this.app.get('port')}${process.env.APP_URL_PREFIX}${process.env.SWAGGER_ROUTE}`;
22+
}
23+
if (Environment.get<string>('MONITOR_ENABLED').toLowerCase() === 'true') {
24+
links.links['monitor'] = `${this.app.get('host')}:${this.app.get('port')}${process.env.APP_URL_PREFIX}${process.env.MONITOR_ROUTE}`;
25+
}
26+
return res.json({
27+
name: pkg.name,
28+
version: pkg.version,
29+
description: pkg.description,
30+
...links
31+
});
2832
});
29-
});
3033
}
3134
}
3235

src/core/api/exceptionHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
* send them directly to the client or otherwise it calls the next middleware.
77
*/
88

9-
import { my } from 'my-express';
9+
import { myExpress } from 'my-express';
1010
import { Environment } from '../Environment';
1111
import { Exception, isException } from '../api/Exception';
1212

1313

14-
export const exceptionHandler = (error: Exception | Error, req: my.Request, res: my.Response, next: my.NextFunction) => {
14+
export const exceptionHandler = (error: Exception | Error, req: myExpress.Request, res: myExpress.Response, next: myExpress.NextFunction) => {
1515
if (error instanceof Exception || error[isException]) {
1616
res.failed(error['code'], error.message, error['body'] || null);
1717
next();

src/core/api/extendExpressResponse.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
*/
99

1010
import * as express from 'express';
11-
import { my } from 'my-express';
11+
import { myExpress } from 'my-express';
1212

1313

14-
export const extendExpressResponse = (req: my.Request, res: my.Response, next: express.NextFunction) => {
14+
export const extendExpressResponse = (req: myExpress.Request, res: myExpress.Response, next: express.NextFunction) => {
1515

1616
/**
1717
* 200 - OK
1818
* This is used for successful responses and a json body
1919
*/
20-
res.ok = <T>(data: T, options: my.ResponseOptions = {}) => {
20+
res.ok = <T>(data: T, options: myExpress.ResponseOptions = {}) => {
2121
res.status(200);
2222
return res.json(bodySuccessful(data, options));
2323
};
@@ -26,7 +26,7 @@ export const extendExpressResponse = (req: my.Request, res: my.Response, next: e
2626
* 201 - Created
2727
* This is used for created resources
2828
*/
29-
res.created = <T>(data: T, options: my.ResponseOptions = {}) => {
29+
res.created = <T>(data: T, options: myExpress.ResponseOptions = {}) => {
3030
res.status(201);
3131
return res.json(bodySuccessful(data, options));
3232
};
@@ -35,23 +35,23 @@ export const extendExpressResponse = (req: my.Request, res: my.Response, next: e
3535
* 200 - Found
3636
* Like the ok function
3737
*/
38-
res.found = <T>(data: T, options: my.ResponseOptions = {}) => {
38+
res.found = <T>(data: T, options: myExpress.ResponseOptions = {}) => {
3939
return res.ok(data, options);
4040
};
4141

4242
/**
4343
* 200 - Updated
4444
* Like the ok function
4545
*/
46-
res.updated = <T>(data: T, options: my.ResponseOptions = {}) => {
46+
res.updated = <T>(data: T, options: myExpress.ResponseOptions = {}) => {
4747
return res.ok(data, options);
4848
};
4949

5050
/**
5151
* 200 - Destroyed
5252
* This is the response after a resource has been removed
5353
*/
54-
res.destroyed = (options: my.ResponseOptions = {}) => {
54+
res.destroyed = (options: myExpress.ResponseOptions = {}) => {
5555
res.status(200);
5656
return res.json(bodySuccessful(null));
5757
};
@@ -72,7 +72,7 @@ export const extendExpressResponse = (req: my.Request, res: my.Response, next: e
7272
/**
7373
* This body parser is used to show successful responses to the client
7474
*/
75-
export function bodySuccessful<T>(data: T, options: my.ResponseOptions = {}): any {
75+
export function bodySuccessful<T>(data: T, options: myExpress.ResponseOptions = {}): any {
7676
return {
7777
success: true,
7878
...message(options.message),
@@ -100,7 +100,7 @@ function message(value?: string): any {
100100
return;
101101
}
102102

103-
function links(values?: my.ResponseLinks[]): any {
103+
function links(values?: myExpress.ResponseLinks[]): any {
104104
if (values) {
105105
return { links: values };
106106
}

src/types/my-express.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@
88

99
declare module 'my-express' {
1010

11-
import * as express from 'express';
11+
import * as expressLib from 'express';
1212
import * as auth0 from 'auth0';
1313
import * as dto from 'dto';
1414

15-
namespace my {
15+
namespace myExpress {
1616

17-
interface Application extends express.Application {
17+
interface Application extends expressLib.Application {
1818
}
1919

20-
interface NextFunction extends express.NextFunction {
20+
interface NextFunction extends expressLib.NextFunction {
2121
}
2222

23-
interface Request extends express.Request {
23+
interface Request extends expressLib.Request {
2424
tokeninfo: auth0.User;
2525
user: dto.User;
2626
}
2727

28-
interface Response extends express.Response {
28+
interface Response extends expressLib.Response {
2929
ok<T>(data: T, options?: ResponseOptions): void;
3030
created<T>(data: T, options?: ResponseOptions): void;
3131
found<T>(data: T, options?: ResponseOptions): void;

0 commit comments

Comments
 (0)