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:
shancheas
2026-08-27 13:09:41 +07:00
parent 790725e227
commit 4c45a4371e
85 changed files with 1824 additions and 365 deletions
+11 -3
View File
@@ -4,7 +4,7 @@ import {
NotFoundException,
} from '@nestjs/common';
import type { PaginationResponse } from '../../common/http/response';
import { toListPage } from '../../common/http/response';
import { pickUserRelation, toListPage } from '../../common/http/response';
import { Status } from '../../common/value-objects/status/status';
import type { PrivilegeAction } from './privilege-action';
import { assertPrivilegeAction } from './privilege-action';
@@ -23,6 +23,8 @@ export type ListPrivilegesQuery = {
readonly code?: string;
readonly status?: string;
readonly search?: string;
readonly orderBy?: string;
readonly orderType?: string;
readonly page?: number;
readonly limit?: number;
readonly offset?: number;
@@ -30,6 +32,8 @@ export type ListPrivilegesQuery = {
export type ListPrivilegeKeysQuery = {
readonly search?: string;
readonly orderBy?: string;
readonly orderType?: string;
readonly page?: number;
readonly limit?: number;
readonly offset?: number;
@@ -59,6 +63,8 @@ export class PrivilegesService {
code: query.code,
status: query.status,
search: query.search,
orderBy: query.orderBy,
orderType: query.orderType,
limit: page.limit,
offset: page.offset,
});
@@ -241,6 +247,8 @@ export class PrivilegesService {
const page = toListPage(query);
return this.privilegesRepository.listKeys({
search: query.search,
orderBy: query.orderBy,
orderType: query.orderType,
limit: page.limit,
offset: page.offset,
});
@@ -313,8 +321,8 @@ export class PrivilegesService {
status: privilege.status.value,
createdAt: privilege.createdAt.value,
updatedAt: privilege.updatedAt.value,
createdBy: privilege.createdBy,
updatedBy: privilege.updatedBy,
createdBy: pickUserRelation(privilege.createdByUser),
updatedBy: pickUserRelation(privilege.updatedByUser),
};
}