Enhance pagination and ordering capabilities in API responses
- Updated pagination-response and read-write-controllers documentation to include `orderBy` and `orderType` parameters for sorting results. - Introduced new `order-clause` module to handle ordering logic, including validation for order types and columns. - Enhanced `PaginationQueryDto` to support ordering fields in API requests. - Updated various repository and service classes to implement ordering in database queries. - Added unit tests for new ordering functionality and ensured existing tests cover the updated behavior. - Refactored related DTOs to include user and code relations for better data representation in responses.
This commit is contained in:
@@ -4,7 +4,11 @@ import {
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import type { PaginationResponse } from '../../../common/http/response';
|
||||
import { toListPage } from '../../../common/http/response';
|
||||
import {
|
||||
pickCodeRelation,
|
||||
pickUserRelation,
|
||||
toListPage,
|
||||
} from '../../../common/http/response';
|
||||
import { InvalidDateTimeError } from '../../../common/value-objects/date-time/invalid-date-time.error';
|
||||
import { DateTime } from '../../../common/value-objects/date-time/date-time';
|
||||
import { Decimal } from '../../../common/value-objects/decimal/decimal';
|
||||
@@ -42,6 +46,8 @@ export type ListSalesPaymentsQuery = {
|
||||
readonly code?: string;
|
||||
readonly status?: string;
|
||||
readonly search?: string;
|
||||
readonly orderBy?: string;
|
||||
readonly orderType?: string;
|
||||
readonly page?: number;
|
||||
readonly limit?: number;
|
||||
readonly offset?: number;
|
||||
@@ -66,6 +72,8 @@ export class SalesPaymentsService {
|
||||
code: query.code,
|
||||
status: query.status,
|
||||
search: query.search,
|
||||
orderBy: query.orderBy,
|
||||
orderType: query.orderType,
|
||||
limit: page.limit,
|
||||
offset: page.offset,
|
||||
});
|
||||
@@ -253,8 +261,8 @@ export class SalesPaymentsService {
|
||||
status: item.status.value,
|
||||
createdAt: item.createdAt.value,
|
||||
updatedAt: item.updatedAt.value,
|
||||
createdBy: item.createdBy,
|
||||
updatedBy: item.updatedBy,
|
||||
createdBy: pickUserRelation(item.createdByUser),
|
||||
updatedBy: pickUserRelation(item.updatedByUser),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -263,7 +271,7 @@ export class SalesPaymentsService {
|
||||
...this.toListItem(item),
|
||||
invoices: item.invoices.map((line) => ({
|
||||
id: line.id,
|
||||
invoiceId: line.invoiceId,
|
||||
invoice: pickCodeRelation(line.invoice),
|
||||
amount: line.amount.value,
|
||||
})),
|
||||
images: item.images.map((image) => ({
|
||||
|
||||
Reference in New Issue
Block a user