Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { Controller, UseGuards, Get, Post, Body, UseInterceptors, UploadedFile, Res } from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { AuthGuard } from '@nestjs/passport';
import { UploadDto, IUploadService } from '@points/shared';
const gm = require('gm').subClass({ imageMagick: true });
import * as sizeOf from 'image-size';
import { ApiAction, ApiPermission, PermissionGaurd, HasPermission } from '../core/acl';
import { UploadService } from './upload.service';
import { UploadFileSettings, uploadDir } from '../app.settings';
import {OnlyApprovedUsers} from '../auth/guards/approved.guard';
const resource = 'upload';
export const to = (action: ApiAction) => new ApiPermission(action, resource, 'userId', 'objectId');
@Controller(resource)
@UseGuards(AuthGuard('jwt'), PermissionGaurd, OnlyApprovedUsers)
export class UploadController implements IUploadService {
constructor(private readonly upload: UploadService) { }
@Post()
@HasPermission(to('create'))
// TODO restrict to only images
@UseInterceptors(FileInterceptor('photo', UploadFileSettings))
async create(@Body() upload: UploadDto, @UploadedFile() photo, @Res() res): Promise {
if (!!photo) {
upload.photo = photo.filename;
this.generateThumbnail(upload.photo);
this.generateMedium(upload.photo);
return res.send(await this.upload.create(upload).catch(err => err));
} else {
return res.status(404).send('Not found');
@Injectable()
class CompaniesService extends RepositoryService {
protected options: RestfulOptions = {};
constructor(@InjectRepository(Company) public repo) {
super(repo);
}
}
@Crud(Company, {
params: {
id: 'uuid',
},
})
@UsePathInterceptors()
@Controller('custom2')
class Custom2Controller {
constructor(public service: CompaniesService) {}
@Get('with/all')
customWithAll(
@ParsedQuery() query: RestfulParamsDto,
@ParsedParams() params,
@ParsedOptions() options,
) {
return { query, params, options };
}
@Get('repo/find-one')
async customFindOne() {
return this.service.findOne(1);
}
import { Controller, Get, Post, Body } from '@nestjs/common';
import { PhotoService } from './photo.service';
import { Photo } from './photo.entity';
@Controller('photo')
export class PhotoController {
constructor(private readonly photoService: PhotoService) {}
@Get()
findAll(): Promise {
console.error('Pass in Photo Controller findAll');
console.error("This photservice", this.photoService);
return this.photoService.findAll();
}
@Post()
create(@Body() photo: Photo) {
return this.photoService.createPhoto(photo);
}
}
import { InjectRepository } from '@nestjs/typeorm';
import { plainToClass } from 'class-transformer';
import { Repository } from 'typeorm';
import { Roles } from '../decorators/roles.decorator';
import { InContentTypeDto } from '../dto/in-content-type.dto';
import { OutContentTypeDto } from '../dto/out-content-type.dto';
import { OutContentTypesDto } from '../dto/out-content-types.dto';
import { ContentType } from '../entities/content-type.entity';
import { AccessGuard } from '../guards/access.guard';
import { ParseIntWithDefaultPipe } from '../pipes/parse-int-with-default.pipe';
import { Permissions } from '../decorators/permissions.decorator';
@ApiUseTags('content-types')
@ApiBearerAuth()
@Controller('/api/content-types')
@UseGuards(AccessGuard)
export class ContentTypesController {
constructor(
@InjectRepository(ContentType)
private readonly contentTypeRepository: Repository
) {
}
@Roles('isSuperuser')
@Permissions('add_content-type')
@HttpCode(HttpStatus.CREATED)
@ApiResponse({
status: HttpStatus.CREATED, type: OutContentTypeDto,
description: 'The record has been successfully created.'
})
@ApiResponse({ status: HttpStatus.FORBIDDEN, description: 'Forbidden.' })
import {Controller} from '@nestjs/common';
import {Client, ClientProxy, MessagePattern, Transport} from '@nestjs/microservices';
import {AppLogger} from '../app.logger';
import {HOME_CMD_DELETE} from '../home/home.constants';
import {HomeFavoriteService} from './home-favorite.service';
import {HomeEntity} from '../home/entity';
@Controller('home-favorite')
export class HomeFavoriteController {
@Client({ transport: Transport.TCP })
private client: ClientProxy;
private logger = new AppLogger(HomeFavoriteController.name);
constructor(private readonly homeFavoriteService: HomeFavoriteService) {
}
@MessagePattern({ cmd: HOME_CMD_DELETE })
public async onHomeDelete(home: HomeEntity): Promise {
this.logger.debug(`[onHomeDelete] soft delete all favorites for home ${home.id}`);
await this.homeFavoriteService.updateAll({homeFavoriteHomeId: {eq: home.id.toString()}}, {'$set': {isDeleted: true}});
}
RolesGuard,
LoggingInterceptor
} from "nestx-common";
import {
KeyValueDto,
CreateUserReq,
EditUserReq,
EditProfileReq,
UsersOfRole,
UserRes,
ChangePasswordReq
} from "./../dto";
import { Tags } from "nest-swagger";
@Tags("core")
@Controller("user")
@UseGuards(AuthGuard("jwt"), RolesGuard)
@UseInterceptors(LoggingInterceptor)
export class UsersController {
constructor(private readonly usersService: UsersService) {}
@Get("profile")
async profile(@Req() request: any): Promise {
const user = request.user;
const instance = this.usersService.getProfile(user);
return instance;
}
@Post()
async create(@Body() user: CreateUserReq): Promise {
return this.usersService.create(plainToClass(CreateUserReq, user));
}
ApiUseTags
} from '@nestjs/swagger';
import { plainToClass } from 'class-transformer';
import { Permissions } from '../decorators/permissions.decorator';
import { Roles } from '../decorators/roles.decorator';
import { InContentTypeDto } from '../dto/in-content-type.dto';
import { OutContentTypeDto } from '../dto/out-content-type.dto';
import { OutContentTypesDto } from '../dto/out-content-types.dto';
import { ContentType } from '../entities/content-type.entity';
import { AccessGuard } from '../guards/access.guard';
import { ParseIntWithDefaultPipe } from '../pipes/parse-int-with-default.pipe';
import { ContentTypesService } from '../services/content-types.service';
@ApiUseTags('content-types')
@ApiBearerAuth()
@Controller('/api/content_types')
@UseGuards(AccessGuard)
export class ContentTypesController {
constructor(private readonly service: ContentTypesService) {}
@Roles('isSuperuser')
@Permissions('add_content-type')
@HttpCode(HttpStatus.CREATED)
@ApiResponse({
status: HttpStatus.CREATED,
type: OutContentTypeDto,
description: 'The record has been successfully created.'
})
@ApiResponse({ status: HttpStatus.FORBIDDEN, description: 'Forbidden.' })
@Post()
async create(@Body() dto: InContentTypeDto) {
try {
return plainToClass(
import { Controller, Get, Param, ParseIntPipe } from '@nestjs/common';
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),
ApiImplicitParam,
ApiOkResponse,
ApiOperation,
ApiUseTags
} from '@nestjs/swagger';
import { AuthGuard } from '@Auth/auth.guard';
import { NoteDTO } from '@Body/index';
import { DbNote } from '@DbModel/index';
import { NotePipe } from '@Note/note.pipe';
import { NoteService } from '@Note/note.service';
import { CharacterIdParam } from '@Parameter/index';
import { Observable } from 'rxjs';
@ApiUseTags('Note')
@Controller('character/note')
export class NoteController {
constructor(private readonly noteService: NoteService) {}
@Get(':charId')
@ApiOperation({
title: 'Get Notes',
description: 'Get all the notes of one character.'
})
@ApiImplicitParam({ name: 'charId', type: 'string', required: true })
@ApiOkResponse({ type: DbNote, isArray: true })
getNotes(@Param() params: CharacterIdParam): Observable {
return this.noteService.getNotes(params.charId);
}
@Post(':charId')
@ApiOperation({