feat: v2 managed organizations pagination (#21359)
* feat: getPagination helper * refactor: bookings use getPagination helper * feat: getPagination helper * refactor: group pagination inputs and outputs in types/pagination * feat: paginated managed orgs * fix tests * swagger
This commit is contained in:
1 parent
008178480a
commit
2aafa1c163
15 files changed
+878
-375
No files matched your search
@@ -1,6 +1,4 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { Transform } from "class-transformer";
|
||||
import { IsNumber, Min, Max, IsOptional } from "class-validator";
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { IsEnum } from "class-validator";
|
||||
import type { Response as BaseResponse } from "express";
|
||||
|
||||
@@ -38,41 +36,6 @@ export type ApiResponse<T = undefined> = T extends undefined
|
||||
|
||||
export type ApiResponseMaybeRedirect<T = undefined> = ApiResponse<T> | ApiRedirectResponseType;
|
||||
|
||||
export class Pagination {
|
||||
@ApiPropertyOptional({ description: "The number of items to return", example: 10 })
|
||||
@Transform(({ value }: { value: string }) => value && parseInt(value))
|
||||
@IsNumber()
|
||||
@Min(1)
|
||||
@Max(250)
|
||||
@IsOptional()
|
||||
limit?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: "The number of items to skip", example: 0 })
|
||||
@Transform(({ value }: { value: string }) => value && parseInt(value))
|
||||
@IsNumber()
|
||||
@Min(0)
|
||||
@Max(250)
|
||||
@IsOptional()
|
||||
offset?: number;
|
||||
}
|
||||
|
||||
export class SkipTakePagination {
|
||||
@ApiProperty({ required: false, description: "The number of items to return", example: 10 })
|
||||
@Transform(({ value }: { value: string }) => value && parseInt(value))
|
||||
@IsNumber()
|
||||
@Min(1)
|
||||
@Max(250)
|
||||
@IsOptional()
|
||||
take?: number;
|
||||
|
||||
@ApiProperty({ required: false, description: "The number of items to skip", example: 0 })
|
||||
@Transform(({ value }: { value: string }) => value && parseInt(value))
|
||||
@IsNumber()
|
||||
@Min(0)
|
||||
@IsOptional()
|
||||
skip?: number;
|
||||
}
|
||||
|
||||
export class ApiResponseWithoutData {
|
||||
@ApiProperty({ example: SUCCESS_STATUS, enum: [SUCCESS_STATUS, ERROR_STATUS] })
|
||||
@IsEnum([SUCCESS_STATUS, ERROR_STATUS])
|
||||
|
||||
@@ -1,77 +1,16 @@
|
||||
import { ApiProperty, ApiExtraModels, getSchemaPath } from "@nestjs/swagger";
|
||||
import { Type } from "class-transformer";
|
||||
import { IsBoolean, IsEnum, IsInt, Min, ValidateNested } from "class-validator";
|
||||
import { IsEnum, ValidateNested } from "class-validator";
|
||||
|
||||
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
|
||||
import {
|
||||
BookingOutput_2024_08_13,
|
||||
GetRecurringSeatedBookingOutput_2024_08_13,
|
||||
GetSeatedBookingOutput_2024_08_13,
|
||||
PaginationMetaDto,
|
||||
RecurringBookingOutput_2024_08_13,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
export class PaginationMetaDto {
|
||||
@ApiProperty({
|
||||
description: "The total number of items available across all pages, matching the query criteria.",
|
||||
example: 123,
|
||||
minimum: 0,
|
||||
})
|
||||
@IsInt()
|
||||
@Min(0)
|
||||
totalItems!: number;
|
||||
|
||||
@ApiProperty({
|
||||
description:
|
||||
"The number of items remaining to be fetched *after* the current page. Calculated as: `totalItems - (skip + itemsPerPage)`.",
|
||||
example: 103, // e.g., if totalItems=123, skip=10, itemsPerPage=10 -> 123 - (10 + 10) = 103
|
||||
minimum: 0,
|
||||
})
|
||||
@IsInt()
|
||||
@Min(0)
|
||||
remainingItems!: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: "The maximum number of items requested per page.",
|
||||
example: 10,
|
||||
minimum: 1,
|
||||
})
|
||||
@IsInt()
|
||||
@Min(1) // Typically, you request at least 1 item per page
|
||||
itemsPerPage!: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: "The current page number being returned.",
|
||||
example: 2, // e.g., if skip=10, itemsPerPage=10 -> page 2
|
||||
minimum: 1,
|
||||
})
|
||||
@IsInt()
|
||||
@Min(1) // Page numbers usually start from 1
|
||||
currentPage!: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: "The total number of pages available.",
|
||||
example: 13, // e.g., if totalItems=123, itemsPerPage=10 -> 13 pages
|
||||
minimum: 0, // Can be 0 if totalItems is 0
|
||||
})
|
||||
@IsInt()
|
||||
@Min(0)
|
||||
totalPages!: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: "Indicates if there is a subsequent page available after the current one.",
|
||||
example: true,
|
||||
})
|
||||
@IsBoolean()
|
||||
hasNextPage!: boolean;
|
||||
|
||||
@ApiProperty({
|
||||
description: "Indicates if there is a preceding page available before the current one.",
|
||||
example: true,
|
||||
})
|
||||
@IsBoolean()
|
||||
hasPreviousPage!: boolean;
|
||||
}
|
||||
|
||||
@ApiExtraModels(
|
||||
BookingOutput_2024_08_13,
|
||||
RecurringBookingOutput_2024_08_13,
|
||||
|
||||
@@ -13,3 +13,5 @@ export * from "./embed";
|
||||
export * from "./oauth-clients";
|
||||
export * from "./routing-forms";
|
||||
export * from "./me";
|
||||
export * from "./pagination/pagination.input";
|
||||
export * from "./pagination/pagination.output";
|
||||
@@ -0,0 +1,52 @@
|
||||
import { ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { Transform } from "class-transformer";
|
||||
import { IsNumber, Min, Max, IsOptional } from "class-validator";
|
||||
|
||||
export class Pagination {
|
||||
@ApiPropertyOptional({ description: "The number of items to return", example: 10 })
|
||||
@Transform(({ value }: { value: string }) => value && parseInt(value))
|
||||
@IsNumber()
|
||||
@Min(1)
|
||||
@Max(250)
|
||||
@IsOptional()
|
||||
limit?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: "The number of items to skip", example: 0 })
|
||||
@Transform(({ value }: { value: string }) => value && parseInt(value))
|
||||
@IsNumber()
|
||||
@Min(0)
|
||||
@Max(250)
|
||||
@IsOptional()
|
||||
offset?: number;
|
||||
}
|
||||
|
||||
const DEFAULT_TAKE = 250;
|
||||
const DEFAULT_SKIP = 0;
|
||||
|
||||
export class SkipTakePagination {
|
||||
@ApiPropertyOptional({
|
||||
description: "Maximum number of items to return",
|
||||
example: 25,
|
||||
default: DEFAULT_TAKE,
|
||||
minimum: 1,
|
||||
maximum: DEFAULT_TAKE,
|
||||
})
|
||||
@Transform(({ value }: { value: string }) => (value ? parseInt(value) : DEFAULT_TAKE))
|
||||
@IsNumber()
|
||||
@Min(1)
|
||||
@Max(DEFAULT_TAKE)
|
||||
@IsOptional()
|
||||
take: number = DEFAULT_TAKE;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: "Number of items to skip",
|
||||
example: 0,
|
||||
default: DEFAULT_SKIP,
|
||||
minimum: 0,
|
||||
})
|
||||
@Transform(({ value }: { value: string }) => (value ? parseInt(value) : DEFAULT_SKIP))
|
||||
@IsNumber()
|
||||
@Min(0)
|
||||
@IsOptional()
|
||||
skip: number = DEFAULT_SKIP;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { IsBoolean, IsInt, Min } from "class-validator";
|
||||
|
||||
export class PaginationMetaDto {
|
||||
@ApiProperty({
|
||||
description: "The total number of items available across all pages, matching the query criteria.",
|
||||
example: 123,
|
||||
minimum: 0,
|
||||
})
|
||||
@IsInt()
|
||||
@Min(0)
|
||||
totalItems!: number;
|
||||
|
||||
@ApiProperty({
|
||||
description:
|
||||
"The number of items remaining to be fetched *after* the current page. Calculated as: `totalItems - (skip + itemsPerPage)`.",
|
||||
example: 103, // e.g., if totalItems=123, skip=10, itemsPerPage=10 -> 123 - (10 + 10) = 103
|
||||
minimum: 0,
|
||||
})
|
||||
@IsInt()
|
||||
@Min(0)
|
||||
remainingItems!: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: "The number of items returned in the current page.",
|
||||
example: 10,
|
||||
})
|
||||
@IsInt()
|
||||
@Min(0)
|
||||
returnedItems!: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: "The maximum number of items requested per page.",
|
||||
example: 10,
|
||||
minimum: 1,
|
||||
})
|
||||
@IsInt()
|
||||
@Min(1) // Typically, you request at least 1 item per page
|
||||
itemsPerPage!: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: "The current page number being returned.",
|
||||
example: 2, // e.g., if skip=10, itemsPerPage=10 -> page 2
|
||||
minimum: 1,
|
||||
})
|
||||
@IsInt()
|
||||
@Min(1) // Page numbers usually start from 1
|
||||
currentPage!: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: "The total number of pages available.",
|
||||
example: 13, // e.g., if totalItems=123, itemsPerPage=10 -> 13 pages
|
||||
minimum: 0, // Can be 0 if totalItems is 0
|
||||
})
|
||||
@IsInt()
|
||||
@Min(0)
|
||||
totalPages!: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: "Indicates if there is a subsequent page available after the current one.",
|
||||
example: true,
|
||||
})
|
||||
@IsBoolean()
|
||||
hasNextPage!: boolean;
|
||||
|
||||
@ApiProperty({
|
||||
description: "Indicates if there is a preceding page available before the current one.",
|
||||
example: true,
|
||||
})
|
||||
@IsBoolean()
|
||||
hasPreviousPage!: boolean;
|
||||
}
|
||||
Reference in new issue
Block a user