Skip to content

Commit

Permalink
Refactor/backend core (#23)
Browse files Browse the repository at this point in the history
* refactor: 백엔드 코어로 대체

* refactor: 에러도 대체 완료

* refactor: jwt 대체

* refactor: 대규모 숙청

* chore: 로깅 강화
  • Loading branch information
potados99 authored Feb 19, 2022
1 parent a684e7a commit ae3d3e1
Show file tree
Hide file tree
Showing 37 changed files with 426 additions and 1,259 deletions.
15 changes: 12 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import startServer from './lib/infrastructure/webserver/server';
import {logger, setupLogger, startTypeORM} from '@inu-cafeteria/backend-core';

async function start() {
console.log('로거를 설정합니다.');

await setupLogger({
consoleTransportOptions: {
prefix: undefined,
Expand All @@ -41,11 +43,18 @@ async function start() {
: undefined,
});

logger.info('DB 시작하는중!!');
await startTypeORM();

logger.info('서버 시작하는중!!');
await startServer();
}

start().then(() => {
logger.info(`우효 wwwwwwwww ${config.server.port}포트♥, 서버 겟또다제~☆`);
});
start()
.then(() => {
logger.info(`우효 wwwwwwwww ${config.server.port}포트♥, 서버 겟또다제~☆`);
})
.catch((e) => {
console.error(e);
console.log(';; 서버 시작에 실패했습니다');
});
3 changes: 1 addition & 2 deletions lib/application/checkin/RealTimeContextService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
*/

import express from 'express';
import {logger} from '@inu-cafeteria/backend-core';
import ConnectionPool from '../../infrastructure/webserver/libs/ConnectionPool';
import GetCheckInContext from './GetCheckInContext';
import {logger, ConnectionPool} from '@inu-cafeteria/backend-core';

class RealTimeContextService {
private pool = new ConnectionPool();
Expand Down
2 changes: 1 addition & 1 deletion lib/application/checkin/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import BadRequest from '../../common/errors/http/BadRequest';
import {BadRequest} from '@inu-cafeteria/backend-core';

export const NoBookingParams = BadRequest.of(
'no_booking_params',
Expand Down
3 changes: 1 addition & 2 deletions lib/application/checkin/handler/CheckInHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import fetch from 'isomorphic-fetch';
import config from '../../../../config';
import {MoreThan} from 'typeorm';
import {subMinutes} from 'date-fns';
import {stringifyError} from '../../../common/utils/error';
import CheckInValidator from '../validation/CheckInValidator';
import {Booking, CheckIn, logger, VisitRecord} from '@inu-cafeteria/backend-core';
import {logger, Booking, CheckIn, VisitRecord, stringifyError} from '@inu-cafeteria/backend-core';

export default class CheckInHandler {
constructor(private readonly booking: Booking, private readonly cafeteriaId: number) {}
Expand Down
11 changes: 6 additions & 5 deletions lib/application/user/Login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import UseCase from '../../core/base/UseCase';
import config from '../../../config';
import {createJwt} from '../../common/utils/jwt';
import assert from 'assert';
import config from '../../../config';
import UseCase from '../../core/base/UseCase';
import {InvalidAuth} from './errors';
import {logger} from '@inu-cafeteria/backend-core';
import {logger, createJwt} from '@inu-cafeteria/backend-core';

export type LoginParams = {
username: string;
Expand All @@ -43,7 +42,9 @@ class Login extends UseCase<LoginParams, LoginResult> {

logger.verbose(`좋아, ${username}에게 로그인을 허가하여 주겠다....`);

const jwt = createJwt({username});
const jwt = createJwt({username}, config.auth.key, {
expiresIn: config.auth.expiresIn,
});

return {jwt};
}
Expand Down
2 changes: 1 addition & 1 deletion lib/application/user/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import Unauthorized from '../../common/errors/http/Unauthorized';
import {Unauthorized} from '@inu-cafeteria/backend-core';

export const InvalidAuth = Unauthorized.of(
'invalid_auth',
Expand Down
2 changes: 1 addition & 1 deletion lib/application/visit/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import BadRequest from '../../common/errors/http/BadRequest';
import {BadRequest} from '@inu-cafeteria/backend-core';

export const NotIdentifiable = BadRequest.of(
'not_identifiable',
Expand Down
24 changes: 0 additions & 24 deletions lib/common/errors/http/BadRequest.ts

This file was deleted.

24 changes: 0 additions & 24 deletions lib/common/errors/http/Forbidden.ts

This file was deleted.

24 changes: 0 additions & 24 deletions lib/common/errors/http/InternalServerError.ts

This file was deleted.

24 changes: 0 additions & 24 deletions lib/common/errors/http/NotFound.ts

This file was deleted.

24 changes: 0 additions & 24 deletions lib/common/errors/http/Unauthorized.ts

This file was deleted.

61 changes: 0 additions & 61 deletions lib/common/errors/http/base/HttpError.ts

This file was deleted.

4 changes: 0 additions & 4 deletions lib/common/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
import moment from 'moment';
import assert from 'assert';

export function checkDateStringFormat(dateString: string) {
return moment(dateString, 'YYYYMMDD', true).isValid();
}

export function parseDateYYYYMMDD(dateString: string) {
const m = moment(dateString, 'YYYYMMDD', true);

Expand Down
24 changes: 0 additions & 24 deletions lib/common/utils/error.ts

This file was deleted.

38 changes: 0 additions & 38 deletions lib/common/utils/jwt.ts

This file was deleted.

22 changes: 0 additions & 22 deletions lib/common/utils/number.ts

This file was deleted.

Loading

0 comments on commit ae3d3e1

Please sign in to comment.