mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-26 11:57:34 -07:00
Refactor
This commit is contained in:
parent
057719a2f6
commit
b00d0c9aae
27 changed files with 98 additions and 173 deletions
|
@ -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.');
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,18 +60,11 @@ export const meta = {
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
const query = {
|
||||
$or: [{
|
||||
userId: user._id,
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue