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 });
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) {
inReplyTo = inReplyToNote.uri;
} else {

View file

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

View file

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

View file

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

View file

@ -49,12 +49,12 @@ export default define(meta, paramDef, async (ps, user) => {
});
// Check if already following
const exist = await Followings.findOneBy({
const exist = await Followings.countBy({
followerId: follower.id,
followeeId: followee.id,
});
if (exist != null) throw new ApiError('ALREADY_FOLLOWING');
if (exist) throw new ApiError('ALREADY_FOLLOWING');
try {
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 already liked
const exist = await GalleryLikes.findOneBy({
const exist = await GalleryLikes.countBy({
postId: post.id,
userId: user.id,
});
if (exist != null) throw new ApiError('ALREADY_LIKED');
if (exist) throw new ApiError('ALREADY_LIKED');
// Create like
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');
// Check if already read
const read = await AnnouncementReads.findOneBy({
const read = await AnnouncementReads.countBy({
announcementId: ps.announcementId,
userId: user.id,
});
if (read != null) return;
if (read) return;
// Create read
await AnnouncementReads.insert({

View file

@ -43,12 +43,12 @@ export default define(meta, paramDef, async (ps, user) => {
});
// Check if already muting
const exist = await Mutings.findOneBy({
const exist = await Mutings.countBy({
muterId: muter.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()) {
return;

View file

@ -31,12 +31,12 @@ export default define(meta, paramDef, async (ps, user) => {
});
// if already favorited
const exist = await NoteFavorites.findOneBy({
const exist = await NoteFavorites.countBy({
noteId: note.id,
userId: user.id,
});
if (exist != null) throw new ApiError('ALREADY_FAVORITED');
if (exist) throw new ApiError('ALREADY_FAVORITED');
// Create favorite
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 already liked
const exist = await PageLikes.findOneBy({
const exist = await PageLikes.countBy({
pageId: page.id,
userId: user.id,
});
if (exist != null) throw new ApiError('ALREADY_LIKED');
if (exist) throw new ApiError('ALREADY_LIKED');
// Create like
await PageLikes.insert({

View file

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

View file

@ -40,7 +40,7 @@ export const paramDef = {
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, user) => {
// if already subscribed
const exist = await SwSubscriptions.findOneBy({
const exist = await SwSubscriptions.countBy({
userId: user.id,
endpoint: ps.endpoint,
auth: ps.auth,
@ -49,7 +49,7 @@ export default define(meta, paramDef, async (ps, user) => {
const instance = await fetchMeta(true);
if (exist != null) {
if (exist) {
return {
state: 'already-subscribed' as const,
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
setTimeout(async () => {
const unread = await AntennaNotes.findOneBy({ antennaId: antenna.id, read: false });
const unread = await AntennaNotes.countBy({ antennaId: antenna.id, read: false });
if (unread) {
publishMainStream(antenna.userId, 'unreadAntenna', antenna);
}

View file

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