feat: refactor sales invoice services and introduce pagination and filtering

- Added SharedSaleInvoicePaginationService for handling pagination logic.
- Introduced SharedSaleInvoiceFilterService to centralize filtering logic for sales invoices.
- Updated SalesInvoicesService to utilize the new pagination and filtering services.
- Refactored findAll methods in SalesInvoicesService, CustomerSaleInvoicesService, and other related services to support pagination and filtering.
- Enhanced DTOs for sales invoice filtering to extend shared filter properties.
- Updated module imports to include new services.
- Cleaned up redundant code related to filtering and pagination across various services.
This commit is contained in:
2026-06-14 16:34:00 +03:30
parent d2bd576277
commit 5f70b95589
20 changed files with 427 additions and 680 deletions
@@ -0,0 +1,29 @@
import { Injectable } from '@nestjs/common'
@Injectable()
export class SharedSaleInvoicePaginationService {
normalize(
page: number = 1,
perPage: number = 10,
defaultPerPage: number = 10,
maxPerPage: number = 50,
) {
const normalizedPageValue = Number(page ?? 1)
const normalizedPage = Number.isFinite(normalizedPageValue)
? Math.max(1, Math.floor(normalizedPageValue))
: 1
const requestedPerPageValue = Number(perPage ?? defaultPerPage)
const requestedPerPage = Number.isFinite(requestedPerPageValue)
? Math.max(1, Math.floor(requestedPerPageValue))
: defaultPerPage
const normalizedPerPage = Math.min(requestedPerPage, maxPerPage)
return {
page: normalizedPage,
perPage: normalizedPerPage,
skip: (normalizedPage - 1) * normalizedPerPage,
take: normalizedPerPage,
}
}
}