Files
psp_api/src/modules/pos/owned-goods/owned-goods.controller.ts
T

73 lines
2.0 KiB
TypeScript
Raw Normal View History

import { PosInfo } from '@/common/decorators/posInfo.decorator'
import type { IPosPayload } from '@/common/models'
import { multerImageOptions } from '@/multer.config'
import {
Body,
Controller,
Get,
Param,
Patch,
Post,
UploadedFile,
UseInterceptors,
} from '@nestjs/common'
import { FileInterceptor } from '@nestjs/platform-express'
import { ApiBody, ApiConsumes } from '@nestjs/swagger'
import { CreateOwnedGoodsDto } from './dto/create-owned-goods.dto'
import { UpdateOwnedGoodsDto } from './dto/update-owned-goods.dto'
import { OwnedGoodsService } from './owned-goods.service'
@Controller('pos/owned-goods')
export class OwnedGoodsController {
constructor(private readonly service: OwnedGoodsService) {}
@Get()
findAll(@PosInfo('business_id') business_id: string) {
return this.service.findAll(business_id)
}
@Get(':id')
findOne(@PosInfo('business_id') business_id: string, @Param('id') id: string) {
return this.service.findOne(business_id, id)
}
@Post()
@UseInterceptors(FileInterceptor('image', multerImageOptions))
@ApiConsumes('multipart/form-data')
@ApiBody({
schema: {
type: 'object',
properties: {
image: { type: 'string', format: 'binary' },
},
},
})
create(
@PosInfo() { business_id, guild_id }: IPosPayload,
@UploadedFile() file: Express.Multer.File,
@Body() dto: CreateOwnedGoodsDto,
) {
return this.service.create(guild_id, business_id, dto, file)
}
@Patch(':id')
@UseInterceptors(FileInterceptor('image', multerImageOptions))
@ApiConsumes('multipart/form-data')
@ApiBody({
schema: {
type: 'object',
properties: {
image: { type: 'string', format: 'binary' },
},
},
})
update(
@PosInfo() { business_id, guild_id }: IPosPayload,
@Param('id') id: string,
@UploadedFile() file: Express.Multer.File,
@Body() dto: UpdateOwnedGoodsDto,
) {
return this.service.update(guild_id, business_id, id, dto, file)
}
}