Skip to content

Commit

Permalink
'.'
Browse files Browse the repository at this point in the history
  • Loading branch information
ManucherKM committed Sep 22, 2023
1 parent 1351646 commit b6285be
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/file/file.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { JwtAuthGuard } from '@/guard/jwt-auth.guard'
import {
Body,
Controller,
Get,
HttpException,
HttpStatus,
Param,
Post,
Request,
UploadedFile,
Expand All @@ -17,11 +21,11 @@ import { FileService } from './file.service'
import { fileStorage } from './storage'

@ApiTags('File')
@UseGuards(JwtAuthGuard)
@Controller('file')
export class FileController {
constructor(private readonly fileService: FileService) {}

@UseGuards(JwtAuthGuard)
@Post()
@UseInterceptors(
FileInterceptor('file', {
Expand All @@ -47,4 +51,24 @@ export class FileController {
) {
return await this.fileService.create(userId, file)
}

@Get('fileName/:fileName')
async findById(@Param('fileName') fileName: string) {
try {
return await this.fileService.findByFileName(fileName)
} catch (e) {
throw new HttpException({ message: e.message }, HttpStatus.BAD_REQUEST)
}
}

@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@Get('userId')
async findByUserId(@GetUserIdByToken() userId: string) {
try {
return await this.fileService.findByUserId(userId)
} catch (e) {
throw new HttpException({ message: e.message }, HttpStatus.BAD_REQUEST)
}
}
}
4 changes: 4 additions & 0 deletions src/file/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ export class FileService {
async findByFileName(fileName: string) {
return await this.fileModel.findOne({ fileName })
}

async findByUserId(userId: string) {
return await this.fileModel.find({ userId })
}
}

0 comments on commit b6285be

Please sign in to comment.