Skip to content

Commit

Permalink
api core module refactor pt. 2
Browse files Browse the repository at this point in the history
  • Loading branch information
mairisb committed Jul 14, 2024
1 parent bccfa81 commit 80f11f9
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import { GameServiceMock } from '../../features/game/game.service.mock';
import { IGameService } from '../../features/game/game.service.type';
import { UserService } from '../../features/user/user.service';
import { IUserService } from '../../features/user/user.service.type';
import { Middleware, Services } from './identifiers';
import { Middleware, Services } from './di.identifiers';

const container = new Container();
const diContainer = new Container();

container.bind<BaseMiddleware>(Middleware.Auth).to(AuthMiddleware);
diContainer.bind<BaseMiddleware>(Middleware.Auth).to(AuthMiddleware);

container.bind<IAuthService>(Services.Auth).to(AuthService);
container.bind<ICardService>(Services.Card).to(CardService);
container.bind<IGameService>(Services.Game).to(GameServiceMock);
container.bind<IUserService>(Services.User).to(UserService);
diContainer.bind<IAuthService>(Services.Auth).to(AuthService);
diContainer.bind<ICardService>(Services.Card).to(CardService);
diContainer.bind<IGameService>(Services.Game).to(GameServiceMock);
diContainer.bind<IUserService>(Services.User).to(UserService);

export { container };
export { diContainer as container };
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { ConfigFunction } from 'inversify-express-utils';

export const configFunction: ConfigFunction = () => {};
export const serverConfigFn: ConfigFunction = () => {};
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { ErrorResponse } from '@tspark/common';
import { NextFunction, Request, Response } from 'express';
import { ConfigFunction } from 'inversify-express-utils';

export const errorConfigFunction: ConfigFunction = (app) => {
export const serverErorConfigFn: ConfigFunction = (app) => {
app.use(
(
err: Error,
req: Request,
res: Response<ErrorResponse>,
next: NextFunction,
) => {
console.error('Something went wrong!', err.stack);
return res.status(500).json({ error: 'Something went wrong!' });
console.error('Oops! Something went wrong.', err);
return res.status(500).json({ error: 'Oops! Something went wrong.' });
},
);
};
2 changes: 1 addition & 1 deletion packages/api/src/features/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import jwt from 'jsonwebtoken';
import { mapper } from '../../core/auto-mapper/mapper';
import { config } from '../../core/config/config';
import { BaseController } from '../../core/controllers/base.controller';
import { Services } from '../../core/inversify/identifiers';
import { Services } from '../../core/di/di.identifiers';
import { User } from '../user/user.entity';
import { IAuthService } from './auth.service.type';

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/features/auth/auth.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Request } from 'express';
import { inject, injectable } from 'inversify';
import { mapper } from '../../core/auto-mapper/mapper';
import { BaseController } from '../../core/controllers/base.controller';
import { Services } from '../../core/inversify/identifiers';
import { Services } from '../../core/di/di.identifiers';
import { User } from '../user/user.entity';
import { IAuthProvider } from './auth.provider.type';
import { IAuthService } from './auth.service.type';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/features/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import bcrypt from 'bcrypt';
import { inject, injectable } from 'inversify';
import jwt, { JwtPayload } from 'jsonwebtoken';
import { config } from '../../core/config/config';
import { Services } from '../../core/inversify/identifiers';
import { Services } from '../../core/di/di.identifiers';
import { User } from '../user/user.entity';
import { userRepository } from '../user/user.repository';
import { IUserService } from '../user/user.service.type';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/features/card/card.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
requestParam,
response,
} from 'inversify-express-utils';
import { Middleware, Services } from '../../core/inversify/identifiers';
import { Middleware, Services } from '../../core/di/di.identifiers';
import { ICardService } from './card.service.type';

@controller('/card', Middleware.Auth)
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/features/game/game.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
controller,
httpGet,
} from 'inversify-express-utils';
import { Services } from '../../core/inversify/identifiers';
import { Services } from '../../core/di/di.identifiers';
import { IGameService } from './game.service.type';

@controller('/game')
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/features/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
controller,
httpGet,
} from 'inversify-express-utils';
import { Services } from '../../core/inversify/identifiers';
import { Services } from '../../core/di/di.identifiers';
import { IUserService } from './user.service.type';

@controller('/user')
Expand Down
10 changes: 5 additions & 5 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { InversifyExpressServer } from 'inversify-express-utils';
import { createMaps } from './core/auto-mapper/mapper';
import { config } from './core/config/config';
import { appDataSource } from './core/db/app-data-source';
import { configFunction } from './core/inversify/config-function';
import { container } from './core/inversify/container';
import { errorConfigFunction } from './core/inversify/error-config-function';
import { container } from './core/di/di.container';
import { serverConfigFn } from './core/server/server-config-fn';
import { serverErorConfigFn } from './core/server/server-error-config-fn';
import { AuthProvider } from './features/auth/auth.provider';

createMaps();
Expand Down Expand Up @@ -47,8 +47,8 @@ const server = new InversifyExpressServer(
AuthProvider,
);

server.setConfig(configFunction);
server.setErrorConfig(errorConfigFunction);
server.setConfig(serverConfigFn);
server.setErrorConfig(serverErorConfigFn);

appDataSource
.initialize()
Expand Down

0 comments on commit 80f11f9

Please sign in to comment.