diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2021-11-12 02:02:25 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2021-11-12 02:02:25 +0900 |
| commit | 0e4a111f81cceed275d9bec2695f6e401fb654d8 (patch) | |
| tree | 40874799472fa07416f17b50a398ac33b7771905 /src/server/api/endpoints/users/lists | |
| parent | update deps (diff) | |
| download | misskey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.gz misskey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.bz2 misskey-0e4a111f81cceed275d9bec2695f6e401fb654d8.zip | |
refactoring
Resolve #7779
Diffstat (limited to 'src/server/api/endpoints/users/lists')
| -rw-r--r-- | src/server/api/endpoints/users/lists/create.ts | 36 | ||||
| -rw-r--r-- | src/server/api/endpoints/users/lists/delete.ts | 40 | ||||
| -rw-r--r-- | src/server/api/endpoints/users/lists/list.ts | 28 | ||||
| -rw-r--r-- | src/server/api/endpoints/users/lists/pull.ts | 62 | ||||
| -rw-r--r-- | src/server/api/endpoints/users/lists/push.ts | 92 | ||||
| -rw-r--r-- | src/server/api/endpoints/users/lists/show.ts | 47 | ||||
| -rw-r--r-- | src/server/api/endpoints/users/lists/update.ts | 55 |
7 files changed, 0 insertions, 360 deletions
diff --git a/src/server/api/endpoints/users/lists/create.ts b/src/server/api/endpoints/users/lists/create.ts deleted file mode 100644 index e0bfe611fc..0000000000 --- a/src/server/api/endpoints/users/lists/create.ts +++ /dev/null @@ -1,36 +0,0 @@ -import $ from 'cafy'; -import define from '../../../define'; -import { UserLists } from '@/models/index'; -import { genId } from '@/misc/gen-id'; -import { UserList } from '@/models/entities/user-list'; - -export const meta = { - tags: ['lists'], - - requireCredential: true as const, - - kind: 'write:account', - - params: { - name: { - validator: $.str.range(1, 100) - } - }, - - res: { - type: 'object' as const, - optional: false as const, nullable: false as const, - ref: 'UserList', - }, -}; - -export default define(meta, async (ps, user) => { - const userList = await UserLists.insert({ - id: genId(), - createdAt: new Date(), - userId: user.id, - name: ps.name, - } as UserList).then(x => UserLists.findOneOrFail(x.identifiers[0])); - - return await UserLists.pack(userList); -}); diff --git a/src/server/api/endpoints/users/lists/delete.ts b/src/server/api/endpoints/users/lists/delete.ts deleted file mode 100644 index 5fe3bfb03d..0000000000 --- a/src/server/api/endpoints/users/lists/delete.ts +++ /dev/null @@ -1,40 +0,0 @@ -import $ from 'cafy'; -import { ID } from '@/misc/cafy-id'; -import define from '../../../define'; -import { ApiError } from '../../../error'; -import { UserLists } from '@/models/index'; - -export const meta = { - tags: ['lists'], - - requireCredential: true as const, - - kind: 'write:account', - - params: { - listId: { - validator: $.type(ID), - } - }, - - errors: { - noSuchList: { - message: 'No such list.', - code: 'NO_SUCH_LIST', - id: '78436795-db79-42f5-b1e2-55ea2cf19166' - } - } -}; - -export default define(meta, async (ps, user) => { - const userList = await UserLists.findOne({ - id: ps.listId, - userId: user.id - }); - - if (userList == null) { - throw new ApiError(meta.errors.noSuchList); - } - - await UserLists.delete(userList.id); -}); diff --git a/src/server/api/endpoints/users/lists/list.ts b/src/server/api/endpoints/users/lists/list.ts deleted file mode 100644 index cf0c92bb84..0000000000 --- a/src/server/api/endpoints/users/lists/list.ts +++ /dev/null @@ -1,28 +0,0 @@ -import define from '../../../define'; -import { UserLists } from '@/models/index'; - -export const meta = { - tags: ['lists', 'account'], - - requireCredential: true as const, - - kind: 'read:account', - - res: { - type: 'array' as const, - optional: false as const, nullable: false as const, - items: { - type: 'object' as const, - optional: false as const, nullable: false as const, - ref: 'UserList', - } - }, -}; - -export default define(meta, async (ps, me) => { - const userLists = await UserLists.find({ - userId: me.id, - }); - - return await Promise.all(userLists.map(x => UserLists.pack(x))); -}); diff --git a/src/server/api/endpoints/users/lists/pull.ts b/src/server/api/endpoints/users/lists/pull.ts deleted file mode 100644 index d4357fc5e7..0000000000 --- a/src/server/api/endpoints/users/lists/pull.ts +++ /dev/null @@ -1,62 +0,0 @@ -import $ from 'cafy'; -import { ID } from '@/misc/cafy-id'; -import { publishUserListStream } from '@/services/stream'; -import define from '../../../define'; -import { ApiError } from '../../../error'; -import { getUser } from '../../../common/getters'; -import { UserLists, UserListJoinings, Users } from '@/models/index'; - -export const meta = { - tags: ['lists', 'users'], - - requireCredential: true as const, - - kind: 'write:account', - - params: { - listId: { - validator: $.type(ID), - }, - - userId: { - validator: $.type(ID), - }, - }, - - errors: { - noSuchList: { - message: 'No such list.', - code: 'NO_SUCH_LIST', - id: '7f44670e-ab16-43b8-b4c1-ccd2ee89cc02' - }, - - noSuchUser: { - message: 'No such user.', - code: 'NO_SUCH_USER', - id: '588e7f72-c744-4a61-b180-d354e912bda2' - } - } -}; - -export default define(meta, async (ps, me) => { - // Fetch the list - const userList = await UserLists.findOne({ - id: ps.listId, - userId: me.id, - }); - - if (userList == null) { - throw new ApiError(meta.errors.noSuchList); - } - - // Fetch the user - const user = await getUser(ps.userId).catch(e => { - if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser); - throw e; - }); - - // Pull the user - await UserListJoinings.delete({ userListId: userList.id, userId: user.id }); - - publishUserListStream(userList.id, 'userRemoved', await Users.pack(user)); -}); diff --git a/src/server/api/endpoints/users/lists/push.ts b/src/server/api/endpoints/users/lists/push.ts deleted file mode 100644 index 8e21059d3d..0000000000 --- a/src/server/api/endpoints/users/lists/push.ts +++ /dev/null @@ -1,92 +0,0 @@ -import $ from 'cafy'; -import { ID } from '@/misc/cafy-id'; -import define from '../../../define'; -import { ApiError } from '../../../error'; -import { getUser } from '../../../common/getters'; -import { pushUserToUserList } from '@/services/user-list/push'; -import { UserLists, UserListJoinings, Blockings } from '@/models/index'; - -export const meta = { - tags: ['lists', 'users'], - - requireCredential: true as const, - - kind: 'write:account', - - params: { - listId: { - validator: $.type(ID), - }, - - userId: { - validator: $.type(ID), - }, - }, - - errors: { - noSuchList: { - message: 'No such list.', - code: 'NO_SUCH_LIST', - id: '2214501d-ac96-4049-b717-91e42272a711' - }, - - noSuchUser: { - message: 'No such user.', - code: 'NO_SUCH_USER', - id: 'a89abd3d-f0bc-4cce-beb1-2f446f4f1e6a' - }, - - alreadyAdded: { - message: 'That user has already been added to that list.', - code: 'ALREADY_ADDED', - id: '1de7c884-1595-49e9-857e-61f12f4d4fc5' - }, - - youHaveBeenBlocked: { - message: 'You cannot push this user because you have been blocked by this user.', - code: 'YOU_HAVE_BEEN_BLOCKED', - id: '990232c5-3f9d-4d83-9f3f-ef27b6332a4b' - }, - } -}; - -export default define(meta, async (ps, me) => { - // Fetch the list - const userList = await UserLists.findOne({ - id: ps.listId, - userId: me.id, - }); - - if (userList == null) { - throw new ApiError(meta.errors.noSuchList); - } - - // Fetch the user - const user = await getUser(ps.userId).catch(e => { - if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser); - throw e; - }); - - // Check blocking - if (user.id !== me.id) { - const block = await Blockings.findOne({ - blockerId: user.id, - blockeeId: me.id, - }); - if (block) { - throw new ApiError(meta.errors.youHaveBeenBlocked); - } - } - - const exist = await UserListJoinings.findOne({ - userListId: userList.id, - userId: user.id - }); - - if (exist) { - throw new ApiError(meta.errors.alreadyAdded); - } - - // Push the user - await pushUserToUserList(user, userList); -}); diff --git a/src/server/api/endpoints/users/lists/show.ts b/src/server/api/endpoints/users/lists/show.ts deleted file mode 100644 index f9a35cdab3..0000000000 --- a/src/server/api/endpoints/users/lists/show.ts +++ /dev/null @@ -1,47 +0,0 @@ -import $ from 'cafy'; -import { ID } from '@/misc/cafy-id'; -import define from '../../../define'; -import { ApiError } from '../../../error'; -import { UserLists } from '@/models/index'; - -export const meta = { - tags: ['lists', 'account'], - - requireCredential: true as const, - - kind: 'read:account', - - params: { - listId: { - validator: $.type(ID), - }, - }, - - res: { - type: 'object' as const, - optional: false as const, nullable: false as const, - ref: 'UserList', - }, - - errors: { - noSuchList: { - message: 'No such list.', - code: 'NO_SUCH_LIST', - id: '7bc05c21-1d7a-41ae-88f1-66820f4dc686' - }, - } -}; - -export default define(meta, async (ps, me) => { - // Fetch the list - const userList = await UserLists.findOne({ - id: ps.listId, - userId: me.id, - }); - - if (userList == null) { - throw new ApiError(meta.errors.noSuchList); - } - - return await UserLists.pack(userList); -}); diff --git a/src/server/api/endpoints/users/lists/update.ts b/src/server/api/endpoints/users/lists/update.ts deleted file mode 100644 index 1185af5043..0000000000 --- a/src/server/api/endpoints/users/lists/update.ts +++ /dev/null @@ -1,55 +0,0 @@ -import $ from 'cafy'; -import { ID } from '@/misc/cafy-id'; -import define from '../../../define'; -import { ApiError } from '../../../error'; -import { UserLists } from '@/models/index'; - -export const meta = { - tags: ['lists'], - - requireCredential: true as const, - - kind: 'write:account', - - params: { - listId: { - validator: $.type(ID), - }, - - name: { - validator: $.str.range(1, 100), - } - }, - - res: { - type: 'object' as const, - optional: false as const, nullable: false as const, - ref: 'UserList', - }, - - errors: { - noSuchList: { - message: 'No such list.', - code: 'NO_SUCH_LIST', - id: '796666fe-3dff-4d39-becb-8a5932c1d5b7' - }, - } -}; - -export default define(meta, async (ps, user) => { - // Fetch the list - const userList = await UserLists.findOne({ - id: ps.listId, - userId: user.id - }); - - if (userList == null) { - throw new ApiError(meta.errors.noSuchList); - } - - await UserLists.update(userList.id, { - name: ps.name - }); - - return await UserLists.pack(userList.id); -}); |