add cover to deck create/update

This commit is contained in:
andres
2023-07-16 14:59:03 +02:00
parent f2437db3b7
commit 2f1579ed48
5 changed files with 65 additions and 12 deletions

View File

@@ -40,10 +40,20 @@ export class DecksController {
constructor(private readonly decksService: DecksService, private commandBus: CommandBus) {}
@UseGuards(JwtAuthGuard)
@UseInterceptors(FileFieldsInterceptor([{ name: 'cover', maxCount: 1 }]))
@Post()
create(@Request() req, @Body() createDeckDto: CreateDeckDto) {
create(
@Request() req,
@UploadedFiles()
files: {
cover: Express.Multer.File[]
},
@Body() createDeckDto: CreateDeckDto
) {
const userId = req.user.id
return this.commandBus.execute(new CreateDeckCommand({ ...createDeckDto, userId: userId }))
return this.commandBus.execute(
new CreateDeckCommand({ ...createDeckDto, userId: userId }, files?.cover?.[0])
)
}
@UseGuards(JwtAuthGuard)
@@ -101,9 +111,20 @@ export class DecksController {
}
@UseGuards(JwtAuthGuard)
@UseInterceptors(FileFieldsInterceptor([{ name: 'cover', maxCount: 1 }]))
@Patch(':id')
update(@Param('id') id: string, @Body() updateDeckDto: UpdateDeckDto, @Req() req) {
return this.commandBus.execute(new UpdateDeckCommand(id, updateDeckDto, req.user.id))
update(
@Param('id') id: string,
@UploadedFiles()
files: {
cover: Express.Multer.File[]
},
@Body() updateDeckDto: UpdateDeckDto,
@Req() req
) {
return this.commandBus.execute(
new UpdateDeckCommand(id, updateDeckDto, req.user.id, files?.cover?.[0])
)
}
@UseGuards(JwtAuthGuard)