Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@Roles(RolesEnum.ADMIN)
@Get(':id')
async findById(@Param('id', new ParseUUIDPipe({ version: '4' })) id: string): Promise {
console.log('in findById', id);
return this.profileService.findOne(id);
}
@ApiOperation({ summary: 'Create new Profile.' })
@ApiConsumes('multipart/form-data')
// TODO @ApiImplicitFile({ name: 'file', required: true, description: 'Profile Picture' })
// @ApiBody({
// description: 'Profile Picture',
// type: CreateProfileDto,
// })
@UseInterceptors(
FileInterceptor('file', {
fileFilter: (req, file, cb) => {
if (ALLOWED_MIME_TYPES.indexOf(file.mimetype) === -1) {
return cb(
new BadRequestException(
`Error! Incorrect mimetype '${file.mimetype}'. Correct: ${ALLOWED_MIME_TYPES.join(', ')}`,
),
false,
);
}
cb(null, true);
},
limits: {
fileSize: 1024000,
},
}),
)
} from '../core/acl';
import { UploadFileSettings } from '../app.settings';
import {OnlyApprovedUsers} from '../auth/guards/approved.guard';
const resource = 'user';
const to = (action: ApiAction) =>
new ApiPermission(action, resource, 'id', 'objectId');
// resource specific action like 'login-as' or 'approve-achievement-for'
@Controller(resource)
@UseGuards(PermissionGaurd)
export class UserController implements IUserService {
constructor(private readonly user: UserService) {}
@Post()
@UseInterceptors(FileInterceptor('photo', UploadFileSettings))
async create(
@Body() user: UserDto,
@UploadedFile() photo
): Promise {
user.photo = photo ? photo.filename : null;
return await this.user.create(user).catch(err => err);
}
@Post('login')
async login(@Body() user: UserDto): Promise {
return await this.user.login(user).catch(err => err);
}
@Get('exists/:userName')
async exists(@Param() user: { userName: string }): Promise {
return await this.user.exists(user).catch(err => err);
import { FileInterceptor } from '@nestjs/platform-express';
import { SeedService } from "./seed.service";
export interface SeedResults {
categories: number;
achievements: number;
users: number;
}
@Controller('seed')
export class SeedController {
constructor(private readonly seed: SeedService) { }
@Post()
@UseInterceptors(FileInterceptor('data'))
async seedData(@UploadedFile() data): Promise {
const json = JSON.parse(data.buffer.toString());
return this.seed.seed(json);
}
}
@Controller()
@UseGuards(RolesGuard)
export class UploadController {
constructor(private readonly uploadService: UploadService) {}
static parentIdSchema = Joi.object({
parentId: Joi.string()
.default('')
.max(50)
.allow(''),
});
@Post('/api/upload/image')
@Roles('admin')
@UseInterceptors(FileInterceptor('file'))
async uploadSingalImage(@UploadedFile() file: any) {
return await this.uploadService.uploadSingalImage(file);
}
@Post('/api/upload/static-files')
@Roles('admin')
@JoiValidationPipe(UploadController.parentIdSchema)
@UseInterceptors(FileInterceptor('file'))
async uploadStaticFile(@UploadedFile() file: any, @Query() query: { parentId: string }) {
return await this.uploadService.uploadStaticFile(file, query.parentId);
}
}
}
@Get('/signature')
async getSignature() {
return this.attachmentService.getSignature();
}
@Post('/oss/callback')
async ossCallback(@Body() request: ICraeteAttachmentByOssCallback) {
return this.saveInOssService.ossCallback(request);
}
@HttpCode(200)
@Post('/upload')
@UseGuards(JwtGuard)
@UseInterceptors(FileInterceptor('file'))
async uploadFile(@Body() body: IAttachmentParams, @UploadedFile() file: Express.Multer.File) {
return this.attachmentService.createAttachmentByLocal(body, file);
}
}
import { FilesInterceptor, FileInterceptor } from "@nestjs/platform-express";
@Tags("cms")
@Controller("media")
export class MediaController {
constructor(private readonly service: MediaService) {}
@Get("search")
async search(
@Query("keyword") keyword?: string,
@Query("value") value?: string
): Promise {
return this.service.search(keyword, value);
}
@Post("upload")
@UseInterceptors(FileInterceptor("file"))
async uploadFile(@UploadedFile() file: MediaFile): Promise {
return {
ok: true,
file: file.path
};
}
@Post("uploads")
@UseInterceptors(FilesInterceptor("files"))
async uploadFiles(
@UploadedFiles() files?: MediaFile[]
): Promise {
const fileNames = (files || []).map(item => item.path);
return {
ok: true,
files: fileNames
import { HasPermission, ApiAction, ApiPermission, PermissionGaurd } from '../core/acl';
import { AchievementService } from './achievement.service';
import { UploadFileSettings } from '../app.settings';
import {OnlyApprovedUsers} from '../auth/guards/approved.guard';
const resource = 'achievement';
export const to = (action: ApiAction) => new ApiPermission(action, resource);
@Controller(resource)
@UseGuards(AuthGuard('jwt'), PermissionGaurd, OnlyApprovedUsers)
export class AchievementController implements IAchievementService {
constructor(private readonly achievement: AchievementService) { }
@Post()
@HasPermission(to('create'))
@UseInterceptors(FileInterceptor('photo', UploadFileSettings))
async create(@Body() achievement: AchievementDto, @UploadedFile() photo?): Promise {
return await this.achievement.create(achievement, photo).catch(err => err);
}
@Get()
@HasPermission(to('read'))
async getAll(): Promise {
return await this.achievement.getAll().catch(err => err);
}
@Get(':achievementId')
@HasPermission(to('read'))
async get(@Param() achievement: { achievementId: string }): Promise {
return await this.achievement.get(achievement).catch(err => err);
}
import { TenantService } from './tenant.service';
@Controller(TENANT_ENDPOINT)
export class TenantController extends CrudControllerFactory(TENANT_ENDPOINT, TenantDto, {
default: [DefaultRoles.admin],
}) {
constructor(
protected readonly service: TenantService,
protected readonly fileService: FileStorageService,
protected readonly mapper: TenantMapper,
) {
super(service, mapper);
}
@Post('logo')
@UseInterceptors(FileInterceptor('file'))
async photo(@UploadedFile() file: any, @Body() { ownerId }: { ownerId: string }): Promise {
try {
const data = new FileStorageDto();
const user = await this.service.findOne({ id: ownerId });
if (user && user.logo) {
data.id = user.logo.id;
}
data.file = file;
data.ownerId = ownerId;
data.object = 'tenant';
data.type = 'logo';
const uploadResult = await this.fileService.upload(data, DefaultRoles.authenticated);
AzureStorageFileInterceptor,
UploadedFileMetadata,
AzureStorageService,
} from '@nestjs/azure-storage';
import { AzureTableContinuationToken } from '@nestjs/azure-database';
import { CatService } from './cat.service';
@Controller('cats')
export class CatController {
constructor(
private readonly catService: CatService,
private azureStorage: AzureStorageService,
) {}
@Post('upload')
@UseInterceptors(FileInterceptor('file'))
async UploadedCatUsingService(
@UploadedFile()
file: UploadedFileMetadata,
) {
Logger.log(
`File "${file.originalname}" was uploaded using Azure Service`,
'CatController',
);
try {
const storageUrl = await this.azureStorage.upload(file);
return this.addCat(storageUrl);
} catch (error) {
throw new BadGatewayException(error);
}
}