58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Delete,
|
|
Body,
|
|
Param,
|
|
Query,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
|
import { CouponService } from '@/modules/shared/coupon/coupon.service';
|
|
import { JwtAuthGuard, RolesGuard } from '@/common';
|
|
import { Roles } from '@/common/decorators/roles.decorator';
|
|
import { CurrentUser } from '@/common/decorators/current-user.decorator';
|
|
import { CreateCouponDto, UpdateCouponDto, QueryCouponDto } from './dto/coupon.dto';
|
|
|
|
@ApiTags('优惠券管理(管理员)')
|
|
@Controller('admin/coupons')
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('admin')
|
|
@ApiBearerAuth()
|
|
export class CouponController {
|
|
constructor(private readonly couponService: CouponService) {}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: '创建优惠券' })
|
|
async create(@Body() dto: CreateCouponDto, @CurrentUser() user: any) {
|
|
return this.couponService.create(dto, user.id);
|
|
}
|
|
|
|
@Put(':id')
|
|
@ApiOperation({ summary: '更新优惠券' })
|
|
async update(@Param('id') id: number, @Body() dto: UpdateCouponDto) {
|
|
return this.couponService.update(id, dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@ApiOperation({ summary: '删除优惠券' })
|
|
async delete(@Param('id') id: number) {
|
|
await this.couponService.delete(id);
|
|
return { message: '删除成功' };
|
|
}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: '查询优惠券列表' })
|
|
async findAll(@Query() dto: QueryCouponDto) {
|
|
return this.couponService.findAll(dto);
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: '获取优惠券详情' })
|
|
async findOne(@Param('id') id: number) {
|
|
return this.couponService.findOne(id);
|
|
}
|
|
}
|