feat: api v2 event types ordering - user, team, org (#25177)

* feat: api-v2-event-types-ordering

* sort team and org event types

* revert: remove accidental changes to api-auth.strategy.ts

* docs: add ordering documentation and test for event types endpoints

- Added test assertion to verify event types are returned in descending order by ID (newest first)
- Added API documentation to user event types endpoint describing default ordering behavior
- Added API documentation to team event types endpoint describing default ordering behavior
- Added API documentation to organization event types endpoints describing default ordering behavior

Addresses PR feedback to document and test the ordering behavior introduced in the API v2 event types ordering feature.

* feat: add optional sortCreatedAt parameter to event types endpoints

- Add sortCreatedAt query parameter (SortOrderType: "asc" | "desc") to all event types endpoints
- Define SortOrder enum and SortOrderType in pagination.input.ts for reusability
- When not provided, no explicit ordering is applied (backward compatible)
- Update user, team, and organization event types endpoints
- Add comprehensive e2e tests for all sorting scenarios
- Fix circular dependency in platform-types import
- Thread sortCreatedAt through all service layers
- Use spread pattern for conditional orderBy to avoid empty array issues

Addresses PR feedback to make ordering opt-in rather than changing default behavior
This commit is contained in:
Dhairyashil Shinde authored and GitHub committed 2025-12-05 19:51:48 +05:30
1 parent 46b88a3c81
commit b014ded5fd
13 files changed
+209 -34

No files matched your search

@@ -1,6 +1,8 @@
import { ApiPropertyOptional } from "@nestjs/swagger";
import { Transform } from "class-transformer";
import { IsNumber, IsOptional, IsString } from "class-validator";
import { IsEnum, IsNumber, IsOptional, IsString } from "class-validator";
import { SkipTakePagination, SortOrder, SortOrderType } from "../../../pagination/pagination.input";
export class GetEventTypesQuery_2024_06_14 {
@IsOptional()
@@ -46,6 +48,14 @@ export class GetEventTypesQuery_2024_06_14 {
type: Number,
})
orgId?: number;
@ApiPropertyOptional({
enum: SortOrder,
description: "Sort event types by creation date. When not provided, no explicit ordering is applied.",
})
@IsOptional()
@IsEnum(SortOrder)
sortCreatedAt?: SortOrderType;
}
export class GetTeamEventTypesQuery_2024_06_14 {
@@ -64,6 +74,24 @@ export class GetTeamEventTypesQuery_2024_06_14 {
"Specifies the maximum number of hosts to include in the response. This limit helps optimize performance. If not provided, all Hosts will be fetched.",
})
hostsLimit?: number;
@ApiPropertyOptional({
enum: SortOrder,
description: "Sort event types by creation date. When not provided, no explicit ordering is applied.",
})
@IsOptional()
@IsEnum(SortOrder)
sortCreatedAt?: SortOrderType;
}
export class GetOrganizationEventTypesQuery_2024_06_14 extends SkipTakePagination {
@ApiPropertyOptional({
enum: SortOrder,
description: "Sort event types by creation date. When not provided, no explicit ordering is applied.",
})
@IsOptional()
@IsEnum(SortOrder)
sortCreatedAt?: SortOrderType;
}
function TransformUsernames() {
@@ -2,6 +2,13 @@ import { ApiPropertyOptional } from "@nestjs/swagger";
import { Transform } from "class-transformer";
import { IsNumber, Min, Max, IsOptional } from "class-validator";
export enum SortOrder {
ASC = "asc",
DESC = "desc",
}
export type SortOrderType = `${SortOrder}`;
export class Pagination {
@ApiPropertyOptional({ description: "The number of items to return", example: 10 })
@Transform(({ value }: { value: string }) => value && parseInt(value))