diff --git a/src/server/api/common/getters.ts b/src/server/api/common/getters.ts index f74f6130cb..1947c95ab6 100644 --- a/src/server/api/common/getters.ts +++ b/src/server/api/common/getters.ts @@ -4,9 +4,9 @@ import User, { isRemoteUser, isLocalUser } from '../../../models/user'; import { IdentifiableError } from '../../../misc/identifiable-error'; /** - * Get valied note for API processing + * Get note for API processing */ -export async function getValiedNote(noteId: mongo.ObjectID) { +export async function getNote(noteId: mongo.ObjectID) { const note = await Note.findOne({ _id: noteId, deletedAt: { $exists: false } @@ -24,10 +24,17 @@ export async function getValiedNote(noteId: mongo.ObjectID) { */ export async function getUser(userId: mongo.ObjectID) { const user = await User.findOne({ - _id: userId + _id: userId, + isDeleted: false + }, { + fields: { + data: false, + profile: false, + clientSettings: false + } }); - if (user == null) { + if (user === null) { throw new IdentifiableError('15348ddd-432d-49c2-8a5a-8069753becff', 'No such user.'); } diff --git a/src/server/api/endpoints/blocking/create.ts b/src/server/api/endpoints/blocking/create.ts index 7e15b2d7ff..0186e1cb09 100644 --- a/src/server/api/endpoints/blocking/create.ts +++ b/src/server/api/endpoints/blocking/create.ts @@ -6,6 +6,7 @@ import Blocking from '../../../../models/blocking'; import create from '../../../../services/blocking/create'; import define from '../../define'; import { ApiError } from '../../error'; +import { getUser } from '../../common/getters'; export const meta = { stability: 'stable', @@ -65,19 +66,11 @@ export default define(meta, async (ps, user) => { } // Get blockee - const blockee = await User.findOne({ - _id: ps.userId - }, { - fields: { - data: false, - profile: false - } + const blockee = await getUser(ps.userId).catch(e => { + if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser); + throw e; }); - if (blockee === null) { - throw new ApiError(meta.errors.noSuchUser); - } - // Check if already blocking const exist = await Blocking.findOne({ blockerId: blocker._id, diff --git a/src/server/api/endpoints/blocking/delete.ts b/src/server/api/endpoints/blocking/delete.ts index 475f2c30a1..494922e401 100644 --- a/src/server/api/endpoints/blocking/delete.ts +++ b/src/server/api/endpoints/blocking/delete.ts @@ -6,6 +6,7 @@ import Blocking from '../../../../models/blocking'; import deleteBlocking from '../../../../services/blocking/delete'; import define from '../../define'; import { ApiError } from '../../error'; +import { getUser } from '../../common/getters'; export const meta = { stability: 'stable', @@ -65,19 +66,11 @@ export default define(meta, async (ps, user) => { } // Get blockee - const blockee = await User.findOne({ - _id: ps.userId - }, { - fields: { - data: false, - 'profile': false - } + const blockee = await getUser(ps.userId).catch(e => { + if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser); + throw e; }); - if (blockee === null) { - throw new ApiError(meta.errors.noSuchUser); - } - // Check not blocking const exist = await Blocking.findOne({ blockerId: blocker._id, diff --git a/src/server/api/endpoints/following/create.ts b/src/server/api/endpoints/following/create.ts index b4a58b996a..06f1787a98 100644 --- a/src/server/api/endpoints/following/create.ts +++ b/src/server/api/endpoints/following/create.ts @@ -6,6 +6,7 @@ import Following from '../../../../models/following'; import create from '../../../../services/following/create'; import define from '../../define'; import { ApiError } from '../../error'; +import { getUser } from '../../common/getters'; export const meta = { stability: 'stable', @@ -77,19 +78,11 @@ export default define(meta, async (ps, user) => { } // Get followee - const followee = await User.findOne({ - _id: ps.userId - }, { - fields: { - data: false, - profile: false - } + const followee = await getUser(ps.userId).catch(e => { + if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser); + throw e; }); - if (followee === null) { - throw new ApiError(meta.errors.noSuchUser); - } - // Check if already following const exist = await Following.findOne({ followerId: follower._id, diff --git a/src/server/api/endpoints/following/delete.ts b/src/server/api/endpoints/following/delete.ts index 6b6fac0719..a6ea551dcd 100644 --- a/src/server/api/endpoints/following/delete.ts +++ b/src/server/api/endpoints/following/delete.ts @@ -6,6 +6,7 @@ import Following from '../../../../models/following'; import deleteFollowing from '../../../../services/following/delete'; import define from '../../define'; import { ApiError } from '../../error'; +import { getUser } from '../../common/getters'; export const meta = { stability: 'stable', @@ -65,19 +66,11 @@ export default define(meta, async (ps, user) => { } // Get followee - const followee = await User.findOne({ - _id: ps.userId - }, { - fields: { - data: false, - 'profile': false - } + const followee = await getUser(ps.userId).catch(e => { + if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser); + throw e; }); - if (followee === null) { - throw new ApiError(meta.errors.noSuchUser); - } - // Check not following const exist = await Following.findOne({ followerId: follower._id, diff --git a/src/server/api/endpoints/following/requests/accept.ts b/src/server/api/endpoints/following/requests/accept.ts index 2aa0434279..82cd4e0ca3 100644 --- a/src/server/api/endpoints/following/requests/accept.ts +++ b/src/server/api/endpoints/following/requests/accept.ts @@ -4,6 +4,7 @@ import acceptFollowRequest from '../../../../../services/following/requests/acce import User from '../../../../../models/user'; import define from '../../../define'; import { ApiError } from '../../../error'; +import { getUser } from '../../../common/getters'; export const meta = { desc: { @@ -37,14 +38,11 @@ export const meta = { export default define(meta, async (ps, user) => { // Fetch follower - const follower = await User.findOne({ - _id: ps.userId + const follower = await getUser(ps.userId).catch(e => { + if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser); + throw e; }); - if (follower === null) { - throw new ApiError(meta.errors.noSuchUser); - } - await acceptFollowRequest(user, follower); return; diff --git a/src/server/api/endpoints/following/requests/cancel.ts b/src/server/api/endpoints/following/requests/cancel.ts index bca9feaba9..82c1e792b0 100644 --- a/src/server/api/endpoints/following/requests/cancel.ts +++ b/src/server/api/endpoints/following/requests/cancel.ts @@ -4,6 +4,7 @@ import cancelFollowRequest from '../../../../../services/following/requests/canc import User, { pack } from '../../../../../models/user'; import define from '../../../define'; import { ApiError } from '../../../error'; +import { getUser } from '../../../common/getters'; export const meta = { desc: { @@ -43,14 +44,11 @@ export const meta = { export default define(meta, async (ps, user) => { // Fetch followee - const followee = await User.findOne({ - _id: ps.userId + const followee = await getUser(ps.userId).catch(e => { + if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser); + throw e; }); - if (followee === null) { - throw new ApiError(meta.errors.noSuchUser); - } - try { await cancelFollowRequest(followee, user); } catch (e) { diff --git a/src/server/api/endpoints/following/requests/reject.ts b/src/server/api/endpoints/following/requests/reject.ts index 760661b55f..9a134c7dff 100644 --- a/src/server/api/endpoints/following/requests/reject.ts +++ b/src/server/api/endpoints/following/requests/reject.ts @@ -4,6 +4,7 @@ import rejectFollowRequest from '../../../../../services/following/requests/reje import User from '../../../../../models/user'; import define from '../../../define'; import { ApiError } from '../../../error'; +import { getUser } from '../../../common/getters'; export const meta = { desc: { @@ -37,14 +38,11 @@ export const meta = { export default define(meta, async (ps, user) => { // Fetch follower - const follower = await User.findOne({ - _id: ps.userId + const follower = await getUser(ps.userId).catch(e => { + if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser); + throw e; }); - if (follower === null) { - throw new ApiError(meta.errors.noSuchUser); - } - await rejectFollowRequest(user, follower); return; diff --git a/src/server/api/endpoints/games/reversi/match.ts b/src/server/api/endpoints/games/reversi/match.ts index 4fd4aedc15..0ae61f9d15 100644 --- a/src/server/api/endpoints/games/reversi/match.ts +++ b/src/server/api/endpoints/games/reversi/match.ts @@ -7,6 +7,7 @@ import { publishMainStream, publishReversiStream } from '../../../../../services import { eighteight } from '../../../../../games/reversi/maps'; import define from '../../../define'; import { ApiError } from '../../../error'; +import { getUser } from '../../../common/getters'; export const meta = { requireCredential: true, @@ -85,18 +86,11 @@ export default define(meta, async (ps, user) => { return await packGame(game, user); } else { // Fetch child - const child = await User.findOne({ - _id: ps.userId - }, { - fields: { - _id: true - } + const child = await getUser(ps.userId).catch(e => { + if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser); + throw e; }); - if (child === null) { - throw new ApiError(meta.errors.noSuchUser); - } - // 以前のセッションはすべて削除しておく await Matching.remove({ parentId: user._id diff --git a/src/server/api/endpoints/messaging/messages.ts b/src/server/api/endpoints/messaging/messages.ts index 9b27d4cac1..6eb950d418 100644 --- a/src/server/api/endpoints/messaging/messages.ts +++ b/src/server/api/endpoints/messaging/messages.ts @@ -6,6 +6,7 @@ import { pack } from '../../../../models/messaging-message'; import read from '../../common/read-messaging-message'; import define from '../../define'; import { ApiError } from '../../error'; +import { getUser } from '../../common/getters'; export const meta = { desc: { @@ -59,17 +60,10 @@ export const meta = { export default define(meta, async (ps, user) => { // Fetch recipient - const recipient = await User.findOne({ - _id: ps.userId - }, { - fields: { - _id: true - } - }); - - if (recipient === null) { - throw new ApiError(meta.errors.noSuchUser); - } + const recipient = await getUser(ps.userId).catch(e => { + if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser); + throw e; + }); const query = { $or: [{ diff --git a/src/server/api/endpoints/messaging/messages/create.ts b/src/server/api/endpoints/messaging/messages/create.ts index 3885d2583c..7ff6526295 100644 --- a/src/server/api/endpoints/messaging/messages/create.ts +++ b/src/server/api/endpoints/messaging/messages/create.ts @@ -11,6 +11,7 @@ import { publishMessagingStream, publishMessagingIndexStream } from '../../../.. import pushSw from '../../../../../services/push-notification'; import define from '../../../define'; import { ApiError } from '../../../error'; +import { getUser } from '../../../common/getters'; export const meta = { desc: { @@ -76,18 +77,11 @@ export default define(meta, async (ps, user) => { } // Fetch recipient - const recipient = await User.findOne({ - _id: ps.userId - }, { - fields: { - _id: true - } + const recipient = await getUser(ps.userId).catch(e => { + if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser); + throw e; }); - if (recipient === null) { - throw new ApiError(meta.errors.noSuchUser); - } - let file = null; if (ps.fileId != null) { file = await DriveFile.findOne({ diff --git a/src/server/api/endpoints/mute/create.ts b/src/server/api/endpoints/mute/create.ts index 166900e62f..45e2080648 100644 --- a/src/server/api/endpoints/mute/create.ts +++ b/src/server/api/endpoints/mute/create.ts @@ -4,6 +4,7 @@ import User from '../../../../models/user'; import Mute from '../../../../models/mute'; import define from '../../define'; import { ApiError } from '../../error'; +import { getUser } from '../../common/getters'; export const meta = { desc: { @@ -56,19 +57,11 @@ export default define(meta, async (ps, user) => { } // Get mutee - const mutee = await User.findOne({ - _id: ps.userId - }, { - fields: { - data: false, - profile: false - } + const mutee = await getUser(ps.userId).catch(e => { + if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser); + throw e; }); - if (mutee === null) { - throw new ApiError(meta.errors.noSuchUser); - } - // Check if already muting const exist = await Mute.findOne({ muterId: muter._id, diff --git a/src/server/api/endpoints/mute/delete.ts b/src/server/api/endpoints/mute/delete.ts index 1d74c45ef1..d9f7025d53 100644 --- a/src/server/api/endpoints/mute/delete.ts +++ b/src/server/api/endpoints/mute/delete.ts @@ -4,6 +4,7 @@ import User from '../../../../models/user'; import Mute from '../../../../models/mute'; import define from '../../define'; import { ApiError } from '../../error'; +import { getUser } from '../../common/getters'; export const meta = { desc: { @@ -56,19 +57,11 @@ export default define(meta, async (ps, user) => { } // Get mutee - const mutee = await User.findOne({ - _id: ps.userId - }, { - fields: { - data: false, - profile: false - } + const mutee = await getUser(ps.userId).catch(e => { + if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser); + throw e; }); - if (mutee === null) { - throw new ApiError(meta.errors.noSuchUser); - } - // Check not muting const exist = await Mute.findOne({ muterId: muter._id, diff --git a/src/server/api/endpoints/notes/conversation.ts b/src/server/api/endpoints/notes/conversation.ts index ec371ecf19..2f08de9e8f 100644 --- a/src/server/api/endpoints/notes/conversation.ts +++ b/src/server/api/endpoints/notes/conversation.ts @@ -3,7 +3,7 @@ import ID, { transform } from '../../../../misc/cafy-id'; import Note, { packMany, INote } from '../../../../models/note'; import define from '../../define'; import { ApiError } from '../../error'; -import { getValiedNote } from '../../common/getters'; +import { getNote } from '../../common/getters'; export const meta = { desc: { @@ -44,7 +44,7 @@ export const meta = { }; export default define(meta, async (ps, user) => { - const note = await getValiedNote(ps.noteId).catch(e => { + const note = await getNote(ps.noteId).catch(e => { if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote); throw e; }); diff --git a/src/server/api/endpoints/notes/delete.ts b/src/server/api/endpoints/notes/delete.ts index 42f7494184..8ca5a3bb08 100644 --- a/src/server/api/endpoints/notes/delete.ts +++ b/src/server/api/endpoints/notes/delete.ts @@ -4,7 +4,7 @@ import deleteNote from '../../../../services/note/delete'; import User from '../../../../models/user'; import define from '../../define'; import * as ms from 'ms'; -import { getValiedNote } from '../../common/getters'; +import { getNote } from '../../common/getters'; import { ApiError } from '../../error'; export const meta = { @@ -52,7 +52,7 @@ export const meta = { }; export default define(meta, async (ps, user) => { - const note = await getValiedNote(ps.noteId).catch(e => { + const note = await getNote(ps.noteId).catch(e => { if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote); throw e; }); diff --git a/src/server/api/endpoints/notes/reactions.ts b/src/server/api/endpoints/notes/reactions.ts index 3e0656c4f8..74f22cc774 100644 --- a/src/server/api/endpoints/notes/reactions.ts +++ b/src/server/api/endpoints/notes/reactions.ts @@ -2,7 +2,7 @@ import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import Reaction, { pack } from '../../../../models/note-reaction'; import define from '../../define'; -import { getValiedNote } from '../../common/getters'; +import { getNote } from '../../common/getters'; import { ApiError } from '../../error'; export const meta = { @@ -54,7 +54,7 @@ export const meta = { }; export default define(meta, async (ps, user) => { - const note = await getValiedNote(ps.noteId).catch(e => { + const note = await getNote(ps.noteId).catch(e => { if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote); throw e; }); diff --git a/src/server/api/endpoints/notes/reactions/create.ts b/src/server/api/endpoints/notes/reactions/create.ts index 65232e231d..816c6a9c29 100644 --- a/src/server/api/endpoints/notes/reactions/create.ts +++ b/src/server/api/endpoints/notes/reactions/create.ts @@ -3,7 +3,7 @@ import ID, { transform } from '../../../../../misc/cafy-id'; import createReaction from '../../../../../services/note/reaction/create'; import { validateReaction } from '../../../../../models/note-reaction'; import define from '../../../define'; -import { getValiedNote } from '../../../common/getters'; +import { getNote } from '../../../common/getters'; import { ApiError } from '../../../error'; export const meta = { @@ -57,7 +57,7 @@ export const meta = { }; export default define(meta, async (ps, user) => { - const note = await getValiedNote(ps.noteId).catch(e => { + const note = await getNote(ps.noteId).catch(e => { if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote); throw e; }); diff --git a/src/server/api/endpoints/notes/reactions/delete.ts b/src/server/api/endpoints/notes/reactions/delete.ts index 47e98f63e4..1afa6526f5 100644 --- a/src/server/api/endpoints/notes/reactions/delete.ts +++ b/src/server/api/endpoints/notes/reactions/delete.ts @@ -3,7 +3,7 @@ import ID, { transform } from '../../../../../misc/cafy-id'; import define from '../../../define'; import * as ms from 'ms'; import deleteReaction from '../../../../../services/note/reaction/delete'; -import { getValiedNote } from '../../../common/getters'; +import { getNote } from '../../../common/getters'; import { ApiError } from '../../../error'; export const meta = { @@ -49,7 +49,7 @@ export const meta = { }; export default define(meta, async (ps, user) => { - const note = await getValiedNote(ps.noteId).catch(e => { + const note = await getNote(ps.noteId).catch(e => { if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote); throw e; }); diff --git a/src/server/api/endpoints/notes/renotes.ts b/src/server/api/endpoints/notes/renotes.ts index 9873f1bffa..b4c99b1f4e 100644 --- a/src/server/api/endpoints/notes/renotes.ts +++ b/src/server/api/endpoints/notes/renotes.ts @@ -2,7 +2,7 @@ import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import Note, { packMany } from '../../../../models/note'; import define from '../../define'; -import { getValiedNote } from '../../common/getters'; +import { getNote } from '../../common/getters'; import { ApiError } from '../../error'; export const meta = { @@ -49,7 +49,7 @@ export const meta = { }; export default define(meta, async (ps, user) => { - const note = await getValiedNote(ps.noteId).catch(e => { + const note = await getNote(ps.noteId).catch(e => { if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote); throw e; }); diff --git a/src/server/api/endpoints/notes/show.ts b/src/server/api/endpoints/notes/show.ts index 2134fad953..f4fd06c03d 100644 --- a/src/server/api/endpoints/notes/show.ts +++ b/src/server/api/endpoints/notes/show.ts @@ -2,7 +2,7 @@ import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import { pack } from '../../../../models/note'; import define from '../../define'; -import { getValiedNote } from '../../common/getters'; +import { getNote } from '../../common/getters'; import { ApiError } from '../../error'; export const meta = { @@ -36,7 +36,7 @@ export const meta = { }; export default define(meta, async (ps, user) => { - const note = await getValiedNote(ps.noteId).catch(e => { + const note = await getNote(ps.noteId).catch(e => { if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote); throw e; }); diff --git a/src/server/api/endpoints/notes/watching/create.ts b/src/server/api/endpoints/notes/watching/create.ts index ebba211fc0..7361237e8d 100644 --- a/src/server/api/endpoints/notes/watching/create.ts +++ b/src/server/api/endpoints/notes/watching/create.ts @@ -2,7 +2,7 @@ import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id'; import define from '../../../define'; import watch from '../../../../../services/note/watch'; -import { getValiedNote } from '../../../common/getters'; +import { getNote } from '../../../common/getters'; import { ApiError } from '../../../error'; export const meta = { @@ -38,7 +38,7 @@ export const meta = { }; export default define(meta, async (ps, user) => { - const note = await getValiedNote(ps.noteId).catch(e => { + const note = await getNote(ps.noteId).catch(e => { if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote); throw e; }); diff --git a/src/server/api/endpoints/notes/watching/delete.ts b/src/server/api/endpoints/notes/watching/delete.ts index 63354d4ab2..33fbef570c 100644 --- a/src/server/api/endpoints/notes/watching/delete.ts +++ b/src/server/api/endpoints/notes/watching/delete.ts @@ -2,7 +2,7 @@ import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id'; import define from '../../../define'; import unwatch from '../../../../../services/note/unwatch'; -import { getValiedNote } from '../../../common/getters'; +import { getNote } from '../../../common/getters'; import { ApiError } from '../../../error'; export const meta = { @@ -38,7 +38,7 @@ export const meta = { }; export default define(meta, async (ps, user) => { - const note = await getValiedNote(ps.noteId).catch(e => { + const note = await getNote(ps.noteId).catch(e => { if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote); throw e; }); diff --git a/src/server/api/endpoints/users/get_frequently_replied_users.ts b/src/server/api/endpoints/users/get_frequently_replied_users.ts index b20d1ef69e..4c6a040a95 100644 --- a/src/server/api/endpoints/users/get_frequently_replied_users.ts +++ b/src/server/api/endpoints/users/get_frequently_replied_users.ts @@ -6,6 +6,7 @@ import define from '../../define'; import { maximum } from '../../../../prelude/array'; import { getHideUserIds } from '../../common/get-hide-users'; import { ApiError } from '../../error'; +import { getUser } from '../../common/getters'; export const meta = { requireCredential: false, @@ -37,18 +38,11 @@ export const meta = { export default define(meta, async (ps, me) => { // Lookup user - const user = await User.findOne({ - _id: ps.userId - }, { - fields: { - _id: true - } + const user = await getUser(ps.userId).catch(e => { + if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser); + throw e; }); - if (user === null) { - throw new ApiError(meta.errors.noSuchUser); - } - // Fetch recent notes const recentNotes = await Note.find({ userId: user._id, diff --git a/src/server/api/endpoints/users/lists/pull.ts b/src/server/api/endpoints/users/lists/pull.ts index 416c1b4b2d..679b71277c 100644 --- a/src/server/api/endpoints/users/lists/pull.ts +++ b/src/server/api/endpoints/users/lists/pull.ts @@ -5,6 +5,7 @@ import User, { pack as packUser } from '../../../../../models/user'; import { publishUserListStream } from '../../../../../services/stream'; import define from '../../../define'; import { ApiError } from '../../../error'; +import { getUser } from '../../../common/getters'; export const meta = { desc: { @@ -59,14 +60,11 @@ export default define(meta, async (ps, me) => { } // Fetch the user - const user = await User.findOne({ - _id: ps.userId + const user = await getUser(ps.userId).catch(e => { + if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser); + throw e; }); - if (user == null) { - throw new ApiError(meta.errors.noSuchUser); - } - // Pull the user await UserList.update({ _id: userList._id }, { $pull: { diff --git a/src/server/api/endpoints/users/lists/push.ts b/src/server/api/endpoints/users/lists/push.ts index 90dd2aa045..6fdf55875d 100644 --- a/src/server/api/endpoints/users/lists/push.ts +++ b/src/server/api/endpoints/users/lists/push.ts @@ -8,6 +8,7 @@ import renderFollow from '../../../../../remote/activitypub/renderer/follow'; import { deliver } from '../../../../../queue'; import define from '../../../define'; import { ApiError } from '../../../error'; +import { getUser } from '../../../common/getters'; export const meta = { desc: { @@ -68,14 +69,11 @@ export default define(meta, async (ps, me) => { } // Fetch the user - const user = await User.findOne({ - _id: ps.userId + const user = await getUser(ps.userId).catch(e => { + if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser); + throw e; }); - if (user == null) { - throw new ApiError(meta.errors.noSuchUser); - } - if (userList.userIds.map(id => id.toHexString()).includes(user._id.toHexString())) { throw new ApiError(meta.errors.alreadyAdded); } diff --git a/src/server/api/endpoints/users/notes.ts b/src/server/api/endpoints/users/notes.ts index 98d67e865a..efa39da001 100644 --- a/src/server/api/endpoints/users/notes.ts +++ b/src/server/api/endpoints/users/notes.ts @@ -5,6 +5,7 @@ import User from '../../../../models/user'; import define from '../../define'; import Following from '../../../../models/following'; import { ApiError } from '../../error'; +import { getUser } from '../../common/getters'; export const meta = { desc: { @@ -135,16 +136,11 @@ export const meta = { export default define(meta, async (ps, me) => { // Lookup user - const user = await User.findOne({ _id: ps.userId }, { - fields: { - _id: true - } + const user = await getUser(ps.userId).catch(e => { + if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser); + throw e; }); - if (user === null) { - throw new ApiError(meta.errors.noSuchUser); - } - const isFollowing = me == null ? false : ((await Following.findOne({ followerId: me._id, followeeId: user._id diff --git a/src/server/api/endpoints/users/report-abuse.ts b/src/server/api/endpoints/users/report-abuse.ts index 32a2393493..36f797f5e6 100644 --- a/src/server/api/endpoints/users/report-abuse.ts +++ b/src/server/api/endpoints/users/report-abuse.ts @@ -5,6 +5,7 @@ import User from '../../../../models/user'; import AbuseUserReport from '../../../../models/abuse-user-report'; import { publishAdminStream } from '../../../../services/stream'; import { ApiError } from '../../error'; +import { getUser } from '../../common/getters'; export const meta = { desc: { @@ -54,14 +55,11 @@ export const meta = { export default define(meta, async (ps, me) => { // Lookup user - const user = await User.findOne({ - _id: ps.userId + const user = await getUser(ps.userId).catch(e => { + if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser); + throw e; }); - if (user === null) { - throw new ApiError(meta.errors.noSuchUser); - } - if (user._id.equals(me._id)) { throw new ApiError(meta.errors.cannotReportYourself); }