refactor(backend): 存在確認のfindOneByexistに置き換え (#11224)

* refactor(backend): 存在確認の`findOneBy`を`exist`に置き換え

* cleanup
This commit is contained in:
okayurisotto 2023-07-11 14:58:58 +09:00 committed by GitHub
parent 48d3341462
commit cf3e39178b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 287 additions and 200 deletions

View file

@ -47,17 +47,26 @@ export class ChannelEntityService {
const banner = channel.bannerId ? await this.driveFilesRepository.findOneBy({ id: channel.bannerId }) : null;
const hasUnreadNote = meId ? (await this.noteUnreadsRepository.findOneBy({ noteChannelId: channel.id, userId: meId })) != null : undefined;
const hasUnreadNote = meId ? await this.noteUnreadsRepository.exist({
where: {
noteChannelId: channel.id,
userId: meId
},
}) : undefined;
const following = meId ? await this.channelFollowingsRepository.findOneBy({
followerId: meId,
followeeId: channel.id,
}) : null;
const isFollowing = meId ? await this.channelFollowingsRepository.exist({
where: {
followerId: meId,
followeeId: channel.id,
},
}) : false;
const favorite = meId ? await this.channelFavoritesRepository.findOneBy({
userId: meId,
channelId: channel.id,
}) : null;
const isFavorited = meId ? await this.channelFavoritesRepository.exist({
where: {
userId: meId,
channelId: channel.id,
},
}) : false;
const pinnedNotes = channel.pinnedNoteIds.length > 0 ? await this.notesRepository.find({
where: {
@ -80,8 +89,8 @@ export class ChannelEntityService {
notesCount: channel.notesCount,
...(me ? {
isFollowing: following != null,
isFavorited: favorite != null,
isFollowing,
isFavorited,
hasUnreadNote,
} : {}),