- Backend (NestJS): 82 suites, 641 tests passing; 0 ESLint errors; 0 tsc errors. Hardened SSL cert/key matching, SSRF IP pinning, and eBank validation. - Admin Panel (Vite/React): 48 suites, 300 tests passing; 0 ESLint errors; 0 tsc errors. Full coverage across all pages and settings. - Storefront (Next.js): 62 suites, 368 tests passing; 0 ESLint errors; 0 tsc errors. - Fixed unmount lifecycle guards, promise error handling, and component edge cases.
93 lines
2.7 KiB
TypeScript
93 lines
2.7 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";
|
|
|
|
import { Throttle } from "@nestjs/throttler";
|
|
|
|
@ApiTags("B2B - مدیریت پنل B2B و درخواستها")
|
|
@Controller("b2b")
|
|
export class B2BController {
|
|
constructor(private readonly b2bService: B2BService) {}
|
|
|
|
@Throttle({ default: { limit: 5, ttl: 60000 } })
|
|
@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();
|
|
}
|
|
}
|