Files
psp_api/src/common/services/saleInvoices/sale-invoice-pagination.service.ts
T
ahasani 5f70b95589 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.
2026-06-14 16:34:00 +03:30

30 lines
872 B
TypeScript

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,
}
}
}