How to use the inversify-express-utils.Controller function in inversify-express-utils

To help you get started, we’ve selected a few inversify-express-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stelltec / public-tech-demos / nodejs-madrid-meetup / demo3 / src / ui / rest_api / controllers / secure_controller.ts View on Github external
import { injectable } from "inversify";
import { Controller, Get } from "inversify-express-utils";
import { authMiddleware } from "../middleware/auth_middleware";

// This is an example of a controller protected by the auth middleware

@injectable()
@Controller("/api/secure", authMiddleware({ role: "admin" }))
export class SecureController {

    @Get("/")
    public async get() {
        return Promise.resolve(["This", "data", "is", "secure!"]);
    }

}
github DefinitelyTyped / DefinitelyTyped / inversify-express-utils / inversify-express-utils-tests.ts View on Github external
next();
            });
        })
        .setErrorConfig((app: express.Application) => {
            app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {
                console.error(err.stack);
                res.status(500).send("Something broke!");
            });
        })
        .build()
        .listen(3000, "localhost");
}

module decorators {

    @Controller("/")
    class TestController {

        @Get("/")
        public testGet() { return "GET"; }

        @All("/")
        public testAll() { return "ALL"; }

        @Delete("/")
        public testDelete() { return "DELETE"; }

        @Head("/")
        public testHead() { return "HEAD"; }

        @Put("/")
        public testPut() { return "PUT"; }
github DefinitelyTyped / DefinitelyTyped / inversify-express-utils / inversify-express-utils-tests.ts View on Github external
public testPatch() { return "PATCH"; }

        @Post("/")
        public testPost() { return "POST"; }

        @Method("foo", "/")
        public testMethod() { return "METHOD:FOO"; }
    }

    kernel.bind(TYPE.Controller).to(TestController);

    function m1(req: express.Request, res: express.Response, next: express.NextFunction) { next(); }
    function m2(req: express.Request, res: express.Response, next: express.NextFunction) { next(); }
    function m3(req: express.Request, res: express.Response, next: express.NextFunction) { next(); }

    @Controller("/", m1, m2, m3)
    class TestMiddlewareController {

        @Get("/", m1, m2, m3)
        public testGet() { return "GET"; }

        @All("/", m1, m2, m3)
        public testAll() { return "ALL"; }

        @Delete("/", m1, m2, m3)
        public testDelete() { return "DELETE"; }

        @Head("/", m1, m2, m3)
        public testHead() { return "HEAD"; }

        @Put("/", m1, m2, m3)
        public testPut() { return "PUT"; }
github tierratelematics / prettygoat / scripts / controllers / ProjectionsManager.ts View on Github external
import * as express from 'express';
import {injectable, inject} from 'inversify';
import Dictionary from "../Dictionary";
import IProjectionRunner from "../projections/IProjectionRunner";
import IProjectionsManager from "./IProjectionsManager";
import { Controller, Get } from 'inversify-express-utils';

@Controller('/projections')
@injectable()
class ProjectionsManager implements Controller,IProjectionsManager{

    constructor(@inject("IProjectionRunnerHolder") private projectionsRunnerCollection:Dictionary>){

    }

    @Get('/stop/:name')
    stop(req: express.Request, res: express.Response): void {
        console.log(this.projectionsRunnerCollection);
        let projection:IProjectionRunner = this.getProjectionRunner(null);

        if(projection)
            projection.stop();

        this.writeResponse(res,projection,req.params.name,"Stop");
github stelltec / public-tech-demos / nodejs-madrid-meetup / demo3 / src / ui / rest_api / controllers / actor_controller.ts View on Github external
import { injectable } from "inversify";
import { Controller, Get, RequestParam } from "inversify-express-utils";
import { actorRepository } from "../../../domain/constants/decorators";
import { ActorRepository } from "../../../domain/interfaces/repositories";

@injectable()
@Controller("/api/actors")
export class ActorController {

    @actorRepository public _actorRepository: ActorRepository;

    @Get("/")
    public async get() {
        return await this._actorRepository.findAll();
    }

    @Get("/:id")
    public async getById(
        @RequestParam("id") id: string,
    ) {
        return await this._actorRepository.findById(id);
    }
github stelltec / public-tech-demos / nodejs-madrid-meetup / demo3 / src / ui / rest_api / controllers / director_controller.ts View on Github external
import { injectable } from "inversify";
import { Controller, Get, RequestParam } from "inversify-express-utils";
import { directorRepository } from "../../../domain/constants/decorators";
import { DirectorRepository } from "../../../domain/interfaces/repositories";

@injectable()
@Controller("/api/directors")
export class DirectorController {

    @directorRepository public _directorRepository: DirectorRepository;

    @Get("/")
    public async get() {
        return await this._directorRepository.findAll();
    }

    @Get("/:id")
    public async getById(
        @RequestParam("id") id: string,
    ) {
        return await this._directorRepository.findById(id);
    }
github stelltec / public-tech-demos / nodejs-madrid-meetup / demo3 / src / ui / rest_api / controllers / search_controller.ts View on Github external
import { injectable } from "inversify";
import { Controller, Get, RequestParam } from "inversify-express-utils";
import { SearchService } from "../../../domain/interfaces/services";
import { searchService } from "../../../domain/constants/decorators";

@injectable()
@Controller("/api/search")
export class SearchController {

    @searchService private _searchService: SearchService;

    @Get("/:query")
    public async get(
        @RequestParam("query") query: string,
    ) {
        return this._searchService.search(query);
    }

}
github stelltec / public-tech-demos / nodejs-madrid-meetup / demo3 / src / ui / rest_api / controllers / movie_controller.ts View on Github external
import { injectable } from "inversify";
import { Controller, Get, RequestParam } from "inversify-express-utils";
import { movieRepository } from "../../../domain/constants/decorators";
import { MovieRepository } from "../../../domain/interfaces/repositories";

@injectable()
@Controller("/api/movies")
export class MovieController {

    @movieRepository public _movieRepository: MovieRepository;

    @Get("/")
    public async get() {
        return await this._movieRepository.findAll();
    }

    @Get("/:id")
    public async getById(
        @RequestParam("id") id: string,
    ) {
        return await this._movieRepository.findById(id);
    }
github w3tecch / express-typescript-boilerplate / src / api / controllers / ApiController.ts View on Github external
import * as express from 'express';
import * as monitor from 'express-status-monitor';
const swaggerUi = require('swagger-ui-express');
import { Controller, Get, Response, Request } from 'inversify-express-utils';
import { injectable } from 'inversify';
import { Environment } from '../../core/Environment';

/**
 * HomeController is a public controller to give some
 * information about this api
 */
@injectable()
@Controller('')
export class ApiController {

    @Get('/info')
    public getInfo( @Response() res: express.Response): any {
        const pkg = require('../../../package.json');
        return res.json({
            name: pkg.name,
            version: pkg.version,
            description: pkg.description
        });
    }

    @Get('/status')
    public getStatus( @Request() req: express.Request, @Response() res: express.Response): any {
        return monitor().pageRoute(req, res);
    }