How to use the routing-controllers.Controller function in routing-controllers

To help you get started, we’ve selected a few routing-controllers 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 art-software / art-core / packages / art-ssr-render / src / controllers / render / RenderController.ts View on Github external
import { Controller, Post, Req, Res } from 'routing-controllers';
import { Request, Response } from 'express';
import { ServerConfig } from '../../config/ServerConfig';
import BatchRenderService from '../../services/BatchRenderService';
import { processBatch } from './processBatch';

@Controller()
export class RenderController {

  @Post(ServerConfig.get().endpoint)
  public render(@Req() req: Request, @Res() res: Response) {
    console.log('req.body: ', req.body);

    // TODO
    // if (isClosing()) {
    //   Logger.info('Starting request when closing!');
    // }

    const serverConfig = ServerConfig.get();
    const batchRenderService = new BatchRenderService(req, res, serverConfig);

    return processBatch(req.body, serverConfig.plugins, batchRenderService, serverConfig.processJobsConcurrent)
      .then(() => {
github RiseVision / rise-node / packages / core-transactions / src / api / TransactionTransport.ts View on Github external
} from '@risevision/core-interfaces';
import { ModelSymbols } from '@risevision/core-models';
import { AttachPeerHeaders, p2pSymbols, ProtoBufHelper, ValidatePeerHeaders } from '@risevision/core-p2p';
import { ConstantsType, SignedAndChainedBlockType } from '@risevision/core-types';
import { HTTPError, IoCSymbol, SchemaValid, ValidateSchema } from '@risevision/core-utils';
import { Request } from 'express';
import { inject, injectable, named } from 'inversify';
import { WordPressHookSystem } from 'mangiafuoco';
import { ContentType, Controller, Get, Post, QueryParam, Req, UseBefore } from 'routing-controllers';

import * as z_schema from 'z-schema';
import { TXSymbols } from '../txSymbols';
//
// const transportSchema = require('../../schema/transport.json');

@Controller('/v2/peer')
@injectable()
@IoCSymbol(TXSymbols.api.transport)
@UseBefore(ValidatePeerHeaders)
@UseBefore(AttachPeerHeaders)
@ContentType('application/octet-stream')
export class TransactionTransport {
  @inject(Symbols.logic.transaction)
  private transactionLogic: ITransactionLogic;

  // TODO: lerna remove me and use tx type constants. (But check if used in transport. )
  private constants: ConstantsType;

  // @inject(Symbols.helpers.bus)
  // private bus: Bus;
  @inject(p2pSymbols.helpers.protoBuf)
  private protoBuf: ProtoBufHelper;
github TEsTsLA / apijson / src / controller / Usercontroller.ts View on Github external
import { Controller, Param, Body, Get, Post, Put, Delete } from "routing-controllers";
import { getRepository } from "typeorm";
import { User } from "../entity/User";
import { Message } from "../entity/Message";
import { UserService } from "../service/user.service";
import { getRandom } from "../util";
const MockJs = require('mockjs');
const story = require('./txt');


@Controller()
export class UserController {
    constructor(
        private userSrv: UserService
    ) { }

    @Get("/users")
    async getAll() {
        // init
        const user = new User();
        const msg = this.userSrv.createMsg();
        user.firstName = MockJs.Random.first();
        user.lastName = MockJs.Random.last();
        user.cName = MockJs.Random.cname() + MockJs.Random.cfirst();
        user.age = getRandom(60);
        user.sex = getRandom(100) > 50 ? 0 : 1
        // save
github geli-lms / geli / api / src / controllers / UploadsController.ts View on Github external
ForbiddenError, NotFoundError
} from 'routing-controllers';
import {Response} from 'express';
import {promisify} from 'util';
import passportJwtMiddlewareMedia from '../security/passportJwtMiddlewareMedia';
import config from '../config/main';
import {errorCodes} from '../config/errorCodes';
import * as fs from 'fs';
import * as path from 'path';

const pathIsInside = require('path-is-inside');

// Note that this isn't meant for uploading files, but for downloads from the '/api/uploads' route.
// That route was previously handled by an unsecured (public) static route in server.ts.
// TODO: Perhaps this functionality could be merged with another controller?
@Controller('/uploads')
@UseBefore(passportJwtMiddlewareMedia)
export class UploadsController {

  /**
   * @api {get} /api/uploads/:filename Request a file in the config.uploadFolder.
   * @apiName GetUploadsFile
   * @apiGroup Uploads
   *
   * @apiParam {String} filename The file path of the requested file in the config.uploadFolder.
   * @apiParam {Response} response Response.
   *
   * @apiSuccess {Response} response File download.
   *
   * @apiError NotFoundError File could not be found.
   * @apiError ForbiddenError Invalid filename (e.g. '..').
   */
github epiphone / routing-controllers-openapi / __tests__ / fixtures / controllers.ts View on Github external
export class UserPostsController {
  @Get('/:postId')
  getUserPost(
    @Param('userId') _userId: number,
    @Param('postId') _postId: string
  ) {
    return
  }

  @Patch('/:postId')
  patchUserPost(@BodyParam('token') _token: string) {
    return
  }
}

@Controller()
@OpenAPI({
  description: 'Common description for all RootController operations',
  security: [{ basicAuth: [] }]
})
export class RootController {
  @Get()
  getDefaultPath() {
    return
  }

  @OpenAPI(spec => ({ ...spec, security: [] }))
  @Get('/stringPath')
  getStringPath() {
    return
  }
}
github art-software / art-core / packages / art-demo-spa-react / mock / mine / IBindCardController.ts View on Github external
import { Controller, Post } from 'routing-controllers';

@Controller('/mine')
export default class IBindCardController {
  @Post('/pb/card/bind')
  public pbCardBind() {
    return {
      code: 0,
      msg: '绑定成功|身份证号不是15或者18位|该用户已经绑定过此卡',
      data: { card_id: 11, customer_id: 1, card_num: '6226661600959567', card_type: 2, is_default: 0, card_pic: '', bank_id: 18, bank_name: '中国银行', bank_short_name: '中国银行', bank_code: 'BOC', bank_status: 1, bank_type: 1, bank_pic: 'http://credit-card-1251122539.cossh.myqcloud.com/credit_card/bank/2018-09-11/bank_MHJH.png', bank_propaganda_pic: '', bank_info: '中国银行', bank_hot_sort: 3, bank_url: 'https://www.baidu.com/' }
    };
  }
}
github TEsTsLA / apijson / src / controller / apijson.controller.ts View on Github external
import {Controller, Param, Body, Get, Post, Put, Delete, Render} from "routing-controllers";
import { getRepository } from "typeorm";
import { User } from "../entity/User";
import { ApiJson } from "../apijson/apijson";
import { async } from "rxjs/internal/scheduler/async";

@Controller()
export class ApiJsonController {
    @Post('/apijson')
    async apijson(@Body() body){
        return await ApiJson(body);
    }
    @Get('/apijson')
    @Render('index.html')
    async apijsonHtml(){
        return {}
    }
}
github art-software / art-core / examples / art-demo-ssr / web / mock / main / IndexController.ts View on Github external
import { Controller, Get } from 'routing-controllers';

@Controller('/main')
export default class IndexController {

  @Get('/testme')
  public mockApi() {
    return {
      code: '200',
      message: 'suceess',
      data: {
        mockData: 'biz mock data!'
      }
    };
  }
}
github rafaell-lycan / sabesp-mananciais-api / src / api / v1.ts View on Github external
import { Controller, Get, Param, InternalServerError } from 'routing-controllers';
import { validateDate, formatDate } from '../common/utils/dateUtils';
import { SabespResponse } from '../services/Sabesp';
import Sabesp from '../services/Sabesp';
import Mapper from '../services/Mapper';
import logger from '../common/utils/logger';

@Controller()
export default class ApiV1Controller {
  public async getData(date: string): Promise {
    const data: SabespResponse = await Sabesp.info(date);
    return Mapper.v1(data);
  }

  @Get('/')
  public get() {
    const date = formatDate(new Date());
    return this.getData(date);
  }

  @Get('/:date')
  public getByDate(@Param('date') date: string) {
    try {
      validateDate(date);
github RiseVision / rise-node / packages / core-blocks / src / apis / transportAPI.ts View on Github external
import { ConstantsType, SignedAndChainedBlockType } from '@risevision/core-types';
import { HTTPError, IoCSymbol, SchemaValid, ValidateSchema } from '@risevision/core-utils';
import { Request } from 'express';
import { inject, injectable, named } from 'inversify';
import { WordPressHookSystem } from 'mangiafuoco';
import { ContentType, Controller, Get, Post, QueryParam, Req, UseBefore } from 'routing-controllers';
import { Op } from 'sequelize';
import * as z_schema from 'z-schema';
import { BlocksSymbols } from '../blocksSymbols';
import { OnReceiveBlock } from '../hooks';
import { BlocksModuleUtils } from '../modules';

const transportSchema = require('../../schema/transport.json');


@Controller('/v2/peer')
@injectable()
@IoCSymbol(BlocksSymbols.api.transport)
@UseBefore(ValidatePeerHeaders)
@UseBefore(AttachPeerHeaders)
@ContentType('application/octet-stream')
export class BlocksTransportV2API {
  @inject(Symbols.generic.zschema)
  public schema: z_schema;
  @inject(Symbols.logic.block)
  private blockLogic: IBlockLogic;
  @inject(Symbols.logic.transaction)
  private transactionLogic: ITransactionLogic;
  @inject(Symbols.modules.blocks)
  private blocksModule: IBlocksModule;
  @inject(Symbols.generic.hookSystem)
  private hookSystem: WordPressHookSystem;