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

@ -122,22 +122,26 @@ export class UserFollowingService implements OnModuleInit {
let autoAccept = false;
// 鍵アカウントであっても、既にフォローされていた場合はスルー
const following = await this.followingsRepository.findOneBy({
followerId: follower.id,
followeeId: followee.id,
const isFollowing = await this.followingsRepository.exist({
where: {
followerId: follower.id,
followeeId: followee.id,
},
});
if (following) {
if (isFollowing) {
autoAccept = true;
}
// フォローしているユーザーは自動承認オプション
if (!autoAccept && (this.userEntityService.isLocalUser(followee) && followeeProfile.autoAcceptFollowed)) {
const followed = await this.followingsRepository.findOneBy({
followerId: followee.id,
followeeId: follower.id,
const isFollowed = await this.followingsRepository.exist({
where: {
followerId: followee.id,
followeeId: follower.id,
},
});
if (followed) autoAccept = true;
if (isFollowed) autoAccept = true;
}
// Automatically accept if the follower is an account who has moved and the locked followee had accepted the old account.
@ -206,12 +210,14 @@ export class UserFollowingService implements OnModuleInit {
this.cacheService.userFollowingsCache.refresh(follower.id);
const req = await this.followRequestsRepository.findOneBy({
followeeId: followee.id,
followerId: follower.id,
const requestExist = await this.followRequestsRepository.exist({
where: {
followeeId: followee.id,
followerId: follower.id,
},
});
if (req) {
if (requestExist) {
await this.followRequestsRepository.delete({
followeeId: followee.id,
followerId: follower.id,
@ -505,12 +511,14 @@ export class UserFollowingService implements OnModuleInit {
}
}
const request = await this.followRequestsRepository.findOneBy({
followeeId: followee.id,
followerId: follower.id,
const requestExist = await this.followRequestsRepository.exist({
where: {
followeeId: followee.id,
followerId: follower.id,
},
});
if (request == null) {
if (!requestExist) {
throw new IdentifiableError('17447091-ce07-46dd-b331-c1fd4f15b1e7', 'request not found');
}