Skip to content

Commit

Permalink
user controller interface
Browse files Browse the repository at this point in the history
  • Loading branch information
pestsov-v committed Feb 20, 2022
1 parent 059994a commit 133cb1b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
24 changes: 15 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Container } from "inversify";
import { Container, ContainerModule, interfaces } from "inversify";

import { App } from "./app";
import { ExeptionFilter } from "./errors/exeption.filter";
Expand All @@ -8,13 +8,19 @@ import { LoggerService } from "./logger/logger.service";
import { UserController } from "./users/users.controller";
import { TYPES } from "./types";

const appContainer = new Container();
appContainer.bind<ILogger>(TYPES.ILoggerService).to(LoggerService);
appContainer.bind<IExeptionFilter>(TYPES.ExeptionFilter).to(ExeptionFilter);
appContainer.bind<UserController>(TYPES.UserController).to(UserController);
appContainer.bind<App>(TYPES.Application).to(App);
export const appBindings = new ContainerModule((bind: interfaces.Bind) => {
bind<ILogger>(TYPES.ILoggerService).to(LoggerService);
bind<IExeptionFilter>(TYPES.ExeptionFilter).to(ExeptionFilter);
bind<UserController>(TYPES.UserController).to(UserController);
bind<App>(TYPES.Application).to(App);
})

const app = appContainer.get<App>(TYPES.Application);
app.init();
function bootstrap () {
const appContainer = new Container();
appContainer.load(appBindings);
const app = appContainer.get<App>(TYPES.Application);
app.init();
return { app, appContainer };
}

export {app, appContainer};
export const {app, appContainer} = bootstrap();
6 changes: 6 additions & 0 deletions src/users/users.controller.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { NextFunction, Request, Response } from "express";

export interface IUserController {
login: (req: Request, res: Response, next: NextFunction) => void;
register: (req: Request, res: Response, next: NextFunction) => void;
}
3 changes: 2 additions & 1 deletion src/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { BaseController } from "../common/base.controller";
import { HTTPError } from "../errors/http-error.class";
import { ILogger } from "../logger/logger.interface";
import { TYPES } from "../types";
import { IUserController } from './users.controller.interface';


@injectable()
export class UserController extends BaseController{
export class UserController extends BaseController implements IUserController{
constructor(@inject(TYPES.ILoggerService) private loggerService: ILogger) {
super(loggerService);
this.bindRoutes([
Expand Down

0 comments on commit 133cb1b

Please sign in to comment.