Skip to content

Commit

Permalink
chore(backend,types): Re-use ClerkPaginationRequest as base paginatio…
Browse files Browse the repository at this point in the history
…n type
  • Loading branch information
dimkl committed Nov 24, 2023
1 parent 6e1cb81 commit 7a06e22
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
20 changes: 8 additions & 12 deletions packages/backend/src/api/endpoints/OrganizationApi.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { ClerkPaginationRequest } from '@clerk/types';

import runtime from '../../runtime';
import { joinPaths } from '../../util/path';
import type {
Expand All @@ -16,12 +18,10 @@ type MetadataParams<TPublic = OrganizationPublicMetadata, TPrivate = Organizatio
privateMetadata?: TPrivate;
};

type GetOrganizationListParams = {
limit?: number;
offset?: number;
type GetOrganizationListParams = ClerkPaginationRequest<{
includeMembersCount?: boolean;
query?: string;
};
}>;

type CreateParams = {
name: string;
Expand All @@ -46,11 +46,9 @@ type UpdateLogoParams = {

type UpdateMetadataParams = MetadataParams;

type GetOrganizationMembershipListParams = {
type GetOrganizationMembershipListParams = ClerkPaginationRequest<{
organizationId: string;
limit?: number;
offset?: number;
};
}>;

type CreateOrganizationMembershipParams = {
organizationId: string;
Expand Down Expand Up @@ -79,12 +77,10 @@ type CreateOrganizationInvitationParams = {
publicMetadata?: OrganizationInvitationPublicMetadata;
};

type GetOrganizationInvitationListParams = {
type GetOrganizationInvitationListParams = ClerkPaginationRequest<{
organizationId: string;
status?: OrganizationInvitationStatus[];
limit?: number;
offset?: number;
};
}>;

type GetOrganizationInvitationParams = {
organizationId: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { ClerkPaginationRequest } from '@clerk/types';

import { joinPaths } from '../../util/path';
import type { DeletedObject, Permission } from '../resources';
import { AbstractAPI } from './AbstractApi';

const basePath = '/organizations_permissions';

type GetOrganizationPermissionListParams = {
limit?: number;
offset?: number;
type GetOrganizationPermissionListParams = ClerkPaginationRequest<{
query?: string;
orderBy?: string;
};
}>;

type CreateParams = {
name: string;
Expand Down
8 changes: 4 additions & 4 deletions packages/backend/src/api/endpoints/OrganizationRoleApi.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { ClerkPaginationRequest } from '@clerk/types';

import { joinPaths } from '../../util/path';
import type { DeletedObject, Role } from '../resources';
import { AbstractAPI } from './AbstractApi';

const basePath = '/organizations_roles';

type GetRoleListParams = {
limit?: number;
offset?: number;
type GetRoleListParams = ClerkPaginationRequest<{
query?: string;
order_by?: string;
};
}>;

type CreateParams = {
/**
Expand Down
18 changes: 8 additions & 10 deletions packages/backend/src/api/endpoints/UserApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OAuthProvider } from '@clerk/types';
import type { ClerkPaginationRequest, OAuthProvider } from '@clerk/types';

import runtime from '../../runtime';
import { joinPaths } from '../../util/path';
Expand All @@ -17,11 +17,11 @@ type UserCountParams = {
externalId?: string[];
};

type UserListParams = UserCountParams & {
limit?: number;
offset?: number;
orderBy?: 'created_at' | 'updated_at' | '+created_at' | '+updated_at' | '-created_at' | '-updated_at';
};
type UserListParams = ClerkPaginationRequest<
UserCountParams & {
orderBy?: 'created_at' | 'updated_at' | '+created_at' | '+updated_at' | '-created_at' | '-updated_at';
}
>;

type UserMetadataParams = {
publicMetadata?: UserPublicMetadata;
Expand Down Expand Up @@ -77,11 +77,9 @@ interface UpdateUserParams extends UserMetadataParams {
createdAt?: Date;
}

type GetOrganizationMembershipListParams = {
type GetOrganizationMembershipListParams = ClerkPaginationRequest<{
userId: string;
limit?: number;
offset?: number;
};
}>;

type VerifyPasswordParams = {
userId: string;
Expand Down
14 changes: 10 additions & 4 deletions packages/types/src/pagination.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
/**
* Pagination params in request
*/
export interface ClerkPaginationRequest {
export type ClerkPaginationRequest<T = any> = {
/**
* Maximum number of items returned per request.
*/
limit?: number;
/**
* This is the starting point for your fetched results.
*/
offset?: number;
}
} & T;

/**
* Pagination params in response
Expand All @@ -19,11 +25,11 @@ export interface ClerkPaginatedResponse<T> {
*/
export type ClerkPaginationParams<T = any> = {
/**
* This is the starting point for your fetched results. The initial value persists between re-renders
* This is the starting point for your fetched results.
*/
initialPage?: number;
/**
* Maximum number of items returned per request. The initial value persists between re-renders
* Maximum number of items returned per request.
*/
pageSize?: number;
} & T;

0 comments on commit 7a06e22

Please sign in to comment.