From 97abfd48ceaebaa0f8e5ee60fcc0a656a3eb13c7 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 13 Apr 2023 13:31:54 +0900 Subject: [PATCH] refactor(backend): tweak repository name --- .../backend/src/core/entities/UserEntityService.ts | 6 +++--- packages/backend/src/di-symbols.ts | 2 +- packages/backend/src/models/RepositoryModule.ts | 8 ++++---- .../src/server/api/endpoints/users/update-memo.ts | 12 ++++++------ 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/backend/src/core/entities/UserEntityService.ts b/packages/backend/src/core/entities/UserEntityService.ts index 3f8254bb6c..68d30fe174 100644 --- a/packages/backend/src/core/entities/UserEntityService.ts +++ b/packages/backend/src/core/entities/UserEntityService.ts @@ -114,8 +114,8 @@ export class UserEntityService implements OnModuleInit { @Inject(DI.pagesRepository) private pagesRepository: PagesRepository, - @Inject(DI.userMemoRepository) - private userMemoRepository: UserMemoRepository, + @Inject(DI.userMemosRepository) + private userMemosRepository: UserMemoRepository, //private noteEntityService: NoteEntityService, //private driveFileEntityService: DriveFileEntityService, @@ -340,7 +340,7 @@ export class UserEntityService implements OnModuleInit { const falsy = opts.detail ? false : undefined; - const memo = meId == null ? null : await this.userMemoRepository.findOneBy({ + const memo = meId == null ? null : await this.userMemosRepository.findOneBy({ userId: meId, targetUserId: user.id, }).then(row => row?.memo ?? null); diff --git a/packages/backend/src/di-symbols.ts b/packages/backend/src/di-symbols.ts index b93ba899fb..190d8d65c2 100644 --- a/packages/backend/src/di-symbols.ts +++ b/packages/backend/src/di-symbols.ts @@ -70,6 +70,6 @@ export const DI = { roleAssignmentsRepository: Symbol('roleAssignmentsRepository'), flashsRepository: Symbol('flashsRepository'), flashLikesRepository: Symbol('flashLikesRepository'), - userMemoRepository: Symbol('userMemoRepository'), + userMemosRepository: Symbol('userMemosRepository'), //#endregion }; diff --git a/packages/backend/src/models/RepositoryModule.ts b/packages/backend/src/models/RepositoryModule.ts index a415e37904..588c98b58d 100644 --- a/packages/backend/src/models/RepositoryModule.ts +++ b/packages/backend/src/models/RepositoryModule.ts @@ -388,8 +388,8 @@ const $roleAssignmentsRepository: Provider = { inject: [DI.db], }; -const $userMemoRepository: Provider = { - provide: DI.userMemoRepository, +const $userMemosRepository: Provider = { + provide: DI.userMemosRepository, useFactory: (db: DataSource) => db.getRepository(UserMemo), inject: [DI.db], }; @@ -462,7 +462,7 @@ const $userMemoRepository: Provider = { $roleAssignmentsRepository, $flashsRepository, $flashLikesRepository, - $userMemoRepository, + $userMemosRepository, ], exports: [ $usersRepository, @@ -529,7 +529,7 @@ const $userMemoRepository: Provider = { $roleAssignmentsRepository, $flashsRepository, $flashLikesRepository, - $userMemoRepository, + $userMemosRepository, ], }) export class RepositoryModule {} diff --git a/packages/backend/src/server/api/endpoints/users/update-memo.ts b/packages/backend/src/server/api/endpoints/users/update-memo.ts index 300435b9ff..ca7756ef75 100644 --- a/packages/backend/src/server/api/endpoints/users/update-memo.ts +++ b/packages/backend/src/server/api/endpoints/users/update-memo.ts @@ -39,8 +39,8 @@ export const paramDef = { @Injectable() export default class extends Endpoint { constructor( - @Inject(DI.userMemoRepository) - private userMemoRepository: UserMemoRepository, + @Inject(DI.userMemosRepository) + private userMemosRepository: UserMemoRepository, private getterService: GetterService, private idService: IdService, ) { @@ -53,7 +53,7 @@ export default class extends Endpoint { // 引数がnullか空文字であれば、パーソナルメモを削除する if (ps.memo === '' || ps.memo == null) { - await this.userMemoRepository.delete({ + await this.userMemosRepository.delete({ userId: me.id, targetUserId: target.id, }); @@ -61,20 +61,20 @@ export default class extends Endpoint { } // 以前に作成されたパーソナルメモがあるかどうか確認 - const previousMemo = await this.userMemoRepository.findOneBy({ + const previousMemo = await this.userMemosRepository.findOneBy({ userId: me.id, targetUserId: target.id, }); if (!previousMemo) { - await this.userMemoRepository.insert({ + await this.userMemosRepository.insert({ id: this.idService.genId(), userId: me.id, targetUserId: target.id, memo: ps.memo, }); } else { - await this.userMemoRepository.update(previousMemo.id, { + await this.userMemosRepository.update(previousMemo.id, { userId: me.id, targetUserId: target.id, memo: ps.memo,