feat(backend): implement Phase A database models and controllers for cross-boundary dependencies
Deploy Canina / deploy (push) Failing after 28s
Deploy Canina / deploy (push) Failing after 28s
This commit is contained in:
1 parent
74fcaa6a4e
commit
1ae4c99ffc
26 files changed
+1205
-345
No files matched your search
@@ -0,0 +1,89 @@
|
||||
import {
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
ForbiddenException,
|
||||
} from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
@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: any[]; 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 },
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user