90 lines
2.6 KiB
TypeScript
90 lines
2.6 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Body,
|
|
Param,
|
|
UseGuards,
|
|
Req,
|
|
} from '@nestjs/common';
|
|
import { B2BService, B2BWholesaleOrderItem } from './b2b.service';
|
|
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
import { RolesGuard } from '../auth/roles.guard';
|
|
import { Roles } from '../auth/roles.decorator';
|
|
|
|
@ApiTags('B2B - مدیریت پنل B2B و درخواستها')
|
|
@Controller('b2b')
|
|
export class B2BController {
|
|
constructor(private readonly b2bService: B2BService) {}
|
|
|
|
@Post('inquire')
|
|
@ApiOperation({ summary: 'ثبت استعلام جدید B2B (فرم ثبت استعلام)' })
|
|
createInquiry(
|
|
@Body()
|
|
body: {
|
|
companyName: string;
|
|
contactName: string;
|
|
email: string;
|
|
phone: string;
|
|
businessType: string;
|
|
estimatedVolume?: string;
|
|
message: string;
|
|
},
|
|
) {
|
|
return this.b2bService.createInquiry(body);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('ADMIN')
|
|
@ApiBearerAuth()
|
|
@Get('inquiries')
|
|
@ApiOperation({ summary: 'لیست تمام استعلامهای B2B (مخصوص ادمین)' })
|
|
findAllInquiries() {
|
|
return this.b2bService.findAllInquiries();
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('ADMIN')
|
|
@ApiBearerAuth()
|
|
@Put('inquiries/:id')
|
|
@ApiOperation({ summary: 'به روزرسانی وضعیت استعلام B2B' })
|
|
updateInquiryStatus(
|
|
@Param('id') id: string,
|
|
@Body() body: { status: string; adminNotes?: string },
|
|
) {
|
|
return this.b2bService.updateInquiryStatus(id, body);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
@Get('partner')
|
|
@ApiOperation({ summary: 'دریافت اطلاعات حساب همکار تجاری' })
|
|
getPartnerProfile(@Req() req: { user: { id?: string; userId?: string } }) {
|
|
const userId = req.user.id || req.user.userId || '';
|
|
return this.b2bService.getPartnerProfile(userId);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
@Post('orders')
|
|
@ApiOperation({ summary: 'ثبت سفارش عمدهفروشی B2B' })
|
|
createWholesaleOrder(
|
|
@Req() req: { user: { id?: string; userId?: string } },
|
|
@Body() body: { items: B2BWholesaleOrderItem[]; totalAmount: number },
|
|
) {
|
|
const userId = req.user.id || req.user.userId || '';
|
|
return this.b2bService.createWholesaleOrder(userId, body);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('ADMIN')
|
|
@ApiBearerAuth()
|
|
@Get('partners')
|
|
@ApiOperation({ summary: 'لیست حسابهای همکاران تجاری (مخصوص ادمین)' })
|
|
getAllPartnerAccounts() {
|
|
return this.b2bService.getAllPartnerAccounts();
|
|
}
|
|
}
|