diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2020-11-29 12:34:39 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2020-11-29 12:34:39 +0900 |
| commit | 17d62b689df22af66486cb50e9de82d745b129ce (patch) | |
| tree | f6ffb958ffc34fcc4335c84d839a8fec6cf649b1 /src/server/api/endpoints/users | |
| parent | wip (diff) | |
| download | sharkey-17d62b689df22af66486cb50e9de82d745b129ce.tar.gz sharkey-17d62b689df22af66486cb50e9de82d745b129ce.tar.bz2 sharkey-17d62b689df22af66486cb50e9de82d745b129ce.zip | |
wip
Diffstat (limited to 'src/server/api/endpoints/users')
| -rw-r--r-- | src/server/api/endpoints/users/clips.ts | 40 | ||||
| -rw-r--r-- | src/server/api/endpoints/users/pages.ts | 40 |
2 files changed, 80 insertions, 0 deletions
diff --git a/src/server/api/endpoints/users/clips.ts b/src/server/api/endpoints/users/clips.ts new file mode 100644 index 0000000000..72aae7252c --- /dev/null +++ b/src/server/api/endpoints/users/clips.ts @@ -0,0 +1,40 @@ +import $ from 'cafy'; +import { ID } from '../../../../misc/cafy-id'; +import define from '../../define'; +import { Clips } from '../../../../models'; +import { makePaginationQuery } from '../../common/make-pagination-query'; + +export const meta = { + tags: ['users', 'clips'], + + params: { + userId: { + validator: $.type(ID), + }, + + limit: { + validator: $.optional.num.range(1, 100), + default: 10 + }, + + sinceId: { + validator: $.optional.type(ID), + }, + + untilId: { + validator: $.optional.type(ID), + }, + } +}; + +export default define(meta, async (ps, user) => { + const query = makePaginationQuery(Clips.createQueryBuilder('clip'), ps.sinceId, ps.untilId) + .andWhere(`clip.userId = :userId`, { userId: ps.userId }) + .andWhere('clip.isPublic = true'); + + const clips = await query + .take(ps.limit!) + .getMany(); + + return await Clips.packMany(clips); +}); diff --git a/src/server/api/endpoints/users/pages.ts b/src/server/api/endpoints/users/pages.ts new file mode 100644 index 0000000000..706a2e115b --- /dev/null +++ b/src/server/api/endpoints/users/pages.ts @@ -0,0 +1,40 @@ +import $ from 'cafy'; +import { ID } from '../../../../misc/cafy-id'; +import define from '../../define'; +import { Pages } from '../../../../models'; +import { makePaginationQuery } from '../../common/make-pagination-query'; + +export const meta = { + tags: ['users', 'pages'], + + params: { + userId: { + validator: $.type(ID), + }, + + limit: { + validator: $.optional.num.range(1, 100), + default: 10 + }, + + sinceId: { + validator: $.optional.type(ID), + }, + + untilId: { + validator: $.optional.type(ID), + }, + } +}; + +export default define(meta, async (ps, user) => { + const query = makePaginationQuery(Pages.createQueryBuilder('page'), ps.sinceId, ps.untilId) + .andWhere(`page.userId = :userId`, { userId: ps.userId }) + .andWhere('page.visibility = \'public\''); + + const pages = await query + .take(ps.limit!) + .getMany(); + + return await Pages.packMany(pages); +}); |