forked from FoundKeyGang/FoundKey
server: fix custom lint typeorm-prefer-count
This commit is contained in:
parent
b54e07caec
commit
417d252e9d
14 changed files with 28 additions and 30 deletions
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in a new issue