fix (backend): replace deprecated exist
method
This commit is contained in:
parent
c64119108e
commit
071ba83704
25 changed files with 99 additions and 146 deletions
|
@ -68,12 +68,10 @@ export async function readUserMessagingMessage(
|
|||
await sendPushNotification(userId, PushNotificationKind.ReadAllChats, {});
|
||||
} else {
|
||||
// そのユーザーとのメッセージで未読がなければイベント発行
|
||||
const hasUnread = await MessagingMessages.exists({
|
||||
where: {
|
||||
userId: otherpartyId,
|
||||
recipientId: userId,
|
||||
isRead: false,
|
||||
},
|
||||
const hasUnread = await MessagingMessages.existsBy({
|
||||
userId: otherpartyId,
|
||||
recipientId: userId,
|
||||
isRead: false,
|
||||
});
|
||||
|
||||
if (!hasUnread) {
|
||||
|
|
|
@ -40,9 +40,9 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
throw err;
|
||||
});
|
||||
|
||||
const exist = await PromoNotes.exist({ where: { noteId: note.id } });
|
||||
const exists = await PromoNotes.existsBy({ noteId: note.id });
|
||||
|
||||
if (exist) {
|
||||
if (exists) {
|
||||
throw new ApiError(meta.errors.alreadyPromoted);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import * as crypto from "node:crypto";
|
|||
import define from "@/server/api/define.js";
|
||||
import { ApiError } from "@/server/api/error.js";
|
||||
import { AuthSessions, AccessTokens, Apps } from "@/models/index.js";
|
||||
import { genId, generateSecureRandomString } from "backend-rs";
|
||||
import { genIdAt, generateSecureRandomString } from "backend-rs";
|
||||
|
||||
export const meta = {
|
||||
tags: ["auth"],
|
||||
|
@ -40,14 +40,12 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
const accessToken = generateSecureRandomString(32);
|
||||
|
||||
// Fetch exist access token
|
||||
const exist = await AccessTokens.exists({
|
||||
where: {
|
||||
appId: session.appId,
|
||||
userId: user.id,
|
||||
},
|
||||
const exists = await AccessTokens.existsBy({
|
||||
appId: session.appId,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
if (!exist) {
|
||||
if (!exists) {
|
||||
// Lookup app
|
||||
const app = await Apps.findOneByOrFail({ id: session.appId });
|
||||
|
||||
|
@ -60,7 +58,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
|
||||
// Insert access token doc
|
||||
await AccessTokens.insert({
|
||||
id: genId(),
|
||||
id: genIdAt(now),
|
||||
createdAt: now,
|
||||
lastUsedAt: now,
|
||||
appId: session.appId,
|
||||
|
|
|
@ -69,14 +69,12 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
});
|
||||
|
||||
// Check if already blocking
|
||||
const exist = await Blockings.exist({
|
||||
where: {
|
||||
blockerId: blocker.id,
|
||||
blockeeId: blockee.id,
|
||||
},
|
||||
const exists = await Blockings.existsBy({
|
||||
blockerId: blocker.id,
|
||||
blockeeId: blockee.id,
|
||||
});
|
||||
|
||||
if (exist) {
|
||||
if (exists) {
|
||||
throw new ApiError(meta.errors.alreadyBlocking);
|
||||
}
|
||||
|
||||
|
|
|
@ -69,14 +69,12 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
});
|
||||
|
||||
// Check not blocking
|
||||
const exist = await Blockings.exist({
|
||||
where: {
|
||||
blockerId: blocker.id,
|
||||
blockeeId: blockee.id,
|
||||
},
|
||||
const exists = await Blockings.existsBy({
|
||||
blockerId: blocker.id,
|
||||
blockeeId: blockee.id,
|
||||
});
|
||||
|
||||
if (!exist) {
|
||||
if (!exists) {
|
||||
throw new ApiError(meta.errors.notBlocking);
|
||||
}
|
||||
|
||||
|
|
|
@ -57,14 +57,12 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
throw err;
|
||||
});
|
||||
|
||||
const exist = await ClipNotes.exist({
|
||||
where: {
|
||||
noteId: note.id,
|
||||
clipId: clip.id,
|
||||
},
|
||||
const exists = await ClipNotes.existsBy({
|
||||
noteId: note.id,
|
||||
clipId: clip.id,
|
||||
});
|
||||
|
||||
if (exist) {
|
||||
if (exists) {
|
||||
throw new ApiError(meta.errors.alreadyClipped);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,12 +26,8 @@ export const paramDef = {
|
|||
} as const;
|
||||
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const exist = await DriveFiles.exist({
|
||||
where: {
|
||||
md5: ps.md5,
|
||||
userId: user.id,
|
||||
},
|
||||
return await DriveFiles.existsBy({
|
||||
md5: ps.md5,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
return exist;
|
||||
});
|
||||
|
|
|
@ -82,14 +82,12 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
});
|
||||
|
||||
// Check if already following
|
||||
const exist = await Followings.exist({
|
||||
where: {
|
||||
followerId: follower.id,
|
||||
followeeId: followee.id,
|
||||
},
|
||||
const exists = await Followings.existsBy({
|
||||
followerId: follower.id,
|
||||
followeeId: followee.id,
|
||||
});
|
||||
|
||||
if (exist) {
|
||||
if (exists) {
|
||||
throw new ApiError(meta.errors.alreadyFollowing);
|
||||
}
|
||||
|
||||
|
|
|
@ -69,14 +69,12 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
});
|
||||
|
||||
// Check not following
|
||||
const exist = await Followings.exist({
|
||||
where: {
|
||||
followerId: follower.id,
|
||||
followeeId: followee.id,
|
||||
},
|
||||
const exists = await Followings.existsBy({
|
||||
followerId: follower.id,
|
||||
followeeId: followee.id,
|
||||
});
|
||||
|
||||
if (!exist) {
|
||||
if (!exists) {
|
||||
throw new ApiError(meta.errors.notFollowing);
|
||||
}
|
||||
|
||||
|
|
|
@ -69,14 +69,12 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
});
|
||||
|
||||
// Check not following
|
||||
const exist = await Followings.exist({
|
||||
where: {
|
||||
followerId: follower.id,
|
||||
followeeId: followee.id,
|
||||
},
|
||||
const exists = await Followings.existsBy({
|
||||
followerId: follower.id,
|
||||
followeeId: followee.id,
|
||||
});
|
||||
|
||||
if (!exist) {
|
||||
if (!exists) {
|
||||
throw new ApiError(meta.errors.notFollowing);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,14 +40,12 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
}
|
||||
|
||||
// if already liked
|
||||
const exist = await GalleryLikes.exist({
|
||||
where: {
|
||||
postId: post.id,
|
||||
userId: user.id,
|
||||
},
|
||||
const exists = await GalleryLikes.existsBy({
|
||||
postId: post.id,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
if (exist) {
|
||||
if (exists) {
|
||||
throw new ApiError(meta.errors.alreadyLiked);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,20 +30,18 @@ export const paramDef = {
|
|||
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
// Check if announcement exists
|
||||
const exist = await Announcements.exist({
|
||||
where: { id: ps.announcementId },
|
||||
const exists = await Announcements.existsBy({
|
||||
id: ps.announcementId,
|
||||
});
|
||||
|
||||
if (!exist) {
|
||||
if (!exists) {
|
||||
throw new ApiError(meta.errors.noSuchAnnouncement);
|
||||
}
|
||||
|
||||
// Check if already read
|
||||
const read = await AnnouncementReads.exist({
|
||||
where: {
|
||||
announcementId: ps.announcementId,
|
||||
userId: user.id,
|
||||
},
|
||||
const read = await AnnouncementReads.existsBy({
|
||||
announcementId: ps.announcementId,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
if (read) {
|
||||
|
|
|
@ -17,9 +17,9 @@ export const paramDef = {
|
|||
} as const;
|
||||
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const exist = await AccessTokens.exist({ where: { id: ps.tokenId } });
|
||||
const exists = await AccessTokens.existsBy({ id: ps.tokenId });
|
||||
|
||||
if (exist) {
|
||||
if (exists) {
|
||||
await AccessTokens.delete({
|
||||
id: ps.tokenId,
|
||||
userId: user.id,
|
||||
|
|
|
@ -64,14 +64,12 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
});
|
||||
|
||||
// Check if already muting
|
||||
const exist = await Mutings.exist({
|
||||
where: {
|
||||
muterId: muter.id,
|
||||
muteeId: mutee.id,
|
||||
},
|
||||
const exists = await Mutings.existsBy({
|
||||
muterId: muter.id,
|
||||
muteeId: mutee.id,
|
||||
});
|
||||
|
||||
if (exist) {
|
||||
if (exists) {
|
||||
throw new ApiError(meta.errors.alreadyMuting);
|
||||
}
|
||||
|
||||
|
|
|
@ -233,11 +233,9 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
|
||||
// Check blocking
|
||||
if (renote.userId !== user.id) {
|
||||
const isBlocked = await Blockings.exists({
|
||||
where: {
|
||||
blockerId: renote.userId,
|
||||
blockeeId: user.id,
|
||||
},
|
||||
const isBlocked = await Blockings.existsBy({
|
||||
blockerId: renote.userId,
|
||||
blockeeId: user.id,
|
||||
});
|
||||
if (isBlocked) {
|
||||
throw new ApiError(meta.errors.youHaveBeenBlocked);
|
||||
|
@ -260,11 +258,9 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
|
||||
// Check blocking
|
||||
if (reply.userId !== user.id) {
|
||||
const isBlocked = await Blockings.exists({
|
||||
where: {
|
||||
blockerId: reply.userId,
|
||||
blockeeId: user.id,
|
||||
},
|
||||
const isBlocked = await Blockings.existsBy({
|
||||
blockerId: reply.userId,
|
||||
blockeeId: user.id,
|
||||
});
|
||||
if (isBlocked) {
|
||||
throw new ApiError(meta.errors.youHaveBeenBlocked);
|
||||
|
|
|
@ -43,14 +43,12 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
});
|
||||
|
||||
// if already favorited
|
||||
const exist = await NoteFavorites.exist({
|
||||
where: {
|
||||
noteId: note.id,
|
||||
userId: user.id,
|
||||
},
|
||||
const exists = await NoteFavorites.existsBy({
|
||||
noteId: note.id,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
if (exist) {
|
||||
if (exists) {
|
||||
throw new ApiError(meta.errors.alreadyFavorited);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,14 +40,12 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
}
|
||||
|
||||
// if already liked
|
||||
const exist = await PageLikes.exist({
|
||||
where: {
|
||||
pageId: page.id,
|
||||
userId: user.id,
|
||||
},
|
||||
const exists = await PageLikes.existsBy({
|
||||
pageId: page.id,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
if (exist) {
|
||||
if (exists) {
|
||||
throw new ApiError(meta.errors.alreadyLiked);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,14 +33,12 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
throw err;
|
||||
});
|
||||
|
||||
const exist = await PromoReads.exist({
|
||||
where: {
|
||||
noteId: note.id,
|
||||
userId: user.id,
|
||||
},
|
||||
const exists = await PromoReads.existsBy({
|
||||
noteId: note.id,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
if (exist) {
|
||||
if (exists) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,14 +47,12 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
});
|
||||
|
||||
// Check if already muting
|
||||
const exist = await RenoteMutings.exist({
|
||||
where: {
|
||||
muterId: muter.id,
|
||||
muteeId: mutee.id,
|
||||
},
|
||||
const exists = await RenoteMutings.existsBy({
|
||||
muterId: muter.id,
|
||||
muteeId: mutee.id,
|
||||
});
|
||||
|
||||
if (exist) {
|
||||
if (exists) {
|
||||
throw new ApiError(meta.errors.alreadyMuting);
|
||||
}
|
||||
|
||||
|
|
|
@ -103,11 +103,9 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||
if (me == null) {
|
||||
throw new ApiError(meta.errors.forbidden);
|
||||
} else if (me.id !== user.id) {
|
||||
const isFollowed = await Followings.exist({
|
||||
where: {
|
||||
followeeId: user.id,
|
||||
followerId: me.id,
|
||||
},
|
||||
const isFollowed = await Followings.existsBy({
|
||||
followeeId: user.id,
|
||||
followerId: me.id,
|
||||
});
|
||||
if (!isFollowed) {
|
||||
throw new ApiError(meta.errors.nullFollowers);
|
||||
|
|
|
@ -102,11 +102,9 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||
if (me == null) {
|
||||
throw new ApiError(meta.errors.forbidden);
|
||||
} else if (me.id !== user.id) {
|
||||
const isFollowing = await Followings.exist({
|
||||
where: {
|
||||
followeeId: user.id,
|
||||
followerId: me.id,
|
||||
},
|
||||
const isFollowing = await Followings.existsBy({
|
||||
followeeId: user.id,
|
||||
followerId: me.id,
|
||||
});
|
||||
if (!isFollowing) {
|
||||
throw new ApiError(meta.errors.cannot_find);
|
||||
|
|
|
@ -70,25 +70,21 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||
|
||||
// Check blocking
|
||||
if (user.id !== me.id) {
|
||||
const isBlocked = await Blockings.exist({
|
||||
where: {
|
||||
blockerId: user.id,
|
||||
blockeeId: me.id,
|
||||
},
|
||||
const isBlocked = await Blockings.existsBy({
|
||||
blockerId: user.id,
|
||||
blockeeId: me.id,
|
||||
});
|
||||
if (isBlocked) {
|
||||
throw new ApiError(meta.errors.youHaveBeenBlocked);
|
||||
}
|
||||
}
|
||||
|
||||
const exist = await UserListJoinings.exist({
|
||||
where: {
|
||||
userListId: ps.listId,
|
||||
userId: user.id,
|
||||
},
|
||||
const exists = await UserListJoinings.existsBy({
|
||||
userListId: ps.listId,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
if (exist) {
|
||||
if (exists) {
|
||||
throw new ApiError(meta.errors.alreadyAdded);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,13 +22,11 @@ export default class extends Channel {
|
|||
this.listId = params.listId as string;
|
||||
|
||||
// Check existence and owner
|
||||
const exist = await UserLists.exists({
|
||||
where: {
|
||||
id: this.listId,
|
||||
userId: this.user!.id,
|
||||
},
|
||||
const exists = await UserLists.existsBy({
|
||||
id: this.listId,
|
||||
userId: this.user!.id,
|
||||
});
|
||||
if (!exist) return;
|
||||
if (!exists) return;
|
||||
|
||||
// Subscribe stream
|
||||
this.subscriber.on(`userListStream:${this.listId}`, this.send);
|
||||
|
|
|
@ -39,8 +39,9 @@ export async function createNotification(
|
|||
(notifier.isSilenced ||
|
||||
(Users.isRemoteUser(notifier) &&
|
||||
(await isSilencedServer(notifier.host)))) &&
|
||||
!(await Followings.exists({
|
||||
where: { followerId: notifieeId, followeeId: data.notifierId },
|
||||
!(await Followings.existsBy({
|
||||
followerId: notifieeId,
|
||||
followeeId: data.notifierId,
|
||||
}))
|
||||
)
|
||||
return null;
|
||||
|
|
|
@ -42,9 +42,9 @@ export async function insertNoteUnread(
|
|||
|
||||
// 2秒経っても既読にならなかったら「未読の投稿がありますよ」イベントを発行する
|
||||
setTimeout(async () => {
|
||||
const exist = await NoteUnreads.exist({ where: { id: unread.id } });
|
||||
const exists = await NoteUnreads.existsBy({ id: unread.id });
|
||||
|
||||
if (!exist) return;
|
||||
if (!exists) return;
|
||||
|
||||
if (params.isMentioned) {
|
||||
publishMainStream(userId, "unreadMention", note.id);
|
||||
|
|
Loading…
Reference in a new issue