Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {Get, Route} from 'tsoa';
import swaggerJson from '../swagger.json';
@Route('spec')
export class SpecController {
/** Get the current spec */
@Get()
async currentSpec() {
return swaggerJson;
}
}
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 {
var products = await ProductMongoose.find({}).exec()
return products
}
/** Get user by ID */
@Get('{productId}')
public async Get(productId: number): Promise {
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 {
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 {
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 {
return this.service.getPaginated(page, limit, fields, sort, q);
}
@Response(400, 'Bad request')
@Security('admin')