refactor: restructure suppliers module and update DTOs

- Removed old supplier DTOs and controller, replacing them with new implementations.
- Introduced new CreateSupplierDto and UpdateSupplierDto in the index directory.
- Updated SuppliersController to handle new routes and methods.
- Implemented SuppliersService with updated logic for creating, finding, updating, and removing suppliers.
- Added new invoices module with corresponding controller and service for handling invoice-related operations.
- Created new DTOs for handling receipt payments and updated the service to manage payment creation and retrieval.
- Updated Prisma migrations to reflect changes in the database schema, including dropping unnecessary columns.
This commit is contained in:
2025-12-27 20:34:00 +03:30
parent d98507fc1f
commit af9695e23c
27 changed files with 636 additions and 575 deletions
@@ -0,0 +1,145 @@
import { Injectable } from '@nestjs/common'
import { ResponseMapper } from '../../../common/response/response-mapper'
import { PrismaService } from '../../../prisma/prisma.service'
import { CreateReceiptPaymentDto } from './dto/create-receipt-payment.dto'
@Injectable()
export class SupplierInvoicesService {
constructor(private prisma: PrismaService) {}
async findAll(supplierId: number) {
const items = await this.prisma.purchaseReceipt.findMany({
where: {
supplierId,
},
include: {
inventory: {
select: {
id: true,
name: true,
},
},
items: {
select: {
id: true,
count: true,
fee: true,
total: true,
product: {
select: {
id: true,
name: true,
sku: true,
},
},
},
},
payments: {
select: {
id: true,
amount: true,
},
},
},
omit: {
inventoryId: true,
supplierId: true,
},
})
return ResponseMapper.list(items)
}
async findOne(supplierId: number, invoiceId: number) {
const invoice = await this.prisma.purchaseReceipt.findUnique({
where: {
id: invoiceId,
supplierId,
},
include: {
inventory: {
select: {
id: true,
name: true,
},
},
items: true,
},
omit: {
inventoryId: true,
supplierId: true,
},
})
return ResponseMapper.single(invoice)
}
async findPayments(invoiceId: number) {
const items = await this.prisma.purchaseReceiptPayments.findMany({
where: {
receipt: {
id: invoiceId,
},
},
include: {
receipt: {
include: {
inventory: {
select: {
id: true,
name: true,
},
},
},
},
},
omit: {
receiptId: true,
},
})
return ResponseMapper.list(items)
}
async findAllPayments(supplierId: number) {
const items = await this.prisma.purchaseReceiptPayments.findMany({
where: {
receipt: {
supplierId,
},
},
include: {
receipt: {
select: {
id: true,
totalAmount: true,
status: true,
paidAmount: true,
},
},
},
omit: {
receiptId: true,
},
})
return ResponseMapper.list(items)
}
async createPayment(invoiceId: number, data: CreateReceiptPaymentDto) {
const payment = await this.prisma.purchaseReceiptPayments.create({
data: {
...data,
payedAt: new Date(data.payedAt),
receipt: {
connect: {
id: invoiceId,
},
},
},
include: {
receipt: true,
},
omit: {
receiptId: true,
},
})
return ResponseMapper.create(payment)
}
}