refactor: migrate to typeorm 3.0 (#8443)
* wip * wip * wip * Update following.ts * wip * wip * wip * Update resolve-user.ts * maxQueryExecutionTime * wip * wip
This commit is contained in:
parent
41c87074e6
commit
1c67c26bd8
325 changed files with 1314 additions and 1494 deletions
|
|
@ -43,11 +43,11 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||
throw e;
|
||||
});
|
||||
|
||||
const clipNotes = await ClipNotes.find({
|
||||
const clipNotes = await ClipNotes.findBy({
|
||||
noteId: note.id,
|
||||
});
|
||||
|
||||
const clips = await Clips.find({
|
||||
const clips = await Clips.findBy({
|
||||
id: In(clipNotes.map(x => x.clipId)),
|
||||
isPublic: true,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
|
||||
async function get(id: any) {
|
||||
i++;
|
||||
const p = await Notes.findOne(id);
|
||||
const p = await Notes.findOneBy({ id });
|
||||
if (p == null) return;
|
||||
|
||||
if (i > ps.offset!) {
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ export const paramDef = {
|
|||
export default define(meta, paramDef, async (ps, user) => {
|
||||
let visibleUsers: User[] = [];
|
||||
if (ps.visibleUserIds) {
|
||||
visibleUsers = (await Promise.all(ps.visibleUserIds.map(id => Users.findOne(id))))
|
||||
visibleUsers = (await Promise.all(ps.visibleUserIds.map(id => Users.findOneBy({ id }))))
|
||||
.filter(x => x != null) as User[];
|
||||
}
|
||||
|
||||
|
|
@ -138,17 +138,17 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
const fileIds = ps.fileIds != null ? ps.fileIds : ps.mediaIds != null ? ps.mediaIds : null;
|
||||
if (fileIds != null) {
|
||||
files = (await Promise.all(fileIds.map(fileId =>
|
||||
DriveFiles.findOne({
|
||||
DriveFiles.findOneBy({
|
||||
id: fileId,
|
||||
userId: user.id,
|
||||
})
|
||||
))).filter(file => file != null) as DriveFile[];
|
||||
}
|
||||
|
||||
let renote: Note | undefined;
|
||||
let renote: Note | null;
|
||||
if (ps.renoteId != null) {
|
||||
// Fetch renote to note
|
||||
renote = await Notes.findOne(ps.renoteId);
|
||||
renote = await Notes.findOneBy({ id: ps.renoteId });
|
||||
|
||||
if (renote == null) {
|
||||
throw new ApiError(meta.errors.noSuchRenoteTarget);
|
||||
|
|
@ -158,7 +158,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
|
||||
// Check blocking
|
||||
if (renote.userId !== user.id) {
|
||||
const block = await Blockings.findOne({
|
||||
const block = await Blockings.findOneBy({
|
||||
blockerId: renote.userId,
|
||||
blockeeId: user.id,
|
||||
});
|
||||
|
|
@ -168,10 +168,10 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
}
|
||||
}
|
||||
|
||||
let reply: Note | undefined;
|
||||
let reply: Note | null;
|
||||
if (ps.replyId != null) {
|
||||
// Fetch reply
|
||||
reply = await Notes.findOne(ps.replyId);
|
||||
reply = await Notes.findOneBy({ id: ps.replyId });
|
||||
|
||||
if (reply == null) {
|
||||
throw new ApiError(meta.errors.noSuchReplyTarget);
|
||||
|
|
@ -184,7 +184,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
|
||||
// Check blocking
|
||||
if (reply.userId !== user.id) {
|
||||
const block = await Blockings.findOne({
|
||||
const block = await Blockings.findOneBy({
|
||||
blockerId: reply.userId,
|
||||
blockeeId: user.id,
|
||||
});
|
||||
|
|
@ -211,7 +211,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
|
||||
let channel: Channel | undefined;
|
||||
if (ps.channelId != null) {
|
||||
channel = await Channels.findOne(ps.channelId);
|
||||
channel = await Channels.findOneBy({ id: ps.channelId });
|
||||
|
||||
if (channel == null) {
|
||||
throw new ApiError(meta.errors.noSuchChannel);
|
||||
|
|
|
|||
|
|
@ -53,5 +53,5 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
}
|
||||
|
||||
// この操作を行うのが投稿者とは限らない(例えばモデレーター)ため
|
||||
await deleteNote(await Users.findOneOrFail(note.userId), note);
|
||||
await deleteNote(await Users.findOneByOrFail({ id: note.userId }), note);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
});
|
||||
|
||||
// if already favorited
|
||||
const exist = await NoteFavorites.findOne({
|
||||
const exist = await NoteFavorites.findOneBy({
|
||||
noteId: note.id,
|
||||
userId: user.id,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
});
|
||||
|
||||
// if already favorited
|
||||
const exist = await NoteFavorites.findOne({
|
||||
const exist = await NoteFavorites.findOneBy({
|
||||
noteId: note.id,
|
||||
userId: user.id,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
|
||||
if (polls.length === 0) return [];
|
||||
|
||||
const notes = await Notes.find({
|
||||
const notes = await Notes.findBy({
|
||||
id: In(polls.map(poll => poll.noteId)),
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
|
||||
// Check blocking
|
||||
if (note.userId !== user.id) {
|
||||
const block = await Blockings.findOne({
|
||||
const block = await Blockings.findOneBy({
|
||||
blockerId: note.userId,
|
||||
blockeeId: user.id,
|
||||
});
|
||||
|
|
@ -92,7 +92,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
}
|
||||
}
|
||||
|
||||
const poll = await Polls.findOneOrFail({ noteId: note.id });
|
||||
const poll = await Polls.findOneByOrFail({ noteId: note.id });
|
||||
|
||||
if (poll.expiresAt && poll.expiresAt < createdAt) {
|
||||
throw new ApiError(meta.errors.alreadyExpired);
|
||||
|
|
@ -103,7 +103,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
}
|
||||
|
||||
// if already voted
|
||||
const exist = await PollVotes.find({
|
||||
const exist = await PollVotes.findBy({
|
||||
noteId: note.id,
|
||||
userId: user.id,
|
||||
});
|
||||
|
|
@ -125,7 +125,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
noteId: note.id,
|
||||
userId: user.id,
|
||||
choice: ps.choice,
|
||||
}).then(x => PollVotes.findOneOrFail(x.identifiers[0]));
|
||||
}).then(x => PollVotes.findOneByOrFail(x.identifiers[0]));
|
||||
|
||||
// Increment votes count
|
||||
const index = ps.choice + 1; // In SQL, array index is 1 based
|
||||
|
|
@ -144,7 +144,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
});
|
||||
|
||||
// Fetch watchers
|
||||
NoteWatchings.find({
|
||||
NoteWatchings.findBy({
|
||||
noteId: note.id,
|
||||
userId: Not(user.id),
|
||||
}).then(watchers => {
|
||||
|
|
@ -159,7 +159,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
|
||||
// リモート投票の場合リプライ送信
|
||||
if (note.userHost != null) {
|
||||
const pollOwner = await Users.findOneOrFail(note.userId) as IRemoteUser;
|
||||
const pollOwner = await Users.findOneByOrFail({ id: note.userId }) as IRemoteUser;
|
||||
|
||||
deliver(user, renderActivity(await renderVote(user, vote, note, poll, pollOwner)), pollOwner.inbox);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ export const paramDef = {
|
|||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const note = await Notes.findOneOrFail(ps.noteId);
|
||||
const note = await Notes.findOneByOrFail({ id: ps.noteId });
|
||||
|
||||
const [favorite, watching, threadMuting] = await Promise.all([
|
||||
NoteFavorites.count({
|
||||
|
|
|
|||
|
|
@ -42,12 +42,12 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
throw e;
|
||||
});
|
||||
|
||||
const renotes = await Notes.find({
|
||||
const renotes = await Notes.findBy({
|
||||
userId: user.id,
|
||||
renoteId: note.id,
|
||||
});
|
||||
|
||||
for (const note of renotes) {
|
||||
deleteNote(await Users.findOneOrFail(user.id), note);
|
||||
deleteNote(await Users.findOneByOrFail({ id: user.id }), note);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ export const paramDef = {
|
|||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const list = await UserLists.findOne({
|
||||
const list = await UserLists.findOneBy({
|
||||
id: ps.listId,
|
||||
userId: user.id,
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue