82 lines
2.7 KiB
TypeScript
82 lines
2.7 KiB
TypeScript
import { Controller, Get, Post, Put, Body, Param, Query, UseGuards } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
|
import { MerchantService } from './merchant.service';
|
|
import { SellerJwtAuthGuard } from '@/common/guards/seller-jwt-auth.guard';
|
|
import { JwtAuthGuard, RolesGuard } from '@/common';
|
|
import { Roles } from '@/common/decorators/roles.decorator';
|
|
import { CurrentSeller } from '@/common/decorators/current-seller.decorator';
|
|
import { ApplyMerchantDto, UpdateMerchantDto, QueryMerchantDto } from './dto/merchant.dto';
|
|
|
|
@ApiTags('商家')
|
|
@Controller('merchant')
|
|
@UseGuards(SellerJwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
export class MerchantController {
|
|
constructor(private readonly merchantService: MerchantService) {}
|
|
|
|
@Post('apply')
|
|
@ApiOperation({ summary: '申请商家入驻' })
|
|
async apply(@CurrentSeller('sub') sellerId: number, @Body() dto: ApplyMerchantDto) {
|
|
return this.merchantService.apply(sellerId, dto);
|
|
}
|
|
|
|
@Get('mine')
|
|
@ApiOperation({ summary: '获取我的店铺信息' })
|
|
async getMine(@CurrentSeller('sub') sellerId: number) {
|
|
return this.merchantService.findBySellerId(sellerId);
|
|
}
|
|
|
|
@Put('update')
|
|
@ApiOperation({ summary: '更新店铺信息' })
|
|
async update(@CurrentSeller('sub') sellerId: number, @Body() dto: UpdateMerchantDto) {
|
|
const merchant = await this.merchantService.findBySellerId(sellerId);
|
|
if (!merchant) throw new Error('店铺不存在');
|
|
return this.merchantService.update(merchant.id, dto);
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: '获取商家详情(公开)' })
|
|
async findById(@Param('id') id: number) {
|
|
return this.merchantService.findById(id);
|
|
}
|
|
}
|
|
|
|
@ApiTags('商家管理(管理员)')
|
|
@Controller('admin/merchants')
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('admin')
|
|
@ApiBearerAuth()
|
|
export class AdminMerchantController {
|
|
constructor(private readonly merchantService: MerchantService) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: '获取商家列表' })
|
|
async findAll(@Query() query: QueryMerchantDto) {
|
|
return this.merchantService.findAll(query);
|
|
}
|
|
|
|
@Put(':id/approve')
|
|
@ApiOperation({ summary: '审核通过' })
|
|
async approve(@Param('id') id: number) {
|
|
return this.merchantService.approve(id);
|
|
}
|
|
|
|
@Put(':id/reject')
|
|
@ApiOperation({ summary: '审核拒绝' })
|
|
async reject(@Param('id') id: number, @Body('reason') reason: string) {
|
|
return this.merchantService.reject(id, reason);
|
|
}
|
|
|
|
@Put(':id/freeze')
|
|
@ApiOperation({ summary: '冻结店铺' })
|
|
async freeze(@Param('id') id: number) {
|
|
return this.merchantService.freeze(id);
|
|
}
|
|
|
|
@Put(':id/unfreeze')
|
|
@ApiOperation({ summary: '解冻店铺' })
|
|
async unfreeze(@Param('id') id: number) {
|
|
return this.merchantService.unfreeze(id);
|
|
}
|
|
}
|