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:
@@ -1,5 +1,6 @@
|
||||
export const DEFAULT_RELATION_FIELDS = ['id', 'code', 'name'] as const;
|
||||
export const USER_RELATION_FIELDS = ['id', 'username'] as const;
|
||||
export const CODE_RELATION_FIELDS = ['id', 'code'] as const;
|
||||
|
||||
export type DefaultRelation = {
|
||||
readonly id: string;
|
||||
@@ -12,6 +13,11 @@ export type UserRelation = {
|
||||
readonly username: string;
|
||||
};
|
||||
|
||||
export type CodeRelation = {
|
||||
readonly id: string;
|
||||
readonly code: string;
|
||||
};
|
||||
|
||||
export function pickRelation<T, K extends keyof NonNullable<T>>(
|
||||
source: T | null | undefined,
|
||||
fields: readonly K[],
|
||||
@@ -40,3 +46,16 @@ export function pickUserRelation(source: UserRelation): UserRelation {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export function pickCodeRelation(
|
||||
source: CodeRelation | null | undefined,
|
||||
): CodeRelation | null {
|
||||
return pickRelation(source, CODE_RELATION_FIELDS);
|
||||
}
|
||||
|
||||
export function fallbackUserRelation(
|
||||
source: UserRelation | null | undefined,
|
||||
fallbackId: string,
|
||||
): UserRelation {
|
||||
return pickUserRelation(source ?? { id: fallbackId, username: '' });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user