Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { List } from './interfaces/list.interface';
import { UsersService } from '../common/users.service';
import { ListsService } from './lists.service';
import { ListDto } from './dto/list.dto';
@ApiUseTags('/users/:userid/favorites')
@ApiBearerAuth()
@Controller('users/:userid/favorites')
export class FavoritesController {
constructor(
private readonly usersService: UsersService,
private readonly listsService: ListsService,
) {}
@ApiOperation({ title: 'Returns the favorite list for the given user' })
@Get()
async list(@Req() request: Request, @Param('userid') userId: string) {
const current: User = await this.usersService.findByAuth0Id(
request.user.auth0Id,
);
const user: User = await this.usersService.findById(userId);
// Make sure user exist
if (!user) {
throw new BadRequestException('User not found');
}
// Only admins or current user can get the favorites
if (!current._id.equals(user._id) && !current.roles.includes(Role.ADMIN)) {
throw new UnauthorizedException(
'Not authorized to perform this operation',
);
@ApiUseTags('role')
@ApiBearerAuth()
@Controller('role')
export class RoleController {
constructor(private readonly roleService: RoleService) {}
@ApiOperation({ title: 'ๆทปๅ ่ง่ฒ' })
@HttpCode(HttpStatus.CREATED)
@Post()
async create(@Body() data: CreateRoleDto): Promise {
return this.roleService.create(data);
}
@ApiOperation({ title: 'ๆฅ่ฏขๆๆ็่ง่ฒ', description: 'ๆฏๆๅ้กตๆฅ่ฏข' })
@Get()
@UseInterceptors(PaginateInterceptor)
@HttpCode(HttpStatus.OK)
async showAll(
@Query('pageSize', new ParseIntPipe()) pageSize: number,
@Query('pageNumber', new ParseIntPipe()) pageNumber: number,
): Promise {
return await this.roleService.showAll(pageSize, pageNumber);
}
@ApiOperation({ title: 'ๆ นๆฎ่ง่ฒidๆฅ่ฏข่ง่ฒ' })
@Get(':id')
@HttpCode(HttpStatus.OK)
async getById(
@Param('id', new ParseIntPipe()) id: string,
): Promise {
return await this.roleService.getById(id);
@Controller()
@UseFilters(HttpExceptionFilter)
@UseInterceptors(LoggingInterceptor)
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
root(): string {
if (Math.random() > 0.5) {
throw new HttpException('FuckYou', HttpStatus.FORBIDDEN);
}
return this.appService.root();
}
@Get('user/:id')
findOne(@User() userInfo) {
return userInfo;
}
}
import { BadRequestException, Controller, Get, Param, Query } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import * as _ from 'lodash';
import * as R from 'ramda';
import { getConnection } from 'typeorm';
import { Profile } from '../common';
import { DBHelper, parseListParam, parseNormalWhereAndRelatedFields, parseOrder, parseWhere } from '../core/db';
import { LoggerFactory } from '../common/logger';
const logger = LoggerFactory.getLogger('SearchController');
@ApiTags('core')
@Controller('api/search')
export class SearchController {
@Get(':model')
async search(
@Param('model') model: string,
@Query('keywords') keywords: string,
@Query('page') page = 1,
@Query('size') size = 10,
@Query('profile') profile?: Profile,
@Query('fields') fields?: string | string[],
@Query('on') onFields?: string | string[],
@Query('where') whereStr?: string,
@Query('sort') sortStr?: string,
@Query('relations') relationsStr?: string,
): Promise<{ query: object; items: any[]; total: number; page: number; size: number }> {
const repository = DBHelper.repo(model);
const select = parseListParam(fields, field => `${model}.${field}`);
const on = parseListParam(onFields);
import { Controller, Get, Post } from '@nestjs/common';
import { Character } from '../../entities/character_schema';
import { CharactersService } from '../characters.service';
@Controller('characters')
export class CharactersController {
constructor(private readonly characterService: CharactersService) {}
@Get('/')
async getAll(): Promise>> {
const characters = await this.characterService.getAll();
return characters;
}
@Post(':userId')
upsertOne() {
return this.characterService.upsertChar();
}
@Get('/user/:userId')
getUser() {
return this.characterService.getUserChars();
}
@Get(':characterId')
import { InjectQueue } from 'nest-bull';
import { Queue } from 'bull';
@Controller()
export class AppController {
constructor(@InjectQueue('test_queue') private readonly queue: Queue) {}
@Get('twice/:x')
async createTwiceJob(@Param('x', new ParseIntPipe()) x: number) {
return {
message: 'Twice job created',
data: await this.queue.add('twice', x),
};
}
@Get('thrice/:x')
async createThriceJob(@Param('x', new ParseIntPipe()) x: number) {
return {
message: 'Thrice job created',
data: await this.queue.add('thrice', x),
};
}
}
import {User} from './user-decorator';
import {UsersService} from './users.service';
@Controller('/api/')
export class AuthController {
private readonly logger = new Logger(AuthController.name);
private readonly envSettings: EnvSettings;
constructor(
private readonly authService: AuthService,
private readonly configService: ConfigService,
private readonly userService: UsersService,
) {
this.envSettings = this.configService.getEnvSettings();
}
@Get('user')
@UseGuards(AuthGuard())
async getUser(@User() user: IGoogleUser) {
await this.userService.doUserLogin(user);
return user;
}
@Get('authenticate')
async doAuth(@Query('code') code: string, @Res() response: Response) {
try {
const up = await this.authService.getUserProfileFromCode(code);
if (up) {
const token = await this.authService.createUserJwtToken(up);
response.cookie(this.envSettings.AuthCookieName, token, {
maxAge: this.envSettings.CookieAge,
});
await this.userService.doUserLogin(up);
): Promise {
return this.menuService.search(keyword, value);
}
@Get("query")
async query(
@Query("isMenu") isMenu: boolean,
@Query("keyword") keyword?: string,
@Query("page", new NullableParseIntPipe()) page: number = 1,
@Query("size", new NullableParseIntPipe()) size: number = 10,
@Query("sort") sort?: string
): Promise> {
return this.menuService.querySearch(isMenu, keyword, page, size, sort);
}
@Get("permissions")
async getPermissionTags(): Promise<
{
id: string;
name: string;
desc: string;
}[]
> {
return this.menuService.getAllPermissionTags();
}
@Get("auth")
async getUserMenus(@Req() request: any): Promise {
return this.menuService.getAuthenticatedMenus(request.user);
}
@Get(":id")
import { Controller, Param, Get } from '@nestjs/common';
import { UserService } from './user.service';
import { User } from './user.entity';
@Controller()
export class UserController {
constructor(
private readonly userService: UserService,
) {}
@Get('user/:openid')
login(@Param('openid') openid): Promise {
return this.userService.login(openid);
}
@Get('users')
getUsers(): Promise {
return this.userService.findAll();
}
}
@Header('Server', 'NestJS')
@Header('Content-Type', 'application/json')
sayHello() {
return JSON.stringify({message: 'Hello, World!'});
}
@Get('/plaintext')
@Header('Server', 'NestJS')
@Header('Content-Type', 'text/plain')
plaintext() {
return 'Hello, World!';
}
@Get('/fortunes')
@Render('fortunes')
@Header('Server', 'NestJS')
fortunes(@Res() res: Response) {
return this.benchService.getFortunes().then( fortunes => ({
fortunes,
}));
}
}