mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-26 20:07:33 -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';
|
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({
|
const note = await Note.findOne({
|
||||||
_id: noteId,
|
_id: noteId,
|
||||||
deletedAt: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
|
@ -24,10 +24,17 @@ export async function getValiedNote(noteId: mongo.ObjectID) {
|
||||||
*/
|
*/
|
||||||
export async function getUser(userId: mongo.ObjectID) {
|
export async function getUser(userId: mongo.ObjectID) {
|
||||||
const user = await User.findOne({
|
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.');
|
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 create from '../../../../services/blocking/create';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
|
import { getUser } from '../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
stability: 'stable',
|
stability: 'stable',
|
||||||
|
@ -65,19 +66,11 @@ export default define(meta, async (ps, user) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get blockee
|
// Get blockee
|
||||||
const blockee = await User.findOne({
|
const blockee = await getUser(ps.userId).catch(e => {
|
||||||
_id: ps.userId
|
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
|
||||||
}, {
|
throw e;
|
||||||
fields: {
|
|
||||||
data: false,
|
|
||||||
profile: false
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (blockee === null) {
|
|
||||||
throw new ApiError(meta.errors.noSuchUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if already blocking
|
// Check if already blocking
|
||||||
const exist = await Blocking.findOne({
|
const exist = await Blocking.findOne({
|
||||||
blockerId: blocker._id,
|
blockerId: blocker._id,
|
||||||
|
|
|
@ -6,6 +6,7 @@ import Blocking from '../../../../models/blocking';
|
||||||
import deleteBlocking from '../../../../services/blocking/delete';
|
import deleteBlocking from '../../../../services/blocking/delete';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
|
import { getUser } from '../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
stability: 'stable',
|
stability: 'stable',
|
||||||
|
@ -65,19 +66,11 @@ export default define(meta, async (ps, user) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get blockee
|
// Get blockee
|
||||||
const blockee = await User.findOne({
|
const blockee = await getUser(ps.userId).catch(e => {
|
||||||
_id: ps.userId
|
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
|
||||||
}, {
|
throw e;
|
||||||
fields: {
|
|
||||||
data: false,
|
|
||||||
'profile': false
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (blockee === null) {
|
|
||||||
throw new ApiError(meta.errors.noSuchUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check not blocking
|
// Check not blocking
|
||||||
const exist = await Blocking.findOne({
|
const exist = await Blocking.findOne({
|
||||||
blockerId: blocker._id,
|
blockerId: blocker._id,
|
||||||
|
|
|
@ -6,6 +6,7 @@ import Following from '../../../../models/following';
|
||||||
import create from '../../../../services/following/create';
|
import create from '../../../../services/following/create';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
|
import { getUser } from '../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
stability: 'stable',
|
stability: 'stable',
|
||||||
|
@ -77,19 +78,11 @@ export default define(meta, async (ps, user) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get followee
|
// Get followee
|
||||||
const followee = await User.findOne({
|
const followee = await getUser(ps.userId).catch(e => {
|
||||||
_id: ps.userId
|
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
|
||||||
}, {
|
throw e;
|
||||||
fields: {
|
|
||||||
data: false,
|
|
||||||
profile: false
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (followee === null) {
|
|
||||||
throw new ApiError(meta.errors.noSuchUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if already following
|
// Check if already following
|
||||||
const exist = await Following.findOne({
|
const exist = await Following.findOne({
|
||||||
followerId: follower._id,
|
followerId: follower._id,
|
||||||
|
|
|
@ -6,6 +6,7 @@ import Following from '../../../../models/following';
|
||||||
import deleteFollowing from '../../../../services/following/delete';
|
import deleteFollowing from '../../../../services/following/delete';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
|
import { getUser } from '../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
stability: 'stable',
|
stability: 'stable',
|
||||||
|
@ -65,19 +66,11 @@ export default define(meta, async (ps, user) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get followee
|
// Get followee
|
||||||
const followee = await User.findOne({
|
const followee = await getUser(ps.userId).catch(e => {
|
||||||
_id: ps.userId
|
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
|
||||||
}, {
|
throw e;
|
||||||
fields: {
|
|
||||||
data: false,
|
|
||||||
'profile': false
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (followee === null) {
|
|
||||||
throw new ApiError(meta.errors.noSuchUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check not following
|
// Check not following
|
||||||
const exist = await Following.findOne({
|
const exist = await Following.findOne({
|
||||||
followerId: follower._id,
|
followerId: follower._id,
|
||||||
|
|
|
@ -4,6 +4,7 @@ import acceptFollowRequest from '../../../../../services/following/requests/acce
|
||||||
import User from '../../../../../models/user';
|
import User from '../../../../../models/user';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import { ApiError } from '../../../error';
|
import { ApiError } from '../../../error';
|
||||||
|
import { getUser } from '../../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
|
@ -37,14 +38,11 @@ export const meta = {
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
export default define(meta, async (ps, user) => {
|
||||||
// Fetch follower
|
// Fetch follower
|
||||||
const follower = await User.findOne({
|
const follower = await getUser(ps.userId).catch(e => {
|
||||||
_id: ps.userId
|
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);
|
await acceptFollowRequest(user, follower);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -4,6 +4,7 @@ import cancelFollowRequest from '../../../../../services/following/requests/canc
|
||||||
import User, { pack } from '../../../../../models/user';
|
import User, { pack } from '../../../../../models/user';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import { ApiError } from '../../../error';
|
import { ApiError } from '../../../error';
|
||||||
|
import { getUser } from '../../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
|
@ -43,14 +44,11 @@ export const meta = {
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
export default define(meta, async (ps, user) => {
|
||||||
// Fetch followee
|
// Fetch followee
|
||||||
const followee = await User.findOne({
|
const followee = await getUser(ps.userId).catch(e => {
|
||||||
_id: ps.userId
|
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 {
|
try {
|
||||||
await cancelFollowRequest(followee, user);
|
await cancelFollowRequest(followee, user);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import rejectFollowRequest from '../../../../../services/following/requests/reje
|
||||||
import User from '../../../../../models/user';
|
import User from '../../../../../models/user';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import { ApiError } from '../../../error';
|
import { ApiError } from '../../../error';
|
||||||
|
import { getUser } from '../../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
|
@ -37,14 +38,11 @@ export const meta = {
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
export default define(meta, async (ps, user) => {
|
||||||
// Fetch follower
|
// Fetch follower
|
||||||
const follower = await User.findOne({
|
const follower = await getUser(ps.userId).catch(e => {
|
||||||
_id: ps.userId
|
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);
|
await rejectFollowRequest(user, follower);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { publishMainStream, publishReversiStream } from '../../../../../services
|
||||||
import { eighteight } from '../../../../../games/reversi/maps';
|
import { eighteight } from '../../../../../games/reversi/maps';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import { ApiError } from '../../../error';
|
import { ApiError } from '../../../error';
|
||||||
|
import { getUser } from '../../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
requireCredential: true,
|
requireCredential: true,
|
||||||
|
@ -85,18 +86,11 @@ export default define(meta, async (ps, user) => {
|
||||||
return await packGame(game, user);
|
return await packGame(game, user);
|
||||||
} else {
|
} else {
|
||||||
// Fetch child
|
// Fetch child
|
||||||
const child = await User.findOne({
|
const child = await getUser(ps.userId).catch(e => {
|
||||||
_id: ps.userId
|
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
|
||||||
}, {
|
throw e;
|
||||||
fields: {
|
|
||||||
_id: true
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (child === null) {
|
|
||||||
throw new ApiError(meta.errors.noSuchUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 以前のセッションはすべて削除しておく
|
// 以前のセッションはすべて削除しておく
|
||||||
await Matching.remove({
|
await Matching.remove({
|
||||||
parentId: user._id
|
parentId: user._id
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { pack } from '../../../../models/messaging-message';
|
||||||
import read from '../../common/read-messaging-message';
|
import read from '../../common/read-messaging-message';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
|
import { getUser } from '../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
|
@ -59,18 +60,11 @@ export const meta = {
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
export default define(meta, async (ps, user) => {
|
||||||
// Fetch recipient
|
// Fetch recipient
|
||||||
const recipient = await User.findOne({
|
const recipient = await getUser(ps.userId).catch(e => {
|
||||||
_id: ps.userId
|
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
|
||||||
}, {
|
throw e;
|
||||||
fields: {
|
|
||||||
_id: true
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (recipient === null) {
|
|
||||||
throw new ApiError(meta.errors.noSuchUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
$or: [{
|
$or: [{
|
||||||
userId: user._id,
|
userId: user._id,
|
||||||
|
|
|
@ -11,6 +11,7 @@ import { publishMessagingStream, publishMessagingIndexStream } from '../../../..
|
||||||
import pushSw from '../../../../../services/push-notification';
|
import pushSw from '../../../../../services/push-notification';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import { ApiError } from '../../../error';
|
import { ApiError } from '../../../error';
|
||||||
|
import { getUser } from '../../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
|
@ -76,18 +77,11 @@ export default define(meta, async (ps, user) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch recipient
|
// Fetch recipient
|
||||||
const recipient = await User.findOne({
|
const recipient = await getUser(ps.userId).catch(e => {
|
||||||
_id: ps.userId
|
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
|
||||||
}, {
|
throw e;
|
||||||
fields: {
|
|
||||||
_id: true
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (recipient === null) {
|
|
||||||
throw new ApiError(meta.errors.noSuchUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
let file = null;
|
let file = null;
|
||||||
if (ps.fileId != null) {
|
if (ps.fileId != null) {
|
||||||
file = await DriveFile.findOne({
|
file = await DriveFile.findOne({
|
||||||
|
|
|
@ -4,6 +4,7 @@ import User from '../../../../models/user';
|
||||||
import Mute from '../../../../models/mute';
|
import Mute from '../../../../models/mute';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
|
import { getUser } from '../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
|
@ -56,19 +57,11 @@ export default define(meta, async (ps, user) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get mutee
|
// Get mutee
|
||||||
const mutee = await User.findOne({
|
const mutee = await getUser(ps.userId).catch(e => {
|
||||||
_id: ps.userId
|
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
|
||||||
}, {
|
throw e;
|
||||||
fields: {
|
|
||||||
data: false,
|
|
||||||
profile: false
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (mutee === null) {
|
|
||||||
throw new ApiError(meta.errors.noSuchUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if already muting
|
// Check if already muting
|
||||||
const exist = await Mute.findOne({
|
const exist = await Mute.findOne({
|
||||||
muterId: muter._id,
|
muterId: muter._id,
|
||||||
|
|
|
@ -4,6 +4,7 @@ import User from '../../../../models/user';
|
||||||
import Mute from '../../../../models/mute';
|
import Mute from '../../../../models/mute';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
|
import { getUser } from '../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
|
@ -56,19 +57,11 @@ export default define(meta, async (ps, user) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get mutee
|
// Get mutee
|
||||||
const mutee = await User.findOne({
|
const mutee = await getUser(ps.userId).catch(e => {
|
||||||
_id: ps.userId
|
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
|
||||||
}, {
|
throw e;
|
||||||
fields: {
|
|
||||||
data: false,
|
|
||||||
profile: false
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (mutee === null) {
|
|
||||||
throw new ApiError(meta.errors.noSuchUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check not muting
|
// Check not muting
|
||||||
const exist = await Mute.findOne({
|
const exist = await Mute.findOne({
|
||||||
muterId: muter._id,
|
muterId: muter._id,
|
||||||
|
|
|
@ -3,7 +3,7 @@ import ID, { transform } from '../../../../misc/cafy-id';
|
||||||
import Note, { packMany, INote } from '../../../../models/note';
|
import Note, { packMany, INote } from '../../../../models/note';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
import { getValiedNote } from '../../common/getters';
|
import { getNote } from '../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
|
@ -44,7 +44,7 @@ export const meta = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
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);
|
if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,7 +4,7 @@ import deleteNote from '../../../../services/note/delete';
|
||||||
import User from '../../../../models/user';
|
import User from '../../../../models/user';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import * as ms from 'ms';
|
import * as ms from 'ms';
|
||||||
import { getValiedNote } from '../../common/getters';
|
import { getNote } from '../../common/getters';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
|
@ -52,7 +52,7 @@ export const meta = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
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);
|
if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,7 @@ import $ from 'cafy';
|
||||||
import ID, { transform } from '../../../../misc/cafy-id';
|
import ID, { transform } from '../../../../misc/cafy-id';
|
||||||
import Reaction, { pack } from '../../../../models/note-reaction';
|
import Reaction, { pack } from '../../../../models/note-reaction';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import { getValiedNote } from '../../common/getters';
|
import { getNote } from '../../common/getters';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
|
@ -54,7 +54,7 @@ export const meta = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
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);
|
if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,7 +3,7 @@ import ID, { transform } from '../../../../../misc/cafy-id';
|
||||||
import createReaction from '../../../../../services/note/reaction/create';
|
import createReaction from '../../../../../services/note/reaction/create';
|
||||||
import { validateReaction } from '../../../../../models/note-reaction';
|
import { validateReaction } from '../../../../../models/note-reaction';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import { getValiedNote } from '../../../common/getters';
|
import { getNote } from '../../../common/getters';
|
||||||
import { ApiError } from '../../../error';
|
import { ApiError } from '../../../error';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
|
@ -57,7 +57,7 @@ export const meta = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
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);
|
if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,7 +3,7 @@ import ID, { transform } from '../../../../../misc/cafy-id';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import * as ms from 'ms';
|
import * as ms from 'ms';
|
||||||
import deleteReaction from '../../../../../services/note/reaction/delete';
|
import deleteReaction from '../../../../../services/note/reaction/delete';
|
||||||
import { getValiedNote } from '../../../common/getters';
|
import { getNote } from '../../../common/getters';
|
||||||
import { ApiError } from '../../../error';
|
import { ApiError } from '../../../error';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
|
@ -49,7 +49,7 @@ export const meta = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
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);
|
if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,7 @@ import $ from 'cafy';
|
||||||
import ID, { transform } from '../../../../misc/cafy-id';
|
import ID, { transform } from '../../../../misc/cafy-id';
|
||||||
import Note, { packMany } from '../../../../models/note';
|
import Note, { packMany } from '../../../../models/note';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import { getValiedNote } from '../../common/getters';
|
import { getNote } from '../../common/getters';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
|
@ -49,7 +49,7 @@ export const meta = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
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);
|
if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,7 @@ import $ from 'cafy';
|
||||||
import ID, { transform } from '../../../../misc/cafy-id';
|
import ID, { transform } from '../../../../misc/cafy-id';
|
||||||
import { pack } from '../../../../models/note';
|
import { pack } from '../../../../models/note';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import { getValiedNote } from '../../common/getters';
|
import { getNote } from '../../common/getters';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
|
@ -36,7 +36,7 @@ export const meta = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
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);
|
if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,7 @@ import $ from 'cafy';
|
||||||
import ID, { transform } from '../../../../../misc/cafy-id';
|
import ID, { transform } from '../../../../../misc/cafy-id';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import watch from '../../../../../services/note/watch';
|
import watch from '../../../../../services/note/watch';
|
||||||
import { getValiedNote } from '../../../common/getters';
|
import { getNote } from '../../../common/getters';
|
||||||
import { ApiError } from '../../../error';
|
import { ApiError } from '../../../error';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
|
@ -38,7 +38,7 @@ export const meta = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
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);
|
if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,7 @@ import $ from 'cafy';
|
||||||
import ID, { transform } from '../../../../../misc/cafy-id';
|
import ID, { transform } from '../../../../../misc/cafy-id';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import unwatch from '../../../../../services/note/unwatch';
|
import unwatch from '../../../../../services/note/unwatch';
|
||||||
import { getValiedNote } from '../../../common/getters';
|
import { getNote } from '../../../common/getters';
|
||||||
import { ApiError } from '../../../error';
|
import { ApiError } from '../../../error';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
|
@ -38,7 +38,7 @@ export const meta = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
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);
|
if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,6 +6,7 @@ import define from '../../define';
|
||||||
import { maximum } from '../../../../prelude/array';
|
import { maximum } from '../../../../prelude/array';
|
||||||
import { getHideUserIds } from '../../common/get-hide-users';
|
import { getHideUserIds } from '../../common/get-hide-users';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
|
import { getUser } from '../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
requireCredential: false,
|
requireCredential: false,
|
||||||
|
@ -37,18 +38,11 @@ export const meta = {
|
||||||
|
|
||||||
export default define(meta, async (ps, me) => {
|
export default define(meta, async (ps, me) => {
|
||||||
// Lookup user
|
// Lookup user
|
||||||
const user = await User.findOne({
|
const user = await getUser(ps.userId).catch(e => {
|
||||||
_id: ps.userId
|
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
|
||||||
}, {
|
throw e;
|
||||||
fields: {
|
|
||||||
_id: true
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (user === null) {
|
|
||||||
throw new ApiError(meta.errors.noSuchUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch recent notes
|
// Fetch recent notes
|
||||||
const recentNotes = await Note.find({
|
const recentNotes = await Note.find({
|
||||||
userId: user._id,
|
userId: user._id,
|
||||||
|
|
|
@ -5,6 +5,7 @@ import User, { pack as packUser } from '../../../../../models/user';
|
||||||
import { publishUserListStream } from '../../../../../services/stream';
|
import { publishUserListStream } from '../../../../../services/stream';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import { ApiError } from '../../../error';
|
import { ApiError } from '../../../error';
|
||||||
|
import { getUser } from '../../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
|
@ -59,14 +60,11 @@ export default define(meta, async (ps, me) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the user
|
// Fetch the user
|
||||||
const user = await User.findOne({
|
const user = await getUser(ps.userId).catch(e => {
|
||||||
_id: ps.userId
|
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
|
// Pull the user
|
||||||
await UserList.update({ _id: userList._id }, {
|
await UserList.update({ _id: userList._id }, {
|
||||||
$pull: {
|
$pull: {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import renderFollow from '../../../../../remote/activitypub/renderer/follow';
|
||||||
import { deliver } from '../../../../../queue';
|
import { deliver } from '../../../../../queue';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import { ApiError } from '../../../error';
|
import { ApiError } from '../../../error';
|
||||||
|
import { getUser } from '../../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
|
@ -68,14 +69,11 @@ export default define(meta, async (ps, me) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the user
|
// Fetch the user
|
||||||
const user = await User.findOne({
|
const user = await getUser(ps.userId).catch(e => {
|
||||||
_id: ps.userId
|
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())) {
|
if (userList.userIds.map(id => id.toHexString()).includes(user._id.toHexString())) {
|
||||||
throw new ApiError(meta.errors.alreadyAdded);
|
throw new ApiError(meta.errors.alreadyAdded);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import User from '../../../../models/user';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import Following from '../../../../models/following';
|
import Following from '../../../../models/following';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
|
import { getUser } from '../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
|
@ -135,16 +136,11 @@ export const meta = {
|
||||||
|
|
||||||
export default define(meta, async (ps, me) => {
|
export default define(meta, async (ps, me) => {
|
||||||
// Lookup user
|
// Lookup user
|
||||||
const user = await User.findOne({ _id: ps.userId }, {
|
const user = await getUser(ps.userId).catch(e => {
|
||||||
fields: {
|
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
|
||||||
_id: true
|
throw e;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (user === null) {
|
|
||||||
throw new ApiError(meta.errors.noSuchUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
const isFollowing = me == null ? false : ((await Following.findOne({
|
const isFollowing = me == null ? false : ((await Following.findOne({
|
||||||
followerId: me._id,
|
followerId: me._id,
|
||||||
followeeId: user._id
|
followeeId: user._id
|
||||||
|
|
|
@ -5,6 +5,7 @@ import User from '../../../../models/user';
|
||||||
import AbuseUserReport from '../../../../models/abuse-user-report';
|
import AbuseUserReport from '../../../../models/abuse-user-report';
|
||||||
import { publishAdminStream } from '../../../../services/stream';
|
import { publishAdminStream } from '../../../../services/stream';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
|
import { getUser } from '../../common/getters';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
|
@ -54,14 +55,11 @@ export const meta = {
|
||||||
|
|
||||||
export default define(meta, async (ps, me) => {
|
export default define(meta, async (ps, me) => {
|
||||||
// Lookup user
|
// Lookup user
|
||||||
const user = await User.findOne({
|
const user = await getUser(ps.userId).catch(e => {
|
||||||
_id: ps.userId
|
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)) {
|
if (user._id.equals(me._id)) {
|
||||||
throw new ApiError(meta.errors.cannotReportYourself);
|
throw new ApiError(meta.errors.cannotReportYourself);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue