Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { BaseContext } from 'koa';
import { getManager, Repository, Not, Equal } from 'typeorm';
import { validate, ValidationError } from 'class-validator';
import { request, summary, path, body, responsesAll, tagsAll } from 'koa-swagger-decorator';
import { User, userSchema } from '../entity/user';
@responsesAll({ 200: { description: 'success'}, 400: { description: 'bad request'}, 401: { description: 'unauthorized, missing/wrong jwt token'}})
@tagsAll(['User'])
export default class UserController {
@request('get', '/users')
@summary('Find all users')
public static async getUsers(ctx: BaseContext) {
// get a user repository to perform operations with user
const userRepository: Repository = getManager().getRepository(User);
// load all users
const users: User[] = await userRepository.find();
// return OK status code and loaded users array
ctx.status = 200;
ctx.body = users;
import { request, summary, path, body, responsesAll, tagsAll, tags } from 'koa-swagger-decorator';
import { BaseContext } from 'koa';
@responsesAll({ 200: { description: 'Success'}, 500: { description: 'Server Error'}})
@tagsAll(['ping'])
export default class PingController {
@request('get', '/ping')
@summary('test if the server is running')
public static async pong(ctx: BaseContext) {
ctx.status = 200;
ctx.body = 'pong';
}
}