How to use the tsoa.Route function in tsoa

To help you get started, we’ve selected a few tsoa 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 vietnam-devs / coolstore-microservices / src / services / rating / src / controllers / ratingController.ts View on Github external
declare var require: any

var uuid = require('uuid')
import { Route, Get, Post, Put, Body, Response } from 'tsoa'
import { default as Rating, RatingCreateRequest, RatingUpdateRequest } from '../models/rating'

@Route(`api/ratings`)
export class RatingController {
  /**
   * Get the all ratings
   */
  @Get()
  public async GetAll(): Promise {
    // @ts-ignore
    var ratings = await Rating.find({}).exec()

    var result = []
    ratings.reduce(function (res, value) {
      if (!res[value.productId]) {
        res[value.productId] = {
          productId: value.productId,
          cost: 0,
          userId: value.userId,
github input-output-hk / smart-contract-backend / src / execution_engine / controllers / smart-contract.ts View on Github external
import { Post, Route, Body, SuccessResponse, Controller } from 'tsoa'
import DockerEngine from '../docker'
import NodeEngine from '../node_js'
import { LoadContractArgs, ExecutionEngine, UnloadContractArgs, SmartContractResponse, ExecutionEngines } from '../ExecutionEngine'
import { ContractNotLoaded } from '../errors'
import { getConfig, ExecutionEngineConfig } from '../config'

function getEngine (config: ExecutionEngineConfig): ExecutionEngine {
  return config.executionEngine === ExecutionEngines.docker
    ? DockerEngine
    : NodeEngine
}

@Route('')
export class ContainerController extends Controller {
  @SuccessResponse('204', 'No Content')
  @Post('loadSmartContract')
  public async loadSmartContract (@Body() { contractAddress, executable }: LoadContractArgs): Promise {
    const engine = getEngine(getConfig())
    contractAddress = contractAddress.toLowerCase()
    this.setStatus(204)

    await engine.load({ contractAddress, executable })
  }

  @SuccessResponse('204', 'No Content')
  @Post('unloadSmartContract')
  public async unloadSmartContract (@Body() { contractAddress }: UnloadContractArgs): Promise {
    const engine = getEngine(getConfig())
    contractAddress = contractAddress.toLowerCase()
github qas / boilerplate-nodejs-swagger / src / controllers / spec.ts View on Github external
import {Get, Route} from 'tsoa';
import swaggerJson from '../swagger.json';

@Route('spec')
export class SpecController {
  /** Get the current spec */
  @Get()
  async currentSpec() {
    return swaggerJson;
  }
}
github lukeautry / ts-app / api / controllers / widgets-controller.ts View on Github external
export interface IWidget {
  id: number;
  label: string;
  color: string;
}

const widgets: IWidget[] = [
  {
    color: "blue",
    id: 1,
    label: "first widget",
  },
];

@Route("widgets")
export class WidgetsController {
  @Get()
  @Tags("Widgets")
  public async GetWidgets(): Promise {
    return widgets;
  }

  @Get("{widgetId}")
  @Tags("Widgets")
  public async GetWidget(widgetId: number): Promise {
    const widget = widgets.find((w) => w.id === widgetId);
    if (!widget) {
      throw new ServerError(`no widget found with id ${widgetId}`);
    }

    return widget;

tsoa

Build swagger-compliant REST APIs using TypeScript and Node

MIT
Latest version published 1 month ago

Package Health Score

95 / 100
Full package analysis