How to use the tsoa.Get 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 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 vietnam-devs / coolstore-microservices / src / services / catalog-typescript / src / controllers / productsController.ts View on Github external
import { Route, Get, Post, Delete, Body } from 'tsoa'
import { Product, ProductCreateRequest } from '../models/product'

const ProductMongoose = mongoose.model('Product', ProductSchema)

@Route('api/products')
export class ProductsController {
  /** Get the current user */
  @Get('')
  public async GetAll(): Promise<Product[]> {
    var products = await ProductMongoose.find({}).exec()
    return products
  }

  /** Get user by ID */
  @Get('{productId}')
  public async Get(productId: number): Promise<Product> {
    return {
      id: 'd831e238-94ae-44cb-8ed9-16d6addf5876',
      name: 'Product Name',
      desc: 'Product Description',
      price: 200.25,
      imageUrl: 'Image Url'
    }
  }

  /**
   * Create a user
   * @param request This is a user creation request description
   */
  @Post()
  public async Create(@Body() request: ProductCreateRequest): Promise<Product> {
github MakingSense / tsoa-api / src / controllers / UserController.ts View on Github external
Tags
} from 'tsoa';

import { ProvideSingleton, inject } from '../ioc';
import { IUserModel, IPaginationModel } from '../models';
import { UserService } from '../services';

@Tags('users')
@Route('users')
@ProvideSingleton(UserController)
export class UserController extends Controller {
  constructor(@inject(UserService) private service: UserService) {
    super();
  }

  @Get('{id}')
  public async getById(id: string): Promise<IUserModel> {
    return this.service.getById(id);
  }

  @Get()
  public async getPaginated(
    @Query('page') page: number,
    @Query('limit') limit: number,
    @Query('fields') fields?: string,
    @Query('sort') sort?: string,
    @Query('q') q?: string): Promise<IPaginationModel> {
    return this.service.getPaginated(page, limit, fields, sort, q);
  }

  @Response(400, 'Bad request')
  @Security('admin')