Files
canina/backend/src/b2b/b2b.service.ts
T
devops ddbf1ca026
Deploy Canina / deploy (push) Successful in 4m1s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 7s
test: comprehensive test suites and quality gates pass across backend, storefront and admin
- 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.
2026-10-13 16:01:00 +00:00

102 lines
2.3 KiB
TypeScript

import {
Injectable,
NotFoundException,
ForbiddenException,
} from "@nestjs/common";
import { PrismaService } from "../prisma/prisma.service";
export interface B2BWholesaleOrderItem {
productId: string;
quantity: number;
}
@Injectable()
export class B2BService {
constructor(private prisma: PrismaService) {}
async createInquiry(data: {
companyName: string;
contactName: string;
email: string;
phone: string;
businessType: string;
estimatedVolume?: string;
message: string;
}) {
return this.prisma.b2BInquiry.create({
data: {
...data,
status: "PENDING",
},
});
}
async findAllInquiries() {
return this.prisma.b2BInquiry.findMany({
orderBy: { createdAt: "desc" },
});
}
async updateInquiryStatus(
id: string,
data: { status: string; adminNotes?: string },
) {
const item = await this.prisma.b2BInquiry.findUnique({ where: { id } });
if (!item) {
throw new NotFoundException(`B2BInquiry with ID ${id} not found`);
}
return this.prisma.b2BInquiry.update({
where: { id },
data,
});
}
async getPartnerProfile(userId: string) {
const partner = await this.prisma.partnerAccount.findUnique({
where: { userId },
include: { user: true },
});
if (!partner) {
throw new NotFoundException(
`Partner account for user ${userId} not found`,
);
}
return partner;
}
async createWholesaleOrder(
userId: string,
data: { items: B2BWholesaleOrderItem[]; totalAmount: number },
) {
const partner = await this.prisma.partnerAccount.findUnique({
where: { userId },
});
if (!partner || partner.status !== "ACTIVE") {
throw new ForbiddenException("User is not an active wholesale partner");
}
return this.prisma.order.create({
data: {
userId,
totalAmount: data.totalAmount,
status: "processing",
isRefill: false,
orderItems: {
create: data.items.map((item) => ({
productId: item.productId,
quantity: item.quantity,
})),
},
},
include: { orderItems: true },
});
}
async getAllPartnerAccounts() {
return this.prisma.partnerAccount.findMany({
include: { user: true },
orderBy: { createdAt: "desc" },
});
}
}