diff --git a/dictation_server/src/features/accounts/accounts.service.ts b/dictation_server/src/features/accounts/accounts.service.ts index 7de2682..4bfffe5 100644 --- a/dictation_server/src/features/accounts/accounts.service.ts +++ b/dictation_server/src/features/accounts/accounts.service.ts @@ -111,6 +111,7 @@ export class AccountsService { const { licenseSummary, isStorageAvailable } = await this.accountRepository.getLicenseSummaryInfo( + context, accountId, currentDate, expiringSoonDate, @@ -440,16 +441,21 @@ export class AccountsService { ); try { let userInfo: User; - userInfo = await this.usersRepository.findUserByExternalId(externalId); + userInfo = await this.usersRepository.findUserByExternalId( + context, + externalId, + ); let accountInfo: Account; accountInfo = await this.accountRepository.findAccountById( + context, userInfo.account_id, ); let parentInfo: Account | undefined; if (accountInfo.parent_account_id) { parentInfo = await this.accountRepository.findAccountById( + context, accountInfo.parent_account_id, ); } @@ -505,8 +511,12 @@ export class AccountsService { // TypistGroup取得 try { - const user = await this.usersRepository.findUserByExternalId(externalId); + const user = await this.usersRepository.findUserByExternalId( + context, + externalId, + ); const userGroups = await this.userGroupsRepository.getUserGroups( + context, user.account_id, ); @@ -543,10 +553,12 @@ export class AccountsService { try { const { account_id } = await this.usersRepository.findUserByExternalId( + context, externalId, ); const { name, userGroupMembers } = await this.userGroupsRepository.getTypistGroup( + context, account_id, typistGroupId, ); @@ -602,6 +614,7 @@ export class AccountsService { // Typist取得 try { const typistUsers = await this.usersRepository.findTypistUsers( + context, externalId, ); const externalIds = typistUsers.map((x) => x.external_id); @@ -651,6 +664,7 @@ export class AccountsService { try { const { account } = await this.usersRepository.findUserByExternalId( + context, externalId, ); @@ -661,6 +675,7 @@ export class AccountsService { } const authorUsers = await this.usersRepository.findAuthorUsers( + context, account.id, ); @@ -733,7 +748,10 @@ export class AccountsService { try { // アクセストークンからユーザーIDを取得する myAccountId = ( - await this.usersRepository.findUserByExternalId(creatorUserId) + await this.usersRepository.findUserByExternalId( + context, + creatorUserId, + ) ).account_id; } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); @@ -909,6 +927,7 @@ export class AccountsService { const getPartnerLicenseResult = await this.accountRepository.getPartnerLicense( + context, accountId, currentDate, expiringSoonDate, @@ -1008,6 +1027,7 @@ export class AccountsService { try { const licenseHistoryInfo = await this.licensesRepository.getLicenseOrderHistoryInfo( + context, accountId, offset, limit, @@ -1079,9 +1099,10 @@ export class AccountsService { try { // アクセストークンからユーザーIDを取得する const myAccountId = ( - await this.usersRepository.findUserByExternalId(userId) + await this.usersRepository.findUserByExternalId(context, userId) ).account_id; await this.licensesRepository.issueLicense( + context, orderedAccountId, myAccountId, tier, @@ -1127,7 +1148,9 @@ export class AccountsService { ); try { - const dealerAccounts = await this.accountRepository.findDealerAccounts(); + const dealerAccounts = await this.accountRepository.findDealerAccounts( + context, + ); const dealers: GetDealersResponse = { dealers: dealerAccounts.map((dealerAccount): Dealer => { @@ -1177,10 +1200,12 @@ export class AccountsService { try { // 外部IDをもとにユーザー情報を取得する const { account_id } = await this.usersRepository.findUserByExternalId( + context, externalId, ); // API実行ユーザーのアカウントIDでタイピストグループを作成し、タイピストグループとtypistIdsのユーザーを紐付ける await this.userGroupsRepository.createTypistGroup( + context, typistGroupName, typistIds, account_id, @@ -1240,11 +1265,13 @@ export class AccountsService { try { // 外部IDをもとにユーザー情報を取得する const { account_id } = await this.usersRepository.findUserByExternalId( + context, externalId, ); // タイピストグループと所属するタイピストを更新する await this.userGroupsRepository.updateTypistGroup( + context, account_id, typistGroupId, typistGroupName, @@ -1310,7 +1337,7 @@ export class AccountsService { try { // ユーザIDからアカウントIDを取得する myAccountId = ( - await this.usersRepository.findUserByExternalId(extarnalId) + await this.usersRepository.findUserByExternalId(context, extarnalId) ).account_id; } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); @@ -1329,6 +1356,7 @@ export class AccountsService { // 注文元アカウントIDの親世代を取得 const parentAccountIds = await this.accountRepository.getHierarchyParents( + context, orderedAccountId, ); // 自身が存在しない場合、エラー @@ -1344,7 +1372,11 @@ export class AccountsService { try { // 発行キャンセル処理 - await this.accountRepository.cancelIssue(orderedAccountId, poNumber); + await this.accountRepository.cancelIssue( + context, + orderedAccountId, + poNumber, + ); } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); switch (e.constructor) { @@ -1394,11 +1426,11 @@ export class AccountsService { try { // 外部IDをもとにユーザー情報を取得する const { account_id: accountId } = - await this.usersRepository.findUserByExternalId(externalId); + await this.usersRepository.findUserByExternalId(context, externalId); // ワークタイプ一覧とActiveWorktypeIDを取得する const { worktypes, active_worktype_id } = - await this.worktypesRepository.getWorktypes(accountId); + await this.worktypesRepository.getWorktypes(context, accountId); return { worktypes: worktypes.map((x) => ({ @@ -1457,9 +1489,10 @@ export class AccountsService { try { // 外部IDをもとにユーザー情報を取得する const { account_id: accountId } = - await this.usersRepository.findUserByExternalId(externalId); + await this.usersRepository.findUserByExternalId(context, externalId); await this.worktypesRepository.createWorktype( + context, accountId, worktypeId, description, @@ -1527,10 +1560,11 @@ export class AccountsService { try { // 外部IDをもとにユーザー情報を取得する const { account_id: accountId } = - await this.usersRepository.findUserByExternalId(externalId); + await this.usersRepository.findUserByExternalId(context, externalId); // ワークタイプを更新する await this.worktypesRepository.updateWorktype( + context, accountId, id, worktypeId, @@ -1593,7 +1627,7 @@ export class AccountsService { try { // 外部IDをもとにユーザー情報を取得する const { account, account_id: accountId } = - await this.usersRepository.findUserByExternalId(externalId); + await this.usersRepository.findUserByExternalId(context, externalId); if (!account) { throw new AccountNotFoundError( @@ -1602,7 +1636,7 @@ export class AccountsService { } // ワークタイプを削除する - await this.worktypesRepository.deleteWorktype(accountId, id); + await this.worktypesRepository.deleteWorktype(context, accountId, id); } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); if (e instanceof Error) { @@ -1669,10 +1703,11 @@ export class AccountsService { try { // 外部IDをもとにユーザー情報を取得する const { account_id: accountId } = - await this.usersRepository.findUserByExternalId(externalId); + await this.usersRepository.findUserByExternalId(context, externalId); // オプションアイテム一覧を取得する const optionItems = await this.worktypesRepository.getOptionItems( + context, accountId, id, ); @@ -1738,10 +1773,11 @@ export class AccountsService { try { // 外部IDをもとにユーザー情報を取得する const { account_id: accountId } = - await this.usersRepository.findUserByExternalId(externalId); + await this.usersRepository.findUserByExternalId(context, externalId); // オプションアイテムを更新する await this.worktypesRepository.updateOptionItems( + context, accountId, id, // initialValueはdefaultValueTypeがDEFAULTの場合以外は空文字を設定する @@ -1804,10 +1840,14 @@ export class AccountsService { try { // 外部IDをもとにユーザー情報を取得する const { account_id: accountId } = - await this.usersRepository.findUserByExternalId(externalId); + await this.usersRepository.findUserByExternalId(context, externalId); // ActiveWorktypeを更新する - await this.accountRepository.updateActiveWorktypeId(accountId, id); + await this.accountRepository.updateActiveWorktypeId( + context, + accountId, + id, + ); } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); if (e instanceof Error) { @@ -1861,9 +1901,10 @@ export class AccountsService { try { const { account_id: accountId } = - await this.usersRepository.findUserByExternalId(externalId); + await this.usersRepository.findUserByExternalId(context, externalId); const partnersRecords = await this.accountRepository.getPartners( + context, accountId, limit, offset, @@ -1959,8 +2000,9 @@ export class AccountsService { try { const { account_id: accountId } = - await this.usersRepository.findUserByExternalId(externalId); + await this.usersRepository.findUserByExternalId(context, externalId); await this.accountRepository.updateAccountInfo( + context, accountId, tier, delegationPermission, @@ -2019,7 +2061,7 @@ export class AccountsService { try { // パラメータとトークンから取得したアカウントIDの突き合わせ const { account_id: myAccountId } = - await this.usersRepository.findUserByExternalId(externalId); + await this.usersRepository.findUserByExternalId(context, externalId); if (myAccountId !== accountId) { throw new HttpException( makeErrorResponse('E000108'), @@ -2029,10 +2071,12 @@ export class AccountsService { // アカウント削除前に必要な情報を退避する const targetAccount = await this.accountRepository.findAccountById( + context, accountId, ); // 削除対象アカウントを削除する dbUsers = await this.accountRepository.deleteAccountAndInsertArchives( + context, accountId, ); this.logger.log( @@ -2109,6 +2153,7 @@ export class AccountsService { try { const { account } = await this.usersRepository.findUserByExternalId( + context, externalId, ); if (!account) { @@ -2168,6 +2213,7 @@ export class AccountsService { try { const { company_name } = await this.accountRepository.findAccountById( + context, accountId, ); diff --git a/dictation_server/src/features/auth/auth.service.ts b/dictation_server/src/features/auth/auth.service.ts index dbcdfc3..9bfce0a 100644 --- a/dictation_server/src/features/auth/auth.service.ts +++ b/dictation_server/src/features/auth/auth.service.ts @@ -61,7 +61,10 @@ export class AuthService { ); try { // IDトークンのユーザーがDBに登録されていてメール認証が完了しているユーザーか検証 - const user = await this.usersRepository.findVerifiedUser(idToken.sub); + const user = await this.usersRepository.findVerifiedUser( + context, + idToken.sub, + ); return user !== undefined; } catch (e) { @@ -96,7 +99,10 @@ export class AuthService { // ユーザー情報とユーザーが属しているアカウント情報を取得 try { - const user = await this.usersRepository.findUserByExternalId(idToken.sub); + const user = await this.usersRepository.findUserByExternalId( + context, + idToken.sub, + ); if (!user.account) { throw new Error('Account information not found'); } @@ -236,11 +242,13 @@ export class AuthService { // ユーザー情報とユーザーが属しているアカウント情報を取得 try { const user = await this.usersRepository.findUserByExternalId( + context, delegateUserExternalId, ); // 代行操作対象アカウントの管理者ユーザーを取得 const adminUser = await this.usersRepository.findDelegateUser( + context, user.account_id, originAccountId, ); @@ -382,6 +390,7 @@ export class AuthService { } const user = await this.usersRepository.findUserByExternalId( + context, delegateUserExternalId, ); @@ -406,6 +415,7 @@ export class AuthService { // 代行操作対象アカウントの管理者ユーザーが存在して、アカウントに対して代行操作権限があるか確認 const delegationPermission = await this.usersRepository.isAllowDelegationPermission( + context, user.account_id, userId, ); @@ -694,7 +704,10 @@ export class AuthService { acceptedDpaVersion, latestDpaVersion, tier, - } = await this.usersRepository.getAcceptedAndLatestVersion(idToken.sub); + } = await this.usersRepository.getAcceptedAndLatestVersion( + context, + idToken.sub, + ); // 第五階層はEULAとPrivacyNoticeのみ判定 if (tier === TIERS.TIER5) { diff --git a/dictation_server/src/features/files/files.service.ts b/dictation_server/src/features/files/files.service.ts index f9f4550..8e73b0a 100644 --- a/dictation_server/src/features/files/files.service.ts +++ b/dictation_server/src/features/files/files.service.ts @@ -166,7 +166,7 @@ export class FilesService { let user: User; try { // ユーザー取得 - user = await this.usersRepository.findUserByExternalId(userId); + user = await this.usersRepository.findUserByExternalId(context, userId); } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); this.logger.log( @@ -190,6 +190,7 @@ export class FilesService { // 文字起こしタスク追加(音声ファイルとオプションアイテムも同時に追加) // 追加時に末尾のJOBナンバーにインクリメントする task = await this.tasksRepositoryService.create( + context, user.account_id, user.id, priority, @@ -218,6 +219,7 @@ export class FilesService { // ルーティング設定に従い、チェックアウト権限を付与する const { typistGroupIds, typistIds } = await this.tasksRepositoryService.autoRouting( + context, task.audio_file_id, user.account_id, user.author_id ?? undefined, @@ -225,6 +227,7 @@ export class FilesService { const groupMembers = await this.userGroupsRepositoryService.getGroupMembersFromGroupIds( + context, typistGroupIds, ); @@ -284,7 +287,10 @@ export class FilesService { //DBから国情報とアカウントIDを取得する try { - const user = await this.usersRepository.findUserByExternalId(externalId); + const user = await this.usersRepository.findUserByExternalId( + context, + externalId, + ); if (!user.account) { throw new AccountNotFoundError('account not found.'); } @@ -299,6 +305,7 @@ export class FilesService { // ライセンスが有効でない場合、エラー const { state } = await this.licensesRepository.getLicenseState( + context, user.id, ); if (state === 'expired') { @@ -378,7 +385,10 @@ export class FilesService { let authorId: string | undefined; let isAdmin: boolean; try { - const user = await this.usersRepository.findUserByExternalId(externalId); + const user = await this.usersRepository.findUserByExternalId( + context, + externalId, + ); if (!user.account) { throw new AccountNotFoundError('account not found.'); } @@ -386,6 +396,7 @@ export class FilesService { if (user.account.tier === TIERS.TIER5) { // ライセンスが有効でない場合、エラー const { state } = await this.licensesRepository.getLicenseState( + context, user.id, ); if (state === 'expired') { @@ -437,6 +448,7 @@ export class FilesService { : Object.values(TASK_STATUS); const task = await this.tasksRepository.getTaskAndAudioFile( + context, audioFileId, accountId, status, @@ -554,7 +566,10 @@ export class FilesService { let isTypist: boolean; let authorId: string | undefined; try { - const user = await this.usersRepository.findUserByExternalId(externalId); + const user = await this.usersRepository.findUserByExternalId( + context, + externalId, + ); if (!user.account) { throw new AccountNotFoundError('account not found.'); } @@ -562,6 +577,7 @@ export class FilesService { if (user.account.tier === TIERS.TIER5) { // ライセンスが有効でない場合、エラー const { state } = await this.licensesRepository.getLicenseState( + context, user.id, ); if (state === 'expired') { @@ -608,6 +624,7 @@ export class FilesService { : Object.values(TASK_STATUS); const task = await this.tasksRepository.getTaskAndAudioFile( + context, audioFileId, accountId, status, @@ -726,6 +743,7 @@ export class FilesService { ); try { const { account } = await this.usersRepository.findUserByExternalId( + context, externalId, ); if (!account) { @@ -788,7 +806,7 @@ export class FilesService { try { // ユーザー取得 const { account_id: accountId } = - await this.usersRepository.findUserByExternalId(externalId); + await this.usersRepository.findUserByExternalId(context, externalId); // URLにSASトークンがついている場合は取り除く; const urlObj = new URL(url); @@ -800,6 +818,7 @@ export class FilesService { // テンプレートファイル情報をDBに登録 await this.templateFilesRepository.upsertTemplateFile( + context, accountId, fileName, fileUrl, diff --git a/dictation_server/src/features/licenses/licenses.service.ts b/dictation_server/src/features/licenses/licenses.service.ts index d6e1c5e..17e61bd 100644 --- a/dictation_server/src/features/licenses/licenses.service.ts +++ b/dictation_server/src/features/licenses/licenses.service.ts @@ -49,7 +49,7 @@ export class LicensesService { // ユーザIDからアカウントIDを取得する try { myAccountId = ( - await this.usersRepository.findUserByExternalId(externalId) + await this.usersRepository.findUserByExternalId(context, externalId) ).account_id; } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); @@ -70,7 +70,7 @@ export class LicensesService { // 親アカウントIDを取得 try { parentAccountId = - (await this.accountsRepository.findAccountById(myAccountId)) + (await this.accountsRepository.findAccountById(context, myAccountId)) .parent_account_id ?? undefined; // 親アカウントIDが取得できない場合はエラー if (parentAccountId === undefined) { @@ -94,6 +94,7 @@ export class LicensesService { try { await this.licensesRepository.order( + context, poNumber, myAccountId, parentAccountId, @@ -134,7 +135,7 @@ export class LicensesService { // ユーザIDからアカウントIDを取得する try { myAccountId = ( - await this.usersRepository.findUserByExternalId(externalId) + await this.usersRepository.findUserByExternalId(context, externalId) ).account_id; } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); @@ -153,6 +154,7 @@ export class LicensesService { } try { const licenseKeys = await this.licensesRepository.createCardLicenses( + context, myAccountId, createCount, ); @@ -194,7 +196,7 @@ export class LicensesService { // ユーザIDからアカウントIDを取得する try { myAccountId = ( - await this.usersRepository.findUserByExternalId(externalId) + await this.usersRepository.findUserByExternalId(context, externalId) ).account_id; } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); @@ -215,6 +217,7 @@ export class LicensesService { // カードライセンスを取り込む try { await this.licensesRepository.activateCardLicense( + context, myAccountId, cardLicenseKey, ); @@ -266,11 +269,14 @@ export class LicensesService { // ユーザIDからアカウントIDを取得する try { const myAccountId = ( - await this.usersRepository.findUserByExternalId(userId) + await this.usersRepository.findUserByExternalId(context, userId) ).account_id; // 割り当て可能なライセンスを取得する const allocatableLicenses = - await this.licensesRepository.getAllocatableLicenses(myAccountId); + await this.licensesRepository.getAllocatableLicenses( + context, + myAccountId, + ); return { allocatableLicenses, @@ -316,10 +322,10 @@ export class LicensesService { try { // ユーザIDからアカウントIDを取得する myAccountId = ( - await this.usersRepository.findUserByExternalId(externalId) + await this.usersRepository.findUserByExternalId(context, externalId) ).account_id; // 注文キャンセル処理 - await this.licensesRepository.cancelOrder(myAccountId, poNumber); + await this.licensesRepository.cancelOrder(context, myAccountId, poNumber); } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); switch (e.constructor) { diff --git a/dictation_server/src/features/notification/notification.service.ts b/dictation_server/src/features/notification/notification.service.ts index 9accc7c..2d9edda 100644 --- a/dictation_server/src/features/notification/notification.service.ts +++ b/dictation_server/src/features/notification/notification.service.ts @@ -34,7 +34,9 @@ export class NotificationService { // ユーザIDからアカウントIDを取得する let userId: number; try { - userId = (await this.usersRepository.findUserByExternalId(externalId)).id; + userId = ( + await this.usersRepository.findUserByExternalId(context, externalId) + ).id; } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); switch (e.constructor) { diff --git a/dictation_server/src/features/tasks/tasks.service.spec.ts b/dictation_server/src/features/tasks/tasks.service.spec.ts index 3c87ea5..ba7f1f4 100644 --- a/dictation_server/src/features/tasks/tasks.service.spec.ts +++ b/dictation_server/src/features/tasks/tasks.service.spec.ts @@ -309,8 +309,9 @@ describe('TasksService', () => { const status = ['Uploaded', 'Backup']; const paramName = 'JOB_NUMBER'; const direction = 'ASC'; + const context = makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'); const result = await service.tasksService.getTasks( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + context, userId, [USER_ROLES.AUTHOR], offset, @@ -360,7 +361,7 @@ describe('TasksService', () => { }); expect( service.taskRepoService.getTasksFromAuthorIdAndAccountId, - ).toHaveBeenCalledWith('abcdef', 1, 0, 20, 'JOB_NUMBER', 'ASC', [ + ).toHaveBeenCalledWith(context, 'abcdef', 1, 0, 20, 'JOB_NUMBER', 'ASC', [ 'Uploaded', 'Backup', ]); @@ -437,8 +438,9 @@ describe('TasksService', () => { const status = ['Uploaded', 'Backup']; const paramName = 'JOB_NUMBER'; const direction = 'ASC'; + const context = makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'); const result = await service.tasksService.getTasks( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + context, userId, [USER_ROLES.TYPIST], offset, @@ -488,7 +490,7 @@ describe('TasksService', () => { }); expect( service.taskRepoService.getTasksFromTypistRelations, - ).toHaveBeenCalledWith('userId', 0, 20, 'JOB_NUMBER', 'ASC', [ + ).toHaveBeenCalledWith(context, 'userId', 0, 20, 'JOB_NUMBER', 'ASC', [ 'Uploaded', 'Backup', ]); diff --git a/dictation_server/src/features/tasks/tasks.service.ts b/dictation_server/src/features/tasks/tasks.service.ts index 200b00f..d1cc1e7 100644 --- a/dictation_server/src/features/tasks/tasks.service.ts +++ b/dictation_server/src/features/tasks/tasks.service.ts @@ -74,10 +74,11 @@ export class TasksService { try { const { account_id, author_id } = - await this.usersRepository.findUserByExternalId(userId); + await this.usersRepository.findUserByExternalId(context, userId); if (roles.includes(ADMIN_ROLES.ADMIN)) { const result = await this.taskRepository.getTasksFromAccountId( + context, account_id, offset, limit, @@ -104,6 +105,7 @@ export class TasksService { } const result = await this.taskRepository.getTasksFromAuthorIdAndAccountId( + context, author_id, account_id, offset, @@ -126,6 +128,7 @@ export class TasksService { if (roles.includes(USER_ROLES.TYPIST)) { const result = await this.taskRepository.getTasksFromTypistRelations( + context, userId, offset, limit, @@ -187,10 +190,11 @@ export class TasksService { try { const { account_id: accountId, id } = - await this.usersRepository.findUserByExternalId(externalId); + await this.usersRepository.findUserByExternalId(context, externalId); // タスク一覧を取得する const tasks = await this.taskRepository.getSortedTasks( + context, accountId, id, fileId, @@ -268,7 +272,7 @@ export class TasksService { ); const { id, account_id, author_id } = - await this.usersRepository.findUserByExternalId(externalId); + await this.usersRepository.findUserByExternalId(context, externalId); if (roles.includes(USER_ROLES.AUTHOR)) { // API実行者がAuthorで、AuthorIDが存在しないことは想定外のため、エラーとする @@ -276,6 +280,7 @@ export class TasksService { throw new Error('AuthorID not found'); } await this.taskRepository.getTaskFromAudioFileId( + context, audioFileId, account_id, author_id, @@ -284,11 +289,13 @@ export class TasksService { } if (roles.includes(USER_ROLES.TYPIST)) { - return await this.taskRepository.checkout(audioFileId, account_id, id, [ - TASK_STATUS.UPLOADED, - TASK_STATUS.PENDING, - TASK_STATUS.IN_PROGRESS, - ]); + return await this.taskRepository.checkout( + context, + audioFileId, + account_id, + id, + [TASK_STATUS.UPLOADED, TASK_STATUS.PENDING, TASK_STATUS.IN_PROGRESS], + ); } throw new InvalidRoleError(`invalid roles: ${roles.join(',')}`); @@ -351,10 +358,12 @@ export class TasksService { } | params: { audioFileId: ${audioFileId}, externalId: ${externalId} };`, ); const { id } = await this.usersRepository.findUserByExternalId( + context, externalId, ); return await this.taskRepository.checkin( + context, audioFileId, id, TASK_STATUS.IN_PROGRESS, @@ -412,7 +421,10 @@ export class TasksService { let user: User; try { // ユーザー取得 - user = await this.usersRepository.findUserByExternalId(externalId); + user = await this.usersRepository.findUserByExternalId( + context, + externalId, + ); } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); this.logger.log(`[OUT] [${context.getTrackingId()}] ${this.cancel.name}`); @@ -425,6 +437,7 @@ export class TasksService { try { // roleにAdminが含まれていれば、文字起こし担当でなくてもキャンセルできるため、ユーザーIDは指定しない await this.taskRepository.cancel( + context, audioFileId, [TASK_STATUS.IN_PROGRESS, TASK_STATUS.PENDING], user.account_id, @@ -462,6 +475,7 @@ export class TasksService { // キャンセルしたタスクに自動ルーティングを行う const { typistGroupIds, typistIds } = await this.taskRepository.autoRouting( + context, audioFileId, user.account_id, user.author_id ?? undefined, @@ -504,10 +518,12 @@ export class TasksService { } | params: { audioFileId: ${audioFileId}, externalId: ${externalId} };`, ); const { id } = await this.usersRepository.findUserByExternalId( + context, externalId, ); return await this.taskRepository.suspend( + context, audioFileId, id, TASK_STATUS.IN_PROGRESS, @@ -564,9 +580,9 @@ export class TasksService { } | params: { audioFileId: ${audioFileId}, externalId: ${externalId} };`, ); const { account_id: accountId } = - await this.usersRepository.findUserByExternalId(externalId); + await this.usersRepository.findUserByExternalId(context, externalId); - await this.taskRepository.backup(accountId, audioFileId, [ + await this.taskRepository.backup(context, accountId, audioFileId, [ TASK_STATUS.FINISHED, TASK_STATUS.BACKUP, ]); @@ -651,13 +667,14 @@ export class TasksService { } | params: { audioFileId: ${audioFileId}, assignees: ${assignees}, externalId: ${externalId}, role: ${role} };`, ); const { author_id, account_id } = - await this.usersRepository.findUserByExternalId(externalId); + await this.usersRepository.findUserByExternalId(context, externalId); // RoleがAuthorで、AuthorIDが存在しないことは想定外のため、エラーとする if (role.includes(USER_ROLES.AUTHOR) && !author_id) { throw new Error('AuthorID not found'); } await this.taskRepository.changeCheckoutPermission( + context, audioFileId, author_id ?? undefined, account_id, @@ -737,6 +754,7 @@ export class TasksService { ); const groupMembers = await this.userGroupsRepositoryService.getGroupMembersFromGroupIds( + context, typistGroupIds, ); @@ -757,6 +775,7 @@ export class TasksService { // 通知内容に含む音声ファイル情報を取得 const { file } = await this.taskRepository.getTaskAndAudioFile( + context, audioFileId, accountId, [TASK_STATUS.UPLOADED], diff --git a/dictation_server/src/features/templates/templates.service.ts b/dictation_server/src/features/templates/templates.service.ts index f256f3a..ae36afe 100644 --- a/dictation_server/src/features/templates/templates.service.ts +++ b/dictation_server/src/features/templates/templates.service.ts @@ -31,10 +31,10 @@ export class TemplatesService { try { const { account_id: accountId } = - await this.usersRepository.findUserByExternalId(externalId); + await this.usersRepository.findUserByExternalId(context, externalId); const templateFileRecords = - await this.templateFilesRepository.getTemplateFiles(accountId); + await this.templateFilesRepository.getTemplateFiles(context, accountId); // DBから取得したテンプレートファイルのレコードをレスポンス用に整形する const resTemplates = templateFileRecords.map((templateFile) => ({ diff --git a/dictation_server/src/features/terms/terms.service.ts b/dictation_server/src/features/terms/terms.service.ts index ee52415..a9a76a0 100644 --- a/dictation_server/src/features/terms/terms.service.ts +++ b/dictation_server/src/features/terms/terms.service.ts @@ -20,7 +20,7 @@ export class TermsService { ); try { const { eulaVersion, privacyNoticeVersion, dpaVersion } = - await this.termsRepository.getLatestTermsInfo(); + await this.termsRepository.getLatestTermsInfo(context); return [ { documentType: TERM_TYPE.EULA, diff --git a/dictation_server/src/features/users/users.service.ts b/dictation_server/src/features/users/users.service.ts index 542e8d3..1bf2959 100644 --- a/dictation_server/src/features/users/users.service.ts +++ b/dictation_server/src/features/users/users.service.ts @@ -94,6 +94,7 @@ export class UsersService { // トランザクションで取得と更新をまとめる const userId = decodedToken.userId; await this.usersRepository.updateUserVerifiedAndCreateTrialLicense( + context, userId, ); } catch (e) { @@ -167,7 +168,10 @@ export class UsersService { //DBよりアクセス者の所属するアカウントIDを取得する let adminUser: EntityUser; try { - adminUser = await this.usersRepository.findUserByExternalId(externalId); + adminUser = await this.usersRepository.findUserByExternalId( + context, + externalId, + ); } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); throw new HttpException( @@ -183,6 +187,7 @@ export class UsersService { let isAuthorIdDuplicated = false; try { isAuthorIdDuplicated = await this.usersRepository.existsAuthorId( + context, accountId, authorId, ); @@ -479,7 +484,7 @@ export class UsersService { try { // ユーザー情報からAzure AD B2CのIDを特定する - const user = await this.usersRepository.findUserById(userId); + const user = await this.usersRepository.findUserById(context, userId); const extarnalId = user.external_id; // パスワードを変更する await this.adB2cService.changePassword( @@ -488,7 +493,7 @@ export class UsersService { ramdomPassword, ); // ユーザを認証済みにする - await this.usersRepository.updateUserVerified(userId); + await this.usersRepository.updateUserVerified(context, userId); // TODO [Task2163] ODMS側が正式にメッセージを決めるまで仮のメール内容とする const subject = 'A temporary password has been issued.'; const text = 'temporary password: ' + ramdomPassword; @@ -663,7 +668,10 @@ export class UsersService { let user: EntityUser; try { // ユーザー情報を取得 - user = await this.usersRepository.findUserByExternalId(externalId); + user = await this.usersRepository.findUserByExternalId( + context, + externalId, + ); } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); @@ -676,6 +684,7 @@ export class UsersService { try { // ユーザーのソート条件を更新 await this.sortCriteriaRepository.updateSortCriteria( + context, user.id, paramName, direction, @@ -712,7 +721,10 @@ export class UsersService { let user: EntityUser; try { // ユーザー情報を取得 - user = await this.usersRepository.findUserByExternalId(externalId); + user = await this.usersRepository.findUserByExternalId( + context, + externalId, + ); } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); @@ -725,6 +737,7 @@ export class UsersService { try { // ユーザーのソート条件を取得 const sortCriteria = await this.sortCriteriaRepository.getSortCriteria( + context, user.id, ); const { direction, parameter } = sortCriteria; @@ -764,11 +777,14 @@ export class UsersService { } | params: { userId: ${userId} };`, ); try { - const { id } = await this.usersRepository.findUserByExternalId(userId); + const { id } = await this.usersRepository.findUserByExternalId( + context, + userId, + ); // ユーザー関連情報を取得 const { user, authors, worktypes, activeWorktype } = - await this.usersRepository.getUserRelations(id); + await this.usersRepository.getUserRelations(context, id); // AuthorIDのリストを作成 const authorIds = authors.flatMap((author) => @@ -883,11 +899,12 @@ export class UsersService { // 実行ユーザーのアカウントIDを取得 const accountId = ( - await this.usersRepository.findUserByExternalId(extarnalId) + await this.usersRepository.findUserByExternalId(context, extarnalId) ).account_id; // ユーザー情報を更新 await this.usersRepository.update( + context, accountId, id, role, @@ -961,10 +978,12 @@ export class UsersService { ); try { - const accountId = (await this.usersRepository.findUserById(userId)) - .account_id; + const accountId = ( + await this.usersRepository.findUserById(context, userId) + ).account_id; await this.licensesRepository.allocateLicense( + context, userId, newLicenseId, accountId, @@ -1010,10 +1029,15 @@ export class UsersService { ); try { - const accountId = (await this.usersRepository.findUserById(userId)) - .account_id; + const accountId = ( + await this.usersRepository.findUserById(context, userId) + ).account_id; - await this.licensesRepository.deallocateLicense(userId, accountId); + await this.licensesRepository.deallocateLicense( + context, + userId, + accountId, + ); } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); if (e instanceof Error) { @@ -1064,6 +1088,7 @@ export class UsersService { try { await this.usersRepository.updateAcceptedTermsVersion( + context, externalId, eulaVersion, privacyNoticeVersion, @@ -1115,7 +1140,7 @@ export class UsersService { try { // extarnalIdの存在チェックを行う - await this.usersRepository.findUserByExternalId(externalId); + await this.usersRepository.findUserByExternalId(context, externalId); // ADB2Cからユーザー名を取得する const adb2cUser = await this.adB2cService.getUser(context, externalId); return adb2cUser.displayName; diff --git a/dictation_server/src/features/workflows/workflows.service.ts b/dictation_server/src/features/workflows/workflows.service.ts index 793449b..dfec854 100644 --- a/dictation_server/src/features/workflows/workflows.service.ts +++ b/dictation_server/src/features/workflows/workflows.service.ts @@ -41,10 +41,11 @@ export class WorkflowsService { ); try { const { account_id: accountId } = - await this.usersRepository.findUserByExternalId(externalId); + await this.usersRepository.findUserByExternalId(context, externalId); // DBからワークフロー一覧を取得 const workflowRecords = await this.workflowsRepository.getWorkflows( + context, accountId, ); @@ -165,9 +166,10 @@ export class WorkflowsService { ); try { const { account_id: accountId } = - await this.usersRepository.findUserByExternalId(externalId); + await this.usersRepository.findUserByExternalId(context, externalId); await this.workflowsRepository.createtWorkflows( + context, accountId, authorId, typists, @@ -253,9 +255,10 @@ export class WorkflowsService { ); try { const { account_id: accountId } = - await this.usersRepository.findUserByExternalId(externalId); + await this.usersRepository.findUserByExternalId(context, externalId); await this.workflowsRepository.updatetWorkflow( + context, accountId, workflowId, authorId, @@ -336,6 +339,7 @@ export class WorkflowsService { ); try { const { account } = await this.usersRepository.findUserByExternalId( + context, externalId, ); @@ -345,7 +349,11 @@ export class WorkflowsService { ); } - await this.workflowsRepository.deleteWorkflow(account.id, workflowId); + await this.workflowsRepository.deleteWorkflow( + context, + account.id, + workflowId, + ); } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); if (e instanceof Error) { diff --git a/dictation_server/src/repositories/accounts/accounts.repository.service.ts b/dictation_server/src/repositories/accounts/accounts.repository.service.ts index d7762bd..be4ce84 100644 --- a/dictation_server/src/repositories/accounts/accounts.repository.service.ts +++ b/dictation_server/src/repositories/accounts/accounts.repository.service.ts @@ -57,6 +57,7 @@ import { AudioOptionItem } from '../audio_option_items/entity/audio_option_item. import { UserGroup } from '../user_groups/entity/user_group.entity'; import { UserGroupMember } from '../user_groups/entity/user_group_member.entity'; import { TemplateFile } from '../template_files/entity/template_file.entity'; +import { Context } from '../../common/log'; @Injectable() export class AccountsRepositoryService { @@ -211,11 +212,12 @@ export class AccountsRepositoryService { * @param id * @returns account */ - async findAccountById(id: number): Promise { + async findAccountById(context: Context, id: number): Promise { const account = await this.dataSource.getRepository(Account).findOne({ where: { id: id, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!account) { @@ -234,6 +236,7 @@ export class AccountsRepositoryService { * @returns expiringSoonLicense */ private async getExpiringSoonLicense( + context: Context, entityManager: EntityManager, id: number, currentDate: Date, @@ -248,6 +251,7 @@ export class AccountsRepositoryService { expiry_date: Between(currentDate, expiringSoonDate), status: Not(LICENSE_ALLOCATED_STATUS.DELETED), }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); return expiringSoonLicense; @@ -262,6 +266,7 @@ export class AccountsRepositoryService { * @returns allocatableLicenseWithMargin */ private async getAllocatableLicenseWithMargin( + context: Context, entityManager: EntityManager, id: number, expiringSoonDate: Date, @@ -288,6 +293,7 @@ export class AccountsRepositoryService { expiry_date: IsNull(), }, ], + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); return allocatableLicenseWithMargin; @@ -301,6 +307,7 @@ export class AccountsRepositoryService { * @returns licenseSummary */ async getLicenseSummaryInfo( + context: Context, id: number, currentDate: Date, expiringSoonDate: Date, @@ -326,6 +333,7 @@ export class AccountsRepositoryService { status: Not(LICENSE_ALLOCATED_STATUS.DELETED), }, ], + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 有効な総ライセンス数のうち、ユーザーに割り当て済みのライセンス数を取得する @@ -360,6 +368,7 @@ export class AccountsRepositoryService { status: LICENSE_ALLOCATED_STATUS.REUSABLE, }, ], + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 総ライセンス数のうち、一度もユーザーに割り当てたことのないライセンス数を取得する @@ -376,10 +385,12 @@ export class AccountsRepositoryService { status: LICENSE_ALLOCATED_STATUS.UNALLOCATED, }, ], + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 有効期限が現在日付からしきい値以内のライセンス数を取得する const expiringSoonLicense = await this.getExpiringSoonLicense( + context, entityManager, id, currentDate, @@ -392,6 +403,7 @@ export class AccountsRepositoryService { from_account_id: id, status: LICENSE_ISSUE_STATUS.ISSUE_REQUESTING, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 未発行状態あるいは発行キャンセルされた注文の総ライセンス数を取得する @@ -402,19 +414,22 @@ export class AccountsRepositoryService { .andWhere('license_orders.status = :status', { status: LICENSE_ISSUE_STATUS.ISSUE_REQUESTING, }) + .comment(`${context.getTrackingId()}_${new Date().toUTCString()}`) .getRawOne(); const issueRequesting = parseInt(result.sum, 10) || 0; // 有効期限がしきい値より未来または未設定で、割り当て可能なライセンス数の取得を行う const allocatableLicenseWithMargin = await this.getAllocatableLicenseWithMargin( + context, entityManager, id, expiringSoonDate, ); // アカウントのロック状態を取得する - const isStorageAvailable = (await this.findAccountById(id)).locked; + const isStorageAvailable = (await this.findAccountById(context, id)) + .locked; let licenseSummary = new LicenseSummaryInfo(); licenseSummary = { @@ -442,6 +457,7 @@ export class AccountsRepositoryService { * @returns issueRequesting */ private async getAccountLicenseOrderStatus( + context: Context, id: number, currentDate: Date, entityManager: EntityManager, @@ -467,6 +483,7 @@ export class AccountsRepositoryService { status: Not(LICENSE_ALLOCATED_STATUS.DELETED), }, ], + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 子アカウントからの、未発行状態あるいは発行キャンセルされた注文の総ライセンス数を取得する @@ -477,6 +494,7 @@ export class AccountsRepositoryService { .andWhere('license_orders.status = :status', { status: LICENSE_ISSUE_STATUS.ISSUE_REQUESTING, }) + .comment(`${context.getTrackingId()}_${new Date().toUTCString()}`) .getRawOne(); const issuedRequested = parseInt(issuedRequestedSqlResult.sum, 10) || 0; @@ -488,6 +506,7 @@ export class AccountsRepositoryService { .andWhere('license_orders.status = :status', { status: LICENSE_ISSUE_STATUS.ISSUE_REQUESTING, }) + .comment(`${context.getTrackingId()}_${new Date().toUTCString()}`) .getRawOne(); const issuedRequesting = parseInt(issuedRequestingSqlResult.sum, 10) || 0; @@ -508,6 +527,7 @@ export class AccountsRepositoryService { * @returns childrenPartnerLicensesFromRepository: リポジトリから取得した子アカウントのライセンス情報 */ async getPartnerLicense( + context: Context, id: number, currentDate: Date, expiringSoonDate: Date, @@ -526,6 +546,7 @@ export class AccountsRepositoryService { where: { id: id, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!ownAccount) { throw new AccountNotFoundError(`Account is Not Found.`); @@ -533,6 +554,7 @@ export class AccountsRepositoryService { // 自アカウントのライセンス注文状況を取得する const ownLicenseOrderStatus = await this.getAccountLicenseOrderStatus( + context, id, currentDate, entityManager, @@ -558,6 +580,7 @@ export class AccountsRepositoryService { }, take: limit, skip: offset, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 各子アカウントのライセンス注文状況を取得する @@ -566,6 +589,7 @@ export class AccountsRepositoryService { for (const childAccount of childAccounts) { // ライセンス注文状況を取得する const childLicenseOrderStatus = await this.getAccountLicenseOrderStatus( + context, childAccount.id, currentDate, entityManager, @@ -576,6 +600,7 @@ export class AccountsRepositoryService { let allocatableLicenseWithMargin: number = 0; if (childAccount.tier === TIERS.TIER5) { expiringSoonLicense = await this.getExpiringSoonLicense( + context, entityManager, childAccount.id, currentDate, @@ -583,6 +608,7 @@ export class AccountsRepositoryService { ); allocatableLicenseWithMargin = await this.getAllocatableLicenseWithMargin( + context, entityManager, childAccount.id, expiringSoonDate, @@ -612,6 +638,7 @@ export class AccountsRepositoryService { where: { parent_account_id: id, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); return { @@ -626,11 +653,12 @@ export class AccountsRepositoryService { * Dealer(Tier4)アカウント情報を取得する * @returns dealer accounts */ - async findDealerAccounts(): Promise { + async findDealerAccounts(context: Context): Promise { const accounts = await this.dataSource.getRepository(Account).find({ where: { tier: TIERS.TIER4, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); return accounts; @@ -642,7 +670,10 @@ export class AccountsRepositoryService { * @param targetAccountId * @returns accountIds */ - async getHierarchyParents(targetAccountId: number): Promise { + async getHierarchyParents( + context: Context, + targetAccountId: number, + ): Promise { return await this.dataSource.transaction(async (entityManager) => { const accountRepository = entityManager.getRepository(Account); const maxTierDifference = TIERS.TIER5 - TIERS.TIER1; @@ -655,6 +686,7 @@ export class AccountsRepositoryService { where: { id: currentAccountId, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!account) { break; @@ -676,7 +708,11 @@ export class AccountsRepositoryService { * @param orderedAccountId:キャンセルしたい発行の注文元アカウントID * @param poNumber:POナンバー */ - async cancelIssue(orderedAccountId: number, poNumber: string): Promise { + async cancelIssue( + context: Context, + orderedAccountId: number, + poNumber: string, + ): Promise { await this.dataSource.transaction(async (entityManager) => { const orderRepo = entityManager.getRepository(LicenseOrder); @@ -687,6 +723,7 @@ export class AccountsRepositoryService { po_number: poNumber, status: LICENSE_ISSUE_STATUS.ISSUED, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // キャンセル対象の発行が存在しない場合エラー @@ -715,6 +752,7 @@ export class AccountsRepositoryService { order_id: targetOrder.id, status: Not(LICENSE_ALLOCATED_STATUS.UNALLOCATED), }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 存在した場合エラー @@ -754,6 +792,7 @@ export class AccountsRepositoryService { * @returns partners: DBから取得できるパートナー一覧情報 */ async getPartners( + context: Context, id: number, limit: number, offset: number, @@ -769,6 +808,7 @@ export class AccountsRepositoryService { where: { parent_account_id: id, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const partnerAccounts = await accountRepo.find({ @@ -780,6 +820,7 @@ export class AccountsRepositoryService { }, take: limit, skip: offset, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // ADB2Cから情報を取得するための外部ユーザIDを取得する(念のためプライマリ管理者IDが存在しない場合を考慮) @@ -797,6 +838,7 @@ export class AccountsRepositoryService { where: { id: In(primaryUserIds), }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // アカウント情報とプライマリ管理者の外部ユーザIDをマージ @@ -836,6 +878,7 @@ export class AccountsRepositoryService { * @returns account: 一階層上のアカウント */ async getOneUpperTierAccount( + context: Context, accountId: number, tier: number, ): Promise { @@ -846,6 +889,7 @@ export class AccountsRepositoryService { id: accountId, tier: tier - 1, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); }); } @@ -860,6 +904,7 @@ export class AccountsRepositoryService { * @param secondryAdminUserId */ async updateAccountInfo( + context: Context, myAccountId: number, tier: number, delegationPermission: boolean, @@ -871,6 +916,7 @@ export class AccountsRepositoryService { // ディーラーアカウントが指定されている場合、存在チェックを行う if (parentAccountId) { const dealerAccount = await this.getOneUpperTierAccount( + context, parentAccountId, tier, ); @@ -891,6 +937,7 @@ export class AccountsRepositoryService { account_id: myAccountId, email_verified: true, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!primaryAdminUser) { throw new AdminUserNotFoundError( @@ -907,6 +954,7 @@ export class AccountsRepositoryService { account_id: myAccountId, email_verified: true, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!secondryAdminUser) { throw new AdminUserNotFoundError( @@ -935,6 +983,7 @@ export class AccountsRepositoryService { * @returns active worktype id */ async updateActiveWorktypeId( + context: Context, accountId: number, id?: number | undefined, ): Promise { @@ -946,6 +995,7 @@ export class AccountsRepositoryService { // 自アカウント内に指定IDのワークタイプが存在するか確認 const worktype = await worktypeRepo.findOne({ where: { account_id: accountId, id: id }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // ワークタイプが存在しない場合はエラー @@ -967,13 +1017,17 @@ export class AccountsRepositoryService { * @param accountId * @returns users 削除対象のユーザー */ - async deleteAccountAndInsertArchives(accountId: number): Promise { + async deleteAccountAndInsertArchives( + context: Context, + accountId: number, + ): Promise { return await this.dataSource.transaction(async (entityManager) => { // 削除対象のユーザーを退避テーブルに退避 const users = await this.dataSource.getRepository(User).find({ where: { account_id: accountId, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const userArchiveRepo = entityManager.getRepository(UserArchive); await userArchiveRepo @@ -988,6 +1042,7 @@ export class AccountsRepositoryService { where: { account_id: accountId, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const licenseArchiveRepo = entityManager.getRepository(LicenseArchive); await licenseArchiveRepo @@ -1004,6 +1059,7 @@ export class AccountsRepositoryService { where: { account_id: accountId, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const licenseHistoryArchiveRepo = entityManager.getRepository( LicenseAllocationHistoryArchive, @@ -1029,6 +1085,7 @@ export class AccountsRepositoryService { where: { account_id: accountId, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const cardLicenseRepo = entityManager.getRepository(CardLicense); await cardLicenseRepo.delete({ @@ -1048,6 +1105,7 @@ export class AccountsRepositoryService { const worktypeRepo = entityManager.getRepository(Worktype); const taggerWorktypes = await worktypeRepo.find({ where: { account_id: accountId }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const optionItemRepo = entityManager.getRepository(OptionItem); @@ -1062,6 +1120,7 @@ export class AccountsRepositoryService { where: { account_id: accountId, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const checkoutPermissionRepo = entityManager.getRepository(CheckoutPermission); @@ -1078,6 +1137,7 @@ export class AccountsRepositoryService { where: { account_id: accountId, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const audioOptionItemsRepo = entityManager.getRepository(AudioOptionItem); await audioOptionItemsRepo.delete({ @@ -1093,6 +1153,7 @@ export class AccountsRepositoryService { where: { account_id: accountId, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const userGroupMemberRepo = entityManager.getRepository(UserGroupMember); await userGroupMemberRepo.delete({ diff --git a/dictation_server/src/repositories/licenses/licenses.repository.service.ts b/dictation_server/src/repositories/licenses/licenses.repository.service.ts index ddac253..b761a22 100644 --- a/dictation_server/src/repositories/licenses/licenses.repository.service.ts +++ b/dictation_server/src/repositories/licenses/licenses.repository.service.ts @@ -32,6 +32,7 @@ import { DateWithZeroTime, } from '../../features/licenses/types/types'; import { NewAllocatedLicenseExpirationDate } from '../../features/licenses/types/types'; +import { Context } from '../../common/log'; @Injectable() export class LicensesRepositoryService { @@ -39,6 +40,7 @@ export class LicensesRepositoryService { private readonly logger = new Logger(LicensesRepositoryService.name); async order( + context: Context, poNumber: string, fromAccountId: number, toAccountId: number, @@ -70,6 +72,7 @@ export class LicensesRepositoryService { status: LICENSE_ISSUE_STATUS.ISSUE_REQUESTING, }, ], + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 重複があった場合はエラーを返却する if (isPoNumberDuplicated) { @@ -92,6 +95,7 @@ export class LicensesRepositoryService { * @returns string[] カードライセンスキーの配列 */ async createCardLicenses( + context: Context, accountId: number, count: number, ): Promise { @@ -139,6 +143,7 @@ export class LicensesRepositoryService { where: { card_license_key: In(generateKeys), }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (existingCardLicenses.length > 0) { // 重複分を配列から削除 @@ -222,6 +227,7 @@ export class LicensesRepositoryService { * @returns void */ async activateCardLicense( + context: Context, accountId: number, licenseKey: string, ): Promise { @@ -233,6 +239,7 @@ export class LicensesRepositoryService { where: { card_license_key: licenseKey, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // カードライセンスが存在しなければエラー if (!targetCardLicense) { @@ -256,6 +263,7 @@ export class LicensesRepositoryService { where: { id: targetCardLicense.license_id, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // ライセンスが存在しなければエラー if (!targetLicense) { @@ -289,6 +297,7 @@ export class LicensesRepositoryService { * @returns licenseOrders */ async getLicenseOrderHistoryInfo( + context: Context, accountId: number, offset: number, limit: number, @@ -303,6 +312,7 @@ export class LicensesRepositoryService { where: { from_account_id: accountId, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const licenseOrders = await licenseOrder.find({ where: { @@ -313,6 +323,7 @@ export class LicensesRepositoryService { }, take: limit, skip: offset, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); return { total: total, @@ -330,6 +341,7 @@ export class LicensesRepositoryService { * @param poNumber */ async issueLicense( + context: Context, orderedAccountId: number, myAccountId: number, tier: number, @@ -345,6 +357,7 @@ export class LicensesRepositoryService { from_account_id: orderedAccountId, po_number: poNumber, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 注文が存在しない場合、エラー if (!issuingOrder) { @@ -394,6 +407,7 @@ export class LicensesRepositoryService { id: 'ASC', }, take: newLicenses.length, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 登録したライセンスに対して自身のライセンスが不足していた場合、エラー @@ -420,6 +434,7 @@ export class LicensesRepositoryService { * @return AllocatableLicenseInfo[] */ async getAllocatableLicenses( + context: Context, myAccountId: number, ): Promise { const nowDate = new DateWithZeroTime(); @@ -438,6 +453,7 @@ export class LicensesRepositoryService { '(license.expiry_date >= :nowDate OR license.expiry_date IS NULL)', { nowDate }, ) + .comment(`${context.getTrackingId()}_${new Date().toUTCString()}`) .orderBy('license.expiry_date IS NULL', 'DESC') .addOrderBy('license.expiry_date', 'DESC') .addOrderBy('license.id', 'ASC'); @@ -453,6 +469,7 @@ export class LicensesRepositoryService { * @param newLicenseId */ async allocateLicense( + context: Context, userId: number, newLicenseId: number, accountId: number, @@ -467,6 +484,7 @@ export class LicensesRepositoryService { where: { id: newLicenseId, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // ライセンスが存在しない場合はエラー @@ -501,6 +519,7 @@ export class LicensesRepositoryService { where: { allocated_user_id: userId, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 既にライセンスが割り当てられているなら、割り当てを解除 @@ -537,6 +556,7 @@ export class LicensesRepositoryService { }, where: { user_id: userId, is_allocated: true }, order: { executed_at: 'DESC' }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); let switchFromType = ''; @@ -574,7 +594,11 @@ export class LicensesRepositoryService { * ユーザーに割り当てられているライセンスを解除する * @param userId */ - async deallocateLicense(userId: number, accountId: number): Promise { + async deallocateLicense( + context: Context, + userId: number, + accountId: number, + ): Promise { await this.dataSource.transaction(async (entityManager) => { const licenseRepo = entityManager.getRepository(License); const licenseAllocationHistoryRepo = entityManager.getRepository( @@ -586,6 +610,7 @@ export class LicensesRepositoryService { allocated_user_id: userId, status: LICENSE_ALLOCATED_STATUS.ALLOCATED, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // ライセンスが割り当てられていない場合はエラー @@ -617,7 +642,11 @@ export class LicensesRepositoryService { * @param accountId * @param poNumber */ - async cancelOrder(accountId: number, poNumber: string): Promise { + async cancelOrder( + context: Context, + accountId: number, + poNumber: string, + ): Promise { await this.dataSource.transaction(async (entityManager) => { const orderRepo = entityManager.getRepository(LicenseOrder); @@ -628,6 +657,7 @@ export class LicensesRepositoryService { po_number: poNumber, status: LICENSE_ISSUE_STATUS.ISSUE_REQUESTING, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // キャンセル対象の注文が存在しない場合エラー @@ -651,6 +681,7 @@ export class LicensesRepositoryService { * @returns Promise<{ state: 'allocated' | 'inallocated' | 'expired' }> */ async getLicenseState( + context: Context, userId: number, ): Promise<{ state: 'allocated' | 'inallocated' | 'expired' }> { const allocatedLicense = await this.dataSource @@ -660,6 +691,7 @@ export class LicensesRepositoryService { allocated_user_id: userId, status: LICENSE_ALLOCATED_STATUS.ALLOCATED, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // ライセンスが割り当てられていない場合は未割当状態 diff --git a/dictation_server/src/repositories/sort_criteria/sort_criteria.repository.service.ts b/dictation_server/src/repositories/sort_criteria/sort_criteria.repository.service.ts index fb3252d..99feba1 100644 --- a/dictation_server/src/repositories/sort_criteria/sort_criteria.repository.service.ts +++ b/dictation_server/src/repositories/sort_criteria/sort_criteria.repository.service.ts @@ -5,6 +5,7 @@ import { TaskListSortableAttribute, SortDirection, } from '../../common/types/sort'; +import { Context } from '../../common/log'; @Injectable() export class SortCriteriaRepositoryService { @@ -18,6 +19,7 @@ export class SortCriteriaRepositoryService { * @returns sort criteria */ async updateSortCriteria( + context: Context, userId: number, parameter: TaskListSortableAttribute, direction: SortDirection, @@ -31,6 +33,7 @@ export class SortCriteriaRepositoryService { where: { user_id: userId, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 運用上はあり得ないが、プログラム上発生しうるのでエラーとして処理 if (!targetSortCriteria) { @@ -49,7 +52,10 @@ export class SortCriteriaRepositoryService { * @param userId * @returns sort criteria */ - async getSortCriteria(userId: number): Promise { + async getSortCriteria( + context: Context, + userId: number, + ): Promise { this.logger.log(` ${this.updateSortCriteria.name}; userId:${userId}`); const repo = this.dataSource.getRepository(SortCriteria); @@ -57,6 +63,7 @@ export class SortCriteriaRepositoryService { where: { user_id: userId, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 運用上はあり得ないが、プログラム上発生しうるのでエラーとして処理 if (!sortCriteria) { diff --git a/dictation_server/src/repositories/tasks/tasks.repository.service.ts b/dictation_server/src/repositories/tasks/tasks.repository.service.ts index d543609..eb2be07 100644 --- a/dictation_server/src/repositories/tasks/tasks.repository.service.ts +++ b/dictation_server/src/repositories/tasks/tasks.repository.service.ts @@ -41,6 +41,7 @@ import { TaskStatus, isTaskStatus } from '../../common/types/taskStatus'; import { SortCriteria } from '../sort_criteria/entity/sort_criteria.entity'; import { Workflow } from '../workflows/entity/workflow.entity'; import { Worktype } from '../worktypes/entity/worktype.entity'; +import { Context } from '../../common/log'; @Injectable() export class TasksRepositoryService { @@ -54,6 +55,7 @@ export class TasksRepositoryService { * @returns task and audio file */ async getTaskAndAudioFile( + context: Context, audioFileId: number, account_id: number, status: string[], @@ -71,6 +73,7 @@ export class TasksRepositoryService { account_id: account_id, status: In(status), }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!task) { throw new TasksNotFoundError( @@ -103,6 +106,7 @@ export class TasksRepositoryService { * @returns task from author id */ async getTaskFromAudioFileId( + context: Context, audio_file_id: number, account_id: number, author_id: string, @@ -117,6 +121,7 @@ export class TasksRepositoryService { where: { audio_file_id: audio_file_id, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!task) { throw new TasksNotFoundError( @@ -147,6 +152,7 @@ export class TasksRepositoryService { * @returns checkout */ async checkout( + context: Context, audio_file_id: number, account_id: number, user_id: number, @@ -159,6 +165,7 @@ export class TasksRepositoryService { where: { audio_file_id: audio_file_id, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!task) { throw new TasksNotFoundError( @@ -173,6 +180,7 @@ export class TasksRepositoryService { status: TASK_STATUS.IN_PROGRESS, typist_user_id: user_id, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (tasks.length > 0) { @@ -210,6 +218,7 @@ export class TasksRepositoryService { id: user_id, }, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // ユーザーの所属するすべてのグループIDを列挙 const groupIds = groups.map((member) => member.user_group_id); @@ -231,6 +240,7 @@ export class TasksRepositoryService { user_group_id: In(groupIds), }, ], + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); //チェックアウト権限がなければエラー @@ -275,6 +285,7 @@ export class TasksRepositoryService { * @returns checkin */ async checkin( + context: Context, audio_file_id: number, user_id: number, permittedSourceStatus: TaskStatus, @@ -285,6 +296,7 @@ export class TasksRepositoryService { where: { audio_file_id: audio_file_id, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!task) { throw new TasksNotFoundError( @@ -322,6 +334,7 @@ export class TasksRepositoryService { * @returns cancel */ async cancel( + context: Context, audio_file_id: number, permittedSourceStatus: TaskStatus[], account_id: number, @@ -333,6 +346,7 @@ export class TasksRepositoryService { where: { audio_file_id: audio_file_id, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!task) { throw new TasksNotFoundError( @@ -388,6 +402,7 @@ export class TasksRepositoryService { * @returns suspend */ async suspend( + context: Context, audio_file_id: number, user_id: number, permittedSourceStatus: TaskStatus, @@ -398,6 +413,7 @@ export class TasksRepositoryService { where: { audio_file_id: audio_file_id, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!task) { throw new TasksNotFoundError( @@ -433,6 +449,7 @@ export class TasksRepositoryService { * @returns backup */ async backup( + context: Context, accountId: number, audio_file_id: number, permittedSourceStatus: TaskStatus[], @@ -444,6 +461,7 @@ export class TasksRepositoryService { account_id: accountId, audio_file_id: audio_file_id, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!task) { throw new TasksNotFoundError( @@ -482,6 +500,7 @@ export class TasksRepositoryService { * @returns tasks: タスク情報 / permissions:タスクに紐づくチェックアウト権限情報 / count: offset|limitを行わなかった場合の該当タスクの合計 */ async getTasksFromAccountId( + context: Context, account_id: number, offset: number, limit: number, @@ -504,6 +523,7 @@ export class TasksRepositoryService { account_id: account_id, status: In(status), }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 条件に該当するTask一覧を取得 @@ -520,6 +540,7 @@ export class TasksRepositoryService { order: order, // 引数によってOrderに使用するパラメータを変更 take: limit, skip: offset, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // TODO [Task2249] Task内にCheckoutPermissionを含める方法が上手くいかなかった(複雑になりすぎた? 原因未調査)ため、 @@ -535,6 +556,7 @@ export class TasksRepositoryService { where: { task_id: In(taskIds), }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); return { tasks, permissions, count }; }); @@ -552,6 +574,7 @@ export class TasksRepositoryService { * @returns tasks: タスク情報 / permissions:タスクに紐づくチェックアウト権限情報 / count: offset|limitを行わなかった場合の該当タスクの合計 */ async getTasksFromAuthorIdAndAccountId( + context: Context, author_id: string, account_id: number, offset: number, @@ -573,6 +596,7 @@ export class TasksRepositoryService { status: In(status), file: { author_id: author_id }, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const tasks = await taskRepo.find({ @@ -589,6 +613,7 @@ export class TasksRepositoryService { order: order, // 引数によってOrderに使用するパラメータを変更 take: limit, skip: offset, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const checkoutRepo = entityManager.getRepository(CheckoutPermission); @@ -601,6 +626,7 @@ export class TasksRepositoryService { where: { task_id: In(taskIds), }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); return { tasks, permissions, count }; }); @@ -608,6 +634,7 @@ export class TasksRepositoryService { } async getTasksFromTypistRelations( + context: Context, external_user_id: string, offset: number, limit: number, @@ -633,6 +660,7 @@ export class TasksRepositoryService { external_id: external_user_id, }, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // ユーザーの所属するすべてのグループIDを列挙 const groupIds = groups.map((member) => member.user_group_id); @@ -655,6 +683,7 @@ export class TasksRepositoryService { user_group_id: In(groupIds), }, ], + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // ユーザー本人、またはユーザーが所属するユーザーグループがチェックアウト可能なタスクIDの一覧を作成 @@ -683,6 +712,7 @@ export class TasksRepositoryService { status: In(status), }, ], + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 条件に該当するTask一覧を取得 @@ -709,6 +739,7 @@ export class TasksRepositoryService { order: order, // 引数によってOrderに使用するパラメータを変更 take: limit, skip: offset, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // TODO [Task2249] Task内にCheckoutPermissionを含める方法が上手くいかなかった(複雑になりすぎた? 原因未調査)ため、 @@ -722,6 +753,7 @@ export class TasksRepositoryService { where: { task_id: In(taskIds), }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); return { tasks, permissions, count }; }); @@ -732,6 +764,7 @@ export class TasksRepositoryService { * 文字起こしタスクと音声ファイル、オプションアイテムを追加 */ async create( + context: Context, account_id: number, owner_user_id: number, priority: string, @@ -786,6 +819,7 @@ export class TasksRepositoryService { const lastTask = await taskRepo.findOne({ where: { account_id: account_id, is_job_number_enabled: true }, order: { created_at: 'DESC', job_number: 'DESC' }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); let newJobNumber = '00000001'; @@ -828,6 +862,7 @@ export class TasksRepositoryService { * @returns checkout permission */ async changeCheckoutPermission( + context: Context, audio_file_id: number, author_id: string | undefined, account_id: number, @@ -848,6 +883,7 @@ export class TasksRepositoryService { account_id: account_id, deleted_at: IsNull(), }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // idはユニークであるため取得件数の一致でグループの存在を確認 if (userGroupIds.length !== groupRecords.length) { @@ -873,6 +909,7 @@ export class TasksRepositoryService { email_verified: true, deleted_at: IsNull(), }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // idはユニークであるため取得件数の一致でユーザーの存在を確認 if (typistUserIds.length !== userRecords.length) { @@ -897,6 +934,7 @@ export class TasksRepositoryService { : author_id, }, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); //タスクが存在しない or ステータスがUploadedでなければエラー if (!taskRecord) { @@ -935,6 +973,7 @@ export class TasksRepositoryService { * @returns sorted tasks */ async getSortedTasks( + context: Context, accountId: number, userId: number, audioFileId: number, @@ -943,7 +982,10 @@ export class TasksRepositoryService { const taskRepo = entityManager.getRepository(Task); const sortRepo = entityManager.getRepository(SortCriteria); - const sort = await sortRepo.findOne({ where: { user_id: userId } }); + const sort = await sortRepo.findOne({ + where: { user_id: userId }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, + }); // 運用上はあり得ないが、プログラム上発生しうるのでエラーとして処理 if (!sort) { @@ -972,6 +1014,7 @@ export class TasksRepositoryService { TASK_STATUS.UPLOADED, ]), }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!targetTask) { @@ -995,6 +1038,7 @@ export class TasksRepositoryService { // ユーザーの所属するユーザーグループがチェックアウト可能である { user_group_id: In(groupIds) }, ], + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // ユーザー本人、またはユーザーが所属するユーザーグループがチェックアウト可能なタスクIDの一覧を作成 @@ -1017,6 +1061,7 @@ export class TasksRepositoryService { }, ], order: order, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); return tasks; @@ -1031,6 +1076,7 @@ export class TasksRepositoryService { * @returns typistIds: タイピストIDの一覧 / typistGroupIds: タイピストグループIDの一覧 */ async autoRouting( + context: Context, audioFileId: number, accountId: number, myAuthorId?: string, // API実行者のAuthorId @@ -1046,6 +1092,7 @@ export class TasksRepositoryService { id: audioFileId, account_id: accountId, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!audioFile) { throw new Error( @@ -1067,6 +1114,7 @@ export class TasksRepositoryService { author_id: audioFile.author_id, account_id: accountId, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 音声ファイル上のworktypeIdをもとにworktypeを取得 @@ -1076,6 +1124,7 @@ export class TasksRepositoryService { custom_worktype_id: audioFile.work_type_id, account_id: accountId, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 音声ファイル上のworktypeIdが設定されているが、一致するworktypeが存在しない場合はエラーを出して終了 @@ -1096,11 +1145,13 @@ export class TasksRepositoryService { author_id: authorUser?.id ?? IsNull(), // authorUserが存在しない場合は、必ずヒットしないようにNULLを設定する worktype_id: worktypeRecord?.id ?? IsNull(), }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // Workflow(ルーティングルール)があればタスクのチェックアウト権限を設定する if (workflow) { return await this.setCheckoutPermissionAndTemplate( + context, workflow, task, accountId, @@ -1121,6 +1172,7 @@ export class TasksRepositoryService { author_id: myAuthorId, account_id: accountId, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!myAuthorUser) { throw new Error( @@ -1136,6 +1188,7 @@ export class TasksRepositoryService { author_id: myAuthorUser.id, worktype_id: worktypeRecord?.id ?? IsNull(), }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // API実行者のAuthorIdと音声ファイルのWorktypeをもとにルーティングルールを取得できない場合はエラーを出して終了 @@ -1147,6 +1200,7 @@ export class TasksRepositoryService { // Workflow(ルーティングルール)があればタスクのチェックアウト権限を設定する return await this.setCheckoutPermissionAndTemplate( + context, defaultWorkflow, task, accountId, @@ -1168,6 +1222,7 @@ export class TasksRepositoryService { * @returns checkout permission */ private async setCheckoutPermissionAndTemplate( + context: Context, workflow: Workflow, task: Task, accountId: number, @@ -1196,6 +1251,7 @@ export class TasksRepositoryService { ); const typistUsers = await userRepo.find({ where: { account_id: accountId, id: In(typistIds) }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (typistUsers.length !== typistIds.length) { throw new Error(`typist not found. ids: ${typistIds}`); @@ -1208,6 +1264,7 @@ export class TasksRepositoryService { const userGroupRepo = entityManager.getRepository(UserGroup); const typistGroups = await userGroupRepo.find({ where: { account_id: accountId, id: In(groupIds) }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (typistGroups.length !== groupIds.length) { throw new Error(`typist group not found. ids: ${groupIds}`); diff --git a/dictation_server/src/repositories/template_files/template_files.repository.service.ts b/dictation_server/src/repositories/template_files/template_files.repository.service.ts index 4647b3f..69ad434 100644 --- a/dictation_server/src/repositories/template_files/template_files.repository.service.ts +++ b/dictation_server/src/repositories/template_files/template_files.repository.service.ts @@ -1,6 +1,7 @@ import { Injectable } from '@nestjs/common'; import { DataSource } from 'typeorm'; import { TemplateFile } from './entity/template_file.entity'; +import { Context } from '../../common/log'; @Injectable() export class TemplateFilesRepositoryService { @@ -11,12 +12,16 @@ export class TemplateFilesRepositoryService { * @param accountId * @returns template files */ - async getTemplateFiles(accountId: number): Promise { + async getTemplateFiles( + context: Context, + accountId: number, + ): Promise { return await this.dataSource.transaction(async (entityManager) => { const templateFilesRepo = entityManager.getRepository(TemplateFile); const templates = await templateFilesRepo.find({ where: { account_id: accountId }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); return templates; @@ -31,6 +36,7 @@ export class TemplateFilesRepositoryService { * @returns template file */ async upsertTemplateFile( + context: Context, accountId: number, fileName: string, url: string, @@ -41,6 +47,7 @@ export class TemplateFilesRepositoryService { // アカウント内に同名ファイルがあるか確認 const template = await templateFilesRepo.findOne({ where: { account_id: accountId, file_name: fileName }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 同名ファイルは同じものとして扱うため、すでにファイルがあれば更新(更新日時の履歴を残しておきたい) diff --git a/dictation_server/src/repositories/terms/terms.repository.service.ts b/dictation_server/src/repositories/terms/terms.repository.service.ts index 7deee0f..66b99e6 100644 --- a/dictation_server/src/repositories/terms/terms.repository.service.ts +++ b/dictation_server/src/repositories/terms/terms.repository.service.ts @@ -4,6 +4,7 @@ import { TermsVersion } from '../../features/terms/types/types'; import { Term } from './entity/term.entity'; import { TERM_TYPE } from '../../constants'; import { TermInfoNotFoundError } from '../users/errors/types'; +import { Context } from '../../common/log'; @Injectable() export class TermsRepositoryService { @@ -13,7 +14,7 @@ export class TermsRepositoryService { * 利用規約の最新バージョンを取得する * @returns Term[] */ - async getLatestTermsInfo(): Promise { + async getLatestTermsInfo(context: Context): Promise { return await this.dataSource.transaction(async (entityManager) => { const termRepo = entityManager.getRepository(Term); const latestEulaInfo = await termRepo.findOne({ @@ -23,6 +24,7 @@ export class TermsRepositoryService { order: { id: 'DESC', }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const latestPrivacyNoticeInfo = await termRepo.findOne({ where: { @@ -31,6 +33,7 @@ export class TermsRepositoryService { order: { id: 'DESC', }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const latestDpaInfo = await termRepo.findOne({ where: { @@ -39,6 +42,7 @@ export class TermsRepositoryService { order: { id: 'DESC', }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!latestEulaInfo || !latestPrivacyNoticeInfo || !latestDpaInfo) { diff --git a/dictation_server/src/repositories/user_groups/user_groups.repository.service.ts b/dictation_server/src/repositories/user_groups/user_groups.repository.service.ts index 061e9e9..eee2390 100644 --- a/dictation_server/src/repositories/user_groups/user_groups.repository.service.ts +++ b/dictation_server/src/repositories/user_groups/user_groups.repository.service.ts @@ -5,18 +5,23 @@ import { UserGroupMember } from './entity/user_group_member.entity'; import { User } from '../users/entity/user.entity'; import { TypistGroupNotExistError, TypistIdInvalidError } from './errors/types'; import { USER_ROLES } from '../../constants'; +import { Context } from '../../common/log'; @Injectable() export class UserGroupsRepositoryService { constructor(private dataSource: DataSource) {} - async getUserGroups(account_id: number): Promise { + async getUserGroups( + context: Context, + account_id: number, + ): Promise { const value = await this.dataSource.transaction(async (entityManager) => { const userGroupRepo = entityManager.getRepository(UserGroup); const userGroups = await userGroupRepo.find({ // 論理削除されていないレコードを取得 where: { account_id: account_id, deleted_at: IsNull() }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); return userGroups; @@ -29,6 +34,7 @@ export class UserGroupsRepositoryService { * @returns users from groups */ async getGroupMembersFromGroupIds( + context: Context, groupIds: number[], ): Promise { return await this.dataSource.transaction(async (entityManager) => { @@ -41,6 +47,7 @@ export class UserGroupsRepositoryService { where: { user_group_id: In(groupIds), }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); return groupMembers; @@ -54,6 +61,7 @@ export class UserGroupsRepositoryService { * @returns typist group */ async getTypistGroup( + context: Context, accountId: number, typistGroupId: number, ): Promise { @@ -69,6 +77,7 @@ export class UserGroupsRepositoryService { relations: { userGroupMembers: true, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!userGroup) { @@ -88,6 +97,7 @@ export class UserGroupsRepositoryService { * @returns createdTypistGroup */ async createTypistGroup( + context: Context, name: string, typistIds: number[], accountId: number, @@ -104,6 +114,7 @@ export class UserGroupsRepositoryService { role: USER_ROLES.TYPIST, email_verified: true, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (userRecords.length !== typistIds.length) { throw new TypistIdInvalidError( @@ -139,6 +150,7 @@ export class UserGroupsRepositoryService { * @returns createdTypistGroup */ async updateTypistGroup( + context: Context, accountId: number, typistGroupId: number, typistGroupName: string, @@ -156,6 +168,7 @@ export class UserGroupsRepositoryService { role: USER_ROLES.TYPIST, email_verified: true, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (userRecords.length !== typistIds.length) { throw new TypistIdInvalidError( @@ -171,6 +184,7 @@ export class UserGroupsRepositoryService { id: typistGroupId, account_id: accountId, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!typistGroup) { throw new TypistGroupNotExistError( diff --git a/dictation_server/src/repositories/users/users.repository.service.ts b/dictation_server/src/repositories/users/users.repository.service.ts index 8894656..7825073 100644 --- a/dictation_server/src/repositories/users/users.repository.service.ts +++ b/dictation_server/src/repositories/users/users.repository.service.ts @@ -99,12 +99,16 @@ export class UsersRepositoryService { return createdEntity; } - async findVerifiedUser(sub: string): Promise { + async findVerifiedUser( + context: Context, + sub: string, + ): Promise { const user = await this.dataSource.getRepository(User).findOne({ where: { external_id: sub, email_verified: true, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!user) { @@ -113,7 +117,7 @@ export class UsersRepositoryService { return user; } - async findUserByExternalId(sub: string): Promise { + async findUserByExternalId(context: Context, sub: string): Promise { const user = await this.dataSource.getRepository(User).findOne({ where: { external_id: sub, @@ -121,6 +125,7 @@ export class UsersRepositoryService { relations: { account: true, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!user) { @@ -129,11 +134,12 @@ export class UsersRepositoryService { return user; } - async findUserById(id: number): Promise { + async findUserById(context: Context, id: number): Promise { const user = await this.dataSource.getRepository(User).findOne({ where: { id: id, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!user) { @@ -147,7 +153,11 @@ export class UsersRepositoryService { * @param user * @returns 存在する:true 存在しない:false */ - async existsAuthorId(accountId: number, authorId: string): Promise { + async existsAuthorId( + context: Context, + accountId: number, + authorId: string, + ): Promise { const user = await this.dataSource.getRepository(User).findOne({ where: [ { @@ -155,6 +165,7 @@ export class UsersRepositoryService { author_id: authorId, }, ], + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (user) { @@ -169,6 +180,7 @@ export class UsersRepositoryService { * @returns update */ async update( + context: Context, accountId: number, id: number, role: string, @@ -186,6 +198,7 @@ export class UsersRepositoryService { // 変更対象のユーザーを取得 const targetUser = await repo.findOne({ where: { id: id, account_id: accountId }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 運用上ユーザがいないことはあり得ないが、プログラム上発生しうるのでエラーとして処理 @@ -202,6 +215,7 @@ export class UsersRepositoryService { // ユーザーのロールがAuthorの場合はAuthorIDの重複チェックを行う const authorIdDuplicatedUser = await repo.findOne({ where: { account_id: accountId, id: Not(id), author_id: authorId }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 重複したAuthorIDがあった場合はエラー @@ -257,13 +271,17 @@ export class UsersRepositoryService { * @param user * @returns update */ - async updateUserVerified(id: number): Promise { + async updateUserVerified( + context: Context, + id: number, + ): Promise { return await this.dataSource.transaction(async (entityManager) => { const repo = entityManager.getRepository(User); const targetUser = await repo.findOne({ where: { id: id, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 運用上ユーザがいないことはあり得ないが、プログラム上発生しうるのでエラーとして処理 @@ -286,7 +304,10 @@ export class UsersRepositoryService { * @param id * @returns user verified and create trial license */ - async updateUserVerifiedAndCreateTrialLicense(id: number): Promise { + async updateUserVerifiedAndCreateTrialLicense( + context: Context, + id: number, + ): Promise { await this.dataSource.transaction(async (entityManager) => { const userRepo = entityManager.getRepository(User); const targetUser = await userRepo.findOne({ @@ -296,6 +317,7 @@ export class UsersRepositoryService { where: { id: id, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 運用上ユーザがいないことはあり得ないが、プログラム上発生しうるのでエラーとして処理 @@ -348,8 +370,12 @@ export class UsersRepositoryService { return await this.dataSource.transaction(async (entityManager) => { const repo = entityManager.getRepository(User); - const accountId = (await repo.findOne({ where: { external_id } })) - ?.account_id; + const accountId = ( + await repo.findOne({ + where: { external_id }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, + }) + )?.account_id; if (!accountId) { throw new AccountNotFoundError('Account is Not Found.'); @@ -363,7 +389,7 @@ export class UsersRepositoryService { license: true, }, where: { account_id: accountId }, - comment: `${context.getTrackingId()}`, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); return dbUsers; @@ -375,7 +401,7 @@ export class UsersRepositoryService { * @param sub * @returns typist users */ - async findTypistUsers(sub: string): Promise { + async findTypistUsers(context: Context, sub: string): Promise { return await this.dataSource.transaction(async (entityManager) => { const repo = entityManager.getRepository(User); @@ -383,6 +409,7 @@ export class UsersRepositoryService { where: { external_id: sub, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 運用上ユーザがいないことはあり得ないが、プログラム上発生しうるのでエラーとして処理 @@ -397,6 +424,7 @@ export class UsersRepositoryService { email_verified: true, deleted_at: IsNull(), }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); return typists; @@ -408,7 +436,7 @@ export class UsersRepositoryService { * @param accountId * @returns author users */ - async findAuthorUsers(accountId: number): Promise { + async findAuthorUsers(context: Context, accountId: number): Promise { return await this.dataSource.transaction(async (entityManager) => { const repo = entityManager.getRepository(User); const authors = await repo.find({ @@ -418,6 +446,7 @@ export class UsersRepositoryService { email_verified: true, deleted_at: IsNull(), }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); return authors; }); @@ -447,6 +476,7 @@ export class UsersRepositoryService { * @returns TermsCheckInfo */ async getAcceptedAndLatestVersion( + context: Context, externalId: string, ): Promise { return await this.dataSource.transaction(async (entityManager) => { @@ -458,6 +488,7 @@ export class UsersRepositoryService { relations: { account: true, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!user) { @@ -475,6 +506,7 @@ export class UsersRepositoryService { order: { id: 'DESC', }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const latestPrivacyNoticeInfo = await termRepo.findOne({ where: { @@ -483,6 +515,7 @@ export class UsersRepositoryService { order: { id: 'DESC', }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const latestDpaInfo = await termRepo.findOne({ where: { @@ -491,6 +524,7 @@ export class UsersRepositoryService { order: { id: 'DESC', }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!latestEulaInfo || !latestPrivacyNoticeInfo || !latestDpaInfo) { throw new TermInfoNotFoundError(`Terms info is not found.`); @@ -518,6 +552,7 @@ export class UsersRepositoryService { * @returns update */ async updateAcceptedTermsVersion( + context: Context, externalId: string, eulaVersion: string, privacyNoticeVersion: string, @@ -532,6 +567,7 @@ export class UsersRepositoryService { relations: { account: true, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!user) { @@ -574,6 +610,7 @@ export class UsersRepositoryService { * @returns delegate accounts */ async findDelegateUser( + context: Context, delegateAccountId: number, originAccountId: number, ): Promise { @@ -587,6 +624,7 @@ export class UsersRepositoryService { parent_account_id: delegateAccountId, tier: TIERS.TIER5, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!account) { @@ -619,6 +657,7 @@ export class UsersRepositoryService { relations: { account: true, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 運用上、代行操作対象アカウントの管理者ユーザーがいないことはあり得ないが、プログラム上発生しうるのでエラーとして処理 @@ -637,6 +676,7 @@ export class UsersRepositoryService { * @returns delegate accounts */ async isAllowDelegationPermission( + context: Context, delegateAccountId: number, originUserExternalId: string, ): Promise { @@ -653,6 +693,7 @@ export class UsersRepositoryService { relations: { account: true, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!primaryUser) { @@ -677,7 +718,10 @@ export class UsersRepositoryService { * @param userId * @returns user relations */ - async getUserRelations(userId: number): Promise<{ + async getUserRelations( + context: Context, + userId: number, + ): Promise<{ user: User; authors: User[]; worktypes: Worktype[]; @@ -689,6 +733,7 @@ export class UsersRepositoryService { const user = await userRepo.findOne({ where: { id: userId }, relations: { account: true }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!user) { @@ -709,6 +754,7 @@ export class UsersRepositoryService { role: USER_ROLES.AUTHOR, email_verified: true, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // ユーザーの所属するアカウント内のアクティブワークタイプを取得する @@ -722,6 +768,7 @@ export class UsersRepositoryService { account_id: user.account_id, id: activeWorktypeId, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, })) ?? undefined; } @@ -740,6 +787,7 @@ export class UsersRepositoryService { option_items: true, }, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); worktypes = workflows.flatMap((workflow) => diff --git a/dictation_server/src/repositories/workflows/workflows.repository.service.ts b/dictation_server/src/repositories/workflows/workflows.repository.service.ts index a1ea660..397956f 100644 --- a/dictation_server/src/repositories/workflows/workflows.repository.service.ts +++ b/dictation_server/src/repositories/workflows/workflows.repository.service.ts @@ -15,6 +15,7 @@ import { AuthorIdAndWorktypeIdPairAlreadyExistsError, WorkflowNotFoundError, } from './errors/types'; +import { Context } from '../../common/log'; @Injectable() export class WorkflowsRepositoryService { @@ -25,7 +26,7 @@ export class WorkflowsRepositoryService { * @param externalId * @returns worktypes and active worktype id */ - async getWorkflows(accountId: number): Promise { + async getWorkflows(context: Context, accountId: number): Promise { return await this.dataSource.transaction(async (entityManager) => { const workflowRepo = entityManager.getRepository(Workflow); @@ -43,6 +44,7 @@ export class WorkflowsRepositoryService { order: { id: 'ASC', }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); return workflows; @@ -59,6 +61,7 @@ export class WorkflowsRepositoryService { * @returns workflows */ async createtWorkflows( + context: Context, accountId: number, authorId: number, typists: WorkflowTypist[], @@ -70,6 +73,7 @@ export class WorkflowsRepositoryService { const userRepo = entityManager.getRepository(User); const author = await userRepo.findOne({ where: { account_id: accountId, id: authorId, email_verified: true }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!author) { throw new UserNotFoundError( @@ -82,6 +86,7 @@ export class WorkflowsRepositoryService { const worktypeRepo = entityManager.getRepository(Worktype); const worktypes = await worktypeRepo.find({ where: { account_id: accountId, id: worktypeId }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (worktypes.length === 0) { throw new WorktypeIdNotFoundError( @@ -95,6 +100,7 @@ export class WorkflowsRepositoryService { const templateRepo = entityManager.getRepository(TemplateFile); const template = await templateRepo.findOne({ where: { account_id: accountId, id: templateId }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!template) { throw new TemplateFileNotExistError('template not found.'); @@ -111,6 +117,7 @@ export class WorkflowsRepositoryService { id: In(typistIds), email_verified: true, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (typistUsers.length !== typistIds.length) { throw new UserNotFoundError( @@ -125,6 +132,7 @@ export class WorkflowsRepositoryService { const userGroupRepo = entityManager.getRepository(UserGroup); const typistGroups = await userGroupRepo.find({ where: { account_id: accountId, id: In(groupIds) }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (typistGroups.length !== groupIds.length) { throw new TypistGroupNotExistError( @@ -141,6 +149,7 @@ export class WorkflowsRepositoryService { author_id: authorId, worktype_id: worktypeId !== undefined ? worktypeId : IsNull(), }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (workflow.length !== 0) { throw new AuthorIdAndWorktypeIdPairAlreadyExistsError( @@ -183,6 +192,7 @@ export class WorkflowsRepositoryService { * @returns workflow */ async updatetWorkflow( + context: Context, accountId: number, workflowId: number, authorId: number, @@ -196,6 +206,7 @@ export class WorkflowsRepositoryService { // ワークフローの存在確認 const targetWorkflow = await workflowRepo.findOne({ where: { account_id: accountId, id: workflowId }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!targetWorkflow) { throw new WorkflowNotFoundError( @@ -207,6 +218,7 @@ export class WorkflowsRepositoryService { const userRepo = entityManager.getRepository(User); const author = await userRepo.findOne({ where: { account_id: accountId, id: authorId, email_verified: true }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!author) { throw new UserNotFoundError( @@ -219,6 +231,7 @@ export class WorkflowsRepositoryService { const worktypeRepo = entityManager.getRepository(Worktype); const worktypes = await worktypeRepo.find({ where: { account_id: accountId, id: worktypeId }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (worktypes.length === 0) { throw new WorktypeIdNotFoundError( @@ -232,6 +245,7 @@ export class WorkflowsRepositoryService { const templateRepo = entityManager.getRepository(TemplateFile); const template = await templateRepo.findOne({ where: { account_id: accountId, id: templateId }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!template) { throw new TemplateFileNotExistError( @@ -250,6 +264,7 @@ export class WorkflowsRepositoryService { id: In(typistIds), email_verified: true, }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (typistUsers.length !== typistIds.length) { throw new UserNotFoundError( @@ -264,6 +279,7 @@ export class WorkflowsRepositoryService { const userGroupRepo = entityManager.getRepository(UserGroup); const typistGroups = await userGroupRepo.find({ where: { account_id: accountId, id: In(groupIds) }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (typistGroups.length !== groupIds.length) { throw new TypistGroupNotExistError( @@ -285,6 +301,7 @@ export class WorkflowsRepositoryService { author_id: authorId, worktype_id: worktypeId !== undefined ? worktypeId : IsNull(), }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (duplicateWorkflow.length !== 0) { throw new AuthorIdAndWorktypeIdPairAlreadyExistsError( @@ -322,7 +339,11 @@ export class WorkflowsRepositoryService { * @param workflowId * @returns workflow */ - async deleteWorkflow(accountId: number, workflowId: number): Promise { + async deleteWorkflow( + context: Context, + accountId: number, + workflowId: number, + ): Promise { return await this.dataSource.transaction(async (entityManager) => { const workflowRepo = entityManager.getRepository(Workflow); const workflowTypistsRepo = entityManager.getRepository(DbWorkflowTypist); @@ -330,6 +351,7 @@ export class WorkflowsRepositoryService { // ワークフローの存在確認 const workflow = await workflowRepo.findOne({ where: { account_id: accountId, id: workflowId }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!workflow) { throw new WorkflowNotFoundError( diff --git a/dictation_server/src/repositories/worktypes/worktypes.repository.service.ts b/dictation_server/src/repositories/worktypes/worktypes.repository.service.ts index 38016c1..6c489f7 100644 --- a/dictation_server/src/repositories/worktypes/worktypes.repository.service.ts +++ b/dictation_server/src/repositories/worktypes/worktypes.repository.service.ts @@ -17,6 +17,7 @@ import { PostWorktypeOptionItem } from '../../features/accounts/types/types'; import { AccountNotFoundError } from '../accounts/errors/types'; import { Account } from '../accounts/entity/account.entity'; import { Workflow } from '../workflows/entity/workflow.entity'; +import { Context } from '../../common/log'; @Injectable() export class WorktypesRepositoryService { @@ -27,7 +28,10 @@ export class WorktypesRepositoryService { * @param externalId * @returns worktypes and active worktype id */ - async getWorktypes(accountId: number): Promise<{ + async getWorktypes( + context: Context, + accountId: number, + ): Promise<{ worktypes: Worktype[]; active_worktype_id?: number | undefined; }> { @@ -35,7 +39,10 @@ export class WorktypesRepositoryService { const WorktypeRepo = entityManager.getRepository(Worktype); const accountRepo = entityManager.getRepository(Account); - const account = await accountRepo.findOne({ where: { id: accountId } }); + const account = await accountRepo.findOne({ + where: { id: accountId }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, + }); // 運用上アカウントがいないことはあり得ないが、プログラム上発生しうるのでエラーとして処理 if (!account) { @@ -44,6 +51,7 @@ export class WorktypesRepositoryService { const worktypes = await WorktypeRepo.find({ where: { account_id: account.id }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); return { @@ -59,6 +67,7 @@ export class WorktypesRepositoryService { * @param [description] */ async createWorktype( + context: Context, accountId: number, worktypeId: string, description?: string, @@ -69,6 +78,7 @@ export class WorktypesRepositoryService { const duplicatedWorktype = await worktypeRepo.findOne({ where: { account_id: accountId, custom_worktype_id: worktypeId }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // ワークタイプIDが重複している場合はエラー @@ -80,6 +90,7 @@ export class WorktypesRepositoryService { const worktypeCount = await worktypeRepo.count({ where: { account_id: accountId }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // ワークタイプの登録数が上限に達している場合はエラー @@ -119,6 +130,7 @@ export class WorktypesRepositoryService { * @param [description] */ async updateWorktype( + context: Context, accountId: number, id: number, worktypeId: string, @@ -129,6 +141,7 @@ export class WorktypesRepositoryService { const worktype = await worktypeRepo.findOne({ where: { account_id: accountId, id: id }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // ワークタイプが存在しない場合はエラー @@ -142,6 +155,7 @@ export class WorktypesRepositoryService { custom_worktype_id: worktypeId, id: Not(id), }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // ワークタイプIDが重複している場合はエラー @@ -164,12 +178,17 @@ export class WorktypesRepositoryService { * @param id * @returns worktype */ - async deleteWorktype(accountId: number, id: number): Promise { + async deleteWorktype( + context: Context, + accountId: number, + id: number, + ): Promise { await this.dataSource.transaction(async (entityManager) => { const worktypeRepo = entityManager.getRepository(Worktype); const worktype = await worktypeRepo.findOne({ where: { account_id: accountId, id: id }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // ワークタイプが存在しない場合はエラー if (!worktype) { @@ -180,6 +199,7 @@ export class WorktypesRepositoryService { const accountRepo = entityManager.getRepository(Account); const account = await accountRepo.findOne({ where: { id: accountId }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (account?.active_worktype_id === id) { @@ -193,6 +213,7 @@ export class WorktypesRepositoryService { const workflowRepo = entityManager.getRepository(Workflow); const workflows = await workflowRepo.find({ where: { account_id: accountId, worktype_id: id }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (workflows.length > 0) { const workflowIds = workflows.map((workflow) => workflow.id); @@ -217,6 +238,7 @@ export class WorktypesRepositoryService { * @returns option items */ async getOptionItems( + context: Context, accountId: number, worktypeId: number, ): Promise { @@ -226,6 +248,7 @@ export class WorktypesRepositoryService { const worktype = await repoWorktype.findOne({ where: { account_id: accountId, id: worktypeId }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // ワークタイプが存在しない場合はエラー @@ -237,6 +260,7 @@ export class WorktypesRepositoryService { const optionItems = await repoOptionItem.find({ where: { worktype_id: worktypeId }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); return optionItems; @@ -251,6 +275,7 @@ export class WorktypesRepositoryService { * @returns option items */ async updateOptionItems( + context: Context, accountId: number, worktypeId: number, worktypeOptionItems: PostWorktypeOptionItem[], @@ -261,6 +286,7 @@ export class WorktypesRepositoryService { const worktype = await worktypeRepo.findOne({ where: { account_id: accountId, id: worktypeId }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // ワークタイプが存在しない場合はエラー if (!worktype) {