Skip to content

Commit 00ea930

Browse files
committed
코딩 컨벤션에 맞게 코드 리포매팅
1 parent 42cb2ef commit 00ea930

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1083
-1078
lines changed

package-scripts.js

+263-263
Large diffs are not rendered by default.

src/api/middlewares/CompressionMiddleware.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { ExpressMiddlewareInterface, Middleware } from 'routing-controllers';
55
@Middleware({ type: 'before' })
66
export class CompressionMiddleware implements ExpressMiddlewareInterface {
77

8-
public use(req: express.Request, res: express.Response, next: express.NextFunction): any {
9-
return compression()(req, res, next);
10-
}
8+
public use(req: express.Request, res: express.Response, next: express.NextFunction): any {
9+
return compression()(req, res, next);
10+
}
1111

1212
}

src/api/middlewares/ErrorHandlerMiddleware.ts

+21-20
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,27 @@ import { env } from '../../env';
77
@Middleware({ type: 'after' })
88
export class ErrorHandlerMiddleware implements ExpressErrorMiddlewareInterface {
99

10-
public isProduction = env.isProduction;
11-
12-
constructor(
13-
@Logger(__filename) private log: LoggerInterface
14-
) { }
15-
16-
public error(error: HttpError, req: express.Request, res: express.Response, next: express.NextFunction): void {
17-
res.status(error.httpCode || 500);
18-
res.json({
19-
name: error.name,
20-
message: error.message,
21-
errors: error[`errors`] || [],
22-
});
23-
24-
if (this.isProduction) {
25-
this.log.error(error.name, error.message);
26-
} else {
27-
this.log.error(error.name, error.stack);
28-
}
29-
10+
public isProduction = env.isProduction;
11+
12+
constructor(
13+
@Logger(__filename) private log: LoggerInterface,
14+
) {
15+
}
16+
17+
public error(error: HttpError, req: express.Request, res: express.Response, next: express.NextFunction): void {
18+
res.status(error.httpCode || 500);
19+
res.json({
20+
name: error.name,
21+
message: error.message,
22+
errors: error[`errors`] || [],
23+
});
24+
25+
if (this.isProduction) {
26+
this.log.error(error.name, error.message);
27+
} else {
28+
this.log.error(error.name, error.stack);
3029
}
3130

31+
}
32+
3233
}

src/api/middlewares/LogMiddleware.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import { Logger } from '../../lib/logger';
88
@Middleware({ type: 'before' })
99
export class LogMiddleware implements ExpressMiddlewareInterface {
1010

11-
private log = new Logger(__dirname);
11+
private log = new Logger(__dirname);
1212

13-
public use(req: express.Request, res: express.Response, next: express.NextFunction): any {
14-
return morgan(env.log.output, {
15-
stream: {
16-
write: this.log.info.bind(this.log),
17-
},
18-
})(req, res, next);
19-
}
13+
public use(req: express.Request, res: express.Response, next: express.NextFunction): any {
14+
return morgan(env.log.output, {
15+
stream: {
16+
write: this.log.info.bind(this.log),
17+
},
18+
})(req, res, next);
19+
}
2020

2121
}

src/api/middlewares/SecurityHstsMiddleware.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { ExpressMiddlewareInterface, Middleware } from 'routing-controllers';
55
@Middleware({ type: 'before' })
66
export class SecurityHstsMiddleware implements ExpressMiddlewareInterface {
77

8-
public use(req: express.Request, res: express.Response, next: express.NextFunction): any {
9-
return helmet.hsts({
10-
maxAge: 31536000,
11-
includeSubdomains: true,
12-
})(req, res, next);
13-
}
8+
public use(req: express.Request, res: express.Response, next: express.NextFunction): any {
9+
return helmet.hsts({
10+
maxAge: 31536000,
11+
includeSubdomains: true,
12+
})(req, res, next);
13+
}
1414

1515
}

src/api/middlewares/SecurityMiddleware.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { ExpressMiddlewareInterface, Middleware } from 'routing-controllers';
55
@Middleware({ type: 'before' })
66
export class SecurityMiddleware implements ExpressMiddlewareInterface {
77

8-
public use(req: express.Request, res: express.Response, next: express.NextFunction): any {
9-
return helmet()(req, res, next);
10-
}
8+
public use(req: express.Request, res: express.Response, next: express.NextFunction): any {
9+
return helmet()(req, res, next);
10+
}
1111

1212
}

src/api/middlewares/SecurityNoCacheMiddleware.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { ExpressMiddlewareInterface, Middleware } from 'routing-controllers';
55
@Middleware({ type: 'before' })
66
export class SecurityNoCacheMiddleware implements ExpressMiddlewareInterface {
77

8-
public use(req: express.Request, res: express.Response, next: express.NextFunction): any {
9-
return helmet.noCache()(req, res, next);
10-
}
8+
public use(req: express.Request, res: express.Response, next: express.NextFunction): any {
9+
return helmet.noCache()(req, res, next);
10+
}
1111

1212
}

src/app.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ import { winstonLoader } from './loaders/winstonLoader';
2626
const log = new Logger(__filename);
2727

2828
bootstrapMicroframework({
29-
/**
30-
* Loader is a place where you can configure all your modules during microframework
31-
* bootstrap process. All loaders are executed one by one in a sequential order.
32-
*/
33-
loaders: [
34-
winstonLoader,
35-
iocLoader,
36-
eventDispatchLoader,
37-
typeormLoader,
38-
expressLoader,
39-
swaggerLoader,
40-
monitorLoader,
41-
homeLoader,
42-
publicLoader,
43-
graphqlLoader,
44-
],
29+
/**
30+
* Loader is a place where you can configure all your modules during microframework
31+
* bootstrap process. All loaders are executed one by one in a sequential order.
32+
*/
33+
loaders: [
34+
winstonLoader,
35+
iocLoader,
36+
eventDispatchLoader,
37+
typeormLoader,
38+
expressLoader,
39+
swaggerLoader,
40+
monitorLoader,
41+
homeLoader,
42+
publicLoader,
43+
graphqlLoader,
44+
],
4545
})
46-
.then(() => banner(log))
47-
.catch(error => log.error('Application is crashed: ' + error));
46+
.then(() => banner(log))
47+
.catch(error => log.error('Application is crashed: ' + error));

src/auth/AuthService.ts

+31-30
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,41 @@ import { Logger, LoggerInterface } from '../decorators/Logger';
99
@Service()
1010
export class AuthService {
1111

12-
constructor(
13-
@Logger(__filename) private log: LoggerInterface,
14-
@OrmRepository() private userRepository: UserRepository
15-
) { }
16-
17-
public parseBasicAuthFromRequest(req: express.Request): { username: string, password: string } {
18-
const authorization = req.header('authorization');
19-
20-
if (authorization && authorization.split(' ')[0] === 'Basic') {
21-
this.log.info('Credentials provided by the client');
22-
const decodedBase64 = Buffer.from(authorization.split(' ')[1], 'base64').toString('ascii');
23-
const username = decodedBase64.split(':')[0];
24-
const password = decodedBase64.split(':')[1];
25-
if (username && password) {
26-
return { username, password };
27-
}
28-
}
29-
30-
this.log.info('No credentials provided by the client');
31-
return undefined;
12+
constructor(
13+
@Logger(__filename) private log: LoggerInterface,
14+
@OrmRepository() private userRepository: UserRepository,
15+
) {
16+
}
17+
18+
public parseBasicAuthFromRequest(req: express.Request): { username: string, password: string } {
19+
const authorization = req.header('authorization');
20+
21+
if (authorization && authorization.split(' ')[0] === 'Basic') {
22+
this.log.info('Credentials provided by the client');
23+
const decodedBase64 = Buffer.from(authorization.split(' ')[1], 'base64').toString('ascii');
24+
const username = decodedBase64.split(':')[0];
25+
const password = decodedBase64.split(':')[1];
26+
if (username && password) {
27+
return { username, password };
28+
}
3229
}
3330

34-
public async validateUser(username: string, password: string): Promise<User> {
35-
const user = await this.userRepository.findOne({
36-
where: {
37-
username,
38-
},
39-
});
31+
this.log.info('No credentials provided by the client');
32+
return undefined;
33+
}
4034

41-
if (await User.comparePassword(user, password)) {
42-
return user;
43-
}
35+
public async validateUser(username: string, password: string): Promise<User> {
36+
const user = await this.userRepository.findOne({
37+
where: {
38+
username,
39+
},
40+
});
4441

45-
return undefined;
42+
if (await User.comparePassword(user, password)) {
43+
return user;
4644
}
4745

46+
return undefined;
47+
}
48+
4849
}

src/auth/authorizationChecker.ts

+21-21
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,29 @@ import { Logger } from '../lib/logger';
66
import { AuthService } from './AuthService';
77

88
export function authorizationChecker(connection: Connection): (action: Action, roles: any[]) => Promise<boolean> | boolean {
9-
const log = new Logger(__filename);
10-
const authService = Container.get<AuthService>(AuthService);
9+
const log = new Logger(__filename);
10+
const authService = Container.get<AuthService>(AuthService);
1111

12-
return async function innerAuthorizationChecker(action: Action, roles: string[]): Promise<boolean> {
13-
// here you can use request/response objects from action
14-
// also if decorator defines roles it needs to access the action
15-
// you can use them to provide granular access check
16-
// checker must return either boolean (true or false)
17-
// either promise that resolves a boolean value
18-
const credentials = authService.parseBasicAuthFromRequest(action.request);
12+
return async function innerAuthorizationChecker(action: Action, roles: string[]): Promise<boolean> {
13+
// here you can use request/response objects from action
14+
// also if decorator defines roles it needs to access the action
15+
// you can use them to provide granular access check
16+
// checker must return either boolean (true or false)
17+
// either promise that resolves a boolean value
18+
const credentials = authService.parseBasicAuthFromRequest(action.request);
1919

20-
if (credentials === undefined) {
21-
log.warn('No credentials given');
22-
return false;
23-
}
20+
if (credentials === undefined) {
21+
log.warn('No credentials given');
22+
return false;
23+
}
2424

25-
action.request.user = await authService.validateUser(credentials.username, credentials.password);
26-
if (action.request.user === undefined) {
27-
log.warn('Invalid credentials given');
28-
return false;
29-
}
25+
action.request.user = await authService.validateUser(credentials.username, credentials.password);
26+
if (action.request.user === undefined) {
27+
log.warn('Invalid credentials given');
28+
return false;
29+
}
3030

31-
log.info('Successfully checked credentials');
32-
return true;
33-
};
31+
log.info('Successfully checked credentials');
32+
return true;
33+
};
3434
}

src/auth/currentUserChecker.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Connection } from 'typeorm';
44
import { User } from '../api/models/User';
55

66
export function currentUserChecker(connection: Connection): (action: Action) => Promise<User | undefined> {
7-
return async function innerCurrentUserChecker(action: Action): Promise<User | undefined> {
8-
return action.request.user;
9-
};
7+
return async function innerCurrentUserChecker(action: Action): Promise<User | undefined> {
8+
return action.request.user;
9+
};
1010
}

src/decorators/DLoader.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { Container, ObjectType } from 'typedi';
33
import { createDataLoader, CreateDataLoaderOptions } from '../lib/graphql';
44

55
export function DLoader<T>(obj: ObjectType<T>, options: CreateDataLoaderOptions = {}): ParameterDecorator {
6-
return (object, propertyKey, index) => {
7-
const dataLoader = createDataLoader(obj, options);
8-
const propertyName = propertyKey ? propertyKey.toString() : '';
9-
Container.registerHandler({ object, propertyName, index, value: () => dataLoader });
10-
};
6+
return (object, propertyKey, index) => {
7+
const dataLoader = createDataLoader(obj, options);
8+
const propertyName = propertyKey ? propertyKey.toString() : '';
9+
Container.registerHandler({ object, propertyName, index, value: () => dataLoader });
10+
};
1111
}
1212

1313
export * from '../lib/graphql';

src/decorators/EventDispatcher.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { EventDispatcher as EventDispatcherClass } from 'event-dispatch';
22
import { Container } from 'typedi';
33

44
export function EventDispatcher(): any {
5-
return (object: any, propertyName: string, index?: number): any => {
6-
const eventDispatcher = new EventDispatcherClass();
7-
Container.registerHandler({ object, propertyName, index, value: () => eventDispatcher });
8-
};
5+
return (object: any, propertyName: string, index?: number): any => {
6+
const eventDispatcher = new EventDispatcherClass();
7+
Container.registerHandler({ object, propertyName, index, value: () => eventDispatcher });
8+
};
99
}
1010

1111
export { EventDispatcher as EventDispatcherInterface } from 'event-dispatch';

src/decorators/Logger.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { Container } from 'typedi';
33
import { Logger as WinstonLogger } from '../lib/logger';
44

55
export function Logger(scope: string): ParameterDecorator {
6-
return (object, propertyKey, index): any => {
7-
const logger = new WinstonLogger(scope);
8-
const propertyName = propertyKey ? propertyKey.toString() : '';
9-
Container.registerHandler({ object, propertyName, index, value: () => logger });
10-
};
6+
return (object, propertyKey, index): any => {
7+
const logger = new WinstonLogger(scope);
8+
const propertyName = propertyKey ? propertyKey.toString() : '';
9+
Container.registerHandler({ object, propertyName, index, value: () => logger });
10+
};
1111
}
1212

1313
export { LoggerInterface } from '../lib/logger';

0 commit comments

Comments
 (0)