server: fix custom lint typeorm-prefer-count

This commit is contained in:
Johann150 2023-01-03 02:42:42 +01:00
parent b54e07caec
commit 417d252e9d
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
14 changed files with 28 additions and 30 deletions

View file

@ -25,9 +25,9 @@ export default async function renderNote(note: Note, dive = true, isTalk = false
inReplyToNote = await Notes.findOneBy({ id: note.replyId }); inReplyToNote = await Notes.findOneBy({ id: note.replyId });
if (inReplyToNote != null) { if (inReplyToNote != null) {
const inReplyToUser = await Users.findOneBy({ id: inReplyToNote.userId }); const inReplyToUserExists = await Users.countBy({ id: inReplyToNote.userId });
if (inReplyToUser != null) { if (!inReplyToUserExists) {
if (inReplyToNote.uri) { if (inReplyToNote.uri) {
inReplyTo = inReplyToNote.uri; inReplyTo = inReplyToNote.uri;
} else { } else {

View file

@ -48,12 +48,12 @@ export default define(meta, paramDef, async (ps, user) => {
}); });
// Check if already blocking // Check if already blocking
const exist = await Blockings.findOneBy({ const blocked = await Blockings.countBy({
blockerId: blocker.id, blockerId: blocker.id,
blockeeId: blockee.id, blockeeId: blockee.id,
}); });
if (exist != null) throw new ApiError('ALREADY_BLOCKING'); if (blocked) throw new ApiError('ALREADY_BLOCKING');
await create(blocker, blockee); await create(blocker, blockee);

View file

@ -37,12 +37,12 @@ export default define(meta, paramDef, async (ps, user) => {
throw err; throw err;
}); });
const exist = await ClipNotes.findOneBy({ const exist = await ClipNotes.countBy({
noteId: note.id, noteId: note.id,
clipId: clip.id, clipId: clip.id,
}); });
if (exist != null) throw new ApiError('ALREADY_CLIPPED'); if (exist) throw new ApiError('ALREADY_CLIPPED');
await ClipNotes.insert({ await ClipNotes.insert({
id: genId(), id: genId(),

View file

@ -26,10 +26,8 @@ export const paramDef = {
// eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, user) => { export default define(meta, paramDef, async (ps, user) => {
const file = await DriveFiles.findOneBy({ return 0 < await DriveFiles.countBy({
md5: ps.md5, md5: ps.md5,
userId: user.id, userId: user.id,
}); });
return file != null;
}); });

View file

@ -49,12 +49,12 @@ export default define(meta, paramDef, async (ps, user) => {
}); });
// Check if already following // Check if already following
const exist = await Followings.findOneBy({ const exist = await Followings.countBy({
followerId: follower.id, followerId: follower.id,
followeeId: followee.id, followeeId: followee.id,
}); });
if (exist != null) throw new ApiError('ALREADY_FOLLOWING'); if (exist) throw new ApiError('ALREADY_FOLLOWING');
try { try {
await create(follower, followee); await create(follower, followee);

View file

@ -27,12 +27,12 @@ export default define(meta, paramDef, async (ps, user) => {
if (post == null) throw new ApiError('NO_SUCH_POST'); if (post == null) throw new ApiError('NO_SUCH_POST');
// if already liked // if already liked
const exist = await GalleryLikes.findOneBy({ const exist = await GalleryLikes.countBy({
postId: post.id, postId: post.id,
userId: user.id, userId: user.id,
}); });
if (exist != null) throw new ApiError('ALREADY_LIKED'); if (exist) throw new ApiError('ALREADY_LIKED');
// Create like // Create like
await GalleryLikes.insert({ await GalleryLikes.insert({

View file

@ -30,12 +30,12 @@ export default define(meta, paramDef, async (ps, user) => {
if (!exists) throw new ApiError('NO_SUCH_ANNOUNCEMENT'); if (!exists) throw new ApiError('NO_SUCH_ANNOUNCEMENT');
// Check if already read // Check if already read
const read = await AnnouncementReads.findOneBy({ const read = await AnnouncementReads.countBy({
announcementId: ps.announcementId, announcementId: ps.announcementId,
userId: user.id, userId: user.id,
}); });
if (read != null) return; if (read) return;
// Create read // Create read
await AnnouncementReads.insert({ await AnnouncementReads.insert({

View file

@ -43,12 +43,12 @@ export default define(meta, paramDef, async (ps, user) => {
}); });
// Check if already muting // Check if already muting
const exist = await Mutings.findOneBy({ const exist = await Mutings.countBy({
muterId: muter.id, muterId: muter.id,
muteeId: mutee.id, muteeId: mutee.id,
}); });
if (exist != null) throw new ApiError('ALREADY_MUTING'); if (exist) throw new ApiError('ALREADY_MUTING');
if (ps.expiresAt && ps.expiresAt <= Date.now()) { if (ps.expiresAt && ps.expiresAt <= Date.now()) {
return; return;

View file

@ -31,12 +31,12 @@ export default define(meta, paramDef, async (ps, user) => {
}); });
// if already favorited // if already favorited
const exist = await NoteFavorites.findOneBy({ const exist = await NoteFavorites.countBy({
noteId: note.id, noteId: note.id,
userId: user.id, userId: user.id,
}); });
if (exist != null) throw new ApiError('ALREADY_FAVORITED'); if (exist) throw new ApiError('ALREADY_FAVORITED');
// Create favorite // Create favorite
await NoteFavorites.insert({ await NoteFavorites.insert({

View file

@ -27,12 +27,12 @@ export default define(meta, paramDef, async (ps, user) => {
if (page == null) throw new ApiError('NO_SUCH_PAGE'); if (page == null) throw new ApiError('NO_SUCH_PAGE');
// if already liked // if already liked
const exist = await PageLikes.findOneBy({ const exist = await PageLikes.countBy({
pageId: page.id, pageId: page.id,
userId: user.id, userId: user.id,
}); });
if (exist != null) throw new ApiError('ALREADY_LIKED'); if (exist) throw new ApiError('ALREADY_LIKED');
// Create like // Create like
await PageLikes.insert({ await PageLikes.insert({

View file

@ -38,12 +38,12 @@ export default define(meta, paramDef, async (ps, user) => {
}); });
// Check if already muting // Check if already muting
const exist = await RenoteMutings.findOneBy({ const exist = await RenoteMutings.countBy({
muterId: muter.id, muterId: muter.id,
muteeId: mutee.id, muteeId: mutee.id,
}); });
if (exist != null) throw new ApiError('ALREADY_MUTING'); if (exist) throw new ApiError('ALREADY_MUTING');
// Create mute // Create mute
await RenoteMutings.insert({ await RenoteMutings.insert({

View file

@ -40,7 +40,7 @@ export const paramDef = {
// eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, user) => { export default define(meta, paramDef, async (ps, user) => {
// if already subscribed // if already subscribed
const exist = await SwSubscriptions.findOneBy({ const exist = await SwSubscriptions.countBy({
userId: user.id, userId: user.id,
endpoint: ps.endpoint, endpoint: ps.endpoint,
auth: ps.auth, auth: ps.auth,
@ -49,7 +49,7 @@ export default define(meta, paramDef, async (ps, user) => {
const instance = await fetchMeta(true); const instance = await fetchMeta(true);
if (exist != null) { if (exist) {
return { return {
state: 'already-subscribed' as const, state: 'already-subscribed' as const,
key: instance.swPublicKey, key: instance.swPublicKey,

View file

@ -46,7 +46,7 @@ export async function addNoteToAntenna(antenna: Antenna, note: Note, noteUser: {
// Notify if not read after 2 seconds // Notify if not read after 2 seconds
setTimeout(async () => { setTimeout(async () => {
const unread = await AntennaNotes.findOneBy({ antennaId: antenna.id, read: false }); const unread = await AntennaNotes.countBy({ antennaId: antenna.id, read: false });
if (unread) { if (unread) {
publishMainStream(antenna.userId, 'unreadAntenna', antenna); publishMainStream(antenna.userId, 'unreadAntenna', antenna);
} }

View file

@ -18,18 +18,18 @@ export async function createFollowRequest(follower: User, followee: User, reques
// check blocking // check blocking
const [blocking, blocked] = await Promise.all([ const [blocking, blocked] = await Promise.all([
Blockings.findOneBy({ Blockings.countBy({
blockerId: follower.id, blockerId: follower.id,
blockeeId: followee.id, blockeeId: followee.id,
}), }),
Blockings.findOneBy({ Blockings.countBy({
blockerId: followee.id, blockerId: followee.id,
blockeeId: follower.id, blockeeId: follower.id,
}), }),
]); ]);
if (blocking != null) throw new Error('blocking'); if (blocking) throw new Error('blocking');
if (blocked != null) throw new Error('blocked'); if (blocked) throw new Error('blocked');
const followRequest = await FollowRequests.insert({ const followRequest = await FollowRequests.insert({
id: genId(), id: genId(),