-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
164 additions
and
78 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/shared/paging/global-pagination-headers.interceptor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Observable, map } from 'rxjs'; | ||
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common'; | ||
import { setPaginationHeaders } from './helpers.js'; | ||
import { PagedResponse } from './paged.response.js'; | ||
import { Response } from 'express'; | ||
|
||
export class GlobalPaginationHeadersInterceptor implements NestInterceptor { | ||
public intercept(context: ExecutionContext, next: CallHandler<unknown>): Observable<unknown | unknown[]> { | ||
return next.handle().pipe( | ||
map((value: unknown) => { | ||
if (value instanceof PagedResponse) { | ||
const response: Response = context.switchToHttp().getResponse(); | ||
|
||
setPaginationHeaders(response, value); | ||
|
||
return value.items as unknown[]; | ||
} | ||
|
||
return value; | ||
}), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Response } from 'express'; | ||
import { PagedResponse } from './paged.response.js'; | ||
|
||
export function setPaginationHeaders<T>(response: Response, payload: PagedResponse<T>): void { | ||
response.setHeader('Pagination-Total', payload.total); | ||
response.setHeader('Pagination-Offset', payload.offset); | ||
response.setHeader('Pagination-Limit', payload.limit); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from './global-pagination-headers.interceptor.js'; | ||
export * from './helpers.js'; | ||
export * from './paged.js'; | ||
export * from './paged.query.params.js'; | ||
export * from './paged.response.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ApiPropertyOptional } from '@nestjs/swagger'; | ||
|
||
export abstract class PagedQueryParams { | ||
@ApiPropertyOptional({ | ||
description: 'The offset of the paginated list.', | ||
}) | ||
public readonly offset?: number; | ||
|
||
@ApiPropertyOptional({ | ||
description: 'The requested limit for the page size.', | ||
}) | ||
public readonly limit?: number; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { Exclude } from 'class-transformer'; | ||
import { Paged } from './paged.js'; | ||
|
||
export class PagedResponse<T> { | ||
@Exclude() | ||
public readonly total: number; | ||
|
||
@Exclude() | ||
public readonly offset: number; | ||
|
||
@Exclude() | ||
public readonly limit: number; | ||
|
||
@ApiProperty() | ||
public readonly items: T[]; | ||
|
||
public constructor(page: Paged<T>) { | ||
this.total = page.total; | ||
this.offset = page.offset; | ||
this.limit = page.limit; | ||
this.items = page.items; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './repo-base.js'; | ||
// export * from './repo-base.js'; | ||
export * from './scope-base.js'; | ||
export * from './scope.enums.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import { AnyEntity, EntityName } from '@mikro-orm/core'; | ||
import { EntityManager } from '@mikro-orm/postgresql'; | ||
// import { AnyEntity, EntityName } from '@mikro-orm/core'; | ||
// import { EntityManager } from '@mikro-orm/postgresql'; | ||
|
||
export abstract class RepoBase<T extends AnyEntity> { | ||
protected constructor(protected readonly em: EntityManager) {} | ||
// export abstract class RepoBase<T extends AnyEntity> { | ||
// protected constructor(protected readonly em: EntityManager) {} | ||
|
||
public abstract get entityName(): EntityName<T>; | ||
// public abstract get entityName(): EntityName<T>; | ||
|
||
public async findById(id: string): Promise<Option<PersonDo<true>>> { | ||
const person: Option<PersonEntity> = await this.em.findOne(this.entityName, { id }); | ||
if (person) { | ||
return this.mapper.map(person, PersonEntity, PersonDo); | ||
} | ||
return null; | ||
} | ||
} | ||
// public async findById(id: string): Promise<Option<PersonDo<true>>> { | ||
// const person: Option<PersonEntity> = await this.em.findOne(this.entityName, { id }); | ||
// if (person) { | ||
// return this.mapper.map(person, PersonEntity, PersonDo); | ||
// } | ||
// return null; | ||
// } | ||
// } |
Oops, something went wrong.