How to use tsoa - 10 common examples

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 / catalog / src / controllers / productController.ts View on Github external
/**
   * Get product by Id
   * @param productId Product Id
   */
  @Get(`{productId}`)
  public Get(productId: string): Promise<any> {
    // @ts-ignore
    let product = Product.findOne({ _id: productId }).exec()
    return Promise.resolve(product)
  }

  /**
   * Create a product
   * @param request This is a product creation request description
   */
  @Post()
  public Create(@Body() request: ProductCreateRequest): Promise<any> {
    let product = new Product({ _id: uuid.v1(), ...request })
    console.log(product)
    let result = Product.create(product)
    return Promise.resolve(result)
  }
}
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<any> {
    // @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 lukeautry / ts-app / api / routes.ts View on Github external
/* tslint:disable */
import { Controller, ValidationService, FieldErrors, ValidateError, TsoaRoute } from 'tsoa';
import { WidgetsController } from './controllers/widgets-controller';
import * as express from 'express';

const models: TsoaRoute.Models = {
  "IWidget": {
    "properties": {
      "id": { "dataType": "double", "required": true },
      "label": { "dataType": "string", "required": true },
      "color": { "dataType": "string", "required": true },
    },
  },
};
const validationService = new ValidationService(models);

export function RegisterRoutes(app: express.Express) {
  app.get('/api/widgets',
    function(request: any, response: any, next: any) {
      const args = {
      };

      let validatedArgs: any[] = [];
      try {
        validatedArgs = getValidatedArgs(args, request);
      } catch (err) {
        return next(err);
      }

      const controller = new WidgetsController();
github vietnam-devs / coolstore-microservices / src / services / rating / src / controllers / ratingController.ts View on Github external
* Create a rating
   * @param request This is a rating creation request description
   */
  @Post()
  public async Create(@Body() request: RatingCreateRequest): Promise<any> {
    console.info(request)
    let rating = new Rating({ _id: uuid.v1(), ...request })
    let result = await Rating.create(rating)
    return Promise.resolve(result)
  }

  /**
   * Update a rating
   * @param request This is a rating update request description
   */
  @Put()
  public async Update(@Body() request: RatingUpdateRequest): Promise<any> {
    let rating = await Rating.findOne({ productId: request.productId, userId: request.userId }).exec() || {}
    if (!rating) return Promise.reject("Could not find a Product or User")
    rating = { rating, ...request }
    let result = await Rating.update(rating)
    return Promise.resolve(result)
  }
}

tsoa

Build swagger-compliant REST APIs using TypeScript and Node

MIT
Latest version published 3 months ago

Package Health Score

92 / 100
Full package analysis

Popular JavaScript code snippets

Find secure code to use in your application or website