set perms
This commit is contained in:
@@ -18,25 +18,20 @@ import {
|
||||
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
||||
import { RestId } from 'src/common/decorators';
|
||||
import { AuthGuard } from 'src/modules/auth/guards/auth.guard';
|
||||
import { API_HEADER_SLUG } from 'src/common/constants';
|
||||
import { Permission } from 'src/common/enums/permission.enum';
|
||||
import { Permissions } from 'src/common/decorators/permissions.decorator';
|
||||
|
||||
@ApiTags('coupons')
|
||||
@Controller()
|
||||
export class CouponController {
|
||||
constructor(private readonly couponService: CouponService) {}
|
||||
constructor(private readonly couponService: CouponService) { }
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Get('public/coupons/me')
|
||||
@ApiOperation({ summary: 'Get paginated list of restaurant coupons' })
|
||||
@ApiHeader({
|
||||
name: 'X-Slug',
|
||||
required: true,
|
||||
schema: {
|
||||
type: 'string',
|
||||
default: 'zhivan',
|
||||
},
|
||||
})
|
||||
@ApiOkResponse({ description: 'Paginated list of restaurant coupons' })
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
@ApiQuery({ name: 'page', required: false, type: Number })
|
||||
@ApiQuery({ name: 'limit', required: false, type: Number })
|
||||
@ApiQuery({ name: 'search', required: false, type: String })
|
||||
@@ -47,9 +42,10 @@ export class CouponController {
|
||||
getMyCoupons(@Query() dto: FindCouponsDto, @RestId() restId: string) {
|
||||
return this.couponService.findAll(restId, dto);
|
||||
}
|
||||
|
||||
/*** Admin ***/
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Permissions(Permission.MANAGE_COUPONS)
|
||||
@Post('admin/coupons')
|
||||
@ApiOperation({ summary: 'Create a new coupon' })
|
||||
@ApiCreatedResponse({ description: 'The coupon has been successfully created.', type: CreateCouponDto })
|
||||
@@ -60,9 +56,9 @@ export class CouponController {
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Permissions(Permission.MANAGE_COUPONS)
|
||||
@Get('admin/coupons')
|
||||
@ApiOperation({ summary: 'Get a paginated list of coupons' })
|
||||
@ApiOkResponse({ description: 'Paginated list of coupons' })
|
||||
@ApiQuery({ name: 'page', required: false, type: Number })
|
||||
@ApiQuery({ name: 'limit', required: false, type: Number })
|
||||
@ApiQuery({ name: 'search', required: false, type: String })
|
||||
@@ -76,28 +72,28 @@ export class CouponController {
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Permissions(Permission.MANAGE_COUPONS)
|
||||
@Get('admin/coupons/:id')
|
||||
@ApiOperation({ summary: 'Get a coupon by id' })
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
@ApiOkResponse({ description: 'The coupon', type: CreateCouponDto })
|
||||
@ApiNotFoundResponse({ description: 'Coupon not found' })
|
||||
findById(@Param('id') id: string) {
|
||||
return this.couponService.findById(id);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Permissions(Permission.MANAGE_COUPONS)
|
||||
@Patch('admin/coupons/:id')
|
||||
@ApiOperation({ summary: 'Update a coupon' })
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
@ApiBody({ type: UpdateCouponDto })
|
||||
@ApiOkResponse({ description: 'The updated coupon', type: UpdateCouponDto })
|
||||
update(@Param('id') id: string, @Body() updateCouponDto: UpdateCouponDto) {
|
||||
return this.couponService.update(id, updateCouponDto);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Permissions(Permission.MANAGE_COUPONS)
|
||||
@Delete('admin/coupons/:id')
|
||||
@ApiOperation({ summary: 'Delete (soft) a coupon' })
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
@@ -107,6 +103,7 @@ export class CouponController {
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Permissions(Permission.MANAGE_COUPONS)
|
||||
@Get('admin/coupons/generate-code')
|
||||
@ApiOperation({ summary: 'generate a coupon code' })
|
||||
generateCouponCode(@RestId() restId: string) {
|
||||
|
||||
Reference in New Issue
Block a user