-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 메타데이터 페이지네이션 * feat: GET reviews * build: 자동 배포 명령어
- Loading branch information
Showing
10 changed files
with
136 additions
and
43 deletions.
There are no files selected for viewing
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,28 @@ | ||
import { SelectQueryBuilder } from 'kysely'; | ||
|
||
type Paginated<O> = { | ||
items: O[], | ||
meta: { | ||
totalItems: number; | ||
totalPages: number; | ||
}; | ||
} | ||
|
||
export const metaPaginated = async <DB, TB extends keyof DB, O>( | ||
qb: SelectQueryBuilder<DB, TB, O>, | ||
{ page, perPage }: { page: number; perPage: number }, | ||
): Promise<Paginated<O>> => { | ||
const { totalItems } = await qb | ||
.clearSelect() | ||
.select(({ fn }) => fn.countAll<number>().as('totalItems')) | ||
.executeTakeFirstOrThrow(); | ||
|
||
const items = await qb | ||
.offset((page - 1) * perPage) | ||
.limit(perPage) | ||
.execute(); | ||
|
||
const totalPages = Math.ceil(totalItems / perPage); | ||
|
||
return { items, meta: { totalItems, totalPages } }; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,7 @@ docs/* | |
node_modules | ||
src | ||
tsconfig.json | ||
.eslintrc.json | ||
*.tgz | ||
*.tar | ||
*.tar.gz |
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