Skip to content

Commit 3b006ef

Browse files
author
hirsch88
committed
refactor files
1 parent 4fb5d1f commit 3b006ef

File tree

11 files changed

+42
-67
lines changed

11 files changed

+42
-67
lines changed

src/api/exceptions/DatabaseException.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { Exception } from '../../core/api/Exception';
2-
31
/**
4-
* DatabaseException should be used for repository errors like
5-
* entity with this id already exists and stuff like that.
2+
* DatabaseException
3+
* ----------------------------------------
64
*
7-
* @export
8-
* @class DatabaseException
9-
* @extends {Exception}
5+
* This should be used for repository errors like
6+
* entity with this id already exists and stuff like that.
107
*/
8+
9+
import { Exception } from '../../core/api/Exception';
10+
11+
1112
export class DatabaseException extends Exception {
1213
constructor(text: string, error: any) {
1314
const value: string = error.stack.split('\n')[0];

src/api/exceptions/NotFoundException.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { Exception } from '../../core/api/Exception';
2-
31
/**
4-
* NotFoundException should be used if a someone requests a
2+
* NotFoundException
3+
* ----------------------------------------
4+
*
5+
* This should be used if a someone requests a
56
* entity with a id, but there is no entity with this id in the
67
* database, then we throw this exception.
7-
*
8-
* @export
9-
* @class NotFoundException
10-
* @extends {Exception}
118
*/
9+
10+
import { Exception } from '../../core/api/Exception';
11+
12+
1213
export class NotFoundException extends Exception {
1314
constructor(id?: number | string) {
1415
super(404, `Entity with identifier ${id} does not exist`);

src/api/exceptions/ValidationException.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { Exception } from '../../core/api/Exception';
2-
31
/**
4-
* ValidationException should be used when we validate
5-
* the request payload, so we can response with a 400 (Bad Request)
2+
* ValidationException
3+
* ----------------------------------------
64
*
7-
* @export
8-
* @class ValidationException
9-
* @extends {Exception}
5+
* This should be used when we validate
6+
* the request payload, so we can response with a 400 (Bad Request)
107
*/
8+
9+
import { Exception } from '../../core/api/Exception';
10+
11+
1112
export class ValidationException extends Exception {
1213
constructor(text: string, errors: any) {
1314
const info = errors.map((e) => ({

src/api/services/UserService.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* This service is here to validate and call the repository layer for
66
* database actions. Furthermore you should throw events here if
77
* necessary.
8-
*
98
*/
109

1110
import * as Bookshelf from 'bookshelf';

src/core/ApiInfo.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ export class ApiInfo {
1717
const links = {
1818
links: {}
1919
};
20+
const appUrl = Environment.get<string>('APP_URL_PREFIX');
2021
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+
links.links['swagger'] =
23+
`${this.app.get('host')}:${this.app.get('port')}${path.join(appUrl, Environment.get<string>('SWAGGER_ROUTE'))}`;
2224
}
2325
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}`;
26+
links.links['monitor'] =
27+
`${this.app.get('host')}:${this.app.get('port')}${path.join(appUrl, Environment.get<string>('MONITOR_ROUTE'))}`;
2528
}
2629
return res.json({
2730
name: pkg.name,

src/core/ApiMonitor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as path from 'path';
12
import * as express from 'express';
23
import * as monitor from 'express-status-monitor';
34
import { Environment } from './Environment';
@@ -10,7 +11,7 @@ export class ApiMonitor {
1011
public setup(): void {
1112
if (Environment.get<string>('MONITOR_ENABLED').toLowerCase() === 'true') {
1213
this.app.use(monitor());
13-
this.app.get(Environment.get<string>('APP_URL_PREFIX') + Environment.get<string>('MONITOR_ROUTE'), monitor().pageRoute);
14+
this.app.get(path.join(Environment.get<string>('APP_URL_PREFIX'), Environment.get<string>('MONITOR_ROUTE')), monitor().pageRoute);
1415
}
1516
}
1617

src/core/Environment.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
import * as packageInfo from '../../package.json';
99

10+
1011
export class Environment {
1112

1213
static getNodeEnv(): string {

src/core/IoC.ts

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

99
import * as glob from 'glob';
10+
import * as path from 'path';
1011
import { Container, decorate, injectable } from 'inversify';
1112
import { Types } from '../constants/Types';
1213
import { Core } from './Targets';
@@ -164,25 +165,21 @@ class IoC {
164165
private getClassOfFileExport(name: string, fileExport: any): any {
165166
const fileParts = name.split('.');
166167
let fileClass = fileExport;
167-
fileParts.forEach((part) => {
168-
fileClass = fileClass[part];
169-
});
168+
fileParts.forEach((part) => fileClass = fileClass[part]);
170169
return fileClass;
171170
}
172171

173172
private getTargetOfFile(name: string, target: any): any {
174173
const fileParts = name.split('.');
175174
let fileTarget = target;
176-
fileParts.forEach((part) => {
177-
fileTarget = fileTarget[part];
178-
});
175+
fileParts.forEach((part) => fileTarget = fileTarget[part]);
179176
return fileTarget;
180177
}
181178

182179
private getBasePath(): string {
183180
const baseFolder = __dirname.indexOf('/src/') >= 0 ? '/src/' : '/dist/';
184181
const baseRoot = __dirname.substring(0, __dirname.indexOf(baseFolder));
185-
return `${baseRoot}${baseFolder}api`;
182+
return path.join(baseRoot, baseFolder, 'api');
186183
}
187184

188185
private getFiles(path: string, done: (files: any[]) => void): void {

src/core/SwaggerUI.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as express from 'express';
2+
import * as path from 'path';
23
import * as swaggerUi from 'swagger-ui-express';
34
import { Environment } from './Environment';
45

@@ -11,8 +12,8 @@ export class SwaggerUI {
1112
if (Environment.get<string>('SWAGGER_ENABLED').toLowerCase() === 'true') {
1213
const baseFolder = __dirname.indexOf('/src/') >= 0 ? '/src/' : '/dist/';
1314
const basePath = __dirname.substring(0, __dirname.indexOf(baseFolder));
14-
const swaggerFile = require(basePath + Environment.get<string>('SWAGGER_FILE'));
15-
const packageJson = require(basePath + '/package.json');
15+
const swaggerFile = require(path.join(basePath, Environment.get<string>('SWAGGER_FILE')));
16+
const packageJson = require(path.join(basePath, '/package.json'));
1617

1718
// Add npm infos to the swagger doc
1819
swaggerFile.info = {
@@ -22,7 +23,7 @@ export class SwaggerUI {
2223
};
2324

2425
// Initialize swagger-jsdoc -> returns validated swagger spec in json format
25-
const route = Environment.get<string>('APP_URL_PREFIX') + Environment.get<string>('SWAGGER_ROUTE');
26+
const route = path.join(Environment.get<string>('APP_URL_PREFIX'), Environment.get<string>('SWAGGER_ROUTE'));
2627
this.app.use(route, swaggerUi.serve, swaggerUi.setup(swaggerFile));
2728
}
2829
}

src/core/api/RequestBody.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,4 @@ export class RequestBody {
4040
return;
4141
}
4242

43-
// TODO check if needed
44-
// /**
45-
// * Returns a new body object
46-
// */
47-
// public toJSON(): any {
48-
// const json = {};
49-
// const keys = Object.keys(this);
50-
// keys.forEach((key) => {
51-
// if (this[key] !== undefined) {
52-
// json[key] = this[key];
53-
// }
54-
// });
55-
// return json;
56-
// }
57-
58-
// /**
59-
// * Sets the values direct into the body object
60-
// */
61-
// protected set(key: string, value: any): void {
62-
// this[key] = value;
63-
// }
64-
65-
// /**
66-
// * Updates the property only if the the value is given
67-
// */
68-
// protected update(key: string, value: any): void {
69-
// if (value !== undefined) {
70-
// this[key] = value;
71-
// }
72-
// }
73-
7443
}

0 commit comments

Comments
 (0)