fix (backend): replace deprecated exist method

This commit is contained in:
naskya 2024-06-02 07:23:07 +09:00
parent c64119108e
commit 071ba83704
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
25 changed files with 99 additions and 146 deletions

View file

@ -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) {

View file

@ -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);
}

View file

@ -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,

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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;
});

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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) {

View file

@ -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,

View file

@ -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);
}

View file

@ -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);

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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);
}

View file

@ -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);

View file

@ -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);

View file

@ -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);
}

View file

@ -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);

View file

@ -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;

View file

@ -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);