From a0da277c05be03ccb0dabe424c846737a52e32af Mon Sep 17 00:00:00 2001 From: "makabe.t" Date: Fri, 8 Dec 2023 02:14:25 +0000 Subject: [PATCH 01/51] =?UTF-8?q?Merged=20PR=20607:=20=E3=83=A1=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=82=A2=E3=83=89=E3=83=AC=E3=82=B9=E5=85=A5=E5=8A=9B?= =?UTF-8?q?=E3=83=81=E3=82=A7=E3=83=83=E3=82=AF=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3232: メールアドレス入力チェックの修正](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3232) - メールアドレス入力に対して規約に則ったチェックを実施するように修正しました。 - 画面での入力チェックとAPIのバリデーションを修正しています。 ## レビューポイント - クライアントのチェック内容は規約に則った内容になっているでしょうか? - 正規表現の構文として不自然な点はないでしょうか? - サーバー側のチェックをIsEmail+禁止文字の追加という形で対応していますが適切でしょうか? ## UIの変更 - なし ## 動作確認状況 - ローカルで確認 --- dictation_client/src/features/partner/selectors.ts | 5 ++++- dictation_client/src/features/signup/selectors.ts | 4 +++- dictation_client/src/features/user/selectors.ts | 5 ++++- dictation_server/src/features/accounts/types/types.ts | 4 ++-- dictation_server/src/features/users/types/types.ts | 3 ++- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/dictation_client/src/features/partner/selectors.ts b/dictation_client/src/features/partner/selectors.ts index e07fd82..061f8b1 100644 --- a/dictation_client/src/features/partner/selectors.ts +++ b/dictation_client/src/features/partner/selectors.ts @@ -8,8 +8,11 @@ export const selectInputValidationErrors = (state: RootState) => { const hasErrorEmptyAdminName = state.partner.apps.addPartner.adminName === ""; const hasErrorEmptyEmail = state.partner.apps.addPartner.email === ""; + const emailPattern = + /^[a-zA-Z0-9!#$%&'_`/=~+\-?^{|}.]+@[a-zA-Z0-9!#$%&'_`/=~+\-?^{|}.]*\.[a-zA-Z0-9!#$%&'_`/=~+\-?^{|}.]*[a-zA-Z]$/; + const hasErrorIncorrectEmail = - (state.partner.apps.addPartner.email as string).match(/^[^@]+@[^@]+$/) + (state.partner.apps.addPartner.email as string).match(emailPattern) ?.length !== 1; return { diff --git a/dictation_client/src/features/signup/selectors.ts b/dictation_client/src/features/signup/selectors.ts index 823347f..29e3206 100644 --- a/dictation_client/src/features/signup/selectors.ts +++ b/dictation_client/src/features/signup/selectors.ts @@ -16,8 +16,10 @@ export const selectInputValidationErrors = (state: RootState) => { state.signup.apps.password ); + const emailPattern = + /^[a-zA-Z0-9!#$%&'_`/=~+\-?^{|}.]+@[a-zA-Z0-9!#$%&'_`/=~+\-?^{|}.]*\.[a-zA-Z0-9!#$%&'_`/=~+\-?^{|}.]*[a-zA-Z]$/; const hasErrorIncorrectEmail = - (state.signup.apps.email as string).match(/^[^@]+@[^@]+$/)?.length !== 1; + (state.signup.apps.email as string).match(emailPattern)?.length !== 1; return { hasErrorEmptyEmail, diff --git a/dictation_client/src/features/user/selectors.ts b/dictation_client/src/features/user/selectors.ts index 0fd057d..e1e3cf1 100644 --- a/dictation_client/src/features/user/selectors.ts +++ b/dictation_client/src/features/user/selectors.ts @@ -26,7 +26,10 @@ export const selectInputValidationErrors = (state: RootState) => { role ); - const hasErrorIncorrectEmail = email.match(/^[^@]+@[^@]+$/)?.length !== 1; + const emailPattern = + /^[a-zA-Z0-9!#$%&'_`/=~+\-?^{|}.]+@[a-zA-Z0-9!#$%&'_`/=~+\-?^{|}.]*\.[a-zA-Z0-9!#$%&'_`/=~+\-?^{|}.]*[a-zA-Z]$/; + + const hasErrorIncorrectEmail = email.match(emailPattern)?.length !== 1; const hasErrorIncorrectEncryptionPassword = checkErrorIncorrectEncryptionPassword(encryptionPassword, role, encryption); diff --git a/dictation_server/src/features/accounts/types/types.ts b/dictation_server/src/features/accounts/types/types.ts index 276fd0e..6e45d8e 100644 --- a/dictation_server/src/features/accounts/types/types.ts +++ b/dictation_server/src/features/accounts/types/types.ts @@ -38,7 +38,7 @@ export class CreateAccountRequest { @ApiProperty() adminName: string; @ApiProperty() - @IsEmail() + @IsEmail({ blacklisted_chars: '*' }) adminMail: string; @ApiProperty() @IsAdminPasswordvalid() @@ -244,7 +244,7 @@ export class CreatePartnerAccountRequest { @ApiProperty() adminName: string; @ApiProperty() - @IsEmail() + @IsEmail({ blacklisted_chars: '*' }) email: string; } diff --git a/dictation_server/src/features/users/types/types.ts b/dictation_server/src/features/users/types/types.ts index d21f72d..c6bcb75 100644 --- a/dictation_server/src/features/users/types/types.ts +++ b/dictation_server/src/features/users/types/types.ts @@ -1,5 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; -import { IsIn } from 'class-validator'; +import { IsEmail, IsIn } from 'class-validator'; import { TASK_LIST_SORTABLE_ATTRIBUTES, USER_LICENSE_STATUS, @@ -88,6 +88,7 @@ export class SignupRequest { authorId?: string; @ApiProperty() + @IsEmail({ blacklisted_chars: '*' }) email: string; @ApiProperty() From b1f169def5d65d3746dce0025f232d26474665bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B9=AF=E6=9C=AC=20=E9=96=8B?= Date: Fri, 8 Dec 2023 05:06:02 +0000 Subject: [PATCH 02/51] =?UTF-8?q?Merged=20PR=20594:=20[TODO=E5=AF=BE?= =?UTF-8?q?=E5=87=A6]=20=E3=83=A1=E3=83=BC=E3=83=AB=E3=81=AE=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E3=81=AB=E3=81=A4=E3=81=84=E3=81=A6=E7=B7=A8=E9=9B=86?= =?UTF-8?q?=E3=81=97=E3=82=84=E3=81=99=E3=81=8F=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task2163: [TODO対処] メールの内容について編集しやすくする](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2163) - メール文面をハードコードしない構造を試作 ## レビューポイント - メールテンプレートの定義場所、定義形式、読み込み方法などは問題なさそうか ## 動作確認状況 - ローカルで確認 --- dictation_server/nest-cli.json | 6 +- .../src/gateways/sendgrid/sendgrid.service.ts | 74 +++++++++++++------ .../src/templates/template_email_verify.html | 8 ++ .../src/templates/template_email_verify.txt | 2 + 4 files changed, 68 insertions(+), 22 deletions(-) create mode 100644 dictation_server/src/templates/template_email_verify.html create mode 100644 dictation_server/src/templates/template_email_verify.txt diff --git a/dictation_server/nest-cli.json b/dictation_server/nest-cli.json index 2566481..8791e11 100644 --- a/dictation_server/nest-cli.json +++ b/dictation_server/nest-cli.json @@ -1,5 +1,9 @@ { "$schema": "https://json.schemastore.org/nest-cli", "collection": "@nestjs/schematics", - "sourceRoot": "src" + "sourceRoot": "src", + "compilerOptions": { + "assets": ["templates/**/*.html", "templates/**/*.txt"], + "watchAssets": true + } } diff --git a/dictation_server/src/gateways/sendgrid/sendgrid.service.ts b/dictation_server/src/gateways/sendgrid/sendgrid.service.ts index f611e65..9b1edfd 100644 --- a/dictation_server/src/gateways/sendgrid/sendgrid.service.ts +++ b/dictation_server/src/gateways/sendgrid/sendgrid.service.ts @@ -4,12 +4,17 @@ import { sign } from '../../common/jwt'; import sendgrid from '@sendgrid/mail'; import { getPrivateKey } from '../../common/jwt/jwt'; import { Context } from '../../common/log'; +import { readFileSync } from 'node:fs'; +import path from 'node:path'; @Injectable() export class SendGridService { private readonly logger = new Logger(SendGridService.name); private readonly emailConfirmLifetime: number; private readonly appDomain: string; + private readonly templateEmailVerifyHtml: string; + private readonly templateEmailVerifyText: string; + constructor(private readonly configService: ConfigService) { this.appDomain = this.configService.getOrThrow('APP_DOMAIN'); this.emailConfirmLifetime = this.configService.getOrThrow( @@ -17,6 +22,18 @@ export class SendGridService { ); const key = this.configService.getOrThrow('SENDGRID_API_KEY'); sendgrid.setApiKey(key); + + // メールテンプレートを読み込む + { + this.templateEmailVerifyHtml = readFileSync( + path.resolve(__dirname, `../../templates/template_email_verify.html`), + 'utf-8', + ); + this.templateEmailVerifyText = readFileSync( + path.resolve(__dirname, `../../templates/template_email_verify.txt`), + 'utf-8', + ); + } } /** @@ -39,29 +56,44 @@ export class SendGridService { `accountId: ${accountId},` + `userId: ${userId} };`, ); + try { + const privateKey = getPrivateKey(this.configService); + const token = sign<{ accountId: number; userId: number; email: string }>( + { + accountId, + userId, + email, + }, + this.emailConfirmLifetime, + privateKey, + ); + const path = 'mail-confirm/'; - const privateKey = getPrivateKey(this.configService); - const token = sign<{ accountId: number; userId: number; email: string }>( - { - accountId, - userId, - email, - }, - this.emailConfirmLifetime, - privateKey, - ); - const path = 'mail-confirm/'; + const html = this.templateEmailVerifyHtml + .replace('VERIFY_LINK', `${this.appDomain}${path}?verify=${token}`) + .replace( + 'VERIFY_LINK_TEXT', + `${this.appDomain}${path}?verify=${token}`, + ); + const text = this.templateEmailVerifyText + .replace('VERIFY_LINK', `${this.appDomain}${path}?verify=${token}`) + .replace( + 'VERIFY_LINK_TEXT', + `${this.appDomain}${path}?verify=${token}`, + ); - this.logger.log( - `[OUT] [${context.getTrackingId()}] ${ - this.createMailContentFromEmailConfirm.name - }`, - ); - return { - subject: 'Verify your new account', - text: `The verification URL. ${this.appDomain}${path}?verify=${token}`, - html: `

The verification URL.

${this.appDomain}${path}?verify=${token}`, - }; + return { + subject: 'Verify your new account', + text: text, + html: html, + }; + } finally { + this.logger.log( + `[OUT] [${context.getTrackingId()}] ${ + this.createMailContentFromEmailConfirm.name + }`, + ); + } } /** diff --git a/dictation_server/src/templates/template_email_verify.html b/dictation_server/src/templates/template_email_verify.html new file mode 100644 index 0000000..cefecea --- /dev/null +++ b/dictation_server/src/templates/template_email_verify.html @@ -0,0 +1,8 @@ + + + + +

The verification URL.

+ VERIFY_LINK_TEXT + + \ No newline at end of file diff --git a/dictation_server/src/templates/template_email_verify.txt b/dictation_server/src/templates/template_email_verify.txt new file mode 100644 index 0000000..73a316d --- /dev/null +++ b/dictation_server/src/templates/template_email_verify.txt @@ -0,0 +1,2 @@ +The verification URL. +VERIFY_LINK \ No newline at end of file From f7ec740e7a7ec093f509ad68c1acc515f8db3686 Mon Sep 17 00:00:00 2001 From: "maruyama.t" Date: Fri, 8 Dec 2023 05:59:30 +0000 Subject: [PATCH 03/51] =?UTF-8?q?Merged=20PR=20615:=20PrivacyNotice?= =?UTF-8?q?=E3=81=AE=E5=A4=9A=E8=A8=80=E8=AA=9E=E5=AF=BE=E5=BF=9C=E3=81=AE?= =?UTF-8?q?=E6=96=87=E8=A8=80=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3292: PrivacyNoticeの多言語対応の文言修正](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3292) - 元PBI or タスクへのリンク(内容・目的などはそちらにあるはず) - 何をどう変更したか、追加したライブラリなど - このPull Requestでの対象/対象外 - 影響範囲(他の機能にも影響があるか) ## レビューポイント - 特にレビューしてほしい箇所 - 軽微なものや自明なものは記載不要 - 修正範囲が大きい場合などに記載 - 全体的にや仕様を満たしているか等は本当に必要な時のみ記載 ## UIの変更 - Before/Afterのスクショなど - スクショ置き場 ## 動作確認状況 - ローカルで確認、develop環境で確認など ## 補足 - 相談、参考資料などがあれば --- dictation_client/src/translation/de.json | 3 +-- dictation_client/src/translation/en.json | 3 +-- dictation_client/src/translation/es.json | 3 +-- dictation_client/src/translation/fr.json | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/dictation_client/src/translation/de.json b/dictation_client/src/translation/de.json index 71b532f..5bc34d0 100644 --- a/dictation_client/src/translation/de.json +++ b/dictation_client/src/translation/de.json @@ -535,8 +535,7 @@ "linkOfPrivacyNotice": "(de)Click here to read the terms of use.", "checkBoxForConsent": "(de)Yes, I agree to the terms of use.", "forOdds": "(de)for ODDS.", - "button": "(de)Continue", - "linkOfPrivacyNotice": "(de)Click here to read the terms of use." + "button": "(de)Continue" } }, "supportPage": { diff --git a/dictation_client/src/translation/en.json b/dictation_client/src/translation/en.json index cbf9f66..785e88a 100644 --- a/dictation_client/src/translation/en.json +++ b/dictation_client/src/translation/en.json @@ -535,8 +535,7 @@ "linkOfPrivacyNotice": "Click here to read the terms of use.", "checkBoxForConsent": "Yes, I agree to the terms of use.", "forOdds": "for ODDS.", - "button": "Continue", - "linkOfPrivacyNotice": "Click here to read the terms of use." + "button": "Continue" } }, "supportPage": { diff --git a/dictation_client/src/translation/es.json b/dictation_client/src/translation/es.json index 552edb2..9fae99a 100644 --- a/dictation_client/src/translation/es.json +++ b/dictation_client/src/translation/es.json @@ -535,8 +535,7 @@ "linkOfPrivacyNotice": "(es)Click here to read the terms of use.", "checkBoxForConsent": "(es)Yes, I agree to the terms of use.", "forOdds": "(es)for ODDS.", - "button": "(es)Continue", - "linkOfPrivacyNotice": "(es)Click here to read the terms of use." + "button": "(es)Continue" } }, "supportPage": { diff --git a/dictation_client/src/translation/fr.json b/dictation_client/src/translation/fr.json index e3bf194..d0a2bfa 100644 --- a/dictation_client/src/translation/fr.json +++ b/dictation_client/src/translation/fr.json @@ -535,8 +535,7 @@ "linkOfPrivacyNotice": "(fr)Click here to read the terms of use.", "checkBoxForConsent": "(fr)Yes, I agree to the terms of use.", "forOdds": "(fr)for ODDS.", - "button": "(fr)Continue", - "linkOfPrivacyNotice": "(fr)Click here to read the terms of use." + "button": "(fr)Continue" } }, "supportPage": { From 375e8e87a828de0ab6c6702cd78e7bb0a3df652e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B9=AF=E6=9C=AC=20=E9=96=8B?= Date: Mon, 11 Dec 2023 06:35:59 +0000 Subject: [PATCH 04/51] =?UTF-8?q?Merged=20PR=20621:=20STG/PROD=E3=81=A7Sou?= =?UTF-8?q?rceMap=E5=87=BA=E5=8A=9B=E3=82=92OFF=E3=81=AB=E3=81=97=E3=81=A6?= =?UTF-8?q?=E3=81=8A=E3=81=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3165: STG/PRODでSourceMap出力をOFFにしておく](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3165) - STG/PRODでsourcemap(ビルド後の圧縮・結合されたjsからデバッグ用の実行行やコメントを復元するための存在)を出力しないように修正 - コメント等がユーザーに見えないようにする目的 ## レビューポイント - 情報共有 ## 動作確認状況 - ローカルで確認 --- dictation_client/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dictation_client/package.json b/dictation_client/package.json index a445672..ac8d5c0 100644 --- a/dictation_client/package.json +++ b/dictation_client/package.json @@ -8,8 +8,8 @@ "scripts": { "start": "vite", "build": "tsc && vite build --mode development", - "build:stg": "tsc && vite build --mode staging", - "build:prod": "tsc && vite build --mode production", + "build:stg": "tsc && vite build --mode staging --sourcemap false", + "build:prod": "tsc && vite build --mode production --sourcemap false", "build:local": "tsc && vite build --mode development && sh localdeploy.sh", "preview": "vite preview", "typecheck": "tsc --noEmit", From 8fe649cb7f8f01de8d34a9f0b73e8ba439393fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B0=B4=E6=9C=AC=20=E7=A5=90=E5=B8=8C?= Date: Tue, 12 Dec 2023 02:08:18 +0000 Subject: [PATCH 05/51] =?UTF-8?q?Merged=20PR=20618:=20=E7=94=BB=E9=9D=A2?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=EF=BC=88=E7=AC=AC=EF=BC=95=E3=81=AE=E3=83=A9?= =?UTF-8?q?=E3=82=A4=E3=82=BB=E3=83=B3=E3=82=B9=E4=B8=80=E8=A6=A7=E3=81=AE?= =?UTF-8?q?=E9=A0=85=E7=9B=AE=E9=A0=86=E3=82=92=E5=A4=89=E6=9B=B4=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3271: 画面修正(第5のライセンス一覧の項目順を変更)](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3271) - 何をどう変更したか、追加したライブラリなど - 項目の配置を変更 - License Inventory→Number of unused licenses→Number of licenses available for reuse→Number of licenses allocatedの順で修正 - Total number of licenses on orderをlicense情報の一番下に配置 - 不要な項目を削除 - Total number of orderを削除 - レイアウトを最新のものに適用 - このPull Requestでの対象/対象外 項目名の変更はOMDS様が翻訳したものを適用すればよいので、対象外 ## レビューポイント 特になし ## UIの変更 - スクショ置き場 https://ndstokyo.sharepoint.com/:f:/r/sites/Piranha/Shared%20Documents/General/OMDS/%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%B7%E3%83%A7%E3%83%83%E3%83%88/Task3271?csf=1&web=1&e=ac0SrH ## 動作確認状況 - ローカルで確認 --- .../src/pages/LicensePage/licenseSummary.tsx | 224 ++++++++++-------- dictation_client/src/translation/de.json | 8 +- dictation_client/src/translation/en.json | 8 +- dictation_client/src/translation/es.json | 8 +- dictation_client/src/translation/fr.json | 8 +- 5 files changed, 149 insertions(+), 107 deletions(-) diff --git a/dictation_client/src/pages/LicensePage/licenseSummary.tsx b/dictation_client/src/pages/LicensePage/licenseSummary.tsx index b305b66..058350d 100644 --- a/dictation_client/src/pages/LicensePage/licenseSummary.tsx +++ b/dictation_client/src/pages/LicensePage/licenseSummary.tsx @@ -121,9 +121,9 @@ export const LicenseSummary: React.FC = (
-
+

{companyName}

-
    +
    • {/* 他アカウントのライセンス情報を見ている場合は、前画面に戻る用のreturnボタンを表示 */} {selectedRow && ( @@ -194,99 +194,133 @@ export const LicenseSummary: React.FC = ( )}
    -
    -
    - {t( - getTranslationID( - "LicenseSummaryPage.label.totalLicense" - ) - )} -
    -
    {licenseSummaryInfo.totalLicense}
    -
    - {t( - getTranslationID( - "LicenseSummaryPage.label.allocatedLicense" - ) - )} -
    -
    {licenseSummaryInfo.allocatedLicense}
    -
    - {t( - getTranslationID( - "LicenseSummaryPage.label.reusableLicense" - ) - )} -
    -
    {licenseSummaryInfo.reusableLicense}
    -
    - {t( - getTranslationID("LicenseSummaryPage.label.freeLicense") - )} -
    -
    {licenseSummaryInfo.freeLicense}
    -
    - {t( - getTranslationID( - "LicenseSummaryPage.label.expiringWithin14daysLicense" - ) - )} -
    -
    {licenseSummaryInfo.expiringWithin14daysLicense}
    -
    - {t( - getTranslationID( - "LicenseSummaryPage.label.issueRequesting" - ) - )} -
    -
    {licenseSummaryInfo.issueRequesting}
    -
    - {t( - getTranslationID( - "LicenseSummaryPage.label.numberOfRequesting" - ) - )} -
    -
    {licenseSummaryInfo.numberOfRequesting}
    -
    - {t(getTranslationID("LicenseSummaryPage.label.shortage"))} -
    -
    - 0 ? styles.isAlert : "" - } - > - {licenseSummaryInfo.shortage} - -
    -
    - {t( - getTranslationID("LicenseSummaryPage.label.storageSize") - )} -
    -
    {licenseSummaryInfo.storageSize}GB
    -
    - {t(getTranslationID("LicenseSummaryPage.label.usedSize"))} -
    -
    {licenseSummaryInfo.usedSize}GB
    -
    - {t( - getTranslationID( - "LicenseSummaryPage.label.storageAvailable" - ) - )} -
    -
    - {licenseSummaryInfo.isStorageAvailable && ( - - )} - {!licenseSummaryInfo.isStorageAvailable && ( - - )} -
    -
    +
    +
    +

    + {t( + getTranslationID( + "LicenseSummaryPage.label.licenseLabel" + ) + )} +

    +
    + {t( + getTranslationID( + "LicenseSummaryPage.label.totalLicense" + ) + )} +
    +
    {licenseSummaryInfo.totalLicense}
    +
    + {t( + getTranslationID( + "LicenseSummaryPage.label.freeLicense" + ) + )} +
    +
    {licenseSummaryInfo.freeLicense}
    +
    + {t( + getTranslationID( + "LicenseSummaryPage.label.reusableLicense" + ) + )} +
    +
    {licenseSummaryInfo.reusableLicense}
    +
    + {t( + getTranslationID( + "LicenseSummaryPage.label.allocatedLicense" + ) + )} +
    +
    {licenseSummaryInfo.allocatedLicense}
    +
    + {t( + getTranslationID( + "LicenseSummaryPage.label.expiringWithin14daysLicense" + ) + )} +
    +
    {licenseSummaryInfo.expiringWithin14daysLicense}
    +
    + {t( + getTranslationID("LicenseSummaryPage.label.shortage") + )} +
    +
    + 0 + ? styles.isAlert + : "" + } + > + {licenseSummaryInfo.shortage} + +
    +
    + {t( + getTranslationID( + "LicenseSummaryPage.label.issueRequesting" + ) + )} +
    +
    {licenseSummaryInfo.issueRequesting}
    +
    +
    +
    +
    +

    + {t( + getTranslationID( + "LicenseSummaryPage.label.storageLabel" + ) + )} +

    +
    + {t( + getTranslationID( + "LicenseSummaryPage.label.storageSize" + ) + )} +
    +
    {licenseSummaryInfo.storageSize}GB
    +
    + {t( + getTranslationID("LicenseSummaryPage.label.usedSize") + )} +
    +
    {licenseSummaryInfo.usedSize}GB
    +
    + {t( + getTranslationID( + "LicenseSummaryPage.label.storageAvailable" + ) + )} +
    +
    + {licenseSummaryInfo.isStorageAvailable && ( + + )} + {!licenseSummaryInfo.isStorageAvailable && ( + + )} +
    +
    +
diff --git a/dictation_client/src/translation/de.json b/dictation_client/src/translation/de.json index 5bc34d0..30aea18 100644 --- a/dictation_client/src/translation/de.json +++ b/dictation_client/src/translation/de.json @@ -180,7 +180,9 @@ "shortage": "Mangel", "storageSize": "Lagerung verfügbar", "usedSize": "Gebrauchter Lagerung", - "storageAvailable": "Speicher nicht verfügbar (Menge überschritten)" + "storageAvailable": "Speicher nicht verfügbar (Menge überschritten)", + "licenseLabel": "(de)License", + "storageLabel": "(de)Storage" } }, "licenseOrderPage": { @@ -532,10 +534,10 @@ "title": "(de)Terms of Use has updated. Please confirm again.", "linkOfEula": "(de)Click here to read the terms of use.", "linkOfDpa": "(de)Click here to read the terms of use.", - "linkOfPrivacyNotice": "(de)Click here to read the terms of use.", "checkBoxForConsent": "(de)Yes, I agree to the terms of use.", "forOdds": "(de)for ODDS.", - "button": "(de)Continue" + "button": "(de)Continue", + "linkOfPrivacyNotice": "(de)Click here to read the terms of use." } }, "supportPage": { diff --git a/dictation_client/src/translation/en.json b/dictation_client/src/translation/en.json index 785e88a..90af47f 100644 --- a/dictation_client/src/translation/en.json +++ b/dictation_client/src/translation/en.json @@ -180,7 +180,9 @@ "shortage": "Shortage", "storageSize": "Storage Available", "usedSize": "Storage Used", - "storageAvailable": "Storage Unavailable (Exceeded Amount)" + "storageAvailable": "Storage Unavailable (Exceeded Amount)", + "licenseLabel": "License", + "storageLabel": "Storage" } }, "licenseOrderPage": { @@ -532,10 +534,10 @@ "title": "Terms of Use has updated. Please confirm again.", "linkOfEula": "Click here to read the terms of use.", "linkOfDpa": "Click here to read the terms of use.", - "linkOfPrivacyNotice": "Click here to read the terms of use.", "checkBoxForConsent": "Yes, I agree to the terms of use.", "forOdds": "for ODDS.", - "button": "Continue" + "button": "Continue", + "linkOfPrivacyNotice": "Click here to read the terms of use." } }, "supportPage": { diff --git a/dictation_client/src/translation/es.json b/dictation_client/src/translation/es.json index 9fae99a..7840ac8 100644 --- a/dictation_client/src/translation/es.json +++ b/dictation_client/src/translation/es.json @@ -180,7 +180,9 @@ "shortage": "Escasez", "storageSize": "Almacenamiento disponible", "usedSize": "Almacenamiento utilizado", - "storageAvailable": "Almacenamiento no disponible (cantidad excedida)" + "storageAvailable": "Almacenamiento no disponible (cantidad excedida)", + "licenseLabel": "(es)License", + "storageLabel": "(es)Storage" } }, "licenseOrderPage": { @@ -532,10 +534,10 @@ "title": "(es)Terms of Use has updated. Please confirm again.", "linkOfEula": "(es)Click here to read the terms of use.", "linkOfDpa": "(es)Click here to read the terms of use.", - "linkOfPrivacyNotice": "(es)Click here to read the terms of use.", "checkBoxForConsent": "(es)Yes, I agree to the terms of use.", "forOdds": "(es)for ODDS.", - "button": "(es)Continue" + "button": "(es)Continue", + "linkOfPrivacyNotice": "(es)Click here to read the terms of use." } }, "supportPage": { diff --git a/dictation_client/src/translation/fr.json b/dictation_client/src/translation/fr.json index d0a2bfa..803a2c4 100644 --- a/dictation_client/src/translation/fr.json +++ b/dictation_client/src/translation/fr.json @@ -180,7 +180,9 @@ "shortage": "Pénurie", "storageSize": "Stockage disponible", "usedSize": "Stockage utilisé", - "storageAvailable": "Stockage indisponible (montant dépassée)" + "storageAvailable": "Stockage indisponible (montant dépassée)", + "licenseLabel": "(fr)License", + "storageLabel": "(fr)Storage" } }, "licenseOrderPage": { @@ -532,10 +534,10 @@ "title": "(fr)Terms of Use has updated. Please confirm again.", "linkOfEula": "(fr)Click here to read the terms of use.", "linkOfDpa": "(fr)Click here to read the terms of use.", - "linkOfPrivacyNotice": "(fr)Click here to read the terms of use.", "checkBoxForConsent": "(fr)Yes, I agree to the terms of use.", "forOdds": "(fr)for ODDS.", - "button": "(fr)Continue" + "button": "(fr)Continue", + "linkOfPrivacyNotice": "(fr)Click here to read the terms of use." } }, "supportPage": { From f1583cf7831fdc58b717decbf8e8573ef70aa79c Mon Sep 17 00:00:00 2001 From: "saito.k" Date: Tue, 12 Dec 2023 04:11:36 +0000 Subject: [PATCH 06/51] =?UTF-8?q?Merged=20PR=20611:=20=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E3=82=92=E7=89=B9=E5=AE=9A=E3=81=A7=E3=81=8D=E3=82=8B=E6=96=87?= =?UTF-8?q?=E5=AD=97=E5=88=97=E3=82=92=E8=BF=BD=E8=B7=A1=E7=94=A8=E3=81=AE?= =?UTF-8?q?ID=E3=81=AB=E8=BF=BD=E5=8A=A0=E3=81=99=E3=82=8B=EF=BC=88IP?= =?UTF-8?q?=E3=82=A2=E3=83=89=E3=83=AC=E3=82=B9=E3=82=82=E3=83=AD=E3=82=B0?= =?UTF-8?q?=E3=81=AB=E5=87=BA=E5=8A=9B=E3=81=99=E3=82=8B=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3265: IPアドレスを追跡用のIDに追加する](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3265) - MiddlewareでUUIDを発行しリクエストのヘッダに追加する - 各コントローラーではヘッダからUUIDとIPアドレスを取得する - 取得したUUIDとADB2Cの外部IDでトラッキングIDを作成する - 作成したトラッキングIDとIPアドレスの繋がりをログに出力する。 ## レビューポイント - ADB2Cの外部IDがない場合にUnauthorized Userという文字列を入れているがほかの表現のほうが良いか - 外部IDもオプショナルにして入れなくてもよくする? - ## UIの変更 - Before/Afterのスクショなど - スクショ置き場 ## 動作確認状況 - ローカルで確認 ## 補足 - 相談、参考資料などがあれば --- dictation_server/src/common/error/code.ts | 2 + dictation_server/src/common/error/message.ts | 2 + dictation_server/src/common/log/context.ts | 26 +- dictation_server/src/common/log/index.ts | 4 +- dictation_server/src/common/log/types.ts | 15 +- .../src/common/loggerMiddleware.ts | 13 +- .../features/accounts/accounts.controller.ts | 530 +++++++++++++++++- .../accounts/accounts.service.spec.ts | 498 ++++++++++++---- .../src/features/accounts/accounts.service.ts | 6 +- .../src/features/auth/auth.controller.ts | 94 +++- .../src/features/auth/auth.service.spec.ts | 78 ++- .../src/features/files/files.controller.ts | 118 +++- .../src/features/files/files.service.spec.ts | 128 +++-- .../features/licenses/licenses.controller.ts | 102 +++- .../licenses/licenses.service.spec.ts | 96 +++- .../notification/notification.controller.ts | 23 +- .../notification/notification.service.spec.ts | 6 +- .../src/features/tasks/tasks.controller.ts | 166 +++++- .../src/features/tasks/tasks.service.spec.ts | 212 ++++--- .../templates/templates.controller.ts | 24 +- .../templates/templates.service.spec.ts | 18 +- .../src/features/terms/terms.controller.ts | 36 +- .../src/features/terms/terms.service.spec.ts | 10 +- .../src/features/users/users.controller.ts | 249 +++++++- .../src/features/users/users.service.spec.ts | 115 ++-- .../src/features/users/users.service.ts | 7 +- .../workflows/workflows.controller.ts | 76 ++- .../workflows/workflows.service.spec.ts | 222 ++++++-- 28 files changed, 2372 insertions(+), 504 deletions(-) diff --git a/dictation_server/src/common/error/code.ts b/dictation_server/src/common/error/code.ts index f8f7225..8f9dc2f 100644 --- a/dictation_server/src/common/error/code.ts +++ b/dictation_server/src/common/error/code.ts @@ -23,6 +23,8 @@ export const ErrorCodes = [ 'E000107', // トークン不足エラー 'E000108', // トークン権限エラー 'E000301', // ADB2Cへのリクエスト上限超過エラー + 'E000401', // IPアドレス未設定エラー + 'E000501', // リクエストID未設定エラー 'E010001', // パラメータ形式不正エラー 'E010201', // 未認証ユーザエラー 'E010202', // 認証済ユーザエラー diff --git a/dictation_server/src/common/error/message.ts b/dictation_server/src/common/error/message.ts index 4786a64..0a27cc5 100644 --- a/dictation_server/src/common/error/message.ts +++ b/dictation_server/src/common/error/message.ts @@ -12,6 +12,8 @@ export const errors: Errors = { E000107: 'Token is not exist Error.', E000108: 'Token authority failed Error.', E000301: 'ADB2C request limit exceeded Error', + E000401: 'IP address not found Error.', + E000501: 'Request ID not found Error.', E010001: 'Param invalid format Error.', E010201: 'Email not verified user Error.', E010202: 'Email already verified user Error.', diff --git a/dictation_server/src/common/log/context.ts b/dictation_server/src/common/log/context.ts index 2c8bbe3..1b887c6 100644 --- a/dictation_server/src/common/log/context.ts +++ b/dictation_server/src/common/log/context.ts @@ -1,8 +1,32 @@ +import { Request } from 'express'; import { Context } from './types'; export const makeContext = ( externalId: string, + requestId: string, delegationId?: string, ): Context => { - return new Context(externalId, delegationId); + return new Context(externalId, requestId, delegationId); +}; + +// リクエストヘッダーからrequestIdを取得する +export const retrieveRequestId = (req: Request): string | undefined => { + return req.header('x-request-id'); +}; + +/** + * リクエストのIPアドレスを取得します + * @param {Request} + * @return {string | undefined} + */ +export const retrieveIp = (req: Request): string | undefined => { + // ローカル環境では直近の送信元IPを取得する + if (process.env.STAGE === 'local') { + return req.ip; + } + const ip = req.header('x-forwarded-for'); + if (typeof ip === 'string') { + return ip; + } + return undefined; }; diff --git a/dictation_server/src/common/log/index.ts b/dictation_server/src/common/log/index.ts index d42adad..7b0bf35 100644 --- a/dictation_server/src/common/log/index.ts +++ b/dictation_server/src/common/log/index.ts @@ -1,4 +1,4 @@ import { Context } from './types'; -import { makeContext } from './context'; +import { makeContext, retrieveRequestId, retrieveIp } from './context'; -export { Context, makeContext }; +export { Context, makeContext, retrieveRequestId, retrieveIp }; diff --git a/dictation_server/src/common/log/types.ts b/dictation_server/src/common/log/types.ts index 7ed3855..6f56bc1 100644 --- a/dictation_server/src/common/log/types.ts +++ b/dictation_server/src/common/log/types.ts @@ -3,23 +3,32 @@ export class Context { * APIの操作ユーザーを追跡するためのID */ trackingId: string; + /** + * APIの操作ユーザーのIPアドレス + */ + ip: string; + /** + * ユーザーの操作を一意に識別するためのID + */ + requestId: string; /** * APIの代行操作ユーザーを追跡するためのID */ delegationId?: string | undefined; - constructor(externalId: string, delegationId?: string) { + constructor(externalId: string, requestId: string, delegationId?: string) { this.trackingId = externalId; this.delegationId = delegationId; + this.requestId = requestId; } /** * ログにユーザーを特定する情報を出力する */ getTrackingId(): string { if (this.delegationId) { - return `${this.trackingId} by ${this.delegationId}`; + return `${this.requestId}_${this.trackingId} by ${this.delegationId}`; } else { - return this.trackingId; + return `${this.requestId}_${this.trackingId}`; } } } diff --git a/dictation_server/src/common/loggerMiddleware.ts b/dictation_server/src/common/loggerMiddleware.ts index a892c02..18b995c 100644 --- a/dictation_server/src/common/loggerMiddleware.ts +++ b/dictation_server/src/common/loggerMiddleware.ts @@ -1,11 +1,16 @@ import { Injectable, Logger, NestMiddleware } from '@nestjs/common'; import { Request, Response } from 'express'; +import { v4 as uuidv4 } from 'uuid'; @Injectable() export class LoggerMiddleware implements NestMiddleware { private readonly logger = new Logger(LoggerMiddleware.name); use(req: Request, res: Response, next: () => void): void { + // ここで一意のリクエストIDを生成して、リクエストヘッダーに設定する + const requestId = uuidv4(); + req.headers['x-request-id'] = requestId; + this.logger.log(this.createReqMsg(req)); res.on('close', () => { @@ -15,13 +20,17 @@ export class LoggerMiddleware implements NestMiddleware { } private createReqMsg(req: Request): string { - const message = `Request [url=${req.url}, method=${req.method}]`; + const message = `[${req.header('x-request-id')}] Request [url=${ + req.url + }, method=${req.method}]`; return message; } private createResMsg(res: Response): string { - const message = `Response [statusCode=${res.statusCode}, message=${res.statusMessage}]`; + const message = `[${res.req.header('x-request-id')}] Response [statusCode=${ + res.statusCode + }, message=${res.statusMessage}]`; return message; } diff --git a/dictation_server/src/features/accounts/accounts.controller.ts b/dictation_server/src/features/accounts/accounts.controller.ts index 619aa2b..5750071 100644 --- a/dictation_server/src/features/accounts/accounts.controller.ts +++ b/dictation_server/src/features/accounts/accounts.controller.ts @@ -9,6 +9,7 @@ import { Param, Query, HttpException, + Logger, } from '@nestjs/common'; import { ApiOperation, @@ -77,14 +78,14 @@ import { RoleGuard } from '../../common/guards/role/roleguards'; import { retrieveAuthorizationToken } from '../../common/http/helper'; import { AccessToken } from '../../common/token'; import jwt from 'jsonwebtoken'; -import { makeContext } from '../../common/log'; +import { makeContext, retrieveRequestId, retrieveIp } from '../../common/log'; import { AuthService } from '../auth/auth.service'; import { makeErrorResponse } from '../../common/error/makeErrorResponse'; -import { v4 as uuidv4 } from 'uuid'; @ApiTags('accounts') @Controller('accounts') export class AccountsController { + private readonly logger = new Logger(AccountsController.name); constructor( private readonly accountService: AccountsService, //private readonly cryptoService: CryptoService, private readonly authService: AuthService, @@ -109,6 +110,7 @@ export class AccountsController { @ApiOperation({ operationId: 'createAccount' }) async createAccount( @Body() body: CreateAccountRequest, + @Req() req: Request, ): Promise { const { companyName, @@ -123,7 +125,24 @@ export class AccountsController { } = body; const role = USER_ROLES.NONE; - const context = makeContext(uuidv4()); + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + + const context = makeContext('anonymous', ip, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.accountService.createAccount( context, @@ -178,6 +197,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -186,7 +221,9 @@ export class AccountsController { ); } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const response = await this.accountService.getLicenseSummary( context, body.accountId, @@ -232,6 +269,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -240,7 +293,9 @@ export class AccountsController { ); } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); //アカウントID取得処理 const accountInfo = await this.accountService.getAccountInfo( context, @@ -283,6 +338,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -291,7 +362,9 @@ export class AccountsController { ); } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const authors = await this.accountService.getAuthors(context, userId); @@ -330,6 +403,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -338,7 +427,9 @@ export class AccountsController { ); } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const typists = await this.accountService.getTypists(context, userId); @@ -377,6 +468,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -385,7 +492,9 @@ export class AccountsController { ); } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const typistGroups = await this.accountService.getTypistGroups( context, @@ -441,6 +550,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -450,7 +575,8 @@ export class AccountsController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const typistGroup = await this.accountService.getTypistGroup( context, @@ -506,6 +632,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -514,7 +656,9 @@ export class AccountsController { ); } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.accountService.createTypistGroup( context, userId, @@ -572,6 +716,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -581,7 +741,8 @@ export class AccountsController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.accountService.updateTypistGroup( context, @@ -637,6 +798,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -646,7 +823,8 @@ export class AccountsController { } const { userId, tier } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.accountService.createPartnerAccount( context, @@ -699,6 +877,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -708,7 +902,8 @@ export class AccountsController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const getPartnerLicensesResponse = await this.accountService.getPartnerLicenses( @@ -759,6 +954,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -768,7 +979,8 @@ export class AccountsController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const getOrderHistoriesResponse = await this.accountService.getOrderHistories( @@ -825,6 +1037,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -834,7 +1062,8 @@ export class AccountsController { } const { userId, tier } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.accountService.issueLicense( context, orderedAccountId, @@ -857,8 +1086,25 @@ export class AccountsController { type: ErrorResponse, }) @ApiOperation({ operationId: 'getDealers' }) - async getDealers(): Promise { - const context = makeContext(uuidv4()); + async getDealers(@Req() req: Request): Promise { + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + + const context = makeContext('anonymous', ip, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); + return await this.accountService.getDealers(context); } @@ -907,6 +1153,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -916,7 +1178,8 @@ export class AccountsController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.accountService.cancelIssue( context, @@ -957,6 +1220,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -966,7 +1245,8 @@ export class AccountsController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const worktypes = await this.accountService.getWorktypes(context, userId); return worktypes; @@ -1012,6 +1292,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -1021,7 +1317,8 @@ export class AccountsController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.accountService.createWorktype( context, userId, @@ -1074,6 +1371,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -1083,7 +1396,8 @@ export class AccountsController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.accountService.updateWorktype( context, @@ -1136,6 +1450,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -1145,7 +1475,8 @@ export class AccountsController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.accountService.deleteWorktype(context, userId, id); return {}; @@ -1191,6 +1522,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -1200,7 +1547,8 @@ export class AccountsController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const optionItems = await this.accountService.getOptionItems( context, @@ -1253,6 +1601,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -1262,7 +1626,8 @@ export class AccountsController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.accountService.updateOptionItems( context, @@ -1314,6 +1679,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -1323,7 +1704,8 @@ export class AccountsController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.accountService.updateActiveWorktype(context, userId, id); return {}; @@ -1372,6 +1754,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -1381,7 +1779,8 @@ export class AccountsController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const response = await this.accountService.getPartners( context, userId, @@ -1439,6 +1838,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -1447,7 +1862,9 @@ export class AccountsController { ); } const { userId, tier } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.accountService.updateAccountInfo( context, @@ -1499,6 +1916,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -1507,7 +1940,9 @@ export class AccountsController { ); } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.accountService.deleteAccountAndData(context, userId, accountId); return {}; @@ -1532,8 +1967,25 @@ export class AccountsController { @ApiOperation({ operationId: 'getAccountInfoMinimalAccess' }) async getAccountInfoMinimalAccess( @Body() body: GetAccountInfoMinimalAccessRequest, + @Req() req: Request, ): Promise { - const context = makeContext(uuidv4()); + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const context = makeContext('anonymous', ip, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); // IDトークンの検証 const idToken = await this.authService.getVerifiedIdToken( @@ -1591,6 +2043,22 @@ export class AccountsController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -1599,7 +2067,9 @@ export class AccountsController { ); } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const companyName = await this.accountService.getCompanyName( context, body.accountId, diff --git a/dictation_server/src/features/accounts/accounts.service.spec.ts b/dictation_server/src/features/accounts/accounts.service.spec.ts index 27c3715..92479ec 100644 --- a/dictation_server/src/features/accounts/accounts.service.spec.ts +++ b/dictation_server/src/features/accounts/accounts.service.spec.ts @@ -136,7 +136,7 @@ describe('createAccount', () => { }); const { accountId, externalUserId, userId } = await service.createAccount( - makeContext('uuid'), + makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), companyName, country, dealerAccountId, @@ -213,7 +213,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid'), + makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), companyName, country, dealerAccountId, @@ -285,7 +285,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid'), + makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), companyName, country, dealerAccountId, @@ -346,7 +346,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid'), + makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), companyName, country, dealerAccountId, @@ -377,7 +377,7 @@ describe('createAccount', () => { // ADB2Cユーザー削除メソッドが呼ばれているか確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('uuid'), + makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), ); }); it('アカウントを作成がDBへの通信失敗によって500エラーが発生した場合、リカバリ処理が実行されるが、ADB2Cユーザー削除で失敗した場合、500エラーが返却される', async () => { @@ -414,7 +414,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid'), + makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), companyName, country, dealerAccountId, @@ -445,7 +445,7 @@ describe('createAccount', () => { // ADB2Cユーザー削除メソッドが呼ばれているか確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('uuid'), + makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), ); }); @@ -485,7 +485,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid'), + makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), companyName, country, dealerAccountId, @@ -516,7 +516,7 @@ describe('createAccount', () => { // ADB2Cユーザー削除メソッドが呼ばれているか確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('uuid'), + makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), ); }); @@ -558,7 +558,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid'), + makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), companyName, country, dealerAccountId, @@ -589,7 +589,7 @@ describe('createAccount', () => { // ADB2Cユーザー削除メソッドが呼ばれているか確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('uuid'), + makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), ); }); @@ -650,7 +650,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid'), + makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), companyName, country, dealerAccountId, @@ -681,11 +681,11 @@ describe('createAccount', () => { // ADB2Cユーザー削除メソッドが呼ばれているか確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('uuid'), + makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), ); // Blobストレージのコンテナ削除メソッドが呼ばれているか確認 expect(blobstorageService.deleteContainer).toBeCalledWith( - makeContext('uuid'), + makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), 1, //新規作成したアカウントのID country, ); @@ -745,7 +745,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid'), + makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), companyName, country, dealerAccountId, @@ -776,11 +776,11 @@ describe('createAccount', () => { // ADB2Cユーザー削除メソッドが呼ばれているか確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('uuid'), + makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), ); // Blobストレージのコンテナ削除メソッドが呼ばれているか確認 expect(blobstorageService.deleteContainer).toBeCalledWith( - makeContext('uuid'), + makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), 1, //新規作成したアカウントのID country, ); @@ -820,7 +820,7 @@ describe('createPartnerAccount', () => { { external_id: adminExternalId }, ); - const context = makeContext('uuid'); + const context = makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'); const companyName = 'test_company_name'; const country = 'US'; const email = 'partner@example.com'; @@ -897,7 +897,7 @@ describe('createPartnerAccount', () => { { external_id: adminExternalId }, ); - const context = makeContext('uuid'); + const context = makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'); const companyName = 'test_company_name'; const country = 'US'; const email = 'partner@example.com'; @@ -975,7 +975,7 @@ describe('createPartnerAccount', () => { { external_id: adminExternalId }, ); - const context = makeContext('uuid'); + const context = makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'); const companyName = 'test_company_name'; const country = 'US'; const email = 'partner@example.com'; @@ -1064,7 +1064,7 @@ describe('createPartnerAccount', () => { { external_id: adminExternalId }, ); - const context = makeContext('uuid'); + const context = makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'); const companyName = 'test_company_name'; const country = 'US'; const email = 'partner@example.com'; @@ -1154,7 +1154,11 @@ describe('createPartnerAccount', () => { { external_id: parentExternalId }, ); - const context = makeContext(parentExternalId); + const context = makeContext( + parentExternalId, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const partnerExternalId = 'partner_external_id'; const companyName = 'partner_company_name'; const country = 'US'; @@ -1236,7 +1240,11 @@ describe('createPartnerAccount', () => { { external_id: parentExternalId }, ); - const context = makeContext(parentExternalId); + const context = makeContext( + parentExternalId, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const partnerExternalId = 'partner_external_id'; const companyName = 'partner_company_name'; const country = 'US'; @@ -1328,7 +1336,11 @@ describe('createPartnerAccount', () => { { external_id: parentExternalId }, ); - const context = makeContext(parentExternalId); + const context = makeContext( + parentExternalId, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const partnerExternalId = 'partner_external_id'; const companyName = 'partner_company_name'; const country = 'US'; @@ -1420,7 +1432,11 @@ describe('createPartnerAccount', () => { { external_id: parentExternalId }, ); - const context = makeContext(parentExternalId); + const context = makeContext( + parentExternalId, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const partnerExternalId = 'partner_external_id'; const companyName = 'partner_company_name'; const country = 'US'; @@ -1515,7 +1531,7 @@ describe('createPartnerAccount', () => { { external_id: adminExternalId }, ); - const context = makeContext('uuid'); + const context = makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'); const companyName = 'test_company_name'; const country = 'US'; const email = 'partner@example.com'; @@ -1608,7 +1624,7 @@ describe('AccountsService', () => { licensesRepositoryMockValue, worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); expect(await service.getLicenseSummary(context, accountId)).toEqual( expectedAccountLisenceCounts, ); @@ -1641,7 +1657,7 @@ describe('AccountsService', () => { licensesRepositoryMockValue, worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect(service.getLicenseSummary(context, accountId)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -1676,7 +1692,7 @@ describe('AccountsService', () => { licensesRepositoryMockValue, worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); expect(await service.getTypists(context, externalId)).toEqual([ { id: 1, name: 'Typist1' }, { id: 2, name: 'Typist2' }, @@ -1710,7 +1726,7 @@ describe('AccountsService', () => { licensesRepositoryMockValue, worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect(service.getTypists(context, externalId)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -1745,7 +1761,7 @@ describe('AccountsService', () => { licensesRepositoryMockValue, worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect(service.getTypists(context, externalId)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -1781,7 +1797,7 @@ describe('AccountsService', () => { worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); expect(await service.getTypistGroups(context, externalId)).toEqual([ { id: 1, name: 'GroupA' }, { id: 2, name: 'GroupB' }, @@ -1815,7 +1831,7 @@ describe('AccountsService', () => { worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect(service.getTypistGroups(context, externalId)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -1851,7 +1867,7 @@ describe('AccountsService', () => { worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect(service.getTypistGroups(context, externalId)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -2034,7 +2050,7 @@ describe('getPartnerAccount', () => { const offset = 0; const limit = 20; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); const response = await service.getPartnerLicenses( context, limit, @@ -2181,7 +2197,7 @@ describe('getPartnerAccount', () => { const offset = 0; const limit = 20; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); const response = await service.getPartnerLicenses( context, limit, @@ -2280,7 +2296,7 @@ describe('getOrderHistories', () => { const offset = 1; const limit = 2; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); const response = await service.getOrderHistories( context, limit, @@ -2325,7 +2341,7 @@ describe('getOrderHistories', () => { licensesRepositoryMockValue, worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect( service.getOrderHistories(context, limit, offset, accountId), ).rejects.toEqual( @@ -2431,7 +2447,11 @@ describe('issueLicense', () => { new Date(now.getTime() + 60 * 60 * 1000), ); - const context = makeContext('userId-parent'); + const context = makeContext( + 'userId-parent', + 'xxx.xxx.xxx.xxx', + 'requestId', + ); // 注文を発行済みにする await service.issueLicense( @@ -2525,7 +2545,11 @@ describe('issueLicense', () => { new Date(now.getTime() + 60 * 60 * 1000), ); - const context = makeContext('userId-parent'); + const context = makeContext( + 'userId-parent', + 'xxx.xxx.xxx.xxx', + 'requestId', + ); // 注文を発行済みにする await service.issueLicense( @@ -2624,7 +2648,11 @@ describe('issueLicense', () => { new Date(now.getTime() + 60 * 60 * 1000), ); - const context = makeContext('userId-parent'); + const context = makeContext( + 'userId-parent', + 'xxx.xxx.xxx.xxx', + 'requestId', + ); // 注文を発行済みにする await expect( @@ -2688,7 +2716,7 @@ describe('getDealers', () => { }) ).account; const service = module.get(AccountsService); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); expect(await service.getDealers(context)).toEqual({ dealers: [ @@ -2717,7 +2745,7 @@ describe('getDealers', () => { const service = module.get(AccountsService); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); expect(await service.getDealers(context)).toEqual({ dealers: [], }); @@ -2781,7 +2809,11 @@ describe('createTypistGroup', () => { const service = module.get(AccountsService); const typistGroupName = 'typist-group-name'; const typistUserIds = userIds; - const context = makeContext(adminExternalId); + const context = makeContext( + adminExternalId, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await service.createTypistGroup( context, adminExternalId, @@ -2845,7 +2877,11 @@ describe('createTypistGroup', () => { const service = module.get(AccountsService); const typistGroupName = 'typist-group-name'; const typistUserIds = userIds; - const context = makeContext(adminExternalId); + const context = makeContext( + adminExternalId, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await expect( service.createTypistGroup( context, @@ -2896,7 +2932,11 @@ describe('createTypistGroup', () => { const service = module.get(AccountsService); const typistGroupName = 'typist-group-name'; const typistUserIds = [...userIds, 9999]; //存在しないユーザーIDを追加 - const context = makeContext(adminExternalId); + const context = makeContext( + adminExternalId, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await expect( service.createTypistGroup( context, @@ -2948,7 +2988,11 @@ describe('createTypistGroup', () => { const service = module.get(AccountsService); const typistGroupName = 'typist-group-name'; const typistUserIds = [...userIds]; - const context = makeContext(adminExternalId); + const context = makeContext( + adminExternalId, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await expect( service.createTypistGroup( context, @@ -2999,7 +3043,11 @@ describe('createTypistGroup', () => { const service = module.get(AccountsService); const typistGroupName = 'typist-group-name'; const typistUserIds = userIds; - const context = makeContext(adminExternalId); + const context = makeContext( + adminExternalId, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //DBアクセスに失敗するようにする const typistGroupService = module.get( UserGroupsRepositoryService, @@ -3069,7 +3117,11 @@ describe('getTypistGroup', () => { const typistGroupName = 'typist-group-name'; const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await service.createTypistGroup( context, @@ -3129,7 +3181,11 @@ describe('getTypistGroup', () => { // アカウントにタイピストグループを作成する const typistGroupName = 'typist-group-name'; const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await service.createTypistGroup( context, admin.external_id, @@ -3184,7 +3240,11 @@ describe('getTypistGroup', () => { // アカウントにタイピストグループを作成する const typistGroupName = 'typist-group-name'; const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await service.createTypistGroup( context, @@ -3266,7 +3326,11 @@ describe('updateTypistGroup', () => { const service = module.get(AccountsService); const typistUserIds = [userIds[1]]; - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const typistGroupName = 'typist-group-name'; await service.createTypistGroup( context, @@ -3338,7 +3402,11 @@ describe('updateTypistGroup', () => { const typistGroupName = 'typist-group-name'; const service = module.get(AccountsService); const typistUserIds = [userIds[2]]; - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await service.createTypistGroup( context, @@ -3402,7 +3470,11 @@ describe('updateTypistGroup', () => { const typistGroupName = 'typist-group-name'; const service = module.get(AccountsService); const typistUserIds = [999]; - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await service.createTypistGroup( context, admin.external_id, @@ -3465,7 +3537,11 @@ describe('updateTypistGroup', () => { const typistGroupName = 'typist-group-name'; const service = module.get(AccountsService); const typistUserIds = [...userIds]; - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await service.createTypistGroup( context, admin.external_id, @@ -3528,7 +3604,11 @@ describe('updateTypistGroup', () => { const typistGroupName = 'typist-group-name'; const service = module.get(AccountsService); const typistUserIds = [userIds[1]]; - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await service.createTypistGroup( context, admin.external_id, @@ -3591,7 +3671,11 @@ describe('updateTypistGroup', () => { const typistGroupName = 'typist-group-name'; const service = module.get(AccountsService); const typistUserIds = [userIds[1]]; - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await service.createTypistGroup( context, admin.external_id, @@ -3667,7 +3751,11 @@ describe('getWorktypes', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await createWorktype(source, account.id, 'worktype1', 'description1', true); await createWorktype(source, account.id, 'worktype2'); @@ -3708,7 +3796,11 @@ describe('getWorktypes', () => { const { admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const resWorktypes = await service.getWorktypes(context, admin.external_id); @@ -3726,7 +3818,11 @@ describe('getWorktypes', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await createWorktype(source, account.id, 'worktype1', 'description1'); await createWorktype(source, account.id, 'worktype2'); @@ -3787,7 +3883,11 @@ describe('createWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); // Worktypeが未登録であることを確認 { @@ -3828,7 +3928,11 @@ describe('createWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const worktypeId = 'worktype1'; await createWorktype(source, account.id, worktypeId); @@ -3859,7 +3963,11 @@ describe('createWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); // あらかじめ最大登録数分のWorktypeを登録する for (let i = 0; i < WORKTYPE_MAX_COUNT; i++) { @@ -3892,7 +4000,11 @@ describe('createWorktype', () => { const { admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //DBアクセスに失敗するようにする const worktypeService = module.get( @@ -3940,7 +4052,11 @@ describe('updateWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const worktype = new Worktype(); worktype.custom_worktype_id = 'worktypeID1'; @@ -3989,7 +4105,11 @@ describe('updateWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const worktype = new Worktype(); worktype.custom_worktype_id = 'worktypeID1'; @@ -4036,7 +4156,11 @@ describe('updateWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const worktype1 = new Worktype(); worktype1.custom_worktype_id = 'worktypeID1'; worktype1.description = 'description1'; @@ -4098,7 +4222,11 @@ describe('updateWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const worktype = new Worktype(); worktype.custom_worktype_id = 'worktypeID1'; @@ -4146,7 +4274,11 @@ describe('updateWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const worktype = new Worktype(); worktype.custom_worktype_id = 'worktypeID1'; @@ -4219,7 +4351,11 @@ describe('deleteWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const { id: worktypeId1 } = await createWorktype( source, @@ -4267,7 +4403,11 @@ describe('deleteWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const { id: worktypeId1 } = await createWorktype( source, @@ -4314,7 +4454,11 @@ describe('deleteWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const { id: worktypeId1 } = await createWorktype( source, @@ -4358,7 +4502,11 @@ describe('deleteWorktype', () => { }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const { id: worktypeId1 } = await createWorktype( source, @@ -4402,7 +4550,11 @@ describe('deleteWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const { id: worktypeId1 } = await createWorktype( source, @@ -4467,7 +4619,11 @@ describe('getOptionItems', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const worktype = await createWorktype(source, account.id, 'worktype1'); const optionItems = await createOptionItems(source, worktype.id); @@ -4510,7 +4666,11 @@ describe('getOptionItems', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const worktype = await createWorktype(source, account.id, 'worktype1'); const optionItems = await createOptionItems(source, worktype.id); @@ -4545,7 +4705,11 @@ describe('getOptionItems', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const worktype = await createWorktype(source, account.id, 'worktype1'); const optionItems = await createOptionItems(source, worktype.id); @@ -4606,7 +4770,11 @@ describe('updateOptionItems', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const worktype = await createWorktype(source, account.id, 'worktype1'); const optionItems = await createOptionItems(source, worktype.id); @@ -4732,7 +4900,11 @@ describe('updateOptionItems', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const worktype = await createWorktype(source, account.id, 'worktype1'); const optionItems = await createOptionItems(source, worktype.id); @@ -4818,7 +4990,11 @@ describe('updateOptionItems', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const worktype = await createWorktype(source, account.id, 'worktype1'); const optionItems = await createOptionItems(source, worktype.id); @@ -4932,7 +5108,11 @@ describe('updateActiveWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const worktype = await createWorktype(source, account.id, 'worktype1'); @@ -4959,7 +5139,11 @@ describe('updateActiveWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const worktype1 = await createWorktype( source, @@ -4997,7 +5181,11 @@ describe('updateActiveWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const worktype1 = await createWorktype( source, @@ -5030,7 +5218,11 @@ describe('updateActiveWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await createWorktype(source, account.id, 'worktype1'); @@ -5063,7 +5255,11 @@ describe('updateActiveWorktype', () => { }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await createWorktype(source, account.id, 'worktype1'); await createWorktype(source, otherAccount.id, 'worktype2'); @@ -5102,7 +5298,11 @@ describe('updateActiveWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await createWorktype(source, account.id, 'worktype1'); @@ -5190,7 +5390,7 @@ describe('ライセンス発行キャンセル', () => { const service = module.get(AccountsService); await service.cancelIssue( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), tier1Accounts[0].users[0].external_id, poNumber, tier5Accounts.account.id, @@ -5253,7 +5453,7 @@ describe('ライセンス発行キャンセル', () => { const service = module.get(AccountsService); await service.cancelIssue( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), tier2Accounts[0].users[0].external_id, poNumber, tier5Accounts.account.id, @@ -5291,7 +5491,7 @@ describe('ライセンス発行キャンセル', () => { const service = module.get(AccountsService); await expect( service.cancelIssue( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), tier1Accounts[0].users[0].external_id, poNumber, tier5Accounts.account.id, @@ -5337,7 +5537,7 @@ describe('ライセンス発行キャンセル', () => { const service = module.get(AccountsService); await expect( service.cancelIssue( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), tier1Accounts[0].users[0].external_id, poNumber, tier5Accounts.account.id, @@ -5383,7 +5583,7 @@ describe('ライセンス発行キャンセル', () => { const service = module.get(AccountsService); await expect( service.cancelIssue( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), tier1Accounts[0].users[0].external_id, poNumber, tier5Accounts.account.id, @@ -5430,7 +5630,7 @@ describe('ライセンス発行キャンセル', () => { const service = module.get(AccountsService); await expect( service.cancelIssue( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), tier1Accounts[0].users[0].external_id, poNumber, tier5Accounts.account.id, @@ -5549,7 +5749,7 @@ describe('パートナー一覧取得', () => { }); const partners = await service.getPartners( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), tier1Accounts[0].users[0].external_id, 15, 0, @@ -5598,7 +5798,7 @@ describe('パートナー一覧取得', () => { }); const partners = await service.getPartners( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), account.admin.external_id, 15, 0, @@ -5640,7 +5840,7 @@ describe('アカウント情報更新', () => { tier: 5, }); await service.updateAccountInfo( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), tier5Accounts.admin.external_id, tier5Accounts.account.tier, true, @@ -5669,7 +5869,7 @@ describe('アカウント情報更新', () => { role: 'typist', }); await service.updateAccountInfo( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), tier4Accounts[0].users[0].external_id, tier4Accounts[0].account.tier, false, @@ -5699,7 +5899,7 @@ describe('アカウント情報更新', () => { role: 'typist', }); await service.updateAccountInfo( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), tier4Accounts[0].users[0].external_id, tier4Accounts[0].account.tier, false, @@ -5730,7 +5930,7 @@ describe('アカウント情報更新', () => { }); await expect( service.updateAccountInfo( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), tier4Accounts[0].users[0].external_id, tier4Accounts[0].account.tier, false, @@ -5756,7 +5956,7 @@ describe('アカウント情報更新', () => { }); await expect( service.updateAccountInfo( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), tier5Accounts.admin.external_id, tier5Accounts.account.tier, true, @@ -5782,7 +5982,7 @@ describe('アカウント情報更新', () => { }); await expect( service.updateAccountInfo( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), tier5Accounts.admin.external_id, tier5Accounts.account.tier, true, @@ -5827,7 +6027,11 @@ describe('getAccountInfo', () => { }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const accountResponse = await service.getAccountInfo( context, @@ -5906,7 +6110,11 @@ describe('getAuthors', () => { } const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const authors = await service.getAuthors(context, admin.external_id); //実行結果を確認 @@ -5946,7 +6154,11 @@ describe('getAuthors', () => { } const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const authors = await service.getAuthors(context, admin.external_id); //実行結果を確認 @@ -5970,7 +6182,11 @@ describe('getAuthors', () => { } const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const authors = await service.getAuthors(context, admin.external_id); //実行結果を確認 @@ -5986,7 +6202,11 @@ describe('getAuthors', () => { const { admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //DBアクセスに失敗するようにする const usersService = module.get( @@ -6069,7 +6289,7 @@ describe('getTypists', () => { ], }); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); const typists = await service.getTypists(context, admin.external_id); //実行結果を確認 @@ -6097,7 +6317,7 @@ describe('getTypists', () => { overrideAdB2cService(service, { getUsers: async () => [{ id: admin.external_id, displayName: '' }], }); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); const typists = await service.getTypists(context, admin.external_id); //実行結果を確認 @@ -6146,7 +6366,7 @@ describe('getTypists', () => { ], }); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); const typists = await service.getTypists(context, admin.external_id); //実行結果を確認 @@ -6173,7 +6393,7 @@ describe('getTypists', () => { UsersRepositoryService, ); usersService.findTypistUsers = jest.fn().mockRejectedValue('DB failed'); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); //実行結果を確認 try { @@ -6240,7 +6460,11 @@ describe('deleteAccountAndData', () => { account_id: tier5AccountsB.account.id, }); - const context = makeContext(tier5AccountsA.admin.external_id); + const context = makeContext( + tier5AccountsA.admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); // 第一階層~第五階層までのライセンス注文を作成 await createLicenseOrder( source, @@ -6421,7 +6645,11 @@ describe('deleteAccountAndData', () => { }); const account = account1; const admin = admin1; - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); // 第五階層のアカウント作成 const tier5Accounts = await makeTestAccount(source, { parent_account_id: account.id, @@ -6485,7 +6713,11 @@ describe('deleteAccountAndData', () => { }); const account = account1; const admin = admin1; - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); // 第五階層のアカウント作成 const tier5Accounts = await makeTestAccount(source, { parent_account_id: account.id, @@ -6540,7 +6772,11 @@ describe('deleteAccountAndData', () => { }); const account = account1; const admin = admin1; - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); // 第五階層のアカウント作成 const tier5Accounts = await makeTestAccount(source, { parent_account_id: account.id, @@ -6609,7 +6845,11 @@ describe('getAccountInfoMinimalAccess', () => { const { account, admin } = await makeTestAccount(source, { tier: 5, }); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); // 作成したデータを確認 { @@ -6634,7 +6874,11 @@ describe('getAccountInfoMinimalAccess', () => { const { account, admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); // 作成したデータを確認 { @@ -6659,7 +6903,11 @@ describe('getAccountInfoMinimalAccess', () => { const { account, admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); // 作成したデータを確認 { @@ -6687,7 +6935,11 @@ describe('getAccountInfoMinimalAccess', () => { const { account, admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); // 作成したデータを確認 { @@ -6744,7 +6996,11 @@ describe('getCompanyName', () => { tier: 5, company_name: 'testCompany', }); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const response = await service.getCompanyName(context, account.id); expect({ companyName: 'testCompany' }).toEqual(response); }); @@ -6759,7 +7015,11 @@ describe('getCompanyName', () => { tier: 5, company_name: 'testCompany', }); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); try { await service.getCompanyName(context, 123); } catch (e) { diff --git a/dictation_server/src/features/accounts/accounts.service.ts b/dictation_server/src/features/accounts/accounts.service.ts index 668f815..7de2682 100644 --- a/dictation_server/src/features/accounts/accounts.service.ts +++ b/dictation_server/src/features/accounts/accounts.service.ts @@ -607,11 +607,7 @@ export class AccountsService { const externalIds = typistUsers.map((x) => x.external_id); // B2Cからユーザー名を取得する - const trackingId = new Context(context.trackingId); - const adb2cUsers = await this.adB2cService.getUsers( - trackingId, - externalIds, - ); + const adb2cUsers = await this.adB2cService.getUsers(context, externalIds); const typists = typistUsers.map((x) => { const user = adb2cUsers.find((adb2c) => adb2c.id === x.external_id); diff --git a/dictation_server/src/features/auth/auth.controller.ts b/dictation_server/src/features/auth/auth.controller.ts index dbec612..a243192 100644 --- a/dictation_server/src/features/auth/auth.controller.ts +++ b/dictation_server/src/features/auth/auth.controller.ts @@ -3,6 +3,7 @@ import { Controller, HttpException, HttpStatus, + Logger, Post, Req, UseGuards, @@ -25,8 +26,7 @@ import { DelegationAccessTokenResponse, } from './types/types'; import { retrieveAuthorizationToken } from '../../common/http/helper'; -import { makeContext } from '../../common/log'; -import { v4 as uuidv4 } from 'uuid'; +import { makeContext, retrieveRequestId, retrieveIp } from '../../common/log'; import { Request } from 'express'; import { AuthGuard } from '../../common/guards/auth/authguards'; import { RoleGuard } from '../../common/guards/role/roleguards'; @@ -39,6 +39,7 @@ import { RedisService } from '../../gateways/redis/redis.service'; @ApiTags('auth') @Controller('auth') export class AuthController { + private readonly logger = new Logger(AuthController.name); constructor( private readonly authService: AuthService, private readonly redisService: RedisService, @@ -65,8 +66,29 @@ export class AuthController { 'AzureADB2Cでのサインイン後に払いだされるIDトークンを元に認証用のアクセストークンとリフレッシュトークンを生成します', operationId: 'token', }) - async token(@Body() body: TokenRequest): Promise { - const context = makeContext(uuidv4()); + async token( + @Body() body: TokenRequest, + @Req() req: Request, + ): Promise { + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + + const context = makeContext('anonymous', ip, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); + const idToken = await this.authService.getVerifiedIdToken( context, body.idToken, @@ -145,7 +167,6 @@ export class AuthController { }) async accessToken(@Req() req: Request): Promise { const refreshToken = retrieveAuthorizationToken(req); - if (!refreshToken) { throw new HttpException( makeErrorResponse('E000107'), @@ -153,7 +174,24 @@ export class AuthController { ); } - const context = makeContext(uuidv4()); + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + + const context = makeContext('anonymous', ip, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const accessToken = await this.authService.generateAccessToken( context, @@ -202,13 +240,29 @@ export class AuthController { ): Promise { const { delegatedAccountId } = body; const token = retrieveAuthorizationToken(req); - if (!token) { throw new HttpException( makeErrorResponse('E000107'), HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const decodedAccessToken = jwt.decode(token, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -218,7 +272,9 @@ export class AuthController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext('anonymous', ip, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); + const refreshToken = await this.authService.generateDelegationRefreshToken( context, userId, @@ -257,13 +313,29 @@ export class AuthController { @Req() req: Request, ): Promise { const refreshToken = retrieveAuthorizationToken(req); - if (!refreshToken) { throw new HttpException( makeErrorResponse('E000107'), HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const decodedRefreshToken = jwt.decode(refreshToken, { json: true }); if (!decodedRefreshToken) { throw new HttpException( @@ -273,7 +345,9 @@ export class AuthController { } const { userId, delegateUserId } = decodedRefreshToken as RefreshToken; - const context = makeContext(userId); + const context = makeContext('anonymous', ip, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); + const accessToken = await this.authService.updateDelegationAccessToken( context, delegateUserId, diff --git a/dictation_server/src/features/auth/auth.service.spec.ts b/dictation_server/src/features/auth/auth.service.spec.ts index f978889..5862140 100644 --- a/dictation_server/src/features/auth/auth.service.spec.ts +++ b/dictation_server/src/features/auth/auth.service.spec.ts @@ -31,7 +31,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdWVyIiwic3ViIjoic3ViIiwiYXVkIjoiYXVkIiwibm9uY2UiOiJkZWZhdWx0Tm9uY2UiLCJpYXQiOjEwMDAwMDAwMDAsImF1dGhfdGltZSI6MTAwMDAwMDAwMCwiZW1haWxzIjpbInh4eEB4eC5jb20iXSwidGZwIjoic2lnbmluX3VzZXJmbG93In0.RyieW-VHsHPQOjXbbhRc307AYJOc1sq2hrcu4SW1-K0pvLlkplepxvx02a3vCwQrnBYrIP5w6HExG-S_JgW5nYyWr6DeY11mA484n9KA8GeAcAXV37StH1gfWUJvfGb4C8BaMbMM9Ix4Z9NGwKA9vjNwevfmBZnz9lQUePgv6BJNmyvCt8ElJ01O-1WODbZuojJ4xXymA1OqluzfbphPOsqWTSNmTn0emkLjjnlMQf1iwM4C_kvvr8dUCFg0_UGDfQVJnzPEKB38UqnhLnC5WacrddDwQ0kBuGKZgZ_63Q_7fOvqAZivqLK7BPmbPxi6mx3R1S9Eq2ugzpY1LfJOjA'; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); expect(await service.getVerifiedIdToken(context, token)).toEqual( idTokenPayload, ); @@ -43,7 +43,7 @@ describe('AuthService', () => { const service = await makeAuthServiceMock(adb2cParam, configMockValue); const token = 'invalid.id.token'; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E000101'), HttpStatus.UNAUTHORIZED), ); @@ -58,7 +58,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjEwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdWVyIiwic3ViIjoic3ViIiwiYXVkIjoiYXVkIiwibm9uY2UiOiJkZWZhdWx0Tm9uY2UiLCJpYXQiOjEwMDAwMDAwMDAsImF1dGhfdGltZSI6MTAwMDAwMDAwMCwiZW1haWxzIjpbInh4eEB4eC5jb20iXSwidGZwIjoic2lnbmluX3VzZXJmbG93In0.r9x61Mf1S2qFgU_QDKB6tRFBmTQXyOEtpoacOlL_bQzFz1t3GsxMy6SJIvQQ-LtDgylQ1UCdMFiRuy4V8nyLuME0fR-9IkKsboGvwllHB_Isai3XFoja0jpDHMVby1m0B3Z9xOTb7YsaQGyEH-qs1TtnRm6Ny98h4Po80nK8HGefQZHBOlfQN_B1LiHwI3nLXV18NL-4olKXj2NloNRYtnWM0PaqDQcGvZFaSNvtrSYpo9ddD906QWDGVOQ7WvGSUgdNCoxX8Lb3r2-VSj6n84jpb-Y1Fz-GhLluNglAsBhasnJfUIvCIO3iG5pRyTYjHFAVHmzjr8xMOmhS3s41Jw'; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E000102'), HttpStatus.UNAUTHORIZED), ); @@ -73,7 +73,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6OTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdWVyIiwic3ViIjoic3ViIiwiYXVkIjoiYXVkIiwibm9uY2UiOiJkZWZhdWx0Tm9uY2UiLCJpYXQiOjEwMDAwMDAwMDAsImF1dGhfdGltZSI6MTAwMDAwMDAwMCwiZW1haWxzIjpbInh4eEB4eC5jb20iXSwidGZwIjoic2lnbmluX3VzZXJmbG93In0.fX2Gbd7fDPNE3Lw-xbum_5CVqQYqEmMhv_v5u8A-U81pmPD2P5rsJEJx66ns1taFLVaE3j9_OzotxrqjqqQqbACkagGcN5wvA3_ZIxyqmhrKYFJc53ZcO7d0pFWiQlluNBI_pnFNDlSMB2Ut8Th5aiPy2uamBM9wC99bcjo7HkHvTKBf6ljU6rPKoD51qGDWqNxjoH-hdSJ29wprvyxyk_yX6dp-cxXUj5DIgXYQuIZF71rdiPtGlAiyTBns8rS2QlEEXapZVlvYrK4mkpUXVDA7ifD8q6gAC2BStqHeys7CGp2MbV4ZwKCVbAUbMs6Tboh8rADZvQhuTEq7qlhZ-w'; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E000103'), HttpStatus.UNAUTHORIZED), ); @@ -86,7 +86,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdXNlciIsInN1YiI6InN1YiIsImF1ZCI6ImF1ZCIsIm5vbmNlIjoiZGVmYXVsdE5vbmNlIiwiaWF0IjoxMDAwMDAwMDAwLCJhdXRoX3RpbWUiOjEwMDAwMDAwMDAsImVtYWlscyI6WyJ4eHhAeHguY29tIl0sInRmcCI6InNpZ25pbl91c2VyZmxvdyJ9.sign'; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E000104'), HttpStatus.UNAUTHORIZED), ); @@ -101,7 +101,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaW52bGlkX2lzc3VlciIsInN1YiI6InN1YiIsImF1ZCI6ImF1ZCIsIm5vbmNlIjoiZGVmYXVsdE5vbmNlIiwiaWF0IjoxMDAwMDAwMDAwLCJhdXRoX3RpbWUiOjEwMDAwMDAwMDAsImVtYWlscyI6WyJ4eHhAeHguY29tIl0sInRmcCI6InNpZ25pbl91c2VyZmxvdyJ9.0bp3e1mDG78PX3lo8zgOLXGenIqG_Vi6kw7CbwauAQM-cnUZ_aVCoJ_dAv_QmPElOQKcCkRrAvAZ91FwuHDlBGuuDqx8OwqN0VaD-4NPouoAswj-9HNvBm8gUn-pGaXkvWt_72UdCJavZJjDj_RHur8y8kFt5Qeab3mUP2x-uNcV2Q2x3M_IIfcRiIZkRZm_azKfiVIy7tzoUFLDss97y938aR8imMVxazoSQvj7RWIWylgeRr9yVt7qYl18cnEVL0IGtslFbqhfNsiEmRCMsttm5kXs7E9B0bhhUe_xbJW9VumQ6G7dgMrswevp_jRgbpWJoZsgErtqIRl9Tc9ikA'; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E000105'), HttpStatus.UNAUTHORIZED), ); @@ -115,7 +115,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdWVyIiwic3ViIjoic3ViIiwiYXVkIjoiYXVkIiwibm9uY2UiOiJkZWZhdWx0Tm9uY2UiLCJpYXQiOjEwMDAwMDAwMDAsImF1dGhfdGltZSI6MTAwMDAwMDAwMCwiZW1haWxzIjpbInh4eEB4eC5jb20iXSwidGZwIjoic2lnbmluX3VzZXJmbG93In0.RyieW-VHsHPQOjXbbhRc307AYJOc1sq2hrcu4SW1-K0pvLlkplepxvx02a3vCwQrnBYrIP5w6HExG-S_JgW5nYyWr6DeY11mA484n9KA8GeAcAXV37StH1gfWUJvfGb4C8BaMbMM9Ix4Z9NGwKA9vjNwevfmBZnz9lQUePgv6BJNmyvCt8ElJ01O-1WODbZuojJ4xXymA1OqluzfbphPOsqWTSNmTn0emkLjjnlMQf1iwM4C_kvvr8dUCFg0_UGDfQVJnzPEKB38UqnhLnC5WacrddDwQ0kBuGKZgZ_63Q_7fOvqAZivqLK7BPmbPxi6mx3R1S9Eq2ugzpY1LfJOjA'; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -131,7 +131,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdWVyIiwic3ViIjoic3ViIiwiYXVkIjoiYXVkIiwibm9uY2UiOiJkZWZhdWx0Tm9uY2UiLCJpYXQiOjEwMDAwMDAwMDAsImF1dGhfdGltZSI6MTAwMDAwMDAwMCwiZW1haWxzIjpbInh4eEB4eC5jb20iXSwidGZwIjoic2lnbmluX3VzZXJmbG93In0.RyieW-VHsHPQOjXbbhRc307AYJOc1sq2hrcu4SW1-K0pvLlkplepxvx02a3vCwQrnBYrIP5w6HExG-S_JgW5nYyWr6DeY11mA484n9KA8GeAcAXV37StH1gfWUJvfGb4C8BaMbMM9Ix4Z9NGwKA9vjNwevfmBZnz9lQUePgv6BJNmyvCt8ElJ01O-1WODbZuojJ4xXymA1OqluzfbphPOsqWTSNmTn0emkLjjnlMQf1iwM4C_kvvr8dUCFg0_UGDfQVJnzPEKB38UqnhLnC5WacrddDwQ0kBuGKZgZ_63Q_7fOvqAZivqLK7BPmbPxi6mx3R1S9Eq2ugzpY1LfJOjA'; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -150,7 +150,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdWVyIiwic3ViIjoic3ViIiwiYXVkIjoiYXVkIiwibm9uY2UiOiJkZWZhdWx0Tm9uY2UiLCJpYXQiOjEwMDAwMDAwMDAsImF1dGhfdGltZSI6MTAwMDAwMDAwMCwiZW1haWxzIjpbInh4eEB4eC5jb20iXSwidGZwIjoic2lnbmluX3VzZXJmbG93In0.RyieW-VHsHPQOjXbbhRc307AYJOc1sq2hrcu4SW1-K0pvLlkplepxvx02a3vCwQrnBYrIP5w6HExG-S_JgW5nYyWr6DeY11mA484n9KA8GeAcAXV37StH1gfWUJvfGb4C8BaMbMM9Ix4Z9NGwKA9vjNwevfmBZnz9lQUePgv6BJNmyvCt8ElJ01O-1WODbZuojJ4xXymA1OqluzfbphPOsqWTSNmTn0emkLjjnlMQf1iwM4C_kvvr8dUCFg0_UGDfQVJnzPEKB38UqnhLnC5WacrddDwQ0kBuGKZgZ_63Q_7fOvqAZivqLK7BPmbPxi6mx3R1S9Eq2ugzpY1LfJOjA'; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -186,7 +186,7 @@ describe('checkIsAcceptedLatestVersion', () => { const { admin } = await makeTestAccount(source, { tier: 5, }); - const context = makeContext(uuidv4()); + const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); const idToken = { emails: [], @@ -210,7 +210,7 @@ describe('checkIsAcceptedLatestVersion', () => { const { admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(uuidv4()); + const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); const idToken = { emails: [], @@ -234,7 +234,7 @@ describe('checkIsAcceptedLatestVersion', () => { const { admin } = await makeTestAccount(source, { tier: 5, }); - const context = makeContext(uuidv4()); + const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); const idToken = { emails: [], @@ -258,7 +258,7 @@ describe('checkIsAcceptedLatestVersion', () => { const { admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(uuidv4()); + const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); const idToken = { emails: [], @@ -282,7 +282,7 @@ describe('checkIsAcceptedLatestVersion', () => { const { admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(uuidv4()); + const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); const idToken = { emails: [], @@ -306,7 +306,7 @@ describe('checkIsAcceptedLatestVersion', () => { const { admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(uuidv4()); + const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); const idToken = { emails: [], @@ -361,7 +361,11 @@ describe('generateDelegationRefreshToken', () => { { role: USER_ROLES.NONE }, ); - const context = makeContext(parentAdmin.external_id); + const context = makeContext( + parentAdmin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const delegationRefreshToken = await service.generateDelegationRefreshToken( context, @@ -399,7 +403,11 @@ describe('generateDelegationRefreshToken', () => { { role: USER_ROLES.NONE }, ); - const context = makeContext(parentAdmin.external_id); + const context = makeContext( + parentAdmin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); try { await service.generateDelegationRefreshToken( @@ -437,7 +445,11 @@ describe('generateDelegationRefreshToken', () => { { role: USER_ROLES.NONE }, ); - const context = makeContext(parentAdmin.external_id); + const context = makeContext( + parentAdmin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); try { await service.generateDelegationRefreshToken( @@ -495,7 +507,11 @@ describe('generateDelegationAccessToken', () => { { role: USER_ROLES.NONE }, ); - const context = makeContext(parentAdmin.external_id); + const context = makeContext( + parentAdmin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const delegationRefreshToken = await service.generateDelegationRefreshToken( context, @@ -540,7 +556,11 @@ describe('generateDelegationAccessToken', () => { tier: 4, }); - const context = makeContext(parentAdmin.external_id); + const context = makeContext( + parentAdmin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); try { await service.generateDelegationAccessToken(context, 'invalid token'); @@ -595,7 +615,11 @@ describe('updateDelegationAccessToken', () => { { role: USER_ROLES.NONE }, ); - const context = makeContext(parentAdmin.external_id); + const context = makeContext( + parentAdmin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const delegationRefreshToken = await service.generateDelegationRefreshToken( context, @@ -653,7 +677,11 @@ describe('updateDelegationAccessToken', () => { { role: USER_ROLES.NONE }, ); - const context = makeContext(parentAdmin.external_id); + const context = makeContext( + parentAdmin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const delegationRefreshToken = await service.generateDelegationRefreshToken( context, @@ -719,7 +747,11 @@ describe('updateDelegationAccessToken', () => { { role: USER_ROLES.NONE }, ); - const context = makeContext(parentAdmin.external_id); + const context = makeContext( + parentAdmin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const delegationRefreshToken = await service.generateDelegationRefreshToken( context, diff --git a/dictation_server/src/features/files/files.controller.ts b/dictation_server/src/features/files/files.controller.ts index 05e941f..af41275 100644 --- a/dictation_server/src/features/files/files.controller.ts +++ b/dictation_server/src/features/files/files.controller.ts @@ -4,6 +4,7 @@ import { Get, HttpException, HttpStatus, + Logger, Post, Query, Req, @@ -37,12 +38,13 @@ import { RoleGuard } from '../../common/guards/role/roleguards'; import { ADMIN_ROLES, USER_ROLES } from '../../constants'; import { retrieveAuthorizationToken } from '../../common/http/helper'; import { Request } from 'express'; -import { makeContext } from '../../common/log'; +import { makeContext, retrieveRequestId, retrieveIp } from '../../common/log'; import { makeErrorResponse } from '../../common/error/makeErrorResponse'; @ApiTags('files') @Controller('files') export class FilesController { + private readonly logger = new Logger(FilesController.name); constructor(private readonly filesService: FilesService) {} @ApiResponse({ @@ -84,6 +86,22 @@ export class FilesController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -93,7 +111,8 @@ export class FilesController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const { url, @@ -176,6 +195,22 @@ export class FilesController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -185,7 +220,8 @@ export class FilesController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const url = await this.filesService.publishUploadSas(context, userId); return { url }; @@ -237,6 +273,22 @@ export class FilesController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -246,7 +298,8 @@ export class FilesController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const url = await this.filesService.publishAudioFileDownloadSas( context, @@ -301,6 +354,22 @@ export class FilesController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -310,7 +379,8 @@ export class FilesController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const url = await this.filesService.publishTemplateFileDownloadSas( context, @@ -357,6 +427,22 @@ export class FilesController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -366,7 +452,8 @@ export class FilesController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const url = await this.filesService.publishTemplateFileUploadSas( context, @@ -418,6 +505,22 @@ export class FilesController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -427,7 +530,8 @@ export class FilesController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.filesService.templateUploadFinished(context, userId, url, name); return {}; } diff --git a/dictation_server/src/features/files/files.service.spec.ts b/dictation_server/src/features/files/files.service.spec.ts index 34c6f00..c8e1229 100644 --- a/dictation_server/src/features/files/files.service.spec.ts +++ b/dictation_server/src/features/files/files.service.spec.ts @@ -85,7 +85,7 @@ describe('publishUploadSas', () => { null, null, ); - const context = makeContext(externalId); + const context = makeContext(externalId, 'xxx.xxx.xxx.xxx', 'requestId'); const baseUrl = `https://saodmsusdev.blob.core.windows.net/account-${account.id}/${userId}`; //SASトークンを返却する @@ -107,7 +107,11 @@ describe('publishUploadSas', () => { // 第四階層のアカウント作成 const { admin } = await makeTestAccount(source, { tier: 4 }); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //Blobコンテナ存在チェックに失敗するようにする overrideBlobstorageService(service, { @@ -135,7 +139,11 @@ describe('publishUploadSas', () => { // 第四階層のアカウント作成 const { admin } = await makeTestAccount(source, { tier: 4 }); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //BlobのSASトークン生成に失敗するようにする overrideBlobstorageService(service, { @@ -164,7 +172,11 @@ describe('publishUploadSas', () => { // 第五階層のアカウント作成 const { admin } = await makeTestAccount(source, { tier: 5, locked: true }); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); try { await service.publishUploadSas(context, admin.external_id); @@ -209,7 +221,10 @@ describe('publishUploadSas', () => { const service = module.get(FilesService); await expect( - service.publishUploadSas(makeContext('trackingId'), externalId), + service.publishUploadSas( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + externalId, + ), ).rejects.toEqual( new HttpException(makeErrorResponse('E010812'), HttpStatus.BAD_REQUEST), ); @@ -267,7 +282,10 @@ describe('publishUploadSas', () => { const service = module.get(FilesService); await expect( - service.publishUploadSas(makeContext('trackingId'), externalId), + service.publishUploadSas( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + externalId, + ), ).rejects.toEqual( new HttpException(makeErrorResponse('E010805'), HttpStatus.BAD_REQUEST), ); @@ -348,7 +366,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { NotificationhubService, ); const result = await service.uploadFinished( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), authorExternalId, 'http://blob/url/file.zip', authorAuthorId ?? '', @@ -368,7 +386,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { expect(result).toEqual({ jobNumber: '00000001' }); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), [`user_${typistUserId}`], { authorId: 'AUTHOR_ID', @@ -449,7 +467,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { NotificationhubService, ); const result = await service.uploadFinished( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), authorExternalId, 'http://blob/url/file.zip', authorAuthorId ?? '', @@ -469,7 +487,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { expect(result).toEqual({ jobNumber: '00000002' }); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), [`user_${typistUserId}`], { authorId: 'AUTHOR_ID', @@ -572,7 +590,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { NotificationhubService, ); const result = await service.uploadFinished( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), myExternalId, // API実行者のユーザーIDを設定 'http://blob/url/file.zip', authorAuthorId ?? '', // 音声ファイルの情報には、録音者のAuthorIDが入る @@ -592,7 +610,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { expect(result).toEqual({ jobNumber: '00000001' }); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), [`user_${typistUserId}`], { authorId: 'AUTHOR_ID', @@ -694,7 +712,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { NotificationhubService, ); const result = await service.uploadFinished( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), myExternalId, // API実行者のユーザーIDを設定 'http://blob/url/file.zip', 'XXXXXXXXXX', // 音声ファイルの情報には、録音者のAuthorIDが入る @@ -714,7 +732,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { expect(result).toEqual({ jobNumber: '00000001' }); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), [`user_${typistUserId}`], { authorId: 'XXXXXXXXXX', @@ -763,7 +781,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { const service = module.get(FilesService); const result = await service.uploadFinished( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), authorExternalId, // API実行者のユーザーIDを設定 'http://blob/url/file.zip', authorAuthorId ?? '', // 音声ファイルの情報には、録音者のAuthorIDが入る @@ -819,7 +837,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { await expect( service.uploadFinished( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), authorExternalId, 'http://blob/url/file.zip', authorAuthorId ?? '', @@ -866,7 +884,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { await expect( service.uploadFinished( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), authorExternalId, 'http://blob/url/file.zip', authorAuthorId ?? '', @@ -907,7 +925,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { await expect( service.uploadFinished( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 'authorExternalId', 'http://blob/url/file.zip', 'authorAuthorId', @@ -958,7 +976,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { await expect( service.uploadFinished( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), authorExternalId, 'http://blob/url/file.zip', authorAuthorId ?? '', @@ -1043,7 +1061,7 @@ describe('音声ファイルダウンロードURL取得', () => { expect( await service.publishAudioFileDownloadSas( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), externalId, audioFileId, ), @@ -1113,7 +1131,7 @@ describe('音声ファイルダウンロードURL取得', () => { expect( await service.publishAudioFileDownloadSas( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), externalId, audioFileId, ), @@ -1160,7 +1178,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishAudioFileDownloadSas( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), externalId, audioFileId, ), @@ -1214,7 +1232,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('tracking'), + makeContext('tracking', 'xxx.xxx.xxx.xxx', 'requestId'), externalId, audioFileId, ), @@ -1259,7 +1277,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishAudioFileDownloadSas( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), externalId, audioFileId, ), @@ -1291,7 +1309,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishAudioFileDownloadSas( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), externalId, 1, ), @@ -1340,7 +1358,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishAudioFileDownloadSas( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), externalId, audioFileId, ), @@ -1395,7 +1413,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishAudioFileDownloadSas( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), externalId, audioFileId, ), @@ -1467,7 +1485,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishAudioFileDownloadSas( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), externalId, audioFileId, ), @@ -1535,7 +1553,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { expect( await service.publishTemplateFileDownloadSas( - makeContext('tracking'), + makeContext('tracking', 'xxx.xxx.xxx.xxx', 'requestId'), externalId, audioFileId, ), @@ -1605,7 +1623,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { expect( await service.publishTemplateFileDownloadSas( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), externalId, audioFileId, ), @@ -1646,7 +1664,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('tracking'), + makeContext('tracking', 'xxx.xxx.xxx.xxx', 'requestId'), externalId, audioFileId, ), @@ -1696,7 +1714,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('tracking'), + makeContext('tracking', 'xxx.xxx.xxx.xxx', 'requestId'), externalId, audioFileId, ), @@ -1741,7 +1759,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('tracking'), + makeContext('tracking', 'xxx.xxx.xxx.xxx', 'requestId'), externalId, audioFileId, ), @@ -1773,7 +1791,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('tracking'), + makeContext('tracking', 'xxx.xxx.xxx.xxx', 'requestId'), externalId, 1, ), @@ -1821,7 +1839,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('tracking'), + makeContext('tracking', 'xxx.xxx.xxx.xxx', 'requestId'), externalId, audioFileId, ), @@ -1876,7 +1894,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), externalId, audioFileId, ), @@ -1948,7 +1966,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), externalId, audioFileId, ), @@ -1985,7 +2003,11 @@ describe('publishTemplateFileUploadSas', () => { // 第五階層のアカウント作成 const { account, admin } = await makeTestAccount(source, { tier: 5 }); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const baseUrl = `https://saodmsusdev.blob.core.windows.net/account-${account.id}/Templates`; //SASトークンを返却する @@ -2010,7 +2032,11 @@ describe('publishTemplateFileUploadSas', () => { // 第五階層のアカウント作成 const { admin } = await makeTestAccount(source, { tier: 5 }); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //Blobコンテナ存在チェックに失敗するようにする overrideBlobstorageService(service, { @@ -2038,7 +2064,11 @@ describe('publishTemplateFileUploadSas', () => { // 第五階層のアカウント作成 const { admin } = await makeTestAccount(source, { tier: 5 }); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //BlobのSASトークン生成に失敗するようにする overrideBlobstorageService(service, { @@ -2087,7 +2117,11 @@ describe('templateUploadFinished', () => { const service = module.get(FilesService); // 第五階層のアカウント作成 const { account, admin } = await makeTestAccount(source, { tier: 5 }); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const fileName = 'test.docs'; const url = `https://blob.url/account-${account.id}/Templates`; @@ -2121,7 +2155,11 @@ describe('templateUploadFinished', () => { const service = module.get(FilesService); // 第五階層のアカウント作成 const { account, admin } = await makeTestAccount(source, { tier: 5 }); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const fileName = 'test.docs'; const url = `https://blob.url/account-${account.id}/Templates`; @@ -2161,7 +2199,11 @@ describe('templateUploadFinished', () => { const service = module.get(FilesService); // 第五階層のアカウント作成 const { account, admin } = await makeTestAccount(source, { tier: 5 }); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const fileName = 'test.docs'; const url = `https://blob.url/account-${account.id}/Templates`; diff --git a/dictation_server/src/features/licenses/licenses.controller.ts b/dictation_server/src/features/licenses/licenses.controller.ts index 33fd5e0..9839333 100644 --- a/dictation_server/src/features/licenses/licenses.controller.ts +++ b/dictation_server/src/features/licenses/licenses.controller.ts @@ -4,6 +4,7 @@ import { Get, HttpException, HttpStatus, + Logger, Post, Req, UseGuards, @@ -34,12 +35,13 @@ import { AuthGuard } from '../../common/guards/auth/authguards'; import { RoleGuard } from '../../common/guards/role/roleguards'; import { ADMIN_ROLES, TIERS } from '../../constants'; import jwt from 'jsonwebtoken'; -import { makeContext } from '../../common/log'; +import { makeContext, retrieveRequestId, retrieveIp } from '../../common/log'; import { makeErrorResponse } from '../../common/error/makeErrorResponse'; @ApiTags('licenses') @Controller('licenses') export class LicensesController { + private readonly logger = new Logger(LicensesController.name); constructor(private readonly licensesService: LicensesService) {} @ApiResponse({ status: HttpStatus.OK, @@ -83,6 +85,22 @@ export class LicensesController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -91,7 +109,9 @@ export class LicensesController { ); } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); // ライセンス注文処理 await this.licensesService.licenseOrders( @@ -136,6 +156,22 @@ export class LicensesController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -144,7 +180,9 @@ export class LicensesController { ); } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const cardLicenseKeys = await this.licensesService.issueCardLicenseKeys( context, @@ -198,6 +236,22 @@ export class LicensesController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -206,7 +260,9 @@ export class LicensesController { ); } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.licensesService.activateCardLicenseKey( context, @@ -257,6 +313,22 @@ export class LicensesController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -266,7 +338,8 @@ export class LicensesController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const allocatableLicenses = await this.licensesService.getAllocatableLicenses(context, userId); @@ -319,6 +392,22 @@ export class LicensesController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -328,7 +417,8 @@ export class LicensesController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.licensesService.cancelOrder(context, userId, body.poNumber); return {}; diff --git a/dictation_server/src/features/licenses/licenses.service.spec.ts b/dictation_server/src/features/licenses/licenses.service.spec.ts index 7804d71..aa4b670 100644 --- a/dictation_server/src/features/licenses/licenses.service.spec.ts +++ b/dictation_server/src/features/licenses/licenses.service.spec.ts @@ -59,7 +59,7 @@ describe('LicensesService', () => { const userId = '0001'; body.orderCount = 1000; body.poNumber = '1'; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); expect( await service.licenseOrders( context, @@ -87,7 +87,7 @@ describe('LicensesService', () => { const userId = ''; body.orderCount = 1000; body.poNumber = '1'; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect( service.licenseOrders(context, userId, body.poNumber, body.orderCount), ).rejects.toEqual( @@ -115,7 +115,7 @@ describe('LicensesService', () => { const userId = '0001'; body.orderCount = 1000; body.poNumber = '1'; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect( service.licenseOrders(context, userId, body.poNumber, body.orderCount), ).rejects.toEqual( @@ -143,7 +143,7 @@ describe('LicensesService', () => { const userId = '0001'; body.orderCount = 1000; body.poNumber = '1'; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect( service.licenseOrders(context, userId, body.poNumber, body.orderCount), ).rejects.toEqual( @@ -181,7 +181,7 @@ describe('LicensesService', () => { 'AEJWRFFSWRQYQQJ6WVLV', ], }; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); expect( await service.issueCardLicenseKeys(context, userId, body.createCount), ).toEqual(issueCardLicensesResponse); @@ -201,7 +201,7 @@ describe('LicensesService', () => { const body = new IssueCardLicensesRequest(); const userId = '0001'; body.createCount = 1000; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect( service.issueCardLicenseKeys(context, userId, body.createCount), ).rejects.toEqual( @@ -225,7 +225,7 @@ describe('LicensesService', () => { const body = new ActivateCardLicensesRequest(); const userId = '0001'; body.cardLicenseKey = 'WZCETXC0Z9PQZ9GKRGGY'; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); expect( await service.activateCardLicenseKey( context, @@ -249,7 +249,7 @@ describe('LicensesService', () => { const body = new ActivateCardLicensesRequest(); const userId = '0001'; body.cardLicenseKey = 'WZCETXC0Z9PQZ9GKRGGY'; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect( service.activateCardLicenseKey(context, userId, body.cardLicenseKey), ).rejects.toEqual( @@ -276,7 +276,7 @@ describe('LicensesService', () => { const body = new ActivateCardLicensesRequest(); const userId = '0001'; body.cardLicenseKey = 'WZCETXC0Z9PQZ9GKRGGY'; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect( service.activateCardLicenseKey(context, userId, body.cardLicenseKey), ).rejects.toEqual( @@ -299,7 +299,7 @@ describe('LicensesService', () => { const body = new ActivateCardLicensesRequest(); const userId = '0001'; body.cardLicenseKey = 'WZCETXC0Z9PQZ9GKRGGY'; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect( service.activateCardLicenseKey(context, userId, body.cardLicenseKey), ).rejects.toEqual( @@ -342,7 +342,7 @@ describe('DBテスト', () => { const service = module.get(LicensesService); const issueCount = 500; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await service.issueCardLicenseKeys(context, externalId, issueCount); const dbSelectResult = await selectCardLicensesCount(source); expect(dbSelectResult.count).toEqual(issueCount); @@ -382,7 +382,7 @@ describe('DBテスト', () => { await createCardLicenseIssue(source, issueId); const service = module.get(LicensesService); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await service.activateCardLicenseKey(context, externalId, cardLicenseKey); const dbSelectResultFromCardLicense = await selectCardLicense( @@ -529,7 +529,7 @@ describe('DBテスト', () => { null, ); const service = module.get(LicensesService); - const context = makeContext('userId'); + const context = makeContext('userId', 'xxx.xxx.xxx.xxx', 'requestId'); const response = await service.getAllocatableLicenses(context, externalId); // 対象外のデータは取得していないことを確認する expect(response.allocatableLicenses.length).toBe(5); @@ -599,7 +599,11 @@ describe('ライセンス割り当て', () => { const expiry_date = new NewAllocatedLicenseExpirationDate(); - await service.allocateLicense(makeContext('trackingId'), userId, 1); + await service.allocateLicense( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + userId, + 1, + ); const resultLicense = await selectLicense(source, 1); expect(resultLicense.license?.allocated_user_id).toBe(userId); expect(resultLicense.license?.status).toBe( @@ -664,7 +668,11 @@ describe('ライセンス割り当て', () => { const service = module.get(UsersService); - await service.allocateLicense(makeContext('trackingId'), userId, 1); + await service.allocateLicense( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + userId, + 1, + ); const result = await selectLicense(source, 1); expect(result.license?.allocated_user_id).toBe(userId); expect(result.license?.status).toBe(LICENSE_ALLOCATED_STATUS.ALLOCATED); @@ -739,7 +747,11 @@ describe('ライセンス割り当て', () => { const expiry_date = new NewAllocatedLicenseExpirationDate(); - await service.allocateLicense(makeContext('trackingId'), userId, 2); + await service.allocateLicense( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + userId, + 2, + ); // もともと割り当てられていたライセンスの状態確認 const result1 = await selectLicense(source, 1); @@ -838,7 +850,11 @@ describe('ライセンス割り当て', () => { ); const service = module.get(UsersService); - await service.allocateLicense(makeContext('trackingId'), userId, 2); + await service.allocateLicense( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + userId, + 2, + ); const licenseAllocationHistory = await selectLicenseAllocationHistory( source, @@ -898,7 +914,11 @@ describe('ライセンス割り当て', () => { ); const service = module.get(UsersService); - await service.allocateLicense(makeContext('trackingId'), userId, 2); + await service.allocateLicense( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + userId, + 2, + ); const licenseAllocationHistory = await selectLicenseAllocationHistory( source, @@ -958,7 +978,11 @@ describe('ライセンス割り当て', () => { ); const service = module.get(UsersService); - await service.allocateLicense(makeContext('trackingId'), userId, 2); + await service.allocateLicense( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + userId, + 2, + ); const licenseAllocationHistory = await selectLicenseAllocationHistory( source, @@ -1000,7 +1024,11 @@ describe('ライセンス割り当て', () => { const service = module.get(UsersService); await expect( - service.allocateLicense(makeContext('trackingId'), userId, 1), + service.allocateLicense( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + userId, + 1, + ), ).rejects.toEqual( new HttpException(makeErrorResponse('E010805'), HttpStatus.BAD_REQUEST), ); @@ -1048,12 +1076,20 @@ describe('ライセンス割り当て', () => { const service = module.get(UsersService); await expect( - service.allocateLicense(makeContext('trackingId'), userId, 1), + service.allocateLicense( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + userId, + 1, + ), ).rejects.toEqual( new HttpException(makeErrorResponse('E010806'), HttpStatus.BAD_REQUEST), ); await expect( - service.allocateLicense(makeContext('trackingId'), userId, 2), + service.allocateLicense( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + userId, + 2, + ), ).rejects.toEqual( new HttpException(makeErrorResponse('E010806'), HttpStatus.BAD_REQUEST), ); @@ -1115,7 +1151,10 @@ describe('ライセンス割り当て解除', () => { ); const service = module.get(UsersService); - await service.deallocateLicense(makeContext('trackingId'), userId); + await service.deallocateLicense( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + userId, + ); // 割り当て解除したライセンスの状態確認 const deallocatedLicense = await selectLicense(source, 1); @@ -1203,7 +1242,10 @@ describe('ライセンス割り当て解除', () => { const service = module.get(UsersService); await expect( - service.deallocateLicense(makeContext('trackingId'), userId), + service.deallocateLicense( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + userId, + ), ).rejects.toEqual( new HttpException(makeErrorResponse('E010807'), HttpStatus.BAD_REQUEST), ); @@ -1259,7 +1301,7 @@ describe('ライセンス注文キャンセル', () => { const service = module.get(LicensesService); await service.cancelOrder( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), tier2Accounts[0].users[0].external_id, poNumber, ); @@ -1295,7 +1337,7 @@ describe('ライセンス注文キャンセル', () => { const service = module.get(LicensesService); await expect( service.cancelOrder( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), tier2Accounts[0].users[0].external_id, poNumber, ), @@ -1326,7 +1368,7 @@ describe('ライセンス注文キャンセル', () => { const service = module.get(LicensesService); await expect( service.cancelOrder( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), tier2Accounts[0].users[0].external_id, poNumber, ), diff --git a/dictation_server/src/features/notification/notification.controller.ts b/dictation_server/src/features/notification/notification.controller.ts index 0a640be..701d13e 100644 --- a/dictation_server/src/features/notification/notification.controller.ts +++ b/dictation_server/src/features/notification/notification.controller.ts @@ -3,6 +3,7 @@ import { Controller, HttpException, HttpStatus, + Logger, Post, Req, UseGuards, @@ -21,12 +22,13 @@ import { AuthGuard } from '../../common/guards/auth/authguards'; import { retrieveAuthorizationToken } from '../../common/http/helper'; import { AccessToken } from '../../common/token'; import jwt from 'jsonwebtoken'; -import { makeContext } from '../../common/log'; +import { makeContext, retrieveRequestId, retrieveIp } from '../../common/log'; import { makeErrorResponse } from '../../common/error/makeErrorResponse'; @ApiTags('notification') @Controller('notification') export class NotificationController { + private readonly logger = new Logger(NotificationController.name); constructor(private readonly notificationService: NotificationService) {} @Post('register') @ApiResponse({ @@ -65,6 +67,22 @@ export class NotificationController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -74,7 +92,8 @@ export class NotificationController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.notificationService.register(context, userId, pns, handler); return {}; diff --git a/dictation_server/src/features/notification/notification.service.spec.ts b/dictation_server/src/features/notification/notification.service.spec.ts index bd714e7..a052fd7 100644 --- a/dictation_server/src/features/notification/notification.service.spec.ts +++ b/dictation_server/src/features/notification/notification.service.spec.ts @@ -19,7 +19,7 @@ describe('NotificationService.register', () => { expect( await service.register( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 'external_id', 'apns', 'handler', @@ -38,7 +38,7 @@ describe('NotificationService.register', () => { await expect( service.register( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 'external_id', 'apns', 'handler', @@ -63,7 +63,7 @@ describe('NotificationService.register', () => { await expect( service.register( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 'external_id', 'apns', 'handler', diff --git a/dictation_server/src/features/tasks/tasks.controller.ts b/dictation_server/src/features/tasks/tasks.controller.ts index 2b976b2..18f3772 100644 --- a/dictation_server/src/features/tasks/tasks.controller.ts +++ b/dictation_server/src/features/tasks/tasks.controller.ts @@ -2,9 +2,9 @@ import { Body, Controller, Get, - Headers, HttpException, HttpStatus, + Logger, Param, ParseIntPipe, Post, @@ -45,12 +45,13 @@ import { AuthGuard } from '../../common/guards/auth/authguards'; import { RoleGuard } from '../../common/guards/role/roleguards'; import { ADMIN_ROLES, USER_ROLES } from '../../constants'; import { Roles } from '../../common/types/role'; -import { makeContext } from '../../common/log'; +import { makeContext, retrieveRequestId, retrieveIp } from '../../common/log'; import { makeErrorResponse } from '../../common/error/makeErrorResponse'; @ApiTags('tasks') @Controller('tasks') export class TasksController { + private readonly logger = new Logger(TasksController.name); constructor(private readonly taskService: TasksService) {} @ApiResponse({ @@ -91,6 +92,23 @@ export class TasksController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -102,7 +120,8 @@ export class TasksController { // RoleGuardでroleの文字列に想定外の文字列や重複がないことは担保されているためここでは型変換のみ行う const roles = role.split(' ') as Roles[]; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const { limit, offset, status } = body; const paramName = isTaskListSortableAttribute(body.paramName ?? '') @@ -164,13 +183,29 @@ export class TasksController { ): Promise { const { endedFileId } = param; - const accessToken = retrieveAuthorizationToken(req) as string; + const accessToken = retrieveAuthorizationToken(req); if (!accessToken) { throw new HttpException( makeErrorResponse('E000107'), HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -179,7 +214,8 @@ export class TasksController { ); } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const nextFileId = await this.taskService.getNextTask( context, @@ -241,6 +277,23 @@ export class TasksController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -253,7 +306,8 @@ export class TasksController { // RoleGuardでroleの文字列に想定外の文字列や重複がないことは担保されているためここでは型変換のみ行う const roles = role.split(' ') as Roles[]; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.taskService.checkout(context, param.audioFileId, roles, userId); return {}; @@ -311,6 +365,23 @@ export class TasksController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -320,7 +391,8 @@ export class TasksController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.taskService.checkin(context, audioFileId, userId); return {}; @@ -378,6 +450,23 @@ export class TasksController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -389,7 +478,8 @@ export class TasksController { // RoleGuardでroleの文字列に想定外の文字列や重複がないことは担保されているためここでは型変換のみ行う const roles = role.split(' ') as Roles[]; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.taskService.cancel(context, audioFileId, userId, roles); return {}; @@ -447,6 +537,23 @@ export class TasksController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -456,7 +563,8 @@ export class TasksController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.taskService.suspend(context, audioFileId, userId); return {}; @@ -513,6 +621,23 @@ export class TasksController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -522,7 +647,8 @@ export class TasksController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.taskService.backup(context, audioFileId, userId); return {}; @@ -585,6 +711,23 @@ export class TasksController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -596,7 +739,8 @@ export class TasksController { // RoleGuardでroleの文字列に想定外の文字列や重複がないことは担保されているためここでは型変換のみ行う const roles = role.split(' ') as Roles[]; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.taskService.changeCheckoutPermission( context, diff --git a/dictation_server/src/features/tasks/tasks.service.spec.ts b/dictation_server/src/features/tasks/tasks.service.spec.ts index cb8ac34..56287ac 100644 --- a/dictation_server/src/features/tasks/tasks.service.spec.ts +++ b/dictation_server/src/features/tasks/tasks.service.spec.ts @@ -63,7 +63,7 @@ describe('TasksService', () => { const direction = 'ASC'; expect( await service.tasksService.getTasks( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), userId, [ADMIN_ROLES.ADMIN, USER_ROLES.NONE], offset, @@ -138,7 +138,7 @@ describe('TasksService', () => { const direction = 'ASC'; await expect( service.tasksService.getTasks( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), userId, [ADMIN_ROLES.ADMIN, USER_ROLES.NONE], offset, @@ -180,7 +180,7 @@ describe('TasksService', () => { const direction = 'ASC'; await expect( service.tasksService.getTasks( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), userId, [ADMIN_ROLES.ADMIN, USER_ROLES.NONE], offset, @@ -266,7 +266,7 @@ describe('TasksService', () => { const direction = 'ASC'; await expect( service.tasksService.getTasks( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), userId, [ADMIN_ROLES.ADMIN, USER_ROLES.NONE], offset, @@ -310,7 +310,7 @@ describe('TasksService', () => { const paramName = 'JOB_NUMBER'; const direction = 'ASC'; const result = await service.tasksService.getTasks( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), userId, [USER_ROLES.AUTHOR], offset, @@ -393,7 +393,7 @@ describe('TasksService', () => { const direction = 'ASC'; await expect( service.tasksService.getTasks( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), userId, [USER_ROLES.AUTHOR], offset, @@ -438,7 +438,7 @@ describe('TasksService', () => { const paramName = 'JOB_NUMBER'; const direction = 'ASC'; const result = await service.tasksService.getTasks( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), userId, [USER_ROLES.TYPIST], offset, @@ -521,7 +521,7 @@ describe('TasksService', () => { const direction = 'ASC'; await expect( service.tasksService.getTasks( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), userId, [USER_ROLES.TYPIST], offset, @@ -563,7 +563,7 @@ describe('TasksService', () => { const direction = 'ASC'; await expect( service.tasksService.getTasks( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), userId, [ADMIN_ROLES.ADMIN, USER_ROLES.NONE], offset, @@ -623,7 +623,7 @@ describe('TasksService', () => { const direction = 'ASC'; const { tasks, total } = await service.getTasks( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), externalId, [ADMIN_ROLES.ADMIN, USER_ROLES.NONE], offset, @@ -681,7 +681,7 @@ describe('TasksService', () => { const direction = 'ASC'; const { tasks, total } = await service.getTasks( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), external_id, [USER_ROLES.AUTHOR], offset, @@ -753,7 +753,7 @@ describe('TasksService', () => { const direction = 'ASC'; const { tasks, total } = await service.getTasks( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), external_id, [USER_ROLES.AUTHOR], offset, @@ -839,7 +839,7 @@ describe('changeCheckoutPermission', () => { NotificationhubService, ); await service.changeCheckoutPermission( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, [{ typistName: 'typist-user-2', typistUserId: typistUserId_2 }], 'author-user-external-id', @@ -856,7 +856,7 @@ describe('changeCheckoutPermission', () => { const resultTask = await getTask(source, taskId); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), [`user_${typistUserId_2}`], { authorId: 'MY_AUTHOR_ID', @@ -922,7 +922,7 @@ describe('changeCheckoutPermission', () => { NotificationhubService, ); await service.changeCheckoutPermission( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, [{ typistName: 'USER_GROUP_B', typistGroupId: userGroupId_2 }], 'author-user-external-id', @@ -940,7 +940,7 @@ describe('changeCheckoutPermission', () => { const resultTask = await getTask(source, taskId); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), [`user_${typistUserId_2}`], { authorId: 'MY_AUTHOR_ID', @@ -992,7 +992,7 @@ describe('changeCheckoutPermission', () => { await createCheckoutPermissions(source, taskId, undefined, userGroupId); const service = module.get(TasksService); await service.changeCheckoutPermission( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, [], 'author-user-external-id', @@ -1045,7 +1045,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, [{ typistName: 'not-exist-user', typistUserId: 999 }], 'author-user-external-id', @@ -1111,7 +1111,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, [{ typistName: 'not-verified-user', typistUserId: typistUserId_2 }], 'author-user-external-id', @@ -1171,7 +1171,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, [{ typistName: 'not-exist-user-group', typistGroupId: 999 }], 'author-user-external-id', @@ -1213,7 +1213,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, [{ typistName: 'typist-user', typistUserId: typistUserId }], 'author-user-external-id', @@ -1265,7 +1265,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, [{ typistName: 'typist-user', typistUserId: typistUserId }], 'author-user-external-id', @@ -1317,7 +1317,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, [{ typistName: 'typist-user', typistUserId: typistUserId }], 'author-user-external-id', @@ -1383,7 +1383,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, [{ typistName: 'typist-user-2', typistUserId: typistUserId_2 }], 'author-user-external-id', @@ -1460,7 +1460,7 @@ describe('checkout', () => { const initTask = await getTask(source, taskId); await service.checkout( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, ['typist'], 'typist-user-external-id', @@ -1520,7 +1520,7 @@ describe('checkout', () => { const initTask = await getTask(source, taskId); await service.checkout( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, ['typist'], 'typist-user-external-id', @@ -1573,7 +1573,7 @@ describe('checkout', () => { const initTask = await getTask(source, taskId); await service.checkout( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, ['typist'], 'typist-user-external-id', @@ -1625,7 +1625,7 @@ describe('checkout', () => { const service = module.get(TasksService); try { await service.checkout( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, ['typist'], 'typist-user-external-id', @@ -1672,7 +1672,7 @@ describe('checkout', () => { const service = module.get(TasksService); try { await service.checkout( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, ['typist'], 'typist-user-external-id', @@ -1733,7 +1733,7 @@ describe('checkout', () => { try { await service.checkout( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), audioFileId, ['typist'], 'typist-user-external-id', @@ -1798,7 +1798,7 @@ describe('checkout', () => { const service = module.get(TasksService); await service.checkout( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 2, ['typist'], 'typist-user-external-id2', @@ -1839,7 +1839,7 @@ describe('checkout', () => { const service = module.get(TasksService); expect( await service.checkout( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, ['author'], 'author-user-external-id', @@ -1873,7 +1873,7 @@ describe('checkout', () => { expect( await service.checkout( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, ['author'], 'author-user-external-id', @@ -1896,7 +1896,7 @@ describe('checkout', () => { const service = module.get(TasksService); try { await service.checkout( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, ['author'], 'author-user-external-id', @@ -1937,7 +1937,7 @@ describe('checkout', () => { const service = module.get(TasksService); try { await service.checkout( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, ['author'], 'author-user-external-id', @@ -1968,7 +1968,7 @@ describe('checkout', () => { const service = module.get(TasksService); try { await service.checkout( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, ['none'], 'none-user-external-id', @@ -2043,7 +2043,7 @@ describe('checkin', () => { const initTask = await getTask(source, taskId); await service.checkin( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, 'typist-user-external-id', ); @@ -2089,7 +2089,11 @@ describe('checkin', () => { const service = module.get(TasksService); await expect( - service.checkin(makeContext('trackingId'), 1, 'typist-user-external-id'), + service.checkin( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + 1, + 'typist-user-external-id', + ), ).rejects.toEqual( new HttpException(makeErrorResponse('E010601'), HttpStatus.BAD_REQUEST), ); @@ -2137,7 +2141,11 @@ describe('checkin', () => { const service = module.get(TasksService); await expect( - service.checkin(makeContext('trackingId'), 1, 'typist-user-external-id'), + service.checkin( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + 1, + 'typist-user-external-id', + ), ).rejects.toEqual( new HttpException(makeErrorResponse('E010601'), HttpStatus.BAD_REQUEST), ); @@ -2169,7 +2177,11 @@ describe('checkin', () => { const service = module.get(TasksService); await expect( - service.checkin(makeContext('trackingId'), 1, 'typist-user-external-id'), + service.checkin( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + 1, + 'typist-user-external-id', + ), ).rejects.toEqual( new HttpException(makeErrorResponse('E010603'), HttpStatus.NOT_FOUND), ); @@ -2231,7 +2243,7 @@ describe('suspend', () => { const service = module.get(TasksService); await service.suspend( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, 'typist-user-external-id', ); @@ -2276,7 +2288,11 @@ describe('suspend', () => { const service = module.get(TasksService); await expect( - service.suspend(makeContext('trackingId'), 1, 'typist-user-external-id'), + service.suspend( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + 1, + 'typist-user-external-id', + ), ).rejects.toEqual( new HttpException(makeErrorResponse('E010601'), HttpStatus.BAD_REQUEST), ); @@ -2324,7 +2340,11 @@ describe('suspend', () => { const service = module.get(TasksService); await expect( - service.checkin(makeContext('trackingId'), 1, 'typist-user-external-id'), + service.checkin( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + 1, + 'typist-user-external-id', + ), ).rejects.toEqual( new HttpException(makeErrorResponse('E010601'), HttpStatus.BAD_REQUEST), ); @@ -2356,7 +2376,11 @@ describe('suspend', () => { const service = module.get(TasksService); await expect( - service.checkin(makeContext('trackingId'), 1, 'typist-user-external-id'), + service.checkin( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + 1, + 'typist-user-external-id', + ), ).rejects.toEqual( new HttpException(makeErrorResponse('E010603'), HttpStatus.NOT_FOUND), ); @@ -2419,7 +2443,7 @@ describe('cancel', () => { const service = module.get(TasksService); await service.cancel( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, 'typist-user-external-id', ['typist', 'standard'], @@ -2468,7 +2492,7 @@ describe('cancel', () => { const service = module.get(TasksService); await service.cancel( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, 'typist-user-external-id', ['typist', 'standard'], @@ -2520,7 +2544,7 @@ describe('cancel', () => { const service = module.get(TasksService); await service.cancel( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, 'typist-user-external-id', ['admin', 'author'], @@ -2571,7 +2595,7 @@ describe('cancel', () => { const service = module.get(TasksService); await service.cancel( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, 'typist-user-external-id', ['admin', 'author'], @@ -2620,10 +2644,12 @@ describe('cancel', () => { const service = module.get(TasksService); await expect( - service.cancel(makeContext('trackingId'), 1, 'typist-user-external-id', [ - 'admin', - 'author', - ]), + service.cancel( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + 1, + 'typist-user-external-id', + ['admin', 'author'], + ), ).rejects.toEqual( new HttpException(makeErrorResponse('E010601'), HttpStatus.BAD_REQUEST), ); @@ -2671,10 +2697,12 @@ describe('cancel', () => { const service = module.get(TasksService); await expect( - service.cancel(makeContext('trackingId'), 1, 'typist-user-external-id', [ - 'typist', - 'standard', - ]), + service.cancel( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + 1, + 'typist-user-external-id', + ['typist', 'standard'], + ), ).rejects.toEqual( new HttpException(makeErrorResponse('E010601'), HttpStatus.BAD_REQUEST), ); @@ -2706,10 +2734,12 @@ describe('cancel', () => { const service = module.get(TasksService); await expect( - service.cancel(makeContext('trackingId'), 1, 'typist-user-external-id', [ - 'typist', - 'standard', - ]), + service.cancel( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + 1, + 'typist-user-external-id', + ['typist', 'standard'], + ), ).rejects.toEqual( new HttpException(makeErrorResponse('E010603'), HttpStatus.NOT_FOUND), ); @@ -2774,7 +2804,7 @@ describe('cancel', () => { NotificationhubService, ); await service.cancel( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, 'typist-user-external-id', ['typist', 'standard'], @@ -2791,7 +2821,7 @@ describe('cancel', () => { expect(permisions[0].user_id).toEqual(typistUserId); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), [`user_${typistUserId}`], { authorId: 'AUTHOR_ID', @@ -2884,7 +2914,7 @@ describe('cancel', () => { NotificationhubService, ); await service.cancel( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, external_id, role.split(' ') as Roles[], @@ -2901,7 +2931,7 @@ describe('cancel', () => { expect(permisions[0].user_id).toEqual(autoRoutingTypistUserId); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), [`user_${autoRoutingTypistUserId}`], { authorId: 'AUTHOR_ID', @@ -2956,7 +2986,7 @@ describe('cancel', () => { NotificationhubService, ); await service.cancel( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), 1, external_id, role.split(' ') as Roles[], @@ -3030,7 +3060,7 @@ describe('backup', () => { const service = module.get(TasksService); await service.backup( - makeContext(admin.external_id), + makeContext(admin.external_id, 'xxx.xxx.xxx.xxx', 'requestId'), audioFileId, admin.external_id, ); @@ -3082,7 +3112,7 @@ describe('backup', () => { const service = module.get(TasksService); await service.backup( - makeContext(admin.external_id), + makeContext(admin.external_id, 'xxx.xxx.xxx.xxx', 'requestId'), audioFileId, admin.external_id, ); @@ -3135,7 +3165,7 @@ describe('backup', () => { try { await service.backup( - makeContext(admin.external_id), + makeContext(admin.external_id, 'xxx.xxx.xxx.xxx', 'requestId'), audioFileId, admin.external_id, ); @@ -3190,7 +3220,7 @@ describe('backup', () => { try { await service.backup( - makeContext(admin.external_id), + makeContext(admin.external_id, 'xxx.xxx.xxx.xxx', 'requestId'), 9999, // 存在しないタスクID admin.external_id, ); @@ -3251,7 +3281,7 @@ describe('backup', () => { try { await service.backup( - makeContext(admin.external_id), + makeContext(admin.external_id, 'xxx.xxx.xxx.xxx', 'requestId'), audioFileId, admin.external_id, ); @@ -3344,7 +3374,11 @@ describe('getNextTask', () => { await createCheckoutPermissions(source, taskId2, typistUserId); const service = module.get(TasksService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const nextAudioFileId = await service.getNextTask( context, @@ -3416,7 +3450,11 @@ describe('getNextTask', () => { await createCheckoutPermissions(source, taskId2, typistUserId); const service = module.get(TasksService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const nextAudioFileId = await service.getNextTask( context, @@ -3488,7 +3526,11 @@ describe('getNextTask', () => { await createCheckoutPermissions(source, taskId2, typistUserId); const service = module.get(TasksService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const nextAudioFileId = await service.getNextTask( context, @@ -3560,7 +3602,11 @@ describe('getNextTask', () => { await createCheckoutPermissions(source, taskId2, typistUserId); const service = module.get(TasksService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const nextAudioFileId = await service.getNextTask( context, @@ -3632,7 +3678,11 @@ describe('getNextTask', () => { await createCheckoutPermissions(source, taskId2, typistUserId); const service = module.get(TasksService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const nextAudioFileId = await service.getNextTask( context, @@ -3680,7 +3730,11 @@ describe('getNextTask', () => { await createCheckoutPermissions(source, taskId1, typistUserId); const service = module.get(TasksService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const nextAudioFileId = await service.getNextTask( context, @@ -3727,7 +3781,11 @@ describe('getNextTask', () => { await createCheckoutPermissions(source, taskId1, typistUserId); const service = module.get(TasksService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); // 実行結果が正しいか確認 try { diff --git a/dictation_server/src/features/templates/templates.controller.ts b/dictation_server/src/features/templates/templates.controller.ts index 08a77d4..d07db64 100644 --- a/dictation_server/src/features/templates/templates.controller.ts +++ b/dictation_server/src/features/templates/templates.controller.ts @@ -3,6 +3,7 @@ import { Get, HttpException, HttpStatus, + Logger, Req, UseGuards, } from '@nestjs/common'; @@ -21,13 +22,14 @@ import { RoleGuard } from '../../common/guards/role/roleguards'; import { ADMIN_ROLES } from '../../constants'; import { retrieveAuthorizationToken } from '../../common/http/helper'; import { Request } from 'express'; -import { makeContext } from '../../common/log'; +import { makeContext, retrieveRequestId, retrieveIp } from '../../common/log'; import { TemplatesService } from './templates.service'; import { makeErrorResponse } from '../../common/error/makeErrorResponse'; @ApiTags('templates') @Controller('templates') export class TemplatesController { + private readonly logger = new Logger(TemplatesController.name); constructor(private readonly templatesService: TemplatesService) {} @ApiResponse({ @@ -63,6 +65,22 @@ export class TemplatesController { HttpStatus.UNAUTHORIZED, ); } + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -72,7 +90,9 @@ export class TemplatesController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); + const templates = await this.templatesService.getTemplates(context, userId); return { templates }; diff --git a/dictation_server/src/features/templates/templates.service.spec.ts b/dictation_server/src/features/templates/templates.service.spec.ts index d3b0160..21abe24 100644 --- a/dictation_server/src/features/templates/templates.service.spec.ts +++ b/dictation_server/src/features/templates/templates.service.spec.ts @@ -35,7 +35,11 @@ describe('getTemplates', () => { const service = module.get(TemplatesService); // 第五階層のアカウント作成 const { account, admin } = await makeTestAccount(source, { tier: 5 }); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const template1 = await createTemplateFile( source, @@ -76,7 +80,11 @@ describe('getTemplates', () => { const service = module.get(TemplatesService); // 第五階層のアカウント作成 const { admin } = await makeTestAccount(source, { tier: 5 }); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); const templates = await service.getTemplates(context, admin.external_id); @@ -94,7 +102,11 @@ describe('getTemplates', () => { const service = module.get(TemplatesService); // 第五階層のアカウント作成 const { admin } = await makeTestAccount(source, { tier: 5 }); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //DBアクセスに失敗するようにする const typistGroupService = module.get( diff --git a/dictation_server/src/features/terms/terms.controller.ts b/dictation_server/src/features/terms/terms.controller.ts index 459ce27..6c9e8ac 100644 --- a/dictation_server/src/features/terms/terms.controller.ts +++ b/dictation_server/src/features/terms/terms.controller.ts @@ -1,14 +1,24 @@ -import { Controller, HttpStatus, Get } from '@nestjs/common'; +import { + Controller, + HttpStatus, + Get, + Logger, + HttpException, + Req, +} from '@nestjs/common'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; import { TermsService } from '../terms/terms.service'; import { ErrorResponse } from '../../common/error/types/types'; -import { makeContext } from '../../common/log'; +import { makeContext, retrieveRequestId, retrieveIp } from '../../common/log'; import { GetTermsInfoResponse } from './types/types'; -import { v4 as uuidv4 } from 'uuid'; +import { makeErrorResponse } from '../../common/error/makeErrorResponse'; + +import { Request } from 'express'; @ApiTags('terms') @Controller('terms') export class TermsController { + private readonly logger = new Logger(TermsController.name); constructor( private readonly termsService: TermsService, //private readonly cryptoService: CryptoService, ) {} @@ -25,8 +35,24 @@ export class TermsController { type: ErrorResponse, }) @ApiOperation({ operationId: 'getTermsInfo' }) - async getTermsInfo(): Promise { - const context = makeContext(uuidv4()); + async getTermsInfo(@Req() req: Request): Promise { + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const context = makeContext('anonymous', ip, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const termsInfo = await this.termsService.getTermsInfo(context); diff --git a/dictation_server/src/features/terms/terms.service.spec.ts b/dictation_server/src/features/terms/terms.service.spec.ts index 6ff1176..a41af4b 100644 --- a/dictation_server/src/features/terms/terms.service.spec.ts +++ b/dictation_server/src/features/terms/terms.service.spec.ts @@ -39,7 +39,7 @@ describe('利用規約取得', () => { await createTermInfo(source, 'DPA', 'v1.0'); await createTermInfo(source, 'DPA', 'v1.2'); - const context = makeContext(uuidv4()); + const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); const result = await service.getTermsInfo(context); expect(result[0].documentType).toBe('EULA'); @@ -55,7 +55,7 @@ describe('利用規約取得', () => { const module = await makeTestingModule(source); if (!module) fail(); const service = module.get(TermsService); - const context = makeContext(uuidv4()); + const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); await expect(service.getTermsInfo(context)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -70,7 +70,7 @@ describe('利用規約取得', () => { if (!module) fail(); const service = module.get(TermsService); await createTermInfo(source, 'DPA', 'v1.0'); - const context = makeContext(uuidv4()); + const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); await expect(service.getTermsInfo(context)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -85,7 +85,7 @@ describe('利用規約取得', () => { if (!module) fail(); const service = module.get(TermsService); await createTermInfo(source, 'PrivacyNotice', 'v1.0'); - const context = makeContext(uuidv4()); + const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); await expect(service.getTermsInfo(context)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -100,7 +100,7 @@ describe('利用規約取得', () => { if (!module) fail(); const service = module.get(TermsService); await createTermInfo(source, 'EULA', 'v1.0'); - const context = makeContext(uuidv4()); + const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); await expect(service.getTermsInfo(context)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), diff --git a/dictation_server/src/features/users/users.controller.ts b/dictation_server/src/features/users/users.controller.ts index c8cdafc..3efa943 100644 --- a/dictation_server/src/features/users/users.controller.ts +++ b/dictation_server/src/features/users/users.controller.ts @@ -5,6 +5,7 @@ import { HttpException, HttpStatus, Ip, + Logger, Post, Query, Req, @@ -52,13 +53,13 @@ import { } from '../../common/types/sort'; import { ADMIN_ROLES, TIERS } from '../../constants'; import { RoleGuard } from '../../common/guards/role/roleguards'; -import { makeContext } from '../../common/log'; +import { makeContext, retrieveRequestId, retrieveIp } from '../../common/log'; import { UserRoles } from '../../common/types/role'; -import { v4 as uuidv4 } from 'uuid'; @ApiTags('users') @Controller('users') export class UsersController { + private readonly logger = new Logger(UsersController.name); constructor( private readonly usersService: UsersService, private readonly authService: AuthService, @@ -81,8 +82,27 @@ export class UsersController { }) @ApiOperation({ operationId: 'confirmUser' }) @Post('confirm') - async confirmUser(@Body() body: ConfirmRequest): Promise { - const context = makeContext(uuidv4()); + async confirmUser( + @Body() body: ConfirmRequest, + @Req() req: Request, + ): Promise { + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const context = makeContext('anonymous', ip, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.usersService.confirmUser(context, body.token); return {}; @@ -107,8 +127,25 @@ export class UsersController { @Post('confirm/initpassword') async confirmUserAndInitPassword( @Body() body: ConfirmRequest, + @Req() req: Request, ): Promise { - const context = makeContext(uuidv4()); + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const context = makeContext('anonymous', ip, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.usersService.confirmUserAndInitPassword(context, body.token); return {}; } @@ -137,13 +174,29 @@ export class UsersController { @Get() async getUsers(@Req() req: Request): Promise { const accessToken = retrieveAuthorizationToken(req); - if (!accessToken) { throw new HttpException( makeErrorResponse('E000107'), HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -152,7 +205,8 @@ export class UsersController { ); } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const users = await this.usersService.getUsers(context, userId); return { users }; @@ -209,6 +263,23 @@ export class UsersController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -218,7 +289,8 @@ export class UsersController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); //ユーザ作成処理 await this.usersService.createUser( @@ -268,6 +340,23 @@ export class UsersController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -277,7 +366,8 @@ export class UsersController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); return await this.usersService.getRelations(context, userId); } @@ -322,6 +412,23 @@ export class UsersController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -330,7 +437,8 @@ export class UsersController { ); } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); //型チェック if ( @@ -386,6 +494,23 @@ export class UsersController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -394,7 +519,8 @@ export class UsersController { ); } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const { direction, paramName } = await this.usersService.getSortCriteria( context, @@ -456,6 +582,23 @@ export class UsersController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -465,7 +608,8 @@ export class UsersController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.usersService.updateUser( context, @@ -528,6 +672,23 @@ export class UsersController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -537,7 +698,8 @@ export class UsersController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.usersService.allocateLicense( context, body.userId, @@ -591,6 +753,23 @@ export class UsersController { HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -600,7 +779,8 @@ export class UsersController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.usersService.deallocateLicense(context, body.userId); return {}; @@ -628,6 +808,7 @@ export class UsersController { @Post('/accepted-version') async updateAcceptedVersion( @Body() body: UpdateAcceptedVersionRequest, + @Req() req: Request, ): Promise { const { idToken, @@ -636,7 +817,23 @@ export class UsersController { acceptedDPAVersion, } = body; - const context = makeContext(uuidv4()); + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const context = makeContext('anonymous', ip, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const verifiedIdToken = await this.authService.getVerifiedIdToken( context, @@ -685,13 +882,30 @@ export class UsersController { @UseGuards(AuthGuard) @Get('me') async getMyUser(@Req() req: Request): Promise { - const accessToken = retrieveAuthorizationToken(req) as string; + const accessToken = retrieveAuthorizationToken(req); if (!accessToken) { throw new HttpException( makeErrorResponse('E000107'), HttpStatus.UNAUTHORIZED, ); } + + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -700,7 +914,8 @@ export class UsersController { ); } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const userName = await this.usersService.getUserName(context, userId); return { userName }; } diff --git a/dictation_server/src/features/users/users.service.spec.ts b/dictation_server/src/features/users/users.service.spec.ts index cea6f31..e7bf8af 100644 --- a/dictation_server/src/features/users/users.service.spec.ts +++ b/dictation_server/src/features/users/users.service.spec.ts @@ -97,7 +97,7 @@ describe('UsersService.confirmUser', () => { // account id:1, user id: 2のトークン const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjEsInVzZXJJZCI6MiwiZW1haWwiOiJ4eHhAeHh4Lnh4eCIsImlhdCI6MTAwMDAwMDAwMCwiZXhwIjo5MDAwMDAwMDAwfQ.26L6BdNg-3TbyKT62PswlJ6RPMkcTtHzlDXW2Uo9XbMPVSrl2ObcuS6EcXjFFN2DEfNTKbqX_zevIWMpHOAdLNgGhk528nLrBrNvPASqtTjvW9muxMXpjUdjRVkmVbOylBHWW3YpWL9JEbJQ7rAzWDfaIdPhMovdaxumnZt_UwnlnrdaVPLACW7tkH_laEcAU507iSiM4mqxxG8FuTs34t6PEdwRuzZAQPN2IOPYNSvGNdJYryPacSeSNZ_z1xeBYXLOLQfOBZzyTReYDOhXdikhrNUbxjgnZQlSXBCVMlZ9PH42bHfp-LJIeJzW0yqnF6oLklvJP-fo8eW0k5iDOw'; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await service.confirmUser(context, token); //result const resultUser = await getUser(source, userId); @@ -141,7 +141,7 @@ describe('UsersService.confirmUser', () => { if (!module) fail(); const token = 'invalid.id.token'; const service = module.get(UsersService); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect(service.confirmUser(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E000101'), HttpStatus.BAD_REQUEST), ); @@ -177,7 +177,7 @@ describe('UsersService.confirmUser', () => { const service = module.get(UsersService); const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjEsInVzZXJJZCI6MiwiZW1haWwiOiJ4eHhAeHh4Lnh4eCIsImlhdCI6MTAwMDAwMDAwMCwiZXhwIjo5MDAwMDAwMDAwfQ.26L6BdNg-3TbyKT62PswlJ6RPMkcTtHzlDXW2Uo9XbMPVSrl2ObcuS6EcXjFFN2DEfNTKbqX_zevIWMpHOAdLNgGhk528nLrBrNvPASqtTjvW9muxMXpjUdjRVkmVbOylBHWW3YpWL9JEbJQ7rAzWDfaIdPhMovdaxumnZt_UwnlnrdaVPLACW7tkH_laEcAU507iSiM4mqxxG8FuTs34t6PEdwRuzZAQPN2IOPYNSvGNdJYryPacSeSNZ_z1xeBYXLOLQfOBZzyTReYDOhXdikhrNUbxjgnZQlSXBCVMlZ9PH42bHfp-LJIeJzW0yqnF6oLklvJP-fo8eW0k5iDOw'; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect(service.confirmUser(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E010202'), HttpStatus.BAD_REQUEST), ); @@ -189,7 +189,7 @@ describe('UsersService.confirmUser', () => { const service = module.get(UsersService); const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjEsInVzZXJJZCI6MiwiZW1haWwiOiJ4eHhAeHh4Lnh4eCIsImlhdCI6MTAwMDAwMDAwMCwiZXhwIjo5MDAwMDAwMDAwfQ.26L6BdNg-3TbyKT62PswlJ6RPMkcTtHzlDXW2Uo9XbMPVSrl2ObcuS6EcXjFFN2DEfNTKbqX_zevIWMpHOAdLNgGhk528nLrBrNvPASqtTjvW9muxMXpjUdjRVkmVbOylBHWW3YpWL9JEbJQ7rAzWDfaIdPhMovdaxumnZt_UwnlnrdaVPLACW7tkH_laEcAU507iSiM4mqxxG8FuTs34t6PEdwRuzZAQPN2IOPYNSvGNdJYryPacSeSNZ_z1xeBYXLOLQfOBZzyTReYDOhXdikhrNUbxjgnZQlSXBCVMlZ9PH42bHfp-LJIeJzW0yqnF6oLklvJP-fo8eW0k5iDOw'; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect(service.confirmUser(context, token)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -246,7 +246,7 @@ describe('UsersService.confirmUserAndInitPassword', () => { 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjEsInVzZXJJZCI6MiwiZW1haWwiOiJ4eHhAeHh4Lnh4eCIsImlhdCI6MTAwMDAwMDAwMCwiZXhwIjo5MDAwMDAwMDAwfQ.26L6BdNg-3TbyKT62PswlJ6RPMkcTtHzlDXW2Uo9XbMPVSrl2ObcuS6EcXjFFN2DEfNTKbqX_zevIWMpHOAdLNgGhk528nLrBrNvPASqtTjvW9muxMXpjUdjRVkmVbOylBHWW3YpWL9JEbJQ7rAzWDfaIdPhMovdaxumnZt_UwnlnrdaVPLACW7tkH_laEcAU507iSiM4mqxxG8FuTs34t6PEdwRuzZAQPN2IOPYNSvGNdJYryPacSeSNZ_z1xeBYXLOLQfOBZzyTReYDOhXdikhrNUbxjgnZQlSXBCVMlZ9PH42bHfp-LJIeJzW0yqnF6oLklvJP-fo8eW0k5iDOw'; expect( await service.confirmUserAndInitPassword( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), token, ), ).toEqual(undefined); @@ -295,7 +295,10 @@ describe('UsersService.confirmUserAndInitPassword', () => { ); const token = 'invalid.id.token'; await expect( - service.confirmUserAndInitPassword(makeContext('trackingId'), token), + service.confirmUserAndInitPassword( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + token, + ), ).rejects.toEqual( new HttpException(makeErrorResponse('E000101'), HttpStatus.BAD_REQUEST), ); @@ -348,7 +351,10 @@ describe('UsersService.confirmUserAndInitPassword', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjEsInVzZXJJZCI6MiwiZW1haWwiOiJ4eHhAeHh4Lnh4eCIsImlhdCI6MTAwMDAwMDAwMCwiZXhwIjo5MDAwMDAwMDAwfQ.26L6BdNg-3TbyKT62PswlJ6RPMkcTtHzlDXW2Uo9XbMPVSrl2ObcuS6EcXjFFN2DEfNTKbqX_zevIWMpHOAdLNgGhk528nLrBrNvPASqtTjvW9muxMXpjUdjRVkmVbOylBHWW3YpWL9JEbJQ7rAzWDfaIdPhMovdaxumnZt_UwnlnrdaVPLACW7tkH_laEcAU507iSiM4mqxxG8FuTs34t6PEdwRuzZAQPN2IOPYNSvGNdJYryPacSeSNZ_z1xeBYXLOLQfOBZzyTReYDOhXdikhrNUbxjgnZQlSXBCVMlZ9PH42bHfp-LJIeJzW0yqnF6oLklvJP-fo8eW0k5iDOw'; await expect( - service.confirmUserAndInitPassword(makeContext('trackingId'), token), + service.confirmUserAndInitPassword( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + token, + ), ).rejects.toEqual( new HttpException(makeErrorResponse('E010202'), HttpStatus.BAD_REQUEST), ); @@ -398,7 +404,10 @@ describe('UsersService.confirmUserAndInitPassword', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjEsInVzZXJJZCI6MiwiZW1haWwiOiJ4eHhAeHh4Lnh4eCIsImlhdCI6MTAwMDAwMDAwMCwiZXhwIjo5MDAwMDAwMDAwfQ.26L6BdNg-3TbyKT62PswlJ6RPMkcTtHzlDXW2Uo9XbMPVSrl2ObcuS6EcXjFFN2DEfNTKbqX_zevIWMpHOAdLNgGhk528nLrBrNvPASqtTjvW9muxMXpjUdjRVkmVbOylBHWW3YpWL9JEbJQ7rAzWDfaIdPhMovdaxumnZt_UwnlnrdaVPLACW7tkH_laEcAU507iSiM4mqxxG8FuTs34t6PEdwRuzZAQPN2IOPYNSvGNdJYryPacSeSNZ_z1xeBYXLOLQfOBZzyTReYDOhXdikhrNUbxjgnZQlSXBCVMlZ9PH42bHfp-LJIeJzW0yqnF6oLklvJP-fo8eW0k5iDOw'; await expect( - service.confirmUserAndInitPassword(makeContext('trackingId'), token), + service.confirmUserAndInitPassword( + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + token, + ), ).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -482,7 +491,7 @@ describe('UsersService.createUser', () => { expect( await service.createUser( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), adminExternalId, name, role, @@ -570,7 +579,7 @@ describe('UsersService.createUser', () => { expect( await service.createUser( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), adminExternalId, name, role, @@ -661,7 +670,7 @@ describe('UsersService.createUser', () => { expect( await service.createUser( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), adminExternalId, name, role, @@ -749,7 +758,7 @@ describe('UsersService.createUser', () => { expect( await service.createUser( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), adminExternalId, name, role, @@ -842,7 +851,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), adminExternalId, name, role, @@ -862,7 +871,7 @@ describe('UsersService.createUser', () => { // ADB2Cに作成したユーザーを削除するメソッドが呼ばれていることを確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), ); }); @@ -929,7 +938,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), adminExternalId, name, role, @@ -954,7 +963,7 @@ describe('UsersService.createUser', () => { // ADB2Cに作成したユーザーを削除するメソッドが呼ばれていることを確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), ); }); @@ -1010,7 +1019,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), adminExternalId, name, role, @@ -1089,7 +1098,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), adminExternalId, name, role, @@ -1170,7 +1179,7 @@ describe('UsersService.createUser', () => { expect( await service.createUser( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), adminExternalId, name, role, @@ -1211,7 +1220,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), adminExternalId, name, role, @@ -1307,7 +1316,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), adminExternalId, name, role, @@ -1335,7 +1344,7 @@ describe('UsersService.createUser', () => { // ADB2Cに作成したユーザーを削除するメソッドが呼ばれていることを確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), ); }); @@ -1396,7 +1405,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), adminExternalId, name, role, @@ -1422,7 +1431,7 @@ describe('UsersService.createUser', () => { // ADB2Cに作成したユーザーを削除するメソッドが呼ばれていることを確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), ); }); @@ -1488,7 +1497,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), adminExternalId, name, role, @@ -1512,7 +1521,7 @@ describe('UsersService.createUser', () => { // ADB2Cに作成したユーザーを削除するメソッドが呼ばれていることを確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('trackingId'), + makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), ); }); }); @@ -1635,7 +1644,7 @@ describe('UsersService.getUsers', () => { }, ]; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); expect(await service.getUsers(context, externalId_author)).toEqual( expectedUsers, ); @@ -1754,7 +1763,7 @@ describe('UsersService.getUsers', () => { }, ]; - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); expect(await service.getUsers(context, external_id1)).toEqual( expectedUsers, ); @@ -1778,7 +1787,7 @@ describe('UsersService.getUsers', () => { prompt: false, }); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); const service = module.get(UsersService); await expect( service.getUsers(context, 'externalId_failed'), @@ -1806,7 +1815,7 @@ describe('UsersService.getUsers', () => { prompt: false, }); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); const service = module.get(UsersService); await expect(service.getUsers(context, externalId_author)).rejects.toEqual( new HttpException(makeErrorResponse('E009999'), HttpStatus.NOT_FOUND), @@ -1831,7 +1840,7 @@ describe('UsersService.updateSortCriteria', () => { configMockValue, sortCriteriaRepositoryMockValue, ); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); expect( await service.updateSortCriteria( @@ -1862,7 +1871,7 @@ describe('UsersService.updateSortCriteria', () => { configMockValue, sortCriteriaRepositoryMockValue, ); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect( service.updateSortCriteria(context, 'AUTHOR_ID', 'ASC', 'external_id'), @@ -1894,7 +1903,7 @@ describe('UsersService.updateSortCriteria', () => { configMockValue, sortCriteriaRepositoryMockValue, ); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect( service.updateSortCriteria(context, 'AUTHOR_ID', 'ASC', 'external_id'), @@ -1924,7 +1933,7 @@ describe('UsersService.getSortCriteria', () => { configMockValue, sortCriteriaRepositoryMockValue, ); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); expect(await service.getSortCriteria(context, 'external_id')).toEqual({ direction: 'ASC', @@ -1953,7 +1962,7 @@ describe('UsersService.getSortCriteria', () => { configMockValue, sortCriteriaRepositoryMockValue, ); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect( service.getSortCriteria(context, 'external_id'), @@ -1988,7 +1997,7 @@ describe('UsersService.getSortCriteria', () => { configMockValue, sortCriteriaRepositoryMockValue, ); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect( service.getSortCriteria(context, 'external_id'), @@ -2048,7 +2057,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); expect( await service.updateUser( @@ -2107,7 +2116,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); expect( await service.updateUser( @@ -2166,7 +2175,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); expect( await service.updateUser( @@ -2225,7 +2234,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); expect( await service.updateUser( @@ -2284,7 +2293,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); expect( await service.updateUser( @@ -2343,7 +2352,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect( service.updateUser( @@ -2392,7 +2401,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); expect( await service.updateUser( @@ -2451,7 +2460,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); expect( await service.updateUser( @@ -2510,7 +2519,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect( service.updateUser( @@ -2570,7 +2579,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`); + const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); await expect( service.updateUser( @@ -2618,7 +2627,7 @@ describe('UsersService.updateAcceptedVersion', () => { const { admin } = await makeTestAccount(source, { tier: 5, }); - const context = makeContext(uuidv4()); + const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); const service = module.get(UsersService); await service.updateAcceptedVersion( @@ -2639,7 +2648,7 @@ describe('UsersService.updateAcceptedVersion', () => { const { admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(uuidv4()); + const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); const service = module.get(UsersService); await service.updateAcceptedVersion( @@ -2662,7 +2671,7 @@ describe('UsersService.updateAcceptedVersion', () => { const { admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(uuidv4()); + const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); const service = module.get(UsersService); await expect( @@ -2705,7 +2714,7 @@ describe('UsersService.getUserName', () => { try { const module = await makeTestingModule(source); if (!module) fail(); - const context = makeContext(uuidv4()); + const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); const service = module.get(UsersService); await service.getUserName(context, 'external_id'); @@ -2800,7 +2809,7 @@ describe('UsersService.getRelations', () => { expect(workflows[3].author_id).toBe(user2); } - const context = makeContext(external_id); + const context = makeContext(external_id, 'xxx.xxx.xxx.xxx', 'requestId'); const service = module.get(UsersService); const relations = await service.getRelations(context, external_id); @@ -2863,7 +2872,7 @@ describe('UsersService.getRelations', () => { expect(workflows[0].author_id).toBe(user2); } - const context = makeContext(external_id); + const context = makeContext(external_id, 'xxx.xxx.xxx.xxx', 'requestId'); const service = module.get(UsersService); const relations = await service.getRelations(context, external_id); @@ -2889,7 +2898,7 @@ describe('UsersService.getRelations', () => { try { const module = await makeTestingModule(source); if (!module) fail(); - const context = makeContext(uuidv4()); + const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); const service = module.get(UsersService); await service.getRelations(context, 'external_id'); diff --git a/dictation_server/src/features/users/users.service.ts b/dictation_server/src/features/users/users.service.ts index e26a1c1..542e8d3 100644 --- a/dictation_server/src/features/users/users.service.ts +++ b/dictation_server/src/features/users/users.service.ts @@ -545,12 +545,7 @@ export class UsersService { // DBから取得したユーザーの外部IDをもとにADB2Cからユーザーを取得する const externalIds = dbUsers.map((x) => x.external_id); - const trackingId = new Context(context.trackingId); - const adb2cUsers = await this.adB2cService.getUsers( - // TODO: 外部連携以外のログ強化時に、ContollerからContextを取得するように修正する - trackingId, - externalIds, - ); + const adb2cUsers = await this.adB2cService.getUsers(context, externalIds); // DBから取得した各ユーザーをもとにADB2C情報をマージしライセンス情報を算出 const users = dbUsers.map((dbUser): User => { diff --git a/dictation_server/src/features/workflows/workflows.controller.ts b/dictation_server/src/features/workflows/workflows.controller.ts index ff312e1..4470f89 100644 --- a/dictation_server/src/features/workflows/workflows.controller.ts +++ b/dictation_server/src/features/workflows/workflows.controller.ts @@ -4,6 +4,7 @@ import { Get, HttpException, HttpStatus, + Logger, Param, Post, Req, @@ -33,13 +34,14 @@ import { RoleGuard } from '../../common/guards/role/roleguards'; import { ADMIN_ROLES } from '../../constants'; import { retrieveAuthorizationToken } from '../../common/http/helper'; import { Request } from 'express'; -import { makeContext } from '../../common/log'; +import { makeContext, retrieveRequestId, retrieveIp } from '../../common/log'; import { WorkflowsService } from './workflows.service'; import { makeErrorResponse } from '../../common/error/makeErrorResponse'; @ApiTags('workflows') @Controller('workflows') export class WorkflowsController { + private readonly logger = new Logger(WorkflowsController.name); constructor(private readonly workflowsService: WorkflowsService) {} @ApiResponse({ @@ -75,6 +77,21 @@ export class WorkflowsController { HttpStatus.UNAUTHORIZED, ); } + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -84,7 +101,8 @@ export class WorkflowsController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const workflows = await this.workflowsService.getWorkflows(context, userId); @@ -134,6 +152,21 @@ export class WorkflowsController { HttpStatus.UNAUTHORIZED, ); } + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -143,7 +176,8 @@ export class WorkflowsController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.workflowsService.createWorkflow( context, userId, @@ -201,6 +235,21 @@ export class WorkflowsController { HttpStatus.UNAUTHORIZED, ); } + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -210,7 +259,8 @@ export class WorkflowsController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.workflowsService.updateWorkflow( context, userId, @@ -267,6 +317,21 @@ export class WorkflowsController { HttpStatus.UNAUTHORIZED, ); } + const ip = retrieveIp(req); + if (!ip) { + throw new HttpException( + makeErrorResponse('E000401'), + HttpStatus.UNAUTHORIZED, + ); + } + + const requestId = retrieveRequestId(req); + if (!requestId) { + throw new HttpException( + makeErrorResponse('E000501'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } const decodedAccessToken = jwt.decode(accessToken, { json: true }); if (!decodedAccessToken) { throw new HttpException( @@ -276,7 +341,8 @@ export class WorkflowsController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext(userId); + const context = makeContext(userId, requestId); + this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.workflowsService.deleteWorkflow(context, userId, workflowId); return {}; } diff --git a/dictation_server/src/features/workflows/workflows.service.spec.ts b/dictation_server/src/features/workflows/workflows.service.spec.ts index e868605..208b1f7 100644 --- a/dictation_server/src/features/workflows/workflows.service.spec.ts +++ b/dictation_server/src/features/workflows/workflows.service.spec.ts @@ -118,7 +118,11 @@ describe('getWorkflows', () => { await createWorkflowTypist(source, workflow3.id, undefined, userGroupId); const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //作成したデータを確認 { @@ -190,7 +194,11 @@ describe('getWorkflows', () => { const { admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); overrideAdB2cService(service, { getUsers: async () => [], @@ -212,7 +220,11 @@ describe('getWorkflows', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //DBアクセスに失敗するようにする const templatesService = module.get( @@ -292,7 +304,11 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await service.createWorkflow( context, @@ -357,7 +373,11 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await service.createWorkflow( context, @@ -421,7 +441,11 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await service.createWorkflow( context, @@ -479,7 +503,11 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await service.createWorkflow( context, @@ -543,7 +571,11 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); // 同一AuthorIDのワークフローを作成 await service.createWorkflow( @@ -616,7 +648,11 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //実行結果を確認 try { await service.createWorkflow( @@ -673,7 +709,11 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //実行結果を確認 try { @@ -734,7 +774,11 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //実行結果を確認 try { @@ -794,7 +838,11 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //実行結果を確認 try { @@ -856,7 +904,11 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //実行結果を確認 try { @@ -924,7 +976,11 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //実行結果を確認 try { @@ -986,7 +1042,11 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //実行結果を確認 try { @@ -1057,7 +1117,11 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //実行結果を確認 try { @@ -1124,7 +1188,11 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //DBアクセスに失敗するようにする const templatesService = module.get( @@ -1243,7 +1311,11 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await service.updateWorkflow( context, @@ -1333,7 +1405,11 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await service.updateWorkflow( context, @@ -1422,7 +1498,11 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await service.updateWorkflow( context, @@ -1505,7 +1585,11 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await service.updateWorkflow( context, @@ -1608,7 +1692,11 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await service.updateWorkflow( context, @@ -1687,7 +1775,11 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //実行結果を確認 try { @@ -1730,7 +1822,11 @@ describe('updateWorkflow', () => { }); const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //実行結果を確認 try { @@ -1804,7 +1900,11 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //実行結果を確認 try { @@ -1873,7 +1973,11 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //実行結果を確認 try { @@ -1941,7 +2045,11 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //実行結果を確認 try { @@ -2016,7 +2124,11 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //実行結果を確認 try { @@ -2097,7 +2209,11 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //実行結果を確認 try { @@ -2172,7 +2288,11 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //実行結果を確認 try { @@ -2241,7 +2361,11 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //実行結果を確認 try { @@ -2310,7 +2434,11 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //DBアクセスに失敗するようにする const workflowsRepositoryService = module.get( @@ -2401,7 +2529,11 @@ describe('deleteWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await service.deleteWorkflow(context, admin.external_id, workflow.id); @@ -2452,7 +2584,11 @@ describe('deleteWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); await service.deleteWorkflow(context, admin.external_id, workflow1.id); @@ -2503,7 +2639,11 @@ describe('deleteWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //実行結果を確認 try { @@ -2578,7 +2718,11 @@ describe('deleteWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //実行結果を確認 try { @@ -2633,7 +2777,11 @@ describe('deleteWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext(admin.external_id); + const context = makeContext( + admin.external_id, + 'xxx.xxx.xxx.xxx', + 'requestId', + ); //DBアクセスに失敗するようにする const workflowsRepositoryService = module.get( From bce9866ba3fd181aeeda168d056ef6f4a6c4ecf4 Mon Sep 17 00:00:00 2001 From: "makabe.t" Date: Tue, 12 Dec 2023 05:56:05 +0000 Subject: [PATCH 07/51] =?UTF-8?q?Merged=20PR=20612:=20/files/template/down?= =?UTF-8?q?load-location=E3=81=AE=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3278: /files/template/download-locationの対応](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3278) - クエリパラメータが不正な場合にバリデータで処理されるようにしました。 ## レビューポイント - 適用したバリデータは適切でしょうか? ## UIの変更 - なし ## 動作確認状況 - ローカルで確認 --- dictation_server/src/features/files/types/types.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dictation_server/src/features/files/types/types.ts b/dictation_server/src/features/files/types/types.ts index 2de8a4a..2fda838 100644 --- a/dictation_server/src/features/files/types/types.ts +++ b/dictation_server/src/features/files/types/types.ts @@ -1,4 +1,6 @@ import { ApiProperty } from '@nestjs/swagger'; +import { Type } from 'class-transformer'; +import { IsInt, Min } from 'class-validator'; export class AudioUploadLocationRequest {} @@ -23,6 +25,9 @@ export class AudioDownloadLocationResponse { export class TemplateDownloadLocationRequest { @ApiProperty({ description: '文字起こし対象の音声ファイルID' }) + @Type(() => Number) + @Min(0) + @IsInt() audioFileId: number; } From 5ef222134e711989a37d8657f319c4244a609a59 Mon Sep 17 00:00:00 2001 From: "saito.k" Date: Tue, 12 Dec 2023 15:46:37 +0900 Subject: [PATCH 08/51] =?UTF-8?q?IP=E3=82=A2=E3=83=89=E3=83=AC=E3=82=B9?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=81=AB=E4=BC=B4=E3=81=86=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E6=BC=8F=E3=82=8C=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../accounts/accounts.service.spec.ts | 238 +++++++++--------- .../src/features/auth/auth.service.spec.ts | 46 ++-- .../src/features/files/files.service.spec.ts | 86 +++---- .../licenses/licenses.service.spec.ts | 54 ++-- .../notification/notification.service.spec.ts | 6 +- .../src/features/tasks/tasks.service.spec.ts | 136 +++++----- .../templates/templates.service.spec.ts | 6 +- .../src/features/terms/terms.service.spec.ts | 10 +- .../src/features/users/users.service.spec.ts | 106 ++++---- .../workflows/workflows.service.spec.ts | 74 +++--- 10 files changed, 381 insertions(+), 381 deletions(-) diff --git a/dictation_server/src/features/accounts/accounts.service.spec.ts b/dictation_server/src/features/accounts/accounts.service.spec.ts index 92479ec..3a50603 100644 --- a/dictation_server/src/features/accounts/accounts.service.spec.ts +++ b/dictation_server/src/features/accounts/accounts.service.spec.ts @@ -136,7 +136,7 @@ describe('createAccount', () => { }); const { accountId, externalUserId, userId } = await service.createAccount( - makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), companyName, country, dealerAccountId, @@ -213,7 +213,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), companyName, country, dealerAccountId, @@ -285,7 +285,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), companyName, country, dealerAccountId, @@ -346,7 +346,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), companyName, country, dealerAccountId, @@ -377,7 +377,7 @@ describe('createAccount', () => { // ADB2Cユーザー削除メソッドが呼ばれているか確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), ); }); it('アカウントを作成がDBへの通信失敗によって500エラーが発生した場合、リカバリ処理が実行されるが、ADB2Cユーザー削除で失敗した場合、500エラーが返却される', async () => { @@ -414,7 +414,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), companyName, country, dealerAccountId, @@ -445,7 +445,7 @@ describe('createAccount', () => { // ADB2Cユーザー削除メソッドが呼ばれているか確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), ); }); @@ -485,7 +485,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), companyName, country, dealerAccountId, @@ -516,7 +516,7 @@ describe('createAccount', () => { // ADB2Cユーザー削除メソッドが呼ばれているか確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), ); }); @@ -558,7 +558,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), companyName, country, dealerAccountId, @@ -589,7 +589,7 @@ describe('createAccount', () => { // ADB2Cユーザー削除メソッドが呼ばれているか確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), ); }); @@ -650,7 +650,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), companyName, country, dealerAccountId, @@ -681,11 +681,11 @@ describe('createAccount', () => { // ADB2Cユーザー削除メソッドが呼ばれているか確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), ); // Blobストレージのコンテナ削除メソッドが呼ばれているか確認 expect(blobstorageService.deleteContainer).toBeCalledWith( - makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), 1, //新規作成したアカウントのID country, ); @@ -745,7 +745,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), companyName, country, dealerAccountId, @@ -776,11 +776,11 @@ describe('createAccount', () => { // ADB2Cユーザー削除メソッドが呼ばれているか確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), ); // Blobストレージのコンテナ削除メソッドが呼ばれているか確認 expect(blobstorageService.deleteContainer).toBeCalledWith( - makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), 1, //新規作成したアカウントのID country, ); @@ -820,7 +820,7 @@ describe('createPartnerAccount', () => { { external_id: adminExternalId }, ); - const context = makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'); const companyName = 'test_company_name'; const country = 'US'; const email = 'partner@example.com'; @@ -897,7 +897,7 @@ describe('createPartnerAccount', () => { { external_id: adminExternalId }, ); - const context = makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'); const companyName = 'test_company_name'; const country = 'US'; const email = 'partner@example.com'; @@ -975,7 +975,7 @@ describe('createPartnerAccount', () => { { external_id: adminExternalId }, ); - const context = makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'); const companyName = 'test_company_name'; const country = 'US'; const email = 'partner@example.com'; @@ -1064,7 +1064,7 @@ describe('createPartnerAccount', () => { { external_id: adminExternalId }, ); - const context = makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'); const companyName = 'test_company_name'; const country = 'US'; const email = 'partner@example.com'; @@ -1156,7 +1156,7 @@ describe('createPartnerAccount', () => { const context = makeContext( parentExternalId, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); const partnerExternalId = 'partner_external_id'; @@ -1242,7 +1242,7 @@ describe('createPartnerAccount', () => { const context = makeContext( parentExternalId, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); const partnerExternalId = 'partner_external_id'; @@ -1338,7 +1338,7 @@ describe('createPartnerAccount', () => { const context = makeContext( parentExternalId, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); const partnerExternalId = 'partner_external_id'; @@ -1434,7 +1434,7 @@ describe('createPartnerAccount', () => { const context = makeContext( parentExternalId, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); const partnerExternalId = 'partner_external_id'; @@ -1531,7 +1531,7 @@ describe('createPartnerAccount', () => { { external_id: adminExternalId }, ); - const context = makeContext('uuid', 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'); const companyName = 'test_company_name'; const country = 'US'; const email = 'partner@example.com'; @@ -1624,7 +1624,7 @@ describe('AccountsService', () => { licensesRepositoryMockValue, worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); expect(await service.getLicenseSummary(context, accountId)).toEqual( expectedAccountLisenceCounts, ); @@ -1657,7 +1657,7 @@ describe('AccountsService', () => { licensesRepositoryMockValue, worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect(service.getLicenseSummary(context, accountId)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -1692,7 +1692,7 @@ describe('AccountsService', () => { licensesRepositoryMockValue, worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); expect(await service.getTypists(context, externalId)).toEqual([ { id: 1, name: 'Typist1' }, { id: 2, name: 'Typist2' }, @@ -1726,7 +1726,7 @@ describe('AccountsService', () => { licensesRepositoryMockValue, worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect(service.getTypists(context, externalId)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -1761,7 +1761,7 @@ describe('AccountsService', () => { licensesRepositoryMockValue, worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect(service.getTypists(context, externalId)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -1797,7 +1797,7 @@ describe('AccountsService', () => { worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); expect(await service.getTypistGroups(context, externalId)).toEqual([ { id: 1, name: 'GroupA' }, { id: 2, name: 'GroupB' }, @@ -1831,7 +1831,7 @@ describe('AccountsService', () => { worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect(service.getTypistGroups(context, externalId)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -1867,7 +1867,7 @@ describe('AccountsService', () => { worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect(service.getTypistGroups(context, externalId)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -2050,7 +2050,7 @@ describe('getPartnerAccount', () => { const offset = 0; const limit = 20; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); const response = await service.getPartnerLicenses( context, limit, @@ -2197,7 +2197,7 @@ describe('getPartnerAccount', () => { const offset = 0; const limit = 20; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); const response = await service.getPartnerLicenses( context, limit, @@ -2296,7 +2296,7 @@ describe('getOrderHistories', () => { const offset = 1; const limit = 2; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); const response = await service.getOrderHistories( context, limit, @@ -2341,7 +2341,7 @@ describe('getOrderHistories', () => { licensesRepositoryMockValue, worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect( service.getOrderHistories(context, limit, offset, accountId), ).rejects.toEqual( @@ -2449,7 +2449,7 @@ describe('issueLicense', () => { const context = makeContext( 'userId-parent', - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -2547,7 +2547,7 @@ describe('issueLicense', () => { const context = makeContext( 'userId-parent', - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -2650,7 +2650,7 @@ describe('issueLicense', () => { const context = makeContext( 'userId-parent', - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -2716,7 +2716,7 @@ describe('getDealers', () => { }) ).account; const service = module.get(AccountsService); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); expect(await service.getDealers(context)).toEqual({ dealers: [ @@ -2745,7 +2745,7 @@ describe('getDealers', () => { const service = module.get(AccountsService); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); expect(await service.getDealers(context)).toEqual({ dealers: [], }); @@ -2811,7 +2811,7 @@ describe('createTypistGroup', () => { const typistUserIds = userIds; const context = makeContext( adminExternalId, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); await service.createTypistGroup( @@ -2879,7 +2879,7 @@ describe('createTypistGroup', () => { const typistUserIds = userIds; const context = makeContext( adminExternalId, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); await expect( @@ -2934,7 +2934,7 @@ describe('createTypistGroup', () => { const typistUserIds = [...userIds, 9999]; //存在しないユーザーIDを追加 const context = makeContext( adminExternalId, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); await expect( @@ -2990,7 +2990,7 @@ describe('createTypistGroup', () => { const typistUserIds = [...userIds]; const context = makeContext( adminExternalId, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); await expect( @@ -3045,7 +3045,7 @@ describe('createTypistGroup', () => { const typistUserIds = userIds; const context = makeContext( adminExternalId, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); //DBアクセスに失敗するようにする @@ -3119,7 +3119,7 @@ describe('getTypistGroup', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -3183,7 +3183,7 @@ describe('getTypistGroup', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); await service.createTypistGroup( @@ -3242,7 +3242,7 @@ describe('getTypistGroup', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -3328,7 +3328,7 @@ describe('updateTypistGroup', () => { const typistUserIds = [userIds[1]]; const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); const typistGroupName = 'typist-group-name'; @@ -3404,7 +3404,7 @@ describe('updateTypistGroup', () => { const typistUserIds = [userIds[2]]; const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -3472,7 +3472,7 @@ describe('updateTypistGroup', () => { const typistUserIds = [999]; const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); await service.createTypistGroup( @@ -3539,7 +3539,7 @@ describe('updateTypistGroup', () => { const typistUserIds = [...userIds]; const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); await service.createTypistGroup( @@ -3606,7 +3606,7 @@ describe('updateTypistGroup', () => { const typistUserIds = [userIds[1]]; const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); await service.createTypistGroup( @@ -3673,7 +3673,7 @@ describe('updateTypistGroup', () => { const typistUserIds = [userIds[1]]; const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); await service.createTypistGroup( @@ -3753,7 +3753,7 @@ describe('getWorktypes', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -3798,7 +3798,7 @@ describe('getWorktypes', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -3820,7 +3820,7 @@ describe('getWorktypes', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -3885,7 +3885,7 @@ describe('createWorktype', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -3930,7 +3930,7 @@ describe('createWorktype', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); const worktypeId = 'worktype1'; @@ -3965,7 +3965,7 @@ describe('createWorktype', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -4002,7 +4002,7 @@ describe('createWorktype', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -4054,7 +4054,7 @@ describe('updateWorktype', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -4107,7 +4107,7 @@ describe('updateWorktype', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -4158,7 +4158,7 @@ describe('updateWorktype', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); const worktype1 = new Worktype(); @@ -4224,7 +4224,7 @@ describe('updateWorktype', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -4276,7 +4276,7 @@ describe('updateWorktype', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -4353,7 +4353,7 @@ describe('deleteWorktype', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -4405,7 +4405,7 @@ describe('deleteWorktype', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -4456,7 +4456,7 @@ describe('deleteWorktype', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -4504,7 +4504,7 @@ describe('deleteWorktype', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -4552,7 +4552,7 @@ describe('deleteWorktype', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -4621,7 +4621,7 @@ describe('getOptionItems', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -4668,7 +4668,7 @@ describe('getOptionItems', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -4707,7 +4707,7 @@ describe('getOptionItems', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -4772,7 +4772,7 @@ describe('updateOptionItems', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -4902,7 +4902,7 @@ describe('updateOptionItems', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -4992,7 +4992,7 @@ describe('updateOptionItems', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -5110,7 +5110,7 @@ describe('updateActiveWorktype', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -5141,7 +5141,7 @@ describe('updateActiveWorktype', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -5183,7 +5183,7 @@ describe('updateActiveWorktype', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -5220,7 +5220,7 @@ describe('updateActiveWorktype', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -5257,7 +5257,7 @@ describe('updateActiveWorktype', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -5300,7 +5300,7 @@ describe('updateActiveWorktype', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -5390,7 +5390,7 @@ describe('ライセンス発行キャンセル', () => { const service = module.get(AccountsService); await service.cancelIssue( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), tier1Accounts[0].users[0].external_id, poNumber, tier5Accounts.account.id, @@ -5453,7 +5453,7 @@ describe('ライセンス発行キャンセル', () => { const service = module.get(AccountsService); await service.cancelIssue( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), tier2Accounts[0].users[0].external_id, poNumber, tier5Accounts.account.id, @@ -5491,7 +5491,7 @@ describe('ライセンス発行キャンセル', () => { const service = module.get(AccountsService); await expect( service.cancelIssue( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), tier1Accounts[0].users[0].external_id, poNumber, tier5Accounts.account.id, @@ -5537,7 +5537,7 @@ describe('ライセンス発行キャンセル', () => { const service = module.get(AccountsService); await expect( service.cancelIssue( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), tier1Accounts[0].users[0].external_id, poNumber, tier5Accounts.account.id, @@ -5583,7 +5583,7 @@ describe('ライセンス発行キャンセル', () => { const service = module.get(AccountsService); await expect( service.cancelIssue( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), tier1Accounts[0].users[0].external_id, poNumber, tier5Accounts.account.id, @@ -5630,7 +5630,7 @@ describe('ライセンス発行キャンセル', () => { const service = module.get(AccountsService); await expect( service.cancelIssue( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), tier1Accounts[0].users[0].external_id, poNumber, tier5Accounts.account.id, @@ -5749,7 +5749,7 @@ describe('パートナー一覧取得', () => { }); const partners = await service.getPartners( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), tier1Accounts[0].users[0].external_id, 15, 0, @@ -5798,7 +5798,7 @@ describe('パートナー一覧取得', () => { }); const partners = await service.getPartners( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), account.admin.external_id, 15, 0, @@ -5840,7 +5840,7 @@ describe('アカウント情報更新', () => { tier: 5, }); await service.updateAccountInfo( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), tier5Accounts.admin.external_id, tier5Accounts.account.tier, true, @@ -5869,7 +5869,7 @@ describe('アカウント情報更新', () => { role: 'typist', }); await service.updateAccountInfo( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), tier4Accounts[0].users[0].external_id, tier4Accounts[0].account.tier, false, @@ -5899,7 +5899,7 @@ describe('アカウント情報更新', () => { role: 'typist', }); await service.updateAccountInfo( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), tier4Accounts[0].users[0].external_id, tier4Accounts[0].account.tier, false, @@ -5930,7 +5930,7 @@ describe('アカウント情報更新', () => { }); await expect( service.updateAccountInfo( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), tier4Accounts[0].users[0].external_id, tier4Accounts[0].account.tier, false, @@ -5956,7 +5956,7 @@ describe('アカウント情報更新', () => { }); await expect( service.updateAccountInfo( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), tier5Accounts.admin.external_id, tier5Accounts.account.tier, true, @@ -5982,7 +5982,7 @@ describe('アカウント情報更新', () => { }); await expect( service.updateAccountInfo( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), tier5Accounts.admin.external_id, tier5Accounts.account.tier, true, @@ -6029,7 +6029,7 @@ describe('getAccountInfo', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -6112,7 +6112,7 @@ describe('getAuthors', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); const authors = await service.getAuthors(context, admin.external_id); @@ -6156,7 +6156,7 @@ describe('getAuthors', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); const authors = await service.getAuthors(context, admin.external_id); @@ -6184,7 +6184,7 @@ describe('getAuthors', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); const authors = await service.getAuthors(context, admin.external_id); @@ -6204,7 +6204,7 @@ describe('getAuthors', () => { const service = module.get(AccountsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -6289,7 +6289,7 @@ describe('getTypists', () => { ], }); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); const typists = await service.getTypists(context, admin.external_id); //実行結果を確認 @@ -6317,7 +6317,7 @@ describe('getTypists', () => { overrideAdB2cService(service, { getUsers: async () => [{ id: admin.external_id, displayName: '' }], }); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); const typists = await service.getTypists(context, admin.external_id); //実行結果を確認 @@ -6366,7 +6366,7 @@ describe('getTypists', () => { ], }); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); const typists = await service.getTypists(context, admin.external_id); //実行結果を確認 @@ -6393,7 +6393,7 @@ describe('getTypists', () => { UsersRepositoryService, ); usersService.findTypistUsers = jest.fn().mockRejectedValue('DB failed'); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); //実行結果を確認 try { @@ -6462,7 +6462,7 @@ describe('deleteAccountAndData', () => { const context = makeContext( tier5AccountsA.admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); // 第一階層~第五階層までのライセンス注文を作成 @@ -6647,7 +6647,7 @@ describe('deleteAccountAndData', () => { const admin = admin1; const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); // 第五階層のアカウント作成 @@ -6715,7 +6715,7 @@ describe('deleteAccountAndData', () => { const admin = admin1; const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); // 第五階層のアカウント作成 @@ -6774,7 +6774,7 @@ describe('deleteAccountAndData', () => { const admin = admin1; const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); // 第五階層のアカウント作成 @@ -6847,7 +6847,7 @@ describe('getAccountInfoMinimalAccess', () => { }); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -6876,7 +6876,7 @@ describe('getAccountInfoMinimalAccess', () => { }); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -6905,7 +6905,7 @@ describe('getAccountInfoMinimalAccess', () => { }); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -6937,7 +6937,7 @@ describe('getAccountInfoMinimalAccess', () => { }); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -6998,7 +6998,7 @@ describe('getCompanyName', () => { }); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); const response = await service.getCompanyName(context, account.id); @@ -7017,7 +7017,7 @@ describe('getCompanyName', () => { }); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); try { diff --git a/dictation_server/src/features/auth/auth.service.spec.ts b/dictation_server/src/features/auth/auth.service.spec.ts index 5862140..e5aabe9 100644 --- a/dictation_server/src/features/auth/auth.service.spec.ts +++ b/dictation_server/src/features/auth/auth.service.spec.ts @@ -31,7 +31,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdWVyIiwic3ViIjoic3ViIiwiYXVkIjoiYXVkIiwibm9uY2UiOiJkZWZhdWx0Tm9uY2UiLCJpYXQiOjEwMDAwMDAwMDAsImF1dGhfdGltZSI6MTAwMDAwMDAwMCwiZW1haWxzIjpbInh4eEB4eC5jb20iXSwidGZwIjoic2lnbmluX3VzZXJmbG93In0.RyieW-VHsHPQOjXbbhRc307AYJOc1sq2hrcu4SW1-K0pvLlkplepxvx02a3vCwQrnBYrIP5w6HExG-S_JgW5nYyWr6DeY11mA484n9KA8GeAcAXV37StH1gfWUJvfGb4C8BaMbMM9Ix4Z9NGwKA9vjNwevfmBZnz9lQUePgv6BJNmyvCt8ElJ01O-1WODbZuojJ4xXymA1OqluzfbphPOsqWTSNmTn0emkLjjnlMQf1iwM4C_kvvr8dUCFg0_UGDfQVJnzPEKB38UqnhLnC5WacrddDwQ0kBuGKZgZ_63Q_7fOvqAZivqLK7BPmbPxi6mx3R1S9Eq2ugzpY1LfJOjA'; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); expect(await service.getVerifiedIdToken(context, token)).toEqual( idTokenPayload, ); @@ -43,7 +43,7 @@ describe('AuthService', () => { const service = await makeAuthServiceMock(adb2cParam, configMockValue); const token = 'invalid.id.token'; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E000101'), HttpStatus.UNAUTHORIZED), ); @@ -58,7 +58,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjEwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdWVyIiwic3ViIjoic3ViIiwiYXVkIjoiYXVkIiwibm9uY2UiOiJkZWZhdWx0Tm9uY2UiLCJpYXQiOjEwMDAwMDAwMDAsImF1dGhfdGltZSI6MTAwMDAwMDAwMCwiZW1haWxzIjpbInh4eEB4eC5jb20iXSwidGZwIjoic2lnbmluX3VzZXJmbG93In0.r9x61Mf1S2qFgU_QDKB6tRFBmTQXyOEtpoacOlL_bQzFz1t3GsxMy6SJIvQQ-LtDgylQ1UCdMFiRuy4V8nyLuME0fR-9IkKsboGvwllHB_Isai3XFoja0jpDHMVby1m0B3Z9xOTb7YsaQGyEH-qs1TtnRm6Ny98h4Po80nK8HGefQZHBOlfQN_B1LiHwI3nLXV18NL-4olKXj2NloNRYtnWM0PaqDQcGvZFaSNvtrSYpo9ddD906QWDGVOQ7WvGSUgdNCoxX8Lb3r2-VSj6n84jpb-Y1Fz-GhLluNglAsBhasnJfUIvCIO3iG5pRyTYjHFAVHmzjr8xMOmhS3s41Jw'; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E000102'), HttpStatus.UNAUTHORIZED), ); @@ -73,7 +73,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6OTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdWVyIiwic3ViIjoic3ViIiwiYXVkIjoiYXVkIiwibm9uY2UiOiJkZWZhdWx0Tm9uY2UiLCJpYXQiOjEwMDAwMDAwMDAsImF1dGhfdGltZSI6MTAwMDAwMDAwMCwiZW1haWxzIjpbInh4eEB4eC5jb20iXSwidGZwIjoic2lnbmluX3VzZXJmbG93In0.fX2Gbd7fDPNE3Lw-xbum_5CVqQYqEmMhv_v5u8A-U81pmPD2P5rsJEJx66ns1taFLVaE3j9_OzotxrqjqqQqbACkagGcN5wvA3_ZIxyqmhrKYFJc53ZcO7d0pFWiQlluNBI_pnFNDlSMB2Ut8Th5aiPy2uamBM9wC99bcjo7HkHvTKBf6ljU6rPKoD51qGDWqNxjoH-hdSJ29wprvyxyk_yX6dp-cxXUj5DIgXYQuIZF71rdiPtGlAiyTBns8rS2QlEEXapZVlvYrK4mkpUXVDA7ifD8q6gAC2BStqHeys7CGp2MbV4ZwKCVbAUbMs6Tboh8rADZvQhuTEq7qlhZ-w'; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E000103'), HttpStatus.UNAUTHORIZED), ); @@ -86,7 +86,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdXNlciIsInN1YiI6InN1YiIsImF1ZCI6ImF1ZCIsIm5vbmNlIjoiZGVmYXVsdE5vbmNlIiwiaWF0IjoxMDAwMDAwMDAwLCJhdXRoX3RpbWUiOjEwMDAwMDAwMDAsImVtYWlscyI6WyJ4eHhAeHguY29tIl0sInRmcCI6InNpZ25pbl91c2VyZmxvdyJ9.sign'; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E000104'), HttpStatus.UNAUTHORIZED), ); @@ -101,7 +101,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaW52bGlkX2lzc3VlciIsInN1YiI6InN1YiIsImF1ZCI6ImF1ZCIsIm5vbmNlIjoiZGVmYXVsdE5vbmNlIiwiaWF0IjoxMDAwMDAwMDAwLCJhdXRoX3RpbWUiOjEwMDAwMDAwMDAsImVtYWlscyI6WyJ4eHhAeHguY29tIl0sInRmcCI6InNpZ25pbl91c2VyZmxvdyJ9.0bp3e1mDG78PX3lo8zgOLXGenIqG_Vi6kw7CbwauAQM-cnUZ_aVCoJ_dAv_QmPElOQKcCkRrAvAZ91FwuHDlBGuuDqx8OwqN0VaD-4NPouoAswj-9HNvBm8gUn-pGaXkvWt_72UdCJavZJjDj_RHur8y8kFt5Qeab3mUP2x-uNcV2Q2x3M_IIfcRiIZkRZm_azKfiVIy7tzoUFLDss97y938aR8imMVxazoSQvj7RWIWylgeRr9yVt7qYl18cnEVL0IGtslFbqhfNsiEmRCMsttm5kXs7E9B0bhhUe_xbJW9VumQ6G7dgMrswevp_jRgbpWJoZsgErtqIRl9Tc9ikA'; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E000105'), HttpStatus.UNAUTHORIZED), ); @@ -115,7 +115,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdWVyIiwic3ViIjoic3ViIiwiYXVkIjoiYXVkIiwibm9uY2UiOiJkZWZhdWx0Tm9uY2UiLCJpYXQiOjEwMDAwMDAwMDAsImF1dGhfdGltZSI6MTAwMDAwMDAwMCwiZW1haWxzIjpbInh4eEB4eC5jb20iXSwidGZwIjoic2lnbmluX3VzZXJmbG93In0.RyieW-VHsHPQOjXbbhRc307AYJOc1sq2hrcu4SW1-K0pvLlkplepxvx02a3vCwQrnBYrIP5w6HExG-S_JgW5nYyWr6DeY11mA484n9KA8GeAcAXV37StH1gfWUJvfGb4C8BaMbMM9Ix4Z9NGwKA9vjNwevfmBZnz9lQUePgv6BJNmyvCt8ElJ01O-1WODbZuojJ4xXymA1OqluzfbphPOsqWTSNmTn0emkLjjnlMQf1iwM4C_kvvr8dUCFg0_UGDfQVJnzPEKB38UqnhLnC5WacrddDwQ0kBuGKZgZ_63Q_7fOvqAZivqLK7BPmbPxi6mx3R1S9Eq2ugzpY1LfJOjA'; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -131,7 +131,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdWVyIiwic3ViIjoic3ViIiwiYXVkIjoiYXVkIiwibm9uY2UiOiJkZWZhdWx0Tm9uY2UiLCJpYXQiOjEwMDAwMDAwMDAsImF1dGhfdGltZSI6MTAwMDAwMDAwMCwiZW1haWxzIjpbInh4eEB4eC5jb20iXSwidGZwIjoic2lnbmluX3VzZXJmbG93In0.RyieW-VHsHPQOjXbbhRc307AYJOc1sq2hrcu4SW1-K0pvLlkplepxvx02a3vCwQrnBYrIP5w6HExG-S_JgW5nYyWr6DeY11mA484n9KA8GeAcAXV37StH1gfWUJvfGb4C8BaMbMM9Ix4Z9NGwKA9vjNwevfmBZnz9lQUePgv6BJNmyvCt8ElJ01O-1WODbZuojJ4xXymA1OqluzfbphPOsqWTSNmTn0emkLjjnlMQf1iwM4C_kvvr8dUCFg0_UGDfQVJnzPEKB38UqnhLnC5WacrddDwQ0kBuGKZgZ_63Q_7fOvqAZivqLK7BPmbPxi6mx3R1S9Eq2ugzpY1LfJOjA'; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -150,7 +150,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdWVyIiwic3ViIjoic3ViIiwiYXVkIjoiYXVkIiwibm9uY2UiOiJkZWZhdWx0Tm9uY2UiLCJpYXQiOjEwMDAwMDAwMDAsImF1dGhfdGltZSI6MTAwMDAwMDAwMCwiZW1haWxzIjpbInh4eEB4eC5jb20iXSwidGZwIjoic2lnbmluX3VzZXJmbG93In0.RyieW-VHsHPQOjXbbhRc307AYJOc1sq2hrcu4SW1-K0pvLlkplepxvx02a3vCwQrnBYrIP5w6HExG-S_JgW5nYyWr6DeY11mA484n9KA8GeAcAXV37StH1gfWUJvfGb4C8BaMbMM9Ix4Z9NGwKA9vjNwevfmBZnz9lQUePgv6BJNmyvCt8ElJ01O-1WODbZuojJ4xXymA1OqluzfbphPOsqWTSNmTn0emkLjjnlMQf1iwM4C_kvvr8dUCFg0_UGDfQVJnzPEKB38UqnhLnC5WacrddDwQ0kBuGKZgZ_63Q_7fOvqAZivqLK7BPmbPxi6mx3R1S9Eq2ugzpY1LfJOjA'; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -186,7 +186,7 @@ describe('checkIsAcceptedLatestVersion', () => { const { admin } = await makeTestAccount(source, { tier: 5, }); - const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); const idToken = { emails: [], @@ -210,7 +210,7 @@ describe('checkIsAcceptedLatestVersion', () => { const { admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); const idToken = { emails: [], @@ -234,7 +234,7 @@ describe('checkIsAcceptedLatestVersion', () => { const { admin } = await makeTestAccount(source, { tier: 5, }); - const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); const idToken = { emails: [], @@ -258,7 +258,7 @@ describe('checkIsAcceptedLatestVersion', () => { const { admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); const idToken = { emails: [], @@ -282,7 +282,7 @@ describe('checkIsAcceptedLatestVersion', () => { const { admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); const idToken = { emails: [], @@ -306,7 +306,7 @@ describe('checkIsAcceptedLatestVersion', () => { const { admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); const idToken = { emails: [], @@ -363,7 +363,7 @@ describe('generateDelegationRefreshToken', () => { const context = makeContext( parentAdmin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -405,7 +405,7 @@ describe('generateDelegationRefreshToken', () => { const context = makeContext( parentAdmin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -447,7 +447,7 @@ describe('generateDelegationRefreshToken', () => { const context = makeContext( parentAdmin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -509,7 +509,7 @@ describe('generateDelegationAccessToken', () => { const context = makeContext( parentAdmin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -558,7 +558,7 @@ describe('generateDelegationAccessToken', () => { const context = makeContext( parentAdmin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -617,7 +617,7 @@ describe('updateDelegationAccessToken', () => { const context = makeContext( parentAdmin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -679,7 +679,7 @@ describe('updateDelegationAccessToken', () => { const context = makeContext( parentAdmin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -749,7 +749,7 @@ describe('updateDelegationAccessToken', () => { const context = makeContext( parentAdmin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); diff --git a/dictation_server/src/features/files/files.service.spec.ts b/dictation_server/src/features/files/files.service.spec.ts index c8e1229..660b0ba 100644 --- a/dictation_server/src/features/files/files.service.spec.ts +++ b/dictation_server/src/features/files/files.service.spec.ts @@ -85,7 +85,7 @@ describe('publishUploadSas', () => { null, null, ); - const context = makeContext(externalId, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(externalId, 'xxx-xxx-xxx-xxx', 'requestId'); const baseUrl = `https://saodmsusdev.blob.core.windows.net/account-${account.id}/${userId}`; //SASトークンを返却する @@ -109,7 +109,7 @@ describe('publishUploadSas', () => { const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -141,7 +141,7 @@ describe('publishUploadSas', () => { const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -174,7 +174,7 @@ describe('publishUploadSas', () => { const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -222,7 +222,7 @@ describe('publishUploadSas', () => { await expect( service.publishUploadSas( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, ), ).rejects.toEqual( @@ -283,7 +283,7 @@ describe('publishUploadSas', () => { await expect( service.publishUploadSas( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, ), ).rejects.toEqual( @@ -366,7 +366,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { NotificationhubService, ); const result = await service.uploadFinished( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), authorExternalId, 'http://blob/url/file.zip', authorAuthorId ?? '', @@ -386,7 +386,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { expect(result).toEqual({ jobNumber: '00000001' }); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), [`user_${typistUserId}`], { authorId: 'AUTHOR_ID', @@ -467,7 +467,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { NotificationhubService, ); const result = await service.uploadFinished( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), authorExternalId, 'http://blob/url/file.zip', authorAuthorId ?? '', @@ -487,7 +487,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { expect(result).toEqual({ jobNumber: '00000002' }); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), [`user_${typistUserId}`], { authorId: 'AUTHOR_ID', @@ -590,7 +590,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { NotificationhubService, ); const result = await service.uploadFinished( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), myExternalId, // API実行者のユーザーIDを設定 'http://blob/url/file.zip', authorAuthorId ?? '', // 音声ファイルの情報には、録音者のAuthorIDが入る @@ -610,7 +610,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { expect(result).toEqual({ jobNumber: '00000001' }); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), [`user_${typistUserId}`], { authorId: 'AUTHOR_ID', @@ -712,7 +712,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { NotificationhubService, ); const result = await service.uploadFinished( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), myExternalId, // API実行者のユーザーIDを設定 'http://blob/url/file.zip', 'XXXXXXXXXX', // 音声ファイルの情報には、録音者のAuthorIDが入る @@ -732,7 +732,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { expect(result).toEqual({ jobNumber: '00000001' }); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), [`user_${typistUserId}`], { authorId: 'XXXXXXXXXX', @@ -781,7 +781,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { const service = module.get(FilesService); const result = await service.uploadFinished( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), authorExternalId, // API実行者のユーザーIDを設定 'http://blob/url/file.zip', authorAuthorId ?? '', // 音声ファイルの情報には、録音者のAuthorIDが入る @@ -837,7 +837,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { await expect( service.uploadFinished( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), authorExternalId, 'http://blob/url/file.zip', authorAuthorId ?? '', @@ -884,7 +884,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { await expect( service.uploadFinished( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), authorExternalId, 'http://blob/url/file.zip', authorAuthorId ?? '', @@ -925,7 +925,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { await expect( service.uploadFinished( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 'authorExternalId', 'http://blob/url/file.zip', 'authorAuthorId', @@ -976,7 +976,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { await expect( service.uploadFinished( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), authorExternalId, 'http://blob/url/file.zip', authorAuthorId ?? '', @@ -1061,7 +1061,7 @@ describe('音声ファイルダウンロードURL取得', () => { expect( await service.publishAudioFileDownloadSas( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, audioFileId, ), @@ -1131,7 +1131,7 @@ describe('音声ファイルダウンロードURL取得', () => { expect( await service.publishAudioFileDownloadSas( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, audioFileId, ), @@ -1178,7 +1178,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishAudioFileDownloadSas( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, audioFileId, ), @@ -1232,7 +1232,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('tracking', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('tracking', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, audioFileId, ), @@ -1277,7 +1277,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishAudioFileDownloadSas( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, audioFileId, ), @@ -1309,7 +1309,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishAudioFileDownloadSas( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, 1, ), @@ -1358,7 +1358,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishAudioFileDownloadSas( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, audioFileId, ), @@ -1413,7 +1413,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishAudioFileDownloadSas( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, audioFileId, ), @@ -1485,7 +1485,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishAudioFileDownloadSas( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, audioFileId, ), @@ -1553,7 +1553,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { expect( await service.publishTemplateFileDownloadSas( - makeContext('tracking', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('tracking', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, audioFileId, ), @@ -1623,7 +1623,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { expect( await service.publishTemplateFileDownloadSas( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, audioFileId, ), @@ -1664,7 +1664,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('tracking', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('tracking', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, audioFileId, ), @@ -1714,7 +1714,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('tracking', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('tracking', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, audioFileId, ), @@ -1759,7 +1759,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('tracking', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('tracking', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, audioFileId, ), @@ -1791,7 +1791,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('tracking', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('tracking', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, 1, ), @@ -1839,7 +1839,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('tracking', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('tracking', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, audioFileId, ), @@ -1894,7 +1894,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, audioFileId, ), @@ -1966,7 +1966,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, audioFileId, ), @@ -2005,7 +2005,7 @@ describe('publishTemplateFileUploadSas', () => { const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); const baseUrl = `https://saodmsusdev.blob.core.windows.net/account-${account.id}/Templates`; @@ -2034,7 +2034,7 @@ describe('publishTemplateFileUploadSas', () => { const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -2066,7 +2066,7 @@ describe('publishTemplateFileUploadSas', () => { const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -2119,7 +2119,7 @@ describe('templateUploadFinished', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -2157,7 +2157,7 @@ describe('templateUploadFinished', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -2201,7 +2201,7 @@ describe('templateUploadFinished', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); diff --git a/dictation_server/src/features/licenses/licenses.service.spec.ts b/dictation_server/src/features/licenses/licenses.service.spec.ts index aa4b670..b6eb33b 100644 --- a/dictation_server/src/features/licenses/licenses.service.spec.ts +++ b/dictation_server/src/features/licenses/licenses.service.spec.ts @@ -59,7 +59,7 @@ describe('LicensesService', () => { const userId = '0001'; body.orderCount = 1000; body.poNumber = '1'; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); expect( await service.licenseOrders( context, @@ -87,7 +87,7 @@ describe('LicensesService', () => { const userId = ''; body.orderCount = 1000; body.poNumber = '1'; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect( service.licenseOrders(context, userId, body.poNumber, body.orderCount), ).rejects.toEqual( @@ -115,7 +115,7 @@ describe('LicensesService', () => { const userId = '0001'; body.orderCount = 1000; body.poNumber = '1'; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect( service.licenseOrders(context, userId, body.poNumber, body.orderCount), ).rejects.toEqual( @@ -143,7 +143,7 @@ describe('LicensesService', () => { const userId = '0001'; body.orderCount = 1000; body.poNumber = '1'; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect( service.licenseOrders(context, userId, body.poNumber, body.orderCount), ).rejects.toEqual( @@ -181,7 +181,7 @@ describe('LicensesService', () => { 'AEJWRFFSWRQYQQJ6WVLV', ], }; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); expect( await service.issueCardLicenseKeys(context, userId, body.createCount), ).toEqual(issueCardLicensesResponse); @@ -201,7 +201,7 @@ describe('LicensesService', () => { const body = new IssueCardLicensesRequest(); const userId = '0001'; body.createCount = 1000; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect( service.issueCardLicenseKeys(context, userId, body.createCount), ).rejects.toEqual( @@ -225,7 +225,7 @@ describe('LicensesService', () => { const body = new ActivateCardLicensesRequest(); const userId = '0001'; body.cardLicenseKey = 'WZCETXC0Z9PQZ9GKRGGY'; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); expect( await service.activateCardLicenseKey( context, @@ -249,7 +249,7 @@ describe('LicensesService', () => { const body = new ActivateCardLicensesRequest(); const userId = '0001'; body.cardLicenseKey = 'WZCETXC0Z9PQZ9GKRGGY'; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect( service.activateCardLicenseKey(context, userId, body.cardLicenseKey), ).rejects.toEqual( @@ -276,7 +276,7 @@ describe('LicensesService', () => { const body = new ActivateCardLicensesRequest(); const userId = '0001'; body.cardLicenseKey = 'WZCETXC0Z9PQZ9GKRGGY'; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect( service.activateCardLicenseKey(context, userId, body.cardLicenseKey), ).rejects.toEqual( @@ -299,7 +299,7 @@ describe('LicensesService', () => { const body = new ActivateCardLicensesRequest(); const userId = '0001'; body.cardLicenseKey = 'WZCETXC0Z9PQZ9GKRGGY'; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect( service.activateCardLicenseKey(context, userId, body.cardLicenseKey), ).rejects.toEqual( @@ -342,7 +342,7 @@ describe('DBテスト', () => { const service = module.get(LicensesService); const issueCount = 500; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await service.issueCardLicenseKeys(context, externalId, issueCount); const dbSelectResult = await selectCardLicensesCount(source); expect(dbSelectResult.count).toEqual(issueCount); @@ -382,7 +382,7 @@ describe('DBテスト', () => { await createCardLicenseIssue(source, issueId); const service = module.get(LicensesService); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await service.activateCardLicenseKey(context, externalId, cardLicenseKey); const dbSelectResultFromCardLicense = await selectCardLicense( @@ -529,7 +529,7 @@ describe('DBテスト', () => { null, ); const service = module.get(LicensesService); - const context = makeContext('userId', 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext('userId', 'xxx-xxx-xxx-xxx', 'requestId'); const response = await service.getAllocatableLicenses(context, externalId); // 対象外のデータは取得していないことを確認する expect(response.allocatableLicenses.length).toBe(5); @@ -600,7 +600,7 @@ describe('ライセンス割り当て', () => { const expiry_date = new NewAllocatedLicenseExpirationDate(); await service.allocateLicense( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), userId, 1, ); @@ -669,7 +669,7 @@ describe('ライセンス割り当て', () => { const service = module.get(UsersService); await service.allocateLicense( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), userId, 1, ); @@ -748,7 +748,7 @@ describe('ライセンス割り当て', () => { const expiry_date = new NewAllocatedLicenseExpirationDate(); await service.allocateLicense( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), userId, 2, ); @@ -851,7 +851,7 @@ describe('ライセンス割り当て', () => { const service = module.get(UsersService); await service.allocateLicense( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), userId, 2, ); @@ -915,7 +915,7 @@ describe('ライセンス割り当て', () => { const service = module.get(UsersService); await service.allocateLicense( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), userId, 2, ); @@ -979,7 +979,7 @@ describe('ライセンス割り当て', () => { const service = module.get(UsersService); await service.allocateLicense( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), userId, 2, ); @@ -1025,7 +1025,7 @@ describe('ライセンス割り当て', () => { await expect( service.allocateLicense( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), userId, 1, ), @@ -1077,7 +1077,7 @@ describe('ライセンス割り当て', () => { await expect( service.allocateLicense( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), userId, 1, ), @@ -1086,7 +1086,7 @@ describe('ライセンス割り当て', () => { ); await expect( service.allocateLicense( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), userId, 2, ), @@ -1152,7 +1152,7 @@ describe('ライセンス割り当て解除', () => { const service = module.get(UsersService); await service.deallocateLicense( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), userId, ); @@ -1243,7 +1243,7 @@ describe('ライセンス割り当て解除', () => { const service = module.get(UsersService); await expect( service.deallocateLicense( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), userId, ), ).rejects.toEqual( @@ -1301,7 +1301,7 @@ describe('ライセンス注文キャンセル', () => { const service = module.get(LicensesService); await service.cancelOrder( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), tier2Accounts[0].users[0].external_id, poNumber, ); @@ -1337,7 +1337,7 @@ describe('ライセンス注文キャンセル', () => { const service = module.get(LicensesService); await expect( service.cancelOrder( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), tier2Accounts[0].users[0].external_id, poNumber, ), @@ -1368,7 +1368,7 @@ describe('ライセンス注文キャンセル', () => { const service = module.get(LicensesService); await expect( service.cancelOrder( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), tier2Accounts[0].users[0].external_id, poNumber, ), diff --git a/dictation_server/src/features/notification/notification.service.spec.ts b/dictation_server/src/features/notification/notification.service.spec.ts index a052fd7..355567f 100644 --- a/dictation_server/src/features/notification/notification.service.spec.ts +++ b/dictation_server/src/features/notification/notification.service.spec.ts @@ -19,7 +19,7 @@ describe('NotificationService.register', () => { expect( await service.register( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 'external_id', 'apns', 'handler', @@ -38,7 +38,7 @@ describe('NotificationService.register', () => { await expect( service.register( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 'external_id', 'apns', 'handler', @@ -63,7 +63,7 @@ describe('NotificationService.register', () => { await expect( service.register( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 'external_id', 'apns', 'handler', diff --git a/dictation_server/src/features/tasks/tasks.service.spec.ts b/dictation_server/src/features/tasks/tasks.service.spec.ts index 56287ac..3c87ea5 100644 --- a/dictation_server/src/features/tasks/tasks.service.spec.ts +++ b/dictation_server/src/features/tasks/tasks.service.spec.ts @@ -63,7 +63,7 @@ describe('TasksService', () => { const direction = 'ASC'; expect( await service.tasksService.getTasks( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), userId, [ADMIN_ROLES.ADMIN, USER_ROLES.NONE], offset, @@ -138,7 +138,7 @@ describe('TasksService', () => { const direction = 'ASC'; await expect( service.tasksService.getTasks( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), userId, [ADMIN_ROLES.ADMIN, USER_ROLES.NONE], offset, @@ -180,7 +180,7 @@ describe('TasksService', () => { const direction = 'ASC'; await expect( service.tasksService.getTasks( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), userId, [ADMIN_ROLES.ADMIN, USER_ROLES.NONE], offset, @@ -266,7 +266,7 @@ describe('TasksService', () => { const direction = 'ASC'; await expect( service.tasksService.getTasks( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), userId, [ADMIN_ROLES.ADMIN, USER_ROLES.NONE], offset, @@ -310,7 +310,7 @@ describe('TasksService', () => { const paramName = 'JOB_NUMBER'; const direction = 'ASC'; const result = await service.tasksService.getTasks( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), userId, [USER_ROLES.AUTHOR], offset, @@ -393,7 +393,7 @@ describe('TasksService', () => { const direction = 'ASC'; await expect( service.tasksService.getTasks( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), userId, [USER_ROLES.AUTHOR], offset, @@ -438,7 +438,7 @@ describe('TasksService', () => { const paramName = 'JOB_NUMBER'; const direction = 'ASC'; const result = await service.tasksService.getTasks( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), userId, [USER_ROLES.TYPIST], offset, @@ -521,7 +521,7 @@ describe('TasksService', () => { const direction = 'ASC'; await expect( service.tasksService.getTasks( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), userId, [USER_ROLES.TYPIST], offset, @@ -563,7 +563,7 @@ describe('TasksService', () => { const direction = 'ASC'; await expect( service.tasksService.getTasks( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), userId, [ADMIN_ROLES.ADMIN, USER_ROLES.NONE], offset, @@ -623,7 +623,7 @@ describe('TasksService', () => { const direction = 'ASC'; const { tasks, total } = await service.getTasks( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), externalId, [ADMIN_ROLES.ADMIN, USER_ROLES.NONE], offset, @@ -681,7 +681,7 @@ describe('TasksService', () => { const direction = 'ASC'; const { tasks, total } = await service.getTasks( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), external_id, [USER_ROLES.AUTHOR], offset, @@ -753,7 +753,7 @@ describe('TasksService', () => { const direction = 'ASC'; const { tasks, total } = await service.getTasks( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), external_id, [USER_ROLES.AUTHOR], offset, @@ -839,7 +839,7 @@ describe('changeCheckoutPermission', () => { NotificationhubService, ); await service.changeCheckoutPermission( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, [{ typistName: 'typist-user-2', typistUserId: typistUserId_2 }], 'author-user-external-id', @@ -856,7 +856,7 @@ describe('changeCheckoutPermission', () => { const resultTask = await getTask(source, taskId); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), [`user_${typistUserId_2}`], { authorId: 'MY_AUTHOR_ID', @@ -922,7 +922,7 @@ describe('changeCheckoutPermission', () => { NotificationhubService, ); await service.changeCheckoutPermission( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, [{ typistName: 'USER_GROUP_B', typistGroupId: userGroupId_2 }], 'author-user-external-id', @@ -940,7 +940,7 @@ describe('changeCheckoutPermission', () => { const resultTask = await getTask(source, taskId); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), [`user_${typistUserId_2}`], { authorId: 'MY_AUTHOR_ID', @@ -992,7 +992,7 @@ describe('changeCheckoutPermission', () => { await createCheckoutPermissions(source, taskId, undefined, userGroupId); const service = module.get(TasksService); await service.changeCheckoutPermission( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, [], 'author-user-external-id', @@ -1045,7 +1045,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, [{ typistName: 'not-exist-user', typistUserId: 999 }], 'author-user-external-id', @@ -1111,7 +1111,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, [{ typistName: 'not-verified-user', typistUserId: typistUserId_2 }], 'author-user-external-id', @@ -1171,7 +1171,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, [{ typistName: 'not-exist-user-group', typistGroupId: 999 }], 'author-user-external-id', @@ -1213,7 +1213,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, [{ typistName: 'typist-user', typistUserId: typistUserId }], 'author-user-external-id', @@ -1265,7 +1265,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, [{ typistName: 'typist-user', typistUserId: typistUserId }], 'author-user-external-id', @@ -1317,7 +1317,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, [{ typistName: 'typist-user', typistUserId: typistUserId }], 'author-user-external-id', @@ -1383,7 +1383,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, [{ typistName: 'typist-user-2', typistUserId: typistUserId_2 }], 'author-user-external-id', @@ -1460,7 +1460,7 @@ describe('checkout', () => { const initTask = await getTask(source, taskId); await service.checkout( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, ['typist'], 'typist-user-external-id', @@ -1520,7 +1520,7 @@ describe('checkout', () => { const initTask = await getTask(source, taskId); await service.checkout( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, ['typist'], 'typist-user-external-id', @@ -1573,7 +1573,7 @@ describe('checkout', () => { const initTask = await getTask(source, taskId); await service.checkout( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, ['typist'], 'typist-user-external-id', @@ -1625,7 +1625,7 @@ describe('checkout', () => { const service = module.get(TasksService); try { await service.checkout( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, ['typist'], 'typist-user-external-id', @@ -1672,7 +1672,7 @@ describe('checkout', () => { const service = module.get(TasksService); try { await service.checkout( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, ['typist'], 'typist-user-external-id', @@ -1733,7 +1733,7 @@ describe('checkout', () => { try { await service.checkout( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), audioFileId, ['typist'], 'typist-user-external-id', @@ -1798,7 +1798,7 @@ describe('checkout', () => { const service = module.get(TasksService); await service.checkout( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 2, ['typist'], 'typist-user-external-id2', @@ -1839,7 +1839,7 @@ describe('checkout', () => { const service = module.get(TasksService); expect( await service.checkout( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, ['author'], 'author-user-external-id', @@ -1873,7 +1873,7 @@ describe('checkout', () => { expect( await service.checkout( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, ['author'], 'author-user-external-id', @@ -1896,7 +1896,7 @@ describe('checkout', () => { const service = module.get(TasksService); try { await service.checkout( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, ['author'], 'author-user-external-id', @@ -1937,7 +1937,7 @@ describe('checkout', () => { const service = module.get(TasksService); try { await service.checkout( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, ['author'], 'author-user-external-id', @@ -1968,7 +1968,7 @@ describe('checkout', () => { const service = module.get(TasksService); try { await service.checkout( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, ['none'], 'none-user-external-id', @@ -2043,7 +2043,7 @@ describe('checkin', () => { const initTask = await getTask(source, taskId); await service.checkin( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, 'typist-user-external-id', ); @@ -2090,7 +2090,7 @@ describe('checkin', () => { const service = module.get(TasksService); await expect( service.checkin( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, 'typist-user-external-id', ), @@ -2142,7 +2142,7 @@ describe('checkin', () => { await expect( service.checkin( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, 'typist-user-external-id', ), @@ -2178,7 +2178,7 @@ describe('checkin', () => { await expect( service.checkin( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, 'typist-user-external-id', ), @@ -2243,7 +2243,7 @@ describe('suspend', () => { const service = module.get(TasksService); await service.suspend( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, 'typist-user-external-id', ); @@ -2289,7 +2289,7 @@ describe('suspend', () => { const service = module.get(TasksService); await expect( service.suspend( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, 'typist-user-external-id', ), @@ -2341,7 +2341,7 @@ describe('suspend', () => { await expect( service.checkin( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, 'typist-user-external-id', ), @@ -2377,7 +2377,7 @@ describe('suspend', () => { await expect( service.checkin( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, 'typist-user-external-id', ), @@ -2443,7 +2443,7 @@ describe('cancel', () => { const service = module.get(TasksService); await service.cancel( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, 'typist-user-external-id', ['typist', 'standard'], @@ -2492,7 +2492,7 @@ describe('cancel', () => { const service = module.get(TasksService); await service.cancel( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, 'typist-user-external-id', ['typist', 'standard'], @@ -2544,7 +2544,7 @@ describe('cancel', () => { const service = module.get(TasksService); await service.cancel( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, 'typist-user-external-id', ['admin', 'author'], @@ -2595,7 +2595,7 @@ describe('cancel', () => { const service = module.get(TasksService); await service.cancel( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, 'typist-user-external-id', ['admin', 'author'], @@ -2645,7 +2645,7 @@ describe('cancel', () => { const service = module.get(TasksService); await expect( service.cancel( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, 'typist-user-external-id', ['admin', 'author'], @@ -2698,7 +2698,7 @@ describe('cancel', () => { await expect( service.cancel( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, 'typist-user-external-id', ['typist', 'standard'], @@ -2735,7 +2735,7 @@ describe('cancel', () => { await expect( service.cancel( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, 'typist-user-external-id', ['typist', 'standard'], @@ -2804,7 +2804,7 @@ describe('cancel', () => { NotificationhubService, ); await service.cancel( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, 'typist-user-external-id', ['typist', 'standard'], @@ -2821,7 +2821,7 @@ describe('cancel', () => { expect(permisions[0].user_id).toEqual(typistUserId); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), [`user_${typistUserId}`], { authorId: 'AUTHOR_ID', @@ -2914,7 +2914,7 @@ describe('cancel', () => { NotificationhubService, ); await service.cancel( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, external_id, role.split(' ') as Roles[], @@ -2931,7 +2931,7 @@ describe('cancel', () => { expect(permisions[0].user_id).toEqual(autoRoutingTypistUserId); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), [`user_${autoRoutingTypistUserId}`], { authorId: 'AUTHOR_ID', @@ -2986,7 +2986,7 @@ describe('cancel', () => { NotificationhubService, ); await service.cancel( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), 1, external_id, role.split(' ') as Roles[], @@ -3060,7 +3060,7 @@ describe('backup', () => { const service = module.get(TasksService); await service.backup( - makeContext(admin.external_id, 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext(admin.external_id, 'xxx-xxx-xxx-xxx', 'requestId'), audioFileId, admin.external_id, ); @@ -3112,7 +3112,7 @@ describe('backup', () => { const service = module.get(TasksService); await service.backup( - makeContext(admin.external_id, 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext(admin.external_id, 'xxx-xxx-xxx-xxx', 'requestId'), audioFileId, admin.external_id, ); @@ -3165,7 +3165,7 @@ describe('backup', () => { try { await service.backup( - makeContext(admin.external_id, 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext(admin.external_id, 'xxx-xxx-xxx-xxx', 'requestId'), audioFileId, admin.external_id, ); @@ -3220,7 +3220,7 @@ describe('backup', () => { try { await service.backup( - makeContext(admin.external_id, 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext(admin.external_id, 'xxx-xxx-xxx-xxx', 'requestId'), 9999, // 存在しないタスクID admin.external_id, ); @@ -3281,7 +3281,7 @@ describe('backup', () => { try { await service.backup( - makeContext(admin.external_id, 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext(admin.external_id, 'xxx-xxx-xxx-xxx', 'requestId'), audioFileId, admin.external_id, ); @@ -3376,7 +3376,7 @@ describe('getNextTask', () => { const service = module.get(TasksService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -3452,7 +3452,7 @@ describe('getNextTask', () => { const service = module.get(TasksService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -3528,7 +3528,7 @@ describe('getNextTask', () => { const service = module.get(TasksService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -3604,7 +3604,7 @@ describe('getNextTask', () => { const service = module.get(TasksService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -3680,7 +3680,7 @@ describe('getNextTask', () => { const service = module.get(TasksService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -3732,7 +3732,7 @@ describe('getNextTask', () => { const service = module.get(TasksService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -3783,7 +3783,7 @@ describe('getNextTask', () => { const service = module.get(TasksService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); diff --git a/dictation_server/src/features/templates/templates.service.spec.ts b/dictation_server/src/features/templates/templates.service.spec.ts index 21abe24..9edeff3 100644 --- a/dictation_server/src/features/templates/templates.service.spec.ts +++ b/dictation_server/src/features/templates/templates.service.spec.ts @@ -37,7 +37,7 @@ describe('getTemplates', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -82,7 +82,7 @@ describe('getTemplates', () => { const { admin } = await makeTestAccount(source, { tier: 5 }); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -104,7 +104,7 @@ describe('getTemplates', () => { const { admin } = await makeTestAccount(source, { tier: 5 }); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); diff --git a/dictation_server/src/features/terms/terms.service.spec.ts b/dictation_server/src/features/terms/terms.service.spec.ts index a41af4b..1f737eb 100644 --- a/dictation_server/src/features/terms/terms.service.spec.ts +++ b/dictation_server/src/features/terms/terms.service.spec.ts @@ -39,7 +39,7 @@ describe('利用規約取得', () => { await createTermInfo(source, 'DPA', 'v1.0'); await createTermInfo(source, 'DPA', 'v1.2'); - const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); const result = await service.getTermsInfo(context); expect(result[0].documentType).toBe('EULA'); @@ -55,7 +55,7 @@ describe('利用規約取得', () => { const module = await makeTestingModule(source); if (!module) fail(); const service = module.get(TermsService); - const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); await expect(service.getTermsInfo(context)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -70,7 +70,7 @@ describe('利用規約取得', () => { if (!module) fail(); const service = module.get(TermsService); await createTermInfo(source, 'DPA', 'v1.0'); - const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); await expect(service.getTermsInfo(context)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -85,7 +85,7 @@ describe('利用規約取得', () => { if (!module) fail(); const service = module.get(TermsService); await createTermInfo(source, 'PrivacyNotice', 'v1.0'); - const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); await expect(service.getTermsInfo(context)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -100,7 +100,7 @@ describe('利用規約取得', () => { if (!module) fail(); const service = module.get(TermsService); await createTermInfo(source, 'EULA', 'v1.0'); - const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); await expect(service.getTermsInfo(context)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), diff --git a/dictation_server/src/features/users/users.service.spec.ts b/dictation_server/src/features/users/users.service.spec.ts index e7bf8af..f9a08b7 100644 --- a/dictation_server/src/features/users/users.service.spec.ts +++ b/dictation_server/src/features/users/users.service.spec.ts @@ -97,7 +97,7 @@ describe('UsersService.confirmUser', () => { // account id:1, user id: 2のトークン const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjEsInVzZXJJZCI6MiwiZW1haWwiOiJ4eHhAeHh4Lnh4eCIsImlhdCI6MTAwMDAwMDAwMCwiZXhwIjo5MDAwMDAwMDAwfQ.26L6BdNg-3TbyKT62PswlJ6RPMkcTtHzlDXW2Uo9XbMPVSrl2ObcuS6EcXjFFN2DEfNTKbqX_zevIWMpHOAdLNgGhk528nLrBrNvPASqtTjvW9muxMXpjUdjRVkmVbOylBHWW3YpWL9JEbJQ7rAzWDfaIdPhMovdaxumnZt_UwnlnrdaVPLACW7tkH_laEcAU507iSiM4mqxxG8FuTs34t6PEdwRuzZAQPN2IOPYNSvGNdJYryPacSeSNZ_z1xeBYXLOLQfOBZzyTReYDOhXdikhrNUbxjgnZQlSXBCVMlZ9PH42bHfp-LJIeJzW0yqnF6oLklvJP-fo8eW0k5iDOw'; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await service.confirmUser(context, token); //result const resultUser = await getUser(source, userId); @@ -141,7 +141,7 @@ describe('UsersService.confirmUser', () => { if (!module) fail(); const token = 'invalid.id.token'; const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect(service.confirmUser(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E000101'), HttpStatus.BAD_REQUEST), ); @@ -177,7 +177,7 @@ describe('UsersService.confirmUser', () => { const service = module.get(UsersService); const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjEsInVzZXJJZCI6MiwiZW1haWwiOiJ4eHhAeHh4Lnh4eCIsImlhdCI6MTAwMDAwMDAwMCwiZXhwIjo5MDAwMDAwMDAwfQ.26L6BdNg-3TbyKT62PswlJ6RPMkcTtHzlDXW2Uo9XbMPVSrl2ObcuS6EcXjFFN2DEfNTKbqX_zevIWMpHOAdLNgGhk528nLrBrNvPASqtTjvW9muxMXpjUdjRVkmVbOylBHWW3YpWL9JEbJQ7rAzWDfaIdPhMovdaxumnZt_UwnlnrdaVPLACW7tkH_laEcAU507iSiM4mqxxG8FuTs34t6PEdwRuzZAQPN2IOPYNSvGNdJYryPacSeSNZ_z1xeBYXLOLQfOBZzyTReYDOhXdikhrNUbxjgnZQlSXBCVMlZ9PH42bHfp-LJIeJzW0yqnF6oLklvJP-fo8eW0k5iDOw'; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect(service.confirmUser(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E010202'), HttpStatus.BAD_REQUEST), ); @@ -189,7 +189,7 @@ describe('UsersService.confirmUser', () => { const service = module.get(UsersService); const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjEsInVzZXJJZCI6MiwiZW1haWwiOiJ4eHhAeHh4Lnh4eCIsImlhdCI6MTAwMDAwMDAwMCwiZXhwIjo5MDAwMDAwMDAwfQ.26L6BdNg-3TbyKT62PswlJ6RPMkcTtHzlDXW2Uo9XbMPVSrl2ObcuS6EcXjFFN2DEfNTKbqX_zevIWMpHOAdLNgGhk528nLrBrNvPASqtTjvW9muxMXpjUdjRVkmVbOylBHWW3YpWL9JEbJQ7rAzWDfaIdPhMovdaxumnZt_UwnlnrdaVPLACW7tkH_laEcAU507iSiM4mqxxG8FuTs34t6PEdwRuzZAQPN2IOPYNSvGNdJYryPacSeSNZ_z1xeBYXLOLQfOBZzyTReYDOhXdikhrNUbxjgnZQlSXBCVMlZ9PH42bHfp-LJIeJzW0yqnF6oLklvJP-fo8eW0k5iDOw'; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect(service.confirmUser(context, token)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -246,7 +246,7 @@ describe('UsersService.confirmUserAndInitPassword', () => { 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjEsInVzZXJJZCI6MiwiZW1haWwiOiJ4eHhAeHh4Lnh4eCIsImlhdCI6MTAwMDAwMDAwMCwiZXhwIjo5MDAwMDAwMDAwfQ.26L6BdNg-3TbyKT62PswlJ6RPMkcTtHzlDXW2Uo9XbMPVSrl2ObcuS6EcXjFFN2DEfNTKbqX_zevIWMpHOAdLNgGhk528nLrBrNvPASqtTjvW9muxMXpjUdjRVkmVbOylBHWW3YpWL9JEbJQ7rAzWDfaIdPhMovdaxumnZt_UwnlnrdaVPLACW7tkH_laEcAU507iSiM4mqxxG8FuTs34t6PEdwRuzZAQPN2IOPYNSvGNdJYryPacSeSNZ_z1xeBYXLOLQfOBZzyTReYDOhXdikhrNUbxjgnZQlSXBCVMlZ9PH42bHfp-LJIeJzW0yqnF6oLklvJP-fo8eW0k5iDOw'; expect( await service.confirmUserAndInitPassword( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), token, ), ).toEqual(undefined); @@ -296,7 +296,7 @@ describe('UsersService.confirmUserAndInitPassword', () => { const token = 'invalid.id.token'; await expect( service.confirmUserAndInitPassword( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), token, ), ).rejects.toEqual( @@ -352,7 +352,7 @@ describe('UsersService.confirmUserAndInitPassword', () => { 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjEsInVzZXJJZCI6MiwiZW1haWwiOiJ4eHhAeHh4Lnh4eCIsImlhdCI6MTAwMDAwMDAwMCwiZXhwIjo5MDAwMDAwMDAwfQ.26L6BdNg-3TbyKT62PswlJ6RPMkcTtHzlDXW2Uo9XbMPVSrl2ObcuS6EcXjFFN2DEfNTKbqX_zevIWMpHOAdLNgGhk528nLrBrNvPASqtTjvW9muxMXpjUdjRVkmVbOylBHWW3YpWL9JEbJQ7rAzWDfaIdPhMovdaxumnZt_UwnlnrdaVPLACW7tkH_laEcAU507iSiM4mqxxG8FuTs34t6PEdwRuzZAQPN2IOPYNSvGNdJYryPacSeSNZ_z1xeBYXLOLQfOBZzyTReYDOhXdikhrNUbxjgnZQlSXBCVMlZ9PH42bHfp-LJIeJzW0yqnF6oLklvJP-fo8eW0k5iDOw'; await expect( service.confirmUserAndInitPassword( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), token, ), ).rejects.toEqual( @@ -405,7 +405,7 @@ describe('UsersService.confirmUserAndInitPassword', () => { 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjEsInVzZXJJZCI6MiwiZW1haWwiOiJ4eHhAeHh4Lnh4eCIsImlhdCI6MTAwMDAwMDAwMCwiZXhwIjo5MDAwMDAwMDAwfQ.26L6BdNg-3TbyKT62PswlJ6RPMkcTtHzlDXW2Uo9XbMPVSrl2ObcuS6EcXjFFN2DEfNTKbqX_zevIWMpHOAdLNgGhk528nLrBrNvPASqtTjvW9muxMXpjUdjRVkmVbOylBHWW3YpWL9JEbJQ7rAzWDfaIdPhMovdaxumnZt_UwnlnrdaVPLACW7tkH_laEcAU507iSiM4mqxxG8FuTs34t6PEdwRuzZAQPN2IOPYNSvGNdJYryPacSeSNZ_z1xeBYXLOLQfOBZzyTReYDOhXdikhrNUbxjgnZQlSXBCVMlZ9PH42bHfp-LJIeJzW0yqnF6oLklvJP-fo8eW0k5iDOw'; await expect( service.confirmUserAndInitPassword( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), token, ), ).rejects.toEqual( @@ -491,7 +491,7 @@ describe('UsersService.createUser', () => { expect( await service.createUser( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), adminExternalId, name, role, @@ -579,7 +579,7 @@ describe('UsersService.createUser', () => { expect( await service.createUser( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), adminExternalId, name, role, @@ -670,7 +670,7 @@ describe('UsersService.createUser', () => { expect( await service.createUser( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), adminExternalId, name, role, @@ -758,7 +758,7 @@ describe('UsersService.createUser', () => { expect( await service.createUser( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), adminExternalId, name, role, @@ -851,7 +851,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), adminExternalId, name, role, @@ -871,7 +871,7 @@ describe('UsersService.createUser', () => { // ADB2Cに作成したユーザーを削除するメソッドが呼ばれていることを確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), ); }); @@ -938,7 +938,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), adminExternalId, name, role, @@ -963,7 +963,7 @@ describe('UsersService.createUser', () => { // ADB2Cに作成したユーザーを削除するメソッドが呼ばれていることを確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), ); }); @@ -1019,7 +1019,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), adminExternalId, name, role, @@ -1098,7 +1098,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), adminExternalId, name, role, @@ -1179,7 +1179,7 @@ describe('UsersService.createUser', () => { expect( await service.createUser( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), adminExternalId, name, role, @@ -1220,7 +1220,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), adminExternalId, name, role, @@ -1316,7 +1316,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), adminExternalId, name, role, @@ -1344,7 +1344,7 @@ describe('UsersService.createUser', () => { // ADB2Cに作成したユーザーを削除するメソッドが呼ばれていることを確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), ); }); @@ -1405,7 +1405,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), adminExternalId, name, role, @@ -1431,7 +1431,7 @@ describe('UsersService.createUser', () => { // ADB2Cに作成したユーザーを削除するメソッドが呼ばれていることを確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), ); }); @@ -1497,7 +1497,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), adminExternalId, name, role, @@ -1521,7 +1521,7 @@ describe('UsersService.createUser', () => { // ADB2Cに作成したユーザーを削除するメソッドが呼ばれていることを確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('trackingId', 'xxx.xxx.xxx.xxx', 'requestId'), + makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), ); }); }); @@ -1644,7 +1644,7 @@ describe('UsersService.getUsers', () => { }, ]; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); expect(await service.getUsers(context, externalId_author)).toEqual( expectedUsers, ); @@ -1763,7 +1763,7 @@ describe('UsersService.getUsers', () => { }, ]; - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); expect(await service.getUsers(context, external_id1)).toEqual( expectedUsers, ); @@ -1787,7 +1787,7 @@ describe('UsersService.getUsers', () => { prompt: false, }); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); const service = module.get(UsersService); await expect( service.getUsers(context, 'externalId_failed'), @@ -1815,7 +1815,7 @@ describe('UsersService.getUsers', () => { prompt: false, }); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); const service = module.get(UsersService); await expect(service.getUsers(context, externalId_author)).rejects.toEqual( new HttpException(makeErrorResponse('E009999'), HttpStatus.NOT_FOUND), @@ -1840,7 +1840,7 @@ describe('UsersService.updateSortCriteria', () => { configMockValue, sortCriteriaRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); expect( await service.updateSortCriteria( @@ -1871,7 +1871,7 @@ describe('UsersService.updateSortCriteria', () => { configMockValue, sortCriteriaRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect( service.updateSortCriteria(context, 'AUTHOR_ID', 'ASC', 'external_id'), @@ -1903,7 +1903,7 @@ describe('UsersService.updateSortCriteria', () => { configMockValue, sortCriteriaRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect( service.updateSortCriteria(context, 'AUTHOR_ID', 'ASC', 'external_id'), @@ -1933,7 +1933,7 @@ describe('UsersService.getSortCriteria', () => { configMockValue, sortCriteriaRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); expect(await service.getSortCriteria(context, 'external_id')).toEqual({ direction: 'ASC', @@ -1962,7 +1962,7 @@ describe('UsersService.getSortCriteria', () => { configMockValue, sortCriteriaRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect( service.getSortCriteria(context, 'external_id'), @@ -1997,7 +1997,7 @@ describe('UsersService.getSortCriteria', () => { configMockValue, sortCriteriaRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect( service.getSortCriteria(context, 'external_id'), @@ -2057,7 +2057,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); expect( await service.updateUser( @@ -2116,7 +2116,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); expect( await service.updateUser( @@ -2175,7 +2175,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); expect( await service.updateUser( @@ -2234,7 +2234,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); expect( await service.updateUser( @@ -2293,7 +2293,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); expect( await service.updateUser( @@ -2352,7 +2352,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect( service.updateUser( @@ -2401,7 +2401,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); expect( await service.updateUser( @@ -2460,7 +2460,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); expect( await service.updateUser( @@ -2519,7 +2519,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect( service.updateUser( @@ -2579,7 +2579,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); await expect( service.updateUser( @@ -2627,7 +2627,7 @@ describe('UsersService.updateAcceptedVersion', () => { const { admin } = await makeTestAccount(source, { tier: 5, }); - const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); const service = module.get(UsersService); await service.updateAcceptedVersion( @@ -2648,7 +2648,7 @@ describe('UsersService.updateAcceptedVersion', () => { const { admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); const service = module.get(UsersService); await service.updateAcceptedVersion( @@ -2671,7 +2671,7 @@ describe('UsersService.updateAcceptedVersion', () => { const { admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); const service = module.get(UsersService); await expect( @@ -2714,7 +2714,7 @@ describe('UsersService.getUserName', () => { try { const module = await makeTestingModule(source); if (!module) fail(); - const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); const service = module.get(UsersService); await service.getUserName(context, 'external_id'); @@ -2809,7 +2809,7 @@ describe('UsersService.getRelations', () => { expect(workflows[3].author_id).toBe(user2); } - const context = makeContext(external_id, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(external_id, 'xxx-xxx-xxx-xxx', 'requestId'); const service = module.get(UsersService); const relations = await service.getRelations(context, external_id); @@ -2872,7 +2872,7 @@ describe('UsersService.getRelations', () => { expect(workflows[0].author_id).toBe(user2); } - const context = makeContext(external_id, 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(external_id, 'xxx-xxx-xxx-xxx', 'requestId'); const service = module.get(UsersService); const relations = await service.getRelations(context, external_id); @@ -2898,7 +2898,7 @@ describe('UsersService.getRelations', () => { try { const module = await makeTestingModule(source); if (!module) fail(); - const context = makeContext(uuidv4(), 'xxx.xxx.xxx.xxx', 'requestId'); + const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); const service = module.get(UsersService); await service.getRelations(context, 'external_id'); diff --git a/dictation_server/src/features/workflows/workflows.service.spec.ts b/dictation_server/src/features/workflows/workflows.service.spec.ts index 208b1f7..51c7b2d 100644 --- a/dictation_server/src/features/workflows/workflows.service.spec.ts +++ b/dictation_server/src/features/workflows/workflows.service.spec.ts @@ -120,7 +120,7 @@ describe('getWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -196,7 +196,7 @@ describe('getWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -222,7 +222,7 @@ describe('getWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -306,7 +306,7 @@ describe('createWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -375,7 +375,7 @@ describe('createWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -443,7 +443,7 @@ describe('createWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -505,7 +505,7 @@ describe('createWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -573,7 +573,7 @@ describe('createWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -650,7 +650,7 @@ describe('createWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); //実行結果を確認 @@ -711,7 +711,7 @@ describe('createWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -776,7 +776,7 @@ describe('createWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -840,7 +840,7 @@ describe('createWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -906,7 +906,7 @@ describe('createWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -978,7 +978,7 @@ describe('createWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -1044,7 +1044,7 @@ describe('createWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -1119,7 +1119,7 @@ describe('createWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -1190,7 +1190,7 @@ describe('createWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -1313,7 +1313,7 @@ describe('updateWorkflow', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -1407,7 +1407,7 @@ describe('updateWorkflow', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -1500,7 +1500,7 @@ describe('updateWorkflow', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -1587,7 +1587,7 @@ describe('updateWorkflow', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -1694,7 +1694,7 @@ describe('updateWorkflow', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -1777,7 +1777,7 @@ describe('updateWorkflow', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -1824,7 +1824,7 @@ describe('updateWorkflow', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -1902,7 +1902,7 @@ describe('updateWorkflow', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -1975,7 +1975,7 @@ describe('updateWorkflow', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -2047,7 +2047,7 @@ describe('updateWorkflow', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -2126,7 +2126,7 @@ describe('updateWorkflow', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -2211,7 +2211,7 @@ describe('updateWorkflow', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -2290,7 +2290,7 @@ describe('updateWorkflow', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -2363,7 +2363,7 @@ describe('updateWorkflow', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -2436,7 +2436,7 @@ describe('updateWorkflow', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -2531,7 +2531,7 @@ describe('deleteWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -2586,7 +2586,7 @@ describe('deleteWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -2641,7 +2641,7 @@ describe('deleteWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -2720,7 +2720,7 @@ describe('deleteWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); @@ -2779,7 +2779,7 @@ describe('deleteWorkflows', () => { const service = module.get(WorkflowsService); const context = makeContext( admin.external_id, - 'xxx.xxx.xxx.xxx', + 'xxx-xxx-xxx-xxx', 'requestId', ); From 6c6970c70a854e4cfa2d51855ffd16d25edaa273 Mon Sep 17 00:00:00 2001 From: "maruyama.t" Date: Tue, 12 Dec 2023 09:28:40 +0000 Subject: [PATCH 09/51] =?UTF-8?q?Merged=20PR=20622:=20delete=E3=81=A7?= =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=99?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3289: deleteでコメントを追加できるようにする](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3289) delete処理にSQLコメントを挿入する形にリファクタ レビューポイント repository/* に存在するdelete文は全て置き換えたはずだが、漏れはなさそうか --- .../src/common/repository/index.ts | 128 +++++++++++++++ .../accounts/accounts.repository.service.ts | 146 ++++++++++++------ .../tasks/tasks.repository.service.ts | 43 ++++-- .../user_groups.repository.service.ts | 13 +- .../users/users.repository.service.ts | 13 +- .../workflows/workflows.repository.service.ts | 20 ++- .../worktypes/worktypes.repository.service.ts | 17 +- 7 files changed, 302 insertions(+), 78 deletions(-) create mode 100644 dictation_server/src/common/repository/index.ts diff --git a/dictation_server/src/common/repository/index.ts b/dictation_server/src/common/repository/index.ts new file mode 100644 index 0000000..eda3501 --- /dev/null +++ b/dictation_server/src/common/repository/index.ts @@ -0,0 +1,128 @@ +import { + ObjectLiteral, + Repository, + EntityTarget, + UpdateResult, + DeleteResult, + UpdateQueryBuilder, + Brackets, + FindOptionsWhere, +} from 'typeorm'; +import { Context } from '../log'; + +/** + * VS Code上で型解析エラーが発生するため、typeorm内の型定義と同一の型定義をここに記述する + */ +type QueryDeepPartialEntity = _QueryDeepPartialEntity< + ObjectLiteral extends T ? unknown : T +>; +type _QueryDeepPartialEntity = { + [P in keyof T]?: + | (T[P] extends Array + ? Array<_QueryDeepPartialEntity> + : T[P] extends ReadonlyArray + ? ReadonlyArray<_QueryDeepPartialEntity> + : _QueryDeepPartialEntity) + | (() => string); +}; + +const insertEntity = async ( + entity: EntityTarget, + repository: Repository, + value: QueryDeepPartialEntity, + isCommentOut: boolean, + // context: Context, +): Promise => { + let query = repository.createQueryBuilder().insert().into(entity); + if (isCommentOut) { + query = query.comment( + `context.getTrackingId()_${new Date().toUTCString()}`, + ); + } + const result = await query.values(value).execute(); + + // 結果をもとにセレクトする + const inserted = await repository.findOne({ + where: { id: result.identifiers[0].id }, + }); + if (!inserted) { + throw new Error('Failed to insert entity'); + } + return inserted; +}; + +const insertEntities = async ( + entity: EntityTarget, + repository: Repository, + values: QueryDeepPartialEntity[], + isCommentOut: boolean, + // context: Context, +): Promise => { + let query = repository.createQueryBuilder().insert().into(entity); + if (isCommentOut) { + query = query.comment( + `context.getTrackingId()_${new Date().toUTCString()}`, + ); + } + const result = await query.values(values).execute(); + + // 挿入するレコードが0で、結果も0であれば、からの配列を返す + if (values.length === 0 && result.identifiers.length === 0) { + return []; + } + + // 挿入するレコード数と挿入されたレコード数が一致しない場合はエラー + if (result.identifiers.length !== values.length) { + throw new Error('Failed to insert entities'); + } + const where: FindOptionsWhere[] = result.identifiers.map((i) => { + return { id: i.id }; + }); + + // 結果をもとにセレクトする + const inserted = await repository.find({ + where, + }); + if (!inserted) { + throw new Error('Failed to insert entity'); + } + return inserted; +}; + +const updateEntity = async ( + repository: Repository, + criteria: + | string + | ((qb: UpdateQueryBuilder) => string) + | Brackets + | ObjectLiteral + | ObjectLiteral[], + values: QueryDeepPartialEntity, + isCommentOut: boolean, + // context: Context, +): Promise => { + let query = repository.createQueryBuilder().update(); + if (isCommentOut) { + query = query.comment( + `context.getTrackingId()_${new Date().toUTCString()}`, + ); + } + return await query.set(values).where(criteria).execute(); +}; + +const deleteEntity = async ( + repository: Repository, + criteria: string | Brackets | ObjectLiteral | ObjectLiteral[], + isCommentOut: boolean, + // context: Context, +): Promise => { + let query = repository.createQueryBuilder().delete(); + if (isCommentOut) { + query = query.comment( + `context.getTrackingId()_${new Date().toUTCString()}`, + ); + } + return await query.where(criteria).execute(); +}; + +export { insertEntity, insertEntities, updateEntity, deleteEntity }; diff --git a/dictation_server/src/repositories/accounts/accounts.repository.service.ts b/dictation_server/src/repositories/accounts/accounts.repository.service.ts index d7762bd..465f8f9 100644 --- a/dictation_server/src/repositories/accounts/accounts.repository.service.ts +++ b/dictation_server/src/repositories/accounts/accounts.repository.service.ts @@ -57,11 +57,12 @@ 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 { deleteEntity } from '../../common/repository'; @Injectable() export class AccountsRepositoryService { constructor(private dataSource: DataSource) {} - + // クエリログにコメントを出力するかどうか + private readonly isCommentOut = process.env.STAGE !== 'local'; /** * 管理ユーザー無しでアカウントを作成する * @param companyName @@ -196,13 +197,15 @@ export class AccountsRepositoryService { const usersRepo = entityManager.getRepository(User); const sortCriteriaRepo = entityManager.getRepository(SortCriteria); // ソート条件を削除 - await sortCriteriaRepo.delete({ - user_id: userId, - }); + await deleteEntity( + sortCriteriaRepo, + { user_id: userId }, + this.isCommentOut, + ); // プライマリ管理者を削除 - await usersRepo.delete({ id: userId }); + await deleteEntity(usersRepo, { id: userId }, this.isCommentOut); // アカウントを削除 - await accountsRepo.delete({ id: accountId }); + await deleteEntity(accountsRepo, { id: accountId }, this.isCommentOut); }); } @@ -741,7 +744,11 @@ export class AccountsRepositoryService { }, ); // 発行時に発行されたライセンスを削除する - await licenseRepo.delete({ order_id: targetOrder.id }); + await deleteEntity( + licenseRepo, + { order_id: targetOrder.id }, + this.isCommentOut, + ); }); } @@ -1017,13 +1024,14 @@ export class AccountsRepositoryService { // アカウントを削除 const accountRepo = entityManager.getRepository(Account); - await accountRepo.delete({ id: accountId }); - + await deleteEntity(accountRepo, { id: accountId }, this.isCommentOut); // ライセンス系(card_license_issue以外)のテーブルのレコードを削除する const orderRepo = entityManager.getRepository(LicenseOrder); - await orderRepo.delete({ - from_account_id: accountId, - }); + await deleteEntity( + orderRepo, + { from_account_id: accountId }, + this.isCommentOut, + ); const licenseRepo = entityManager.getRepository(License); const targetLicenses = await licenseRepo.find({ where: { @@ -1031,18 +1039,24 @@ export class AccountsRepositoryService { }, }); const cardLicenseRepo = entityManager.getRepository(CardLicense); - await cardLicenseRepo.delete({ - license_id: In(targetLicenses.map((license) => license.id)), - }); - await licenseRepo.delete({ - account_id: accountId, - }); + await deleteEntity( + cardLicenseRepo, + { license_id: In(targetLicenses.map((license) => license.id)) }, + this.isCommentOut, + ); + await deleteEntity( + licenseRepo, + { account_id: accountId }, + this.isCommentOut, + ); const LicenseAllocationHistoryRepo = entityManager.getRepository( LicenseAllocationHistory, ); - await LicenseAllocationHistoryRepo.delete({ - account_id: accountId, - }); + await deleteEntity( + LicenseAllocationHistoryRepo, + { account_id: accountId }, + this.isCommentOut, + ); // ワークタイプ系のテーブルのレコードを削除する const worktypeRepo = entityManager.getRepository(Worktype); @@ -1051,10 +1065,16 @@ export class AccountsRepositoryService { }); const optionItemRepo = entityManager.getRepository(OptionItem); - await optionItemRepo.delete({ - worktype_id: In(taggerWorktypes.map((worktype) => worktype.id)), - }); - await worktypeRepo.delete({ account_id: accountId }); + await deleteEntity( + optionItemRepo, + { worktype_id: In(taggerWorktypes.map((worktype) => worktype.id)) }, + this.isCommentOut, + ); + await deleteEntity( + worktypeRepo, + { account_id: accountId }, + this.isCommentOut, + ); // タスク系のテーブルのレコードを削除する const taskRepo = entityManager.getRepository(Task); @@ -1065,12 +1085,16 @@ export class AccountsRepositoryService { }); const checkoutPermissionRepo = entityManager.getRepository(CheckoutPermission); - await checkoutPermissionRepo.delete({ - task_id: In(targetTasks.map((task) => task.id)), - }); - await taskRepo.delete({ - account_id: accountId, - }); + await deleteEntity( + checkoutPermissionRepo, + { task_id: In(targetTasks.map((task) => task.id)) }, + this.isCommentOut, + ); + await deleteEntity( + taskRepo, + { account_id: accountId }, + this.isCommentOut, + ); // オーディオファイル系のテーブルのレコードを削除する const audioFileRepo = entityManager.getRepository(AudioFile); @@ -1080,12 +1104,18 @@ export class AccountsRepositoryService { }, }); const audioOptionItemsRepo = entityManager.getRepository(AudioOptionItem); - await audioOptionItemsRepo.delete({ - audio_file_id: In(targetaudioFiles.map((audioFile) => audioFile.id)), - }); - await audioFileRepo.delete({ - account_id: accountId, - }); + await deleteEntity( + audioOptionItemsRepo, + { + audio_file_id: In(targetaudioFiles.map((audioFile) => audioFile.id)), + }, + this.isCommentOut, + ); + await deleteEntity( + audioFileRepo, + { account_id: accountId }, + this.isCommentOut, + ); // ユーザーグループ系のテーブルのレコードを削除する const userGroupRepo = entityManager.getRepository(UserGroup); @@ -1095,28 +1125,42 @@ export class AccountsRepositoryService { }, }); const userGroupMemberRepo = entityManager.getRepository(UserGroupMember); - await userGroupMemberRepo.delete({ - user_group_id: In(targetUserGroup.map((userGroup) => userGroup.id)), - }); - await userGroupRepo.delete({ - account_id: accountId, - }); + await deleteEntity( + userGroupMemberRepo, + { + user_group_id: In(targetUserGroup.map((userGroup) => userGroup.id)), + }, + this.isCommentOut, + ); + await deleteEntity( + userGroupRepo, + { account_id: accountId }, + this.isCommentOut, + ); // テンプレートファイルテーブルのレコードを削除する const templateFileRepo = entityManager.getRepository(TemplateFile); - await templateFileRepo.delete({ account_id: accountId }); + await deleteEntity( + templateFileRepo, + { account_id: accountId }, + this.isCommentOut, + ); // ユーザテーブルのレコードを削除する const userRepo = entityManager.getRepository(User); - await userRepo.delete({ - account_id: accountId, - }); + await deleteEntity( + userRepo, + { account_id: accountId }, + this.isCommentOut, + ); // ソート条件のテーブルのレコードを削除する const sortCriteriaRepo = entityManager.getRepository(SortCriteria); - await sortCriteriaRepo.delete({ - user_id: In(users.map((user) => user.id)), - }); + await deleteEntity( + sortCriteriaRepo, + { user_id: In(users.map((user) => user.id)) }, + this.isCommentOut, + ); return users; }); } diff --git a/dictation_server/src/repositories/tasks/tasks.repository.service.ts b/dictation_server/src/repositories/tasks/tasks.repository.service.ts index d543609..693f0e2 100644 --- a/dictation_server/src/repositories/tasks/tasks.repository.service.ts +++ b/dictation_server/src/repositories/tasks/tasks.repository.service.ts @@ -41,9 +41,12 @@ 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 { deleteEntity } from '../../common/repository'; @Injectable() export class TasksRepositoryService { + //クエリログにコメントを出力するかどうか + private readonly isCommentOut = process.env.STAGE !== 'local'; constructor(private dataSource: DataSource) {} /** @@ -255,9 +258,13 @@ export class TasksRepositoryService { ); //対象のタスクに紐づくチェックアウト権限レコードを削除 - await checkoutRepo.delete({ - task_id: task.id, - }); + await deleteEntity( + checkoutRepo, + { + task_id: task.id, + }, + this.isCommentOut, + ); //対象のタスクチェックアウト権限を自身のユーザーIDで作成 await checkoutRepo.save({ @@ -374,9 +381,13 @@ export class TasksRepositoryService { // 対象タスクの文字起こし候補を削除 /* 対象タスクがInprogress,Pendingの状態の場合、文字起こし担当者個人指定のレコードのみだが、ユーザーIDの指定はしない (データの不整合があっても問題ないように)*/ - await checkoutPermissionRepo.delete({ - task_id: task.id, - }); + await deleteEntity( + checkoutPermissionRepo, + { + task_id: task.id, + }, + this.isCommentOut, + ); }); } @@ -908,9 +919,13 @@ export class TasksRepositoryService { // 当該タスクに紐づく既存checkoutPermissionをdelete const checkoutPermissionRepo = entityManager.getRepository(CheckoutPermission); - await checkoutPermissionRepo.delete({ - task_id: taskRecord.id, - }); + await deleteEntity( + checkoutPermissionRepo, + { + task_id: taskRecord.id, + }, + this.isCommentOut, + ); // 当該タスクに紐づく新規checkoutPermissionをinsert const checkoutPermissions: CheckoutPermission[] = assignees.map( @@ -1217,9 +1232,13 @@ export class TasksRepositoryService { entityManager.getRepository(CheckoutPermission); // 当該タスクに紐づく既存checkoutPermissionをdelete - await checkoutPermissionRepo.delete({ - task_id: task.id, - }); + await deleteEntity( + checkoutPermissionRepo, + { + task_id: task.id, + }, + this.isCommentOut, + ); // ルーティング候補ユーザーのチェックアウト権限を作成 const typistPermissions = typistUsers.map((typistUser) => { 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..e4fa49e 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,9 +5,12 @@ 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 { deleteEntity } from '../../common/repository'; @Injectable() export class UserGroupsRepositoryService { + //クエリログにコメントを出力するかどうか + private readonly isCommentOut = process.env.STAGE !== 'local'; constructor(private dataSource: DataSource) {} async getUserGroups(account_id: number): Promise { @@ -184,9 +187,13 @@ export class UserGroupsRepositoryService { await userGroupRepo.save(typistGroup); // user_group_membersテーブルから対象のタイピストグループのユーザーを削除する - await userGroupMemberRepo.delete({ - user_group_id: typistGroupId, - }); + await deleteEntity( + userGroupMemberRepo, + { + user_group_id: typistGroupId, + }, + this.isCommentOut, + ); const typistGroupMembers = userRecords.map((typist) => { return { diff --git a/dictation_server/src/repositories/users/users.repository.service.ts b/dictation_server/src/repositories/users/users.repository.service.ts index 8894656..3efbc50 100644 --- a/dictation_server/src/repositories/users/users.repository.service.ts +++ b/dictation_server/src/repositories/users/users.repository.service.ts @@ -36,9 +36,12 @@ import { Account } from '../accounts/entity/account.entity'; import { Workflow } from '../workflows/entity/workflow.entity'; import { Worktype } from '../worktypes/entity/worktype.entity'; import { Context } from '../../common/log'; +import { deleteEntity } from '../../common/repository'; @Injectable() export class UsersRepositoryService { + //クエリログにコメントを出力するかどうか + private readonly isCommentOut = process.env.STAGE !== 'local'; constructor(private dataSource: DataSource) {} /** @@ -433,11 +436,13 @@ export class UsersRepositoryService { const usersRepo = entityManager.getRepository(User); const sortCriteriaRepo = entityManager.getRepository(SortCriteria); // ソート条件を削除 - await sortCriteriaRepo.delete({ - user_id: userId, - }); + await deleteEntity( + sortCriteriaRepo, + { user_id: userId }, + this.isCommentOut, + ); // プライマリ管理者を削除 - await usersRepo.delete({ id: userId }); + await deleteEntity(usersRepo, { id: userId }, this.isCommentOut); }); } diff --git a/dictation_server/src/repositories/workflows/workflows.repository.service.ts b/dictation_server/src/repositories/workflows/workflows.repository.service.ts index a1ea660..d26c5a7 100644 --- a/dictation_server/src/repositories/workflows/workflows.repository.service.ts +++ b/dictation_server/src/repositories/workflows/workflows.repository.service.ts @@ -15,9 +15,12 @@ import { AuthorIdAndWorktypeIdPairAlreadyExistsError, WorkflowNotFoundError, } from './errors/types'; +import { deleteEntity } from '../../common/repository'; @Injectable() export class WorkflowsRepositoryService { + //クエリログにコメントを出力するかどうか + private readonly isCommentOut = process.env.STAGE !== 'local'; constructor(private dataSource: DataSource) {} /** @@ -274,8 +277,12 @@ export class WorkflowsRepositoryService { const workflowTypistsRepo = entityManager.getRepository(DbWorkflowTypist); // 既存データの削除 - await workflowTypistsRepo.delete({ workflow_id: workflowId }); - await workflowRepo.delete(workflowId); + await deleteEntity( + workflowTypistsRepo, + { workflow_id: workflowId }, + this.isCommentOut, + ); + await deleteEntity(workflowRepo, { id: workflowId }, this.isCommentOut); { // ワークフローの重複確認 @@ -336,9 +343,12 @@ export class WorkflowsRepositoryService { `workflow not found. id: ${workflowId}`, ); } - - await workflowTypistsRepo.delete({ workflow_id: workflowId }); - await workflowRepo.delete(workflowId); + await deleteEntity( + workflowTypistsRepo, + { workflow_id: workflowId }, + this.isCommentOut, + ); + await deleteEntity(workflowRepo, { id: workflowId }, this.isCommentOut); }); } diff --git a/dictation_server/src/repositories/worktypes/worktypes.repository.service.ts b/dictation_server/src/repositories/worktypes/worktypes.repository.service.ts index 38016c1..ff419cb 100644 --- a/dictation_server/src/repositories/worktypes/worktypes.repository.service.ts +++ b/dictation_server/src/repositories/worktypes/worktypes.repository.service.ts @@ -17,9 +17,12 @@ 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 { deleteEntity } from '../../common/repository'; @Injectable() export class WorktypesRepositoryService { + //クエリログにコメントを出力するかどうか + private readonly isCommentOut = process.env.STAGE !== 'local'; constructor(private dataSource: DataSource) {} /** @@ -203,10 +206,14 @@ export class WorktypesRepositoryService { // ワークタイプに紐づくオプションアイテムを削除 const optionItemRepo = entityManager.getRepository(OptionItem); - await optionItemRepo.delete({ worktype_id: id }); + await deleteEntity( + optionItemRepo, + { worktype_id: id }, + this.isCommentOut, + ); // ワークタイプを削除 - await worktypeRepo.delete({ id: id }); + await deleteEntity(worktypeRepo, { id: id }, this.isCommentOut); }); } @@ -281,7 +288,11 @@ export class WorktypesRepositoryService { }); // ワークタイプに紐づくオプションアイテムを削除してから再登録 - await optionItemRepo.delete({ worktype_id: worktypeId }); + await deleteEntity( + optionItemRepo, + { worktype_id: worktypeId }, + this.isCommentOut, + ); await optionItemRepo.save(optionItems); }); } From 934ee7f44d1bc82f6dc6223be4d7680702fadf93 Mon Sep 17 00:00:00 2001 From: "maruyama.t" Date: Tue, 12 Dec 2023 09:45:30 +0000 Subject: [PATCH 10/51] =?UTF-8?q?Merged=20PR=20626:=20Revert=20'delete?= =?UTF-8?q?=E3=81=A7=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=99=E3=82=8B'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3289: deleteでコメントを追加できるようにする](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3289) delete処理にSQLコメントを挿入する形にリファクタ レビューポイント repository/* に存在するdelete文は全て置き換えたはずだが、漏れはなさそうか Reverts !622 --- .../src/common/repository/index.ts | 128 --------------- .../accounts/accounts.repository.service.ts | 146 ++++++------------ .../tasks/tasks.repository.service.ts | 43 ++---- .../user_groups.repository.service.ts | 13 +- .../users/users.repository.service.ts | 13 +- .../workflows/workflows.repository.service.ts | 20 +-- .../worktypes/worktypes.repository.service.ts | 17 +- 7 files changed, 78 insertions(+), 302 deletions(-) delete mode 100644 dictation_server/src/common/repository/index.ts diff --git a/dictation_server/src/common/repository/index.ts b/dictation_server/src/common/repository/index.ts deleted file mode 100644 index eda3501..0000000 --- a/dictation_server/src/common/repository/index.ts +++ /dev/null @@ -1,128 +0,0 @@ -import { - ObjectLiteral, - Repository, - EntityTarget, - UpdateResult, - DeleteResult, - UpdateQueryBuilder, - Brackets, - FindOptionsWhere, -} from 'typeorm'; -import { Context } from '../log'; - -/** - * VS Code上で型解析エラーが発生するため、typeorm内の型定義と同一の型定義をここに記述する - */ -type QueryDeepPartialEntity = _QueryDeepPartialEntity< - ObjectLiteral extends T ? unknown : T ->; -type _QueryDeepPartialEntity = { - [P in keyof T]?: - | (T[P] extends Array - ? Array<_QueryDeepPartialEntity> - : T[P] extends ReadonlyArray - ? ReadonlyArray<_QueryDeepPartialEntity> - : _QueryDeepPartialEntity) - | (() => string); -}; - -const insertEntity = async ( - entity: EntityTarget, - repository: Repository, - value: QueryDeepPartialEntity, - isCommentOut: boolean, - // context: Context, -): Promise => { - let query = repository.createQueryBuilder().insert().into(entity); - if (isCommentOut) { - query = query.comment( - `context.getTrackingId()_${new Date().toUTCString()}`, - ); - } - const result = await query.values(value).execute(); - - // 結果をもとにセレクトする - const inserted = await repository.findOne({ - where: { id: result.identifiers[0].id }, - }); - if (!inserted) { - throw new Error('Failed to insert entity'); - } - return inserted; -}; - -const insertEntities = async ( - entity: EntityTarget, - repository: Repository, - values: QueryDeepPartialEntity[], - isCommentOut: boolean, - // context: Context, -): Promise => { - let query = repository.createQueryBuilder().insert().into(entity); - if (isCommentOut) { - query = query.comment( - `context.getTrackingId()_${new Date().toUTCString()}`, - ); - } - const result = await query.values(values).execute(); - - // 挿入するレコードが0で、結果も0であれば、からの配列を返す - if (values.length === 0 && result.identifiers.length === 0) { - return []; - } - - // 挿入するレコード数と挿入されたレコード数が一致しない場合はエラー - if (result.identifiers.length !== values.length) { - throw new Error('Failed to insert entities'); - } - const where: FindOptionsWhere[] = result.identifiers.map((i) => { - return { id: i.id }; - }); - - // 結果をもとにセレクトする - const inserted = await repository.find({ - where, - }); - if (!inserted) { - throw new Error('Failed to insert entity'); - } - return inserted; -}; - -const updateEntity = async ( - repository: Repository, - criteria: - | string - | ((qb: UpdateQueryBuilder) => string) - | Brackets - | ObjectLiteral - | ObjectLiteral[], - values: QueryDeepPartialEntity, - isCommentOut: boolean, - // context: Context, -): Promise => { - let query = repository.createQueryBuilder().update(); - if (isCommentOut) { - query = query.comment( - `context.getTrackingId()_${new Date().toUTCString()}`, - ); - } - return await query.set(values).where(criteria).execute(); -}; - -const deleteEntity = async ( - repository: Repository, - criteria: string | Brackets | ObjectLiteral | ObjectLiteral[], - isCommentOut: boolean, - // context: Context, -): Promise => { - let query = repository.createQueryBuilder().delete(); - if (isCommentOut) { - query = query.comment( - `context.getTrackingId()_${new Date().toUTCString()}`, - ); - } - return await query.where(criteria).execute(); -}; - -export { insertEntity, insertEntities, updateEntity, deleteEntity }; diff --git a/dictation_server/src/repositories/accounts/accounts.repository.service.ts b/dictation_server/src/repositories/accounts/accounts.repository.service.ts index 465f8f9..d7762bd 100644 --- a/dictation_server/src/repositories/accounts/accounts.repository.service.ts +++ b/dictation_server/src/repositories/accounts/accounts.repository.service.ts @@ -57,12 +57,11 @@ 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 { deleteEntity } from '../../common/repository'; + @Injectable() export class AccountsRepositoryService { constructor(private dataSource: DataSource) {} - // クエリログにコメントを出力するかどうか - private readonly isCommentOut = process.env.STAGE !== 'local'; + /** * 管理ユーザー無しでアカウントを作成する * @param companyName @@ -197,15 +196,13 @@ export class AccountsRepositoryService { const usersRepo = entityManager.getRepository(User); const sortCriteriaRepo = entityManager.getRepository(SortCriteria); // ソート条件を削除 - await deleteEntity( - sortCriteriaRepo, - { user_id: userId }, - this.isCommentOut, - ); + await sortCriteriaRepo.delete({ + user_id: userId, + }); // プライマリ管理者を削除 - await deleteEntity(usersRepo, { id: userId }, this.isCommentOut); + await usersRepo.delete({ id: userId }); // アカウントを削除 - await deleteEntity(accountsRepo, { id: accountId }, this.isCommentOut); + await accountsRepo.delete({ id: accountId }); }); } @@ -744,11 +741,7 @@ export class AccountsRepositoryService { }, ); // 発行時に発行されたライセンスを削除する - await deleteEntity( - licenseRepo, - { order_id: targetOrder.id }, - this.isCommentOut, - ); + await licenseRepo.delete({ order_id: targetOrder.id }); }); } @@ -1024,14 +1017,13 @@ export class AccountsRepositoryService { // アカウントを削除 const accountRepo = entityManager.getRepository(Account); - await deleteEntity(accountRepo, { id: accountId }, this.isCommentOut); + await accountRepo.delete({ id: accountId }); + // ライセンス系(card_license_issue以外)のテーブルのレコードを削除する const orderRepo = entityManager.getRepository(LicenseOrder); - await deleteEntity( - orderRepo, - { from_account_id: accountId }, - this.isCommentOut, - ); + await orderRepo.delete({ + from_account_id: accountId, + }); const licenseRepo = entityManager.getRepository(License); const targetLicenses = await licenseRepo.find({ where: { @@ -1039,24 +1031,18 @@ export class AccountsRepositoryService { }, }); const cardLicenseRepo = entityManager.getRepository(CardLicense); - await deleteEntity( - cardLicenseRepo, - { license_id: In(targetLicenses.map((license) => license.id)) }, - this.isCommentOut, - ); - await deleteEntity( - licenseRepo, - { account_id: accountId }, - this.isCommentOut, - ); + await cardLicenseRepo.delete({ + license_id: In(targetLicenses.map((license) => license.id)), + }); + await licenseRepo.delete({ + account_id: accountId, + }); const LicenseAllocationHistoryRepo = entityManager.getRepository( LicenseAllocationHistory, ); - await deleteEntity( - LicenseAllocationHistoryRepo, - { account_id: accountId }, - this.isCommentOut, - ); + await LicenseAllocationHistoryRepo.delete({ + account_id: accountId, + }); // ワークタイプ系のテーブルのレコードを削除する const worktypeRepo = entityManager.getRepository(Worktype); @@ -1065,16 +1051,10 @@ export class AccountsRepositoryService { }); const optionItemRepo = entityManager.getRepository(OptionItem); - await deleteEntity( - optionItemRepo, - { worktype_id: In(taggerWorktypes.map((worktype) => worktype.id)) }, - this.isCommentOut, - ); - await deleteEntity( - worktypeRepo, - { account_id: accountId }, - this.isCommentOut, - ); + await optionItemRepo.delete({ + worktype_id: In(taggerWorktypes.map((worktype) => worktype.id)), + }); + await worktypeRepo.delete({ account_id: accountId }); // タスク系のテーブルのレコードを削除する const taskRepo = entityManager.getRepository(Task); @@ -1085,16 +1065,12 @@ export class AccountsRepositoryService { }); const checkoutPermissionRepo = entityManager.getRepository(CheckoutPermission); - await deleteEntity( - checkoutPermissionRepo, - { task_id: In(targetTasks.map((task) => task.id)) }, - this.isCommentOut, - ); - await deleteEntity( - taskRepo, - { account_id: accountId }, - this.isCommentOut, - ); + await checkoutPermissionRepo.delete({ + task_id: In(targetTasks.map((task) => task.id)), + }); + await taskRepo.delete({ + account_id: accountId, + }); // オーディオファイル系のテーブルのレコードを削除する const audioFileRepo = entityManager.getRepository(AudioFile); @@ -1104,18 +1080,12 @@ export class AccountsRepositoryService { }, }); const audioOptionItemsRepo = entityManager.getRepository(AudioOptionItem); - await deleteEntity( - audioOptionItemsRepo, - { - audio_file_id: In(targetaudioFiles.map((audioFile) => audioFile.id)), - }, - this.isCommentOut, - ); - await deleteEntity( - audioFileRepo, - { account_id: accountId }, - this.isCommentOut, - ); + await audioOptionItemsRepo.delete({ + audio_file_id: In(targetaudioFiles.map((audioFile) => audioFile.id)), + }); + await audioFileRepo.delete({ + account_id: accountId, + }); // ユーザーグループ系のテーブルのレコードを削除する const userGroupRepo = entityManager.getRepository(UserGroup); @@ -1125,42 +1095,28 @@ export class AccountsRepositoryService { }, }); const userGroupMemberRepo = entityManager.getRepository(UserGroupMember); - await deleteEntity( - userGroupMemberRepo, - { - user_group_id: In(targetUserGroup.map((userGroup) => userGroup.id)), - }, - this.isCommentOut, - ); - await deleteEntity( - userGroupRepo, - { account_id: accountId }, - this.isCommentOut, - ); + await userGroupMemberRepo.delete({ + user_group_id: In(targetUserGroup.map((userGroup) => userGroup.id)), + }); + await userGroupRepo.delete({ + account_id: accountId, + }); // テンプレートファイルテーブルのレコードを削除する const templateFileRepo = entityManager.getRepository(TemplateFile); - await deleteEntity( - templateFileRepo, - { account_id: accountId }, - this.isCommentOut, - ); + await templateFileRepo.delete({ account_id: accountId }); // ユーザテーブルのレコードを削除する const userRepo = entityManager.getRepository(User); - await deleteEntity( - userRepo, - { account_id: accountId }, - this.isCommentOut, - ); + await userRepo.delete({ + account_id: accountId, + }); // ソート条件のテーブルのレコードを削除する const sortCriteriaRepo = entityManager.getRepository(SortCriteria); - await deleteEntity( - sortCriteriaRepo, - { user_id: In(users.map((user) => user.id)) }, - this.isCommentOut, - ); + await sortCriteriaRepo.delete({ + user_id: In(users.map((user) => user.id)), + }); return users; }); } diff --git a/dictation_server/src/repositories/tasks/tasks.repository.service.ts b/dictation_server/src/repositories/tasks/tasks.repository.service.ts index 693f0e2..d543609 100644 --- a/dictation_server/src/repositories/tasks/tasks.repository.service.ts +++ b/dictation_server/src/repositories/tasks/tasks.repository.service.ts @@ -41,12 +41,9 @@ 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 { deleteEntity } from '../../common/repository'; @Injectable() export class TasksRepositoryService { - //クエリログにコメントを出力するかどうか - private readonly isCommentOut = process.env.STAGE !== 'local'; constructor(private dataSource: DataSource) {} /** @@ -258,13 +255,9 @@ export class TasksRepositoryService { ); //対象のタスクに紐づくチェックアウト権限レコードを削除 - await deleteEntity( - checkoutRepo, - { - task_id: task.id, - }, - this.isCommentOut, - ); + await checkoutRepo.delete({ + task_id: task.id, + }); //対象のタスクチェックアウト権限を自身のユーザーIDで作成 await checkoutRepo.save({ @@ -381,13 +374,9 @@ export class TasksRepositoryService { // 対象タスクの文字起こし候補を削除 /* 対象タスクがInprogress,Pendingの状態の場合、文字起こし担当者個人指定のレコードのみだが、ユーザーIDの指定はしない (データの不整合があっても問題ないように)*/ - await deleteEntity( - checkoutPermissionRepo, - { - task_id: task.id, - }, - this.isCommentOut, - ); + await checkoutPermissionRepo.delete({ + task_id: task.id, + }); }); } @@ -919,13 +908,9 @@ export class TasksRepositoryService { // 当該タスクに紐づく既存checkoutPermissionをdelete const checkoutPermissionRepo = entityManager.getRepository(CheckoutPermission); - await deleteEntity( - checkoutPermissionRepo, - { - task_id: taskRecord.id, - }, - this.isCommentOut, - ); + await checkoutPermissionRepo.delete({ + task_id: taskRecord.id, + }); // 当該タスクに紐づく新規checkoutPermissionをinsert const checkoutPermissions: CheckoutPermission[] = assignees.map( @@ -1232,13 +1217,9 @@ export class TasksRepositoryService { entityManager.getRepository(CheckoutPermission); // 当該タスクに紐づく既存checkoutPermissionをdelete - await deleteEntity( - checkoutPermissionRepo, - { - task_id: task.id, - }, - this.isCommentOut, - ); + await checkoutPermissionRepo.delete({ + task_id: task.id, + }); // ルーティング候補ユーザーのチェックアウト権限を作成 const typistPermissions = typistUsers.map((typistUser) => { 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 e4fa49e..061e9e9 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,12 +5,9 @@ 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 { deleteEntity } from '../../common/repository'; @Injectable() export class UserGroupsRepositoryService { - //クエリログにコメントを出力するかどうか - private readonly isCommentOut = process.env.STAGE !== 'local'; constructor(private dataSource: DataSource) {} async getUserGroups(account_id: number): Promise { @@ -187,13 +184,9 @@ export class UserGroupsRepositoryService { await userGroupRepo.save(typistGroup); // user_group_membersテーブルから対象のタイピストグループのユーザーを削除する - await deleteEntity( - userGroupMemberRepo, - { - user_group_id: typistGroupId, - }, - this.isCommentOut, - ); + await userGroupMemberRepo.delete({ + user_group_id: typistGroupId, + }); const typistGroupMembers = userRecords.map((typist) => { return { diff --git a/dictation_server/src/repositories/users/users.repository.service.ts b/dictation_server/src/repositories/users/users.repository.service.ts index 3efbc50..8894656 100644 --- a/dictation_server/src/repositories/users/users.repository.service.ts +++ b/dictation_server/src/repositories/users/users.repository.service.ts @@ -36,12 +36,9 @@ import { Account } from '../accounts/entity/account.entity'; import { Workflow } from '../workflows/entity/workflow.entity'; import { Worktype } from '../worktypes/entity/worktype.entity'; import { Context } from '../../common/log'; -import { deleteEntity } from '../../common/repository'; @Injectable() export class UsersRepositoryService { - //クエリログにコメントを出力するかどうか - private readonly isCommentOut = process.env.STAGE !== 'local'; constructor(private dataSource: DataSource) {} /** @@ -436,13 +433,11 @@ export class UsersRepositoryService { const usersRepo = entityManager.getRepository(User); const sortCriteriaRepo = entityManager.getRepository(SortCriteria); // ソート条件を削除 - await deleteEntity( - sortCriteriaRepo, - { user_id: userId }, - this.isCommentOut, - ); + await sortCriteriaRepo.delete({ + user_id: userId, + }); // プライマリ管理者を削除 - await deleteEntity(usersRepo, { id: userId }, this.isCommentOut); + await usersRepo.delete({ id: userId }); }); } diff --git a/dictation_server/src/repositories/workflows/workflows.repository.service.ts b/dictation_server/src/repositories/workflows/workflows.repository.service.ts index d26c5a7..a1ea660 100644 --- a/dictation_server/src/repositories/workflows/workflows.repository.service.ts +++ b/dictation_server/src/repositories/workflows/workflows.repository.service.ts @@ -15,12 +15,9 @@ import { AuthorIdAndWorktypeIdPairAlreadyExistsError, WorkflowNotFoundError, } from './errors/types'; -import { deleteEntity } from '../../common/repository'; @Injectable() export class WorkflowsRepositoryService { - //クエリログにコメントを出力するかどうか - private readonly isCommentOut = process.env.STAGE !== 'local'; constructor(private dataSource: DataSource) {} /** @@ -277,12 +274,8 @@ export class WorkflowsRepositoryService { const workflowTypistsRepo = entityManager.getRepository(DbWorkflowTypist); // 既存データの削除 - await deleteEntity( - workflowTypistsRepo, - { workflow_id: workflowId }, - this.isCommentOut, - ); - await deleteEntity(workflowRepo, { id: workflowId }, this.isCommentOut); + await workflowTypistsRepo.delete({ workflow_id: workflowId }); + await workflowRepo.delete(workflowId); { // ワークフローの重複確認 @@ -343,12 +336,9 @@ export class WorkflowsRepositoryService { `workflow not found. id: ${workflowId}`, ); } - await deleteEntity( - workflowTypistsRepo, - { workflow_id: workflowId }, - this.isCommentOut, - ); - await deleteEntity(workflowRepo, { id: workflowId }, this.isCommentOut); + + await workflowTypistsRepo.delete({ workflow_id: workflowId }); + await workflowRepo.delete(workflowId); }); } diff --git a/dictation_server/src/repositories/worktypes/worktypes.repository.service.ts b/dictation_server/src/repositories/worktypes/worktypes.repository.service.ts index ff419cb..38016c1 100644 --- a/dictation_server/src/repositories/worktypes/worktypes.repository.service.ts +++ b/dictation_server/src/repositories/worktypes/worktypes.repository.service.ts @@ -17,12 +17,9 @@ 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 { deleteEntity } from '../../common/repository'; @Injectable() export class WorktypesRepositoryService { - //クエリログにコメントを出力するかどうか - private readonly isCommentOut = process.env.STAGE !== 'local'; constructor(private dataSource: DataSource) {} /** @@ -206,14 +203,10 @@ export class WorktypesRepositoryService { // ワークタイプに紐づくオプションアイテムを削除 const optionItemRepo = entityManager.getRepository(OptionItem); - await deleteEntity( - optionItemRepo, - { worktype_id: id }, - this.isCommentOut, - ); + await optionItemRepo.delete({ worktype_id: id }); // ワークタイプを削除 - await deleteEntity(worktypeRepo, { id: id }, this.isCommentOut); + await worktypeRepo.delete({ id: id }); }); } @@ -288,11 +281,7 @@ export class WorktypesRepositoryService { }); // ワークタイプに紐づくオプションアイテムを削除してから再登録 - await deleteEntity( - optionItemRepo, - { worktype_id: worktypeId }, - this.isCommentOut, - ); + await optionItemRepo.delete({ worktype_id: worktypeId }); await optionItemRepo.save(optionItems); }); } From b8b341679565db86834d1658adcfe181dc9b4c38 Mon Sep 17 00:00:00 2001 From: "makabe.t" Date: Wed, 13 Dec 2023 00:00:15 +0000 Subject: [PATCH 11/51] =?UTF-8?q?Merged=20PR=20625:=20=E3=82=BB=E3=83=AC?= =?UTF-8?q?=E3=82=AF=E3=83=88=E3=81=AE=E3=82=AF=E3=82=A8=E3=83=AA=E3=81=AB?= =?UTF-8?q?=E8=BF=BD=E8=B7=A1=E7=94=A8=E3=81=AEID=E3=81=A8=E5=AE=9F?= =?UTF-8?q?=E8=A1=8C=E6=97=A5=E6=99=82=E3=81=AE=E6=83=85=E5=A0=B1=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3288: セレクトのクエリに追跡用のIDと実行日時の情報を追加する](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3288) - リポジトリ内でのDB操作でSelect文となる部分にコメント(追跡ID_日時)を追加しました。 - `find`, `fineOne`, `count`を対象にしています。 - コメントを追加するにあたってContextをリポジトリメソッドの引数に追加しています。 ## レビューポイント - 対応箇所の漏れはないでしょうか? - コメントのつけ方は適切でしょうか? ## UIの変更 - なし ## 動作確認状況 - ローカルで確認 --- .../src/features/accounts/accounts.service.ts | 86 ++++++++++++++----- .../src/features/auth/auth.service.ts | 19 +++- .../src/features/files/files.service.ts | 29 +++++-- .../src/features/licenses/licenses.service.ts | 22 +++-- .../notification/notification.service.ts | 4 +- .../src/features/tasks/tasks.service.spec.ts | 10 ++- .../src/features/tasks/tasks.service.ts | 43 +++++++--- .../features/templates/templates.service.ts | 4 +- .../src/features/terms/terms.service.ts | 2 +- .../src/features/users/users.service.ts | 53 +++++++++--- .../features/workflows/workflows.service.ts | 16 +++- .../accounts/accounts.repository.service.ts | 73 ++++++++++++++-- .../licenses/licenses.repository.service.ts | 36 +++++++- .../sort_criteria.repository.service.ts | 9 +- .../tasks/tasks.repository.service.ts | 59 ++++++++++++- .../template_files.repository.service.ts | 9 +- .../terms/terms.repository.service.ts | 6 +- .../user_groups.repository.service.ts | 16 +++- .../users/users.repository.service.ts | 72 +++++++++++++--- .../workflows/workflows.repository.service.ts | 26 +++++- .../worktypes/worktypes.repository.service.ts | 32 ++++++- 21 files changed, 522 insertions(+), 104 deletions(-) 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) { From 45b2cad30cfe61bf5610b5a9e15874cefc127794 Mon Sep 17 00:00:00 2001 From: "saito.k" Date: Wed, 13 Dec 2023 01:07:36 +0000 Subject: [PATCH 12/51] =?UTF-8?q?Merged=20PR=20624:=20=E3=82=AF=E3=82=A8?= =?UTF-8?q?=E3=83=AA=E3=83=AD=E3=82=B0=E3=81=AB=E8=BF=BD=E8=B7=A1=E7=94=A8?= =?UTF-8?q?ID=E3=81=A8=E5=AE=9F=E8=A1=8C=E6=97=A5=E6=99=82=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=81=99=E3=82=8B=EF=BC=88=E5=90=84=E4=BD=9C?= =?UTF-8?q?=E6=A5=AD=E3=81=BE=E3=81=A8=E3=82=81=E3=83=96=E3=83=A9=E3=83=B3?= =?UTF-8?q?=E3=83=81=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3309: 修正をまとめる用のブランチ](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3309) - 元PBI or タスクへのリンク(内容・目的などはそちらにあるはず) - 何をどう変更したか、追加したライブラリなど - このPull Requestでの対象/対象外 - 影響範囲(他の機能にも影響があるか) ## レビューポイント - 特にレビューしてほしい箇所 - 軽微なものや自明なものは記載不要 - 修正範囲が大きい場合などに記載 - 全体的にや仕様を満たしているか等は本当に必要な時のみ記載 ## UIの変更 - Before/Afterのスクショなど - スクショ置き場 ## 動作確認状況 - ローカルで確認、develop環境で確認など ## 補足 - 相談、参考資料などがあれば --- .../src/common/repository/index.ts | 143 +++++ .../accounts/accounts.service.spec.ts | 498 +++++------------- .../src/features/accounts/accounts.service.ts | 4 +- .../src/features/auth/auth.service.spec.ts | 78 +-- .../src/features/files/files.service.spec.ts | 122 ++--- .../licenses/licenses.service.spec.ts | 58 +- .../notification/notification.service.spec.ts | 6 +- .../src/features/tasks/tasks.service.spec.ts | 164 +++--- .../templates/templates.service.spec.ts | 18 +- .../src/features/terms/terms.service.spec.ts | 10 +- .../src/features/users/users.controller.ts | 1 + .../src/features/users/users.service.spec.ts | 106 ++-- .../src/features/users/users.service.ts | 7 +- .../workflows/workflows.service.spec.ts | 222 ++------ .../src/gateways/sendgrid/sendgrid.service.ts | 2 +- .../accounts/accounts.repository.service.ts | 296 ++++++++--- .../licenses/licenses.repository.service.ts | 149 ++++-- .../sort_criteria.repository.service.ts | 12 +- .../tasks/tasks.repository.service.ts | 141 ++++- .../template_files.repository.service.ts | 17 +- .../user_groups.repository.service.ts | 57 +- .../users/users.repository.service.ts | 85 ++- .../workflows/workflows.repository.service.ts | 69 ++- .../worktypes/worktypes.repository.service.ts | 70 ++- 24 files changed, 1238 insertions(+), 1097 deletions(-) create mode 100644 dictation_server/src/common/repository/index.ts diff --git a/dictation_server/src/common/repository/index.ts b/dictation_server/src/common/repository/index.ts new file mode 100644 index 0000000..b3e21fa --- /dev/null +++ b/dictation_server/src/common/repository/index.ts @@ -0,0 +1,143 @@ +import { + ObjectLiteral, + Repository, + EntityTarget, + UpdateResult, + DeleteResult, + UpdateQueryBuilder, + Brackets, + FindOptionsWhere, +} from 'typeorm'; +import { Context } from '../log'; + +/** + * VS Code上で型解析エラーが発生するため、typeorm内の型定義と同一の型定義をここに記述する + */ +type QueryDeepPartialEntity = _QueryDeepPartialEntity< + ObjectLiteral extends T ? unknown : T +>; +type _QueryDeepPartialEntity = { + [P in keyof T]?: + | (T[P] extends Array + ? Array<_QueryDeepPartialEntity> + : T[P] extends ReadonlyArray + ? ReadonlyArray<_QueryDeepPartialEntity> + : _QueryDeepPartialEntity) + | (() => string); +}; + +interface InsertEntityOptions { + id: number; +} + +const insertEntity = async ( + entity: EntityTarget, + repository: Repository, + value: QueryDeepPartialEntity, + isCommentOut: boolean, + context: Context, +): Promise => { + let query = repository.createQueryBuilder().insert().into(entity); + if (isCommentOut) { + query = query.comment( + `${context.getTrackingId()}_${new Date().toUTCString()}`, + ); + } + const result = await query.values(value).execute(); + // result.identifiers[0].idがnumber型でない場合はエラー + if (typeof result.identifiers[0].id !== 'number') { + throw new Error('Failed to insert entity'); + } + const where: FindOptionsWhere = { id: result.identifiers[0].id } as T; + + // 結果をもとにセレクトする + const inserted = await repository.findOne({ + where, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, + }); + if (!inserted) { + throw new Error('Failed to insert entity'); + } + return inserted; +}; + +const insertEntities = async ( + entity: EntityTarget, + repository: Repository, + values: QueryDeepPartialEntity[], + isCommentOut: boolean, + context: Context, +): Promise => { + let query = repository.createQueryBuilder().insert().into(entity); + if (isCommentOut) { + query = query.comment( + `${context.getTrackingId()}_${new Date().toUTCString()}`, + ); + } + const result = await query.values(values).execute(); + + // 挿入するレコードが0で、結果も0であれば、からの配列を返す + if (values.length === 0 && result.identifiers.length === 0) { + return []; + } + + // 挿入するレコード数と挿入されたレコード数が一致しない場合はエラー + if (result.identifiers.length !== values.length) { + throw new Error('Failed to insert entities'); + } + const where: FindOptionsWhere[] = result.identifiers.map((i) => { + // idがnumber型でない場合はエラー + if (typeof i.id !== 'number') { + throw new Error('Failed to insert entities'); + } + return { id: i.id } as T; + }); + + // 結果をもとにセレクトする + const inserted = await repository.find({ + where, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, + }); + if (!inserted) { + throw new Error('Failed to insert entity'); + } + return inserted; +}; + +const updateEntity = async ( + repository: Repository, + criteria: + | string + | ((qb: UpdateQueryBuilder) => string) + | Brackets + | ObjectLiteral + | ObjectLiteral[], + values: QueryDeepPartialEntity, + isCommentOut: boolean, + context: Context, +): Promise => { + let query = repository.createQueryBuilder().update(); + if (isCommentOut) { + query = query.comment( + `${context.getTrackingId()}_${new Date().toUTCString()}`, + ); + } + return await query.set(values).where(criteria).execute(); +}; + +const deleteEntity = async ( + repository: Repository, + criteria: string | Brackets | ObjectLiteral | ObjectLiteral[], + isCommentOut: boolean, + context: Context, +): Promise => { + let query = repository.createQueryBuilder().delete(); + if (isCommentOut) { + query = query.comment( + `${context.getTrackingId()}_${new Date().toUTCString()}`, + ); + } + return await query.where(criteria).execute(); +}; + +export { insertEntity, insertEntities, updateEntity, deleteEntity }; diff --git a/dictation_server/src/features/accounts/accounts.service.spec.ts b/dictation_server/src/features/accounts/accounts.service.spec.ts index 3a50603..a21f1d6 100644 --- a/dictation_server/src/features/accounts/accounts.service.spec.ts +++ b/dictation_server/src/features/accounts/accounts.service.spec.ts @@ -136,7 +136,7 @@ describe('createAccount', () => { }); const { accountId, externalUserId, userId } = await service.createAccount( - makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('uuid', 'requestId'), companyName, country, dealerAccountId, @@ -213,7 +213,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('uuid', 'requestId'), companyName, country, dealerAccountId, @@ -285,7 +285,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('uuid', 'requestId'), companyName, country, dealerAccountId, @@ -346,7 +346,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('uuid', 'requestId'), companyName, country, dealerAccountId, @@ -377,7 +377,7 @@ describe('createAccount', () => { // ADB2Cユーザー削除メソッドが呼ばれているか確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('uuid', 'requestId'), ); }); it('アカウントを作成がDBへの通信失敗によって500エラーが発生した場合、リカバリ処理が実行されるが、ADB2Cユーザー削除で失敗した場合、500エラーが返却される', async () => { @@ -414,7 +414,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('uuid', 'requestId'), companyName, country, dealerAccountId, @@ -445,7 +445,7 @@ describe('createAccount', () => { // ADB2Cユーザー削除メソッドが呼ばれているか確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('uuid', 'requestId'), ); }); @@ -485,7 +485,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('uuid', 'requestId'), companyName, country, dealerAccountId, @@ -516,7 +516,7 @@ describe('createAccount', () => { // ADB2Cユーザー削除メソッドが呼ばれているか確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('uuid', 'requestId'), ); }); @@ -558,7 +558,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('uuid', 'requestId'), companyName, country, dealerAccountId, @@ -589,7 +589,7 @@ describe('createAccount', () => { // ADB2Cユーザー削除メソッドが呼ばれているか確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('uuid', 'requestId'), ); }); @@ -650,7 +650,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('uuid', 'requestId'), companyName, country, dealerAccountId, @@ -681,11 +681,11 @@ describe('createAccount', () => { // ADB2Cユーザー削除メソッドが呼ばれているか確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('uuid', 'requestId'), ); // Blobストレージのコンテナ削除メソッドが呼ばれているか確認 expect(blobstorageService.deleteContainer).toBeCalledWith( - makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('uuid', 'requestId'), 1, //新規作成したアカウントのID country, ); @@ -745,7 +745,7 @@ describe('createAccount', () => { try { await service.createAccount( - makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('uuid', 'requestId'), companyName, country, dealerAccountId, @@ -776,11 +776,11 @@ describe('createAccount', () => { // ADB2Cユーザー削除メソッドが呼ばれているか確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('uuid', 'requestId'), ); // Blobストレージのコンテナ削除メソッドが呼ばれているか確認 expect(blobstorageService.deleteContainer).toBeCalledWith( - makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('uuid', 'requestId'), 1, //新規作成したアカウントのID country, ); @@ -820,7 +820,7 @@ describe('createPartnerAccount', () => { { external_id: adminExternalId }, ); - const context = makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext('uuid', 'requestId'); const companyName = 'test_company_name'; const country = 'US'; const email = 'partner@example.com'; @@ -897,7 +897,7 @@ describe('createPartnerAccount', () => { { external_id: adminExternalId }, ); - const context = makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext('uuid', 'requestId'); const companyName = 'test_company_name'; const country = 'US'; const email = 'partner@example.com'; @@ -975,7 +975,7 @@ describe('createPartnerAccount', () => { { external_id: adminExternalId }, ); - const context = makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext('uuid', 'requestId'); const companyName = 'test_company_name'; const country = 'US'; const email = 'partner@example.com'; @@ -1064,7 +1064,7 @@ describe('createPartnerAccount', () => { { external_id: adminExternalId }, ); - const context = makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext('uuid', 'requestId'); const companyName = 'test_company_name'; const country = 'US'; const email = 'partner@example.com'; @@ -1154,11 +1154,7 @@ describe('createPartnerAccount', () => { { external_id: parentExternalId }, ); - const context = makeContext( - parentExternalId, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(parentExternalId, 'requestId'); const partnerExternalId = 'partner_external_id'; const companyName = 'partner_company_name'; const country = 'US'; @@ -1240,11 +1236,7 @@ describe('createPartnerAccount', () => { { external_id: parentExternalId }, ); - const context = makeContext( - parentExternalId, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(parentExternalId, 'requestId'); const partnerExternalId = 'partner_external_id'; const companyName = 'partner_company_name'; const country = 'US'; @@ -1336,11 +1328,7 @@ describe('createPartnerAccount', () => { { external_id: parentExternalId }, ); - const context = makeContext( - parentExternalId, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(parentExternalId, 'requestId'); const partnerExternalId = 'partner_external_id'; const companyName = 'partner_company_name'; const country = 'US'; @@ -1432,11 +1420,7 @@ describe('createPartnerAccount', () => { { external_id: parentExternalId }, ); - const context = makeContext( - parentExternalId, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(parentExternalId, 'requestId'); const partnerExternalId = 'partner_external_id'; const companyName = 'partner_company_name'; const country = 'US'; @@ -1531,7 +1515,7 @@ describe('createPartnerAccount', () => { { external_id: adminExternalId }, ); - const context = makeContext('uuid', 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext('uuid', 'requestId'); const companyName = 'test_company_name'; const country = 'US'; const email = 'partner@example.com'; @@ -1624,7 +1608,7 @@ describe('AccountsService', () => { licensesRepositoryMockValue, worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); expect(await service.getLicenseSummary(context, accountId)).toEqual( expectedAccountLisenceCounts, ); @@ -1657,7 +1641,7 @@ describe('AccountsService', () => { licensesRepositoryMockValue, worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect(service.getLicenseSummary(context, accountId)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -1692,7 +1676,7 @@ describe('AccountsService', () => { licensesRepositoryMockValue, worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); expect(await service.getTypists(context, externalId)).toEqual([ { id: 1, name: 'Typist1' }, { id: 2, name: 'Typist2' }, @@ -1726,7 +1710,7 @@ describe('AccountsService', () => { licensesRepositoryMockValue, worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect(service.getTypists(context, externalId)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -1761,7 +1745,7 @@ describe('AccountsService', () => { licensesRepositoryMockValue, worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect(service.getTypists(context, externalId)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -1797,7 +1781,7 @@ describe('AccountsService', () => { worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); expect(await service.getTypistGroups(context, externalId)).toEqual([ { id: 1, name: 'GroupA' }, { id: 2, name: 'GroupB' }, @@ -1831,7 +1815,7 @@ describe('AccountsService', () => { worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect(service.getTypistGroups(context, externalId)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -1867,7 +1851,7 @@ describe('AccountsService', () => { worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect(service.getTypistGroups(context, externalId)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -2050,7 +2034,7 @@ describe('getPartnerAccount', () => { const offset = 0; const limit = 20; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); const response = await service.getPartnerLicenses( context, limit, @@ -2197,7 +2181,7 @@ describe('getPartnerAccount', () => { const offset = 0; const limit = 20; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); const response = await service.getPartnerLicenses( context, limit, @@ -2296,7 +2280,7 @@ describe('getOrderHistories', () => { const offset = 1; const limit = 2; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); const response = await service.getOrderHistories( context, limit, @@ -2341,7 +2325,7 @@ describe('getOrderHistories', () => { licensesRepositoryMockValue, worktypesRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect( service.getOrderHistories(context, limit, offset, accountId), ).rejects.toEqual( @@ -2447,11 +2431,7 @@ describe('issueLicense', () => { new Date(now.getTime() + 60 * 60 * 1000), ); - const context = makeContext( - 'userId-parent', - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext('userId-parent', 'requestId'); // 注文を発行済みにする await service.issueLicense( @@ -2545,11 +2525,7 @@ describe('issueLicense', () => { new Date(now.getTime() + 60 * 60 * 1000), ); - const context = makeContext( - 'userId-parent', - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext('userId-parent', 'requestId'); // 注文を発行済みにする await service.issueLicense( @@ -2648,11 +2624,7 @@ describe('issueLicense', () => { new Date(now.getTime() + 60 * 60 * 1000), ); - const context = makeContext( - 'userId-parent', - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext('userId-parent', 'requestId'); // 注文を発行済みにする await expect( @@ -2716,7 +2688,7 @@ describe('getDealers', () => { }) ).account; const service = module.get(AccountsService); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); expect(await service.getDealers(context)).toEqual({ dealers: [ @@ -2745,7 +2717,7 @@ describe('getDealers', () => { const service = module.get(AccountsService); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); expect(await service.getDealers(context)).toEqual({ dealers: [], }); @@ -2809,11 +2781,7 @@ describe('createTypistGroup', () => { const service = module.get(AccountsService); const typistGroupName = 'typist-group-name'; const typistUserIds = userIds; - const context = makeContext( - adminExternalId, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(adminExternalId, 'requestId'); await service.createTypistGroup( context, adminExternalId, @@ -2877,11 +2845,7 @@ describe('createTypistGroup', () => { const service = module.get(AccountsService); const typistGroupName = 'typist-group-name'; const typistUserIds = userIds; - const context = makeContext( - adminExternalId, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(adminExternalId, 'requestId'); await expect( service.createTypistGroup( context, @@ -2932,11 +2896,7 @@ describe('createTypistGroup', () => { const service = module.get(AccountsService); const typistGroupName = 'typist-group-name'; const typistUserIds = [...userIds, 9999]; //存在しないユーザーIDを追加 - const context = makeContext( - adminExternalId, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(adminExternalId, 'requestId'); await expect( service.createTypistGroup( context, @@ -2988,11 +2948,7 @@ describe('createTypistGroup', () => { const service = module.get(AccountsService); const typistGroupName = 'typist-group-name'; const typistUserIds = [...userIds]; - const context = makeContext( - adminExternalId, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(adminExternalId, 'requestId'); await expect( service.createTypistGroup( context, @@ -3043,11 +2999,7 @@ describe('createTypistGroup', () => { const service = module.get(AccountsService); const typistGroupName = 'typist-group-name'; const typistUserIds = userIds; - const context = makeContext( - adminExternalId, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(adminExternalId, 'requestId'); //DBアクセスに失敗するようにする const typistGroupService = module.get( UserGroupsRepositoryService, @@ -3117,11 +3069,7 @@ describe('getTypistGroup', () => { const typistGroupName = 'typist-group-name'; const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await service.createTypistGroup( context, @@ -3181,11 +3129,7 @@ describe('getTypistGroup', () => { // アカウントにタイピストグループを作成する const typistGroupName = 'typist-group-name'; const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await service.createTypistGroup( context, admin.external_id, @@ -3240,11 +3184,7 @@ describe('getTypistGroup', () => { // アカウントにタイピストグループを作成する const typistGroupName = 'typist-group-name'; const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await service.createTypistGroup( context, @@ -3326,11 +3266,7 @@ describe('updateTypistGroup', () => { const service = module.get(AccountsService); const typistUserIds = [userIds[1]]; - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const typistGroupName = 'typist-group-name'; await service.createTypistGroup( context, @@ -3402,11 +3338,7 @@ describe('updateTypistGroup', () => { const typistGroupName = 'typist-group-name'; const service = module.get(AccountsService); const typistUserIds = [userIds[2]]; - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await service.createTypistGroup( context, @@ -3470,11 +3402,7 @@ describe('updateTypistGroup', () => { const typistGroupName = 'typist-group-name'; const service = module.get(AccountsService); const typistUserIds = [999]; - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await service.createTypistGroup( context, admin.external_id, @@ -3537,11 +3465,7 @@ describe('updateTypistGroup', () => { const typistGroupName = 'typist-group-name'; const service = module.get(AccountsService); const typistUserIds = [...userIds]; - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await service.createTypistGroup( context, admin.external_id, @@ -3604,11 +3528,7 @@ describe('updateTypistGroup', () => { const typistGroupName = 'typist-group-name'; const service = module.get(AccountsService); const typistUserIds = [userIds[1]]; - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await service.createTypistGroup( context, admin.external_id, @@ -3671,11 +3591,7 @@ describe('updateTypistGroup', () => { const typistGroupName = 'typist-group-name'; const service = module.get(AccountsService); const typistUserIds = [userIds[1]]; - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await service.createTypistGroup( context, admin.external_id, @@ -3751,11 +3667,7 @@ describe('getWorktypes', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await createWorktype(source, account.id, 'worktype1', 'description1', true); await createWorktype(source, account.id, 'worktype2'); @@ -3796,11 +3708,7 @@ describe('getWorktypes', () => { const { admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const resWorktypes = await service.getWorktypes(context, admin.external_id); @@ -3818,11 +3726,7 @@ describe('getWorktypes', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await createWorktype(source, account.id, 'worktype1', 'description1'); await createWorktype(source, account.id, 'worktype2'); @@ -3883,11 +3787,7 @@ describe('createWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); // Worktypeが未登録であることを確認 { @@ -3928,11 +3828,7 @@ describe('createWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const worktypeId = 'worktype1'; await createWorktype(source, account.id, worktypeId); @@ -3963,11 +3859,7 @@ describe('createWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); // あらかじめ最大登録数分のWorktypeを登録する for (let i = 0; i < WORKTYPE_MAX_COUNT; i++) { @@ -4000,11 +3892,7 @@ describe('createWorktype', () => { const { admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //DBアクセスに失敗するようにする const worktypeService = module.get( @@ -4052,11 +3940,7 @@ describe('updateWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const worktype = new Worktype(); worktype.custom_worktype_id = 'worktypeID1'; @@ -4105,11 +3989,7 @@ describe('updateWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const worktype = new Worktype(); worktype.custom_worktype_id = 'worktypeID1'; @@ -4156,11 +4036,7 @@ describe('updateWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const worktype1 = new Worktype(); worktype1.custom_worktype_id = 'worktypeID1'; worktype1.description = 'description1'; @@ -4222,11 +4098,7 @@ describe('updateWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const worktype = new Worktype(); worktype.custom_worktype_id = 'worktypeID1'; @@ -4274,11 +4146,7 @@ describe('updateWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const worktype = new Worktype(); worktype.custom_worktype_id = 'worktypeID1'; @@ -4351,11 +4219,7 @@ describe('deleteWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const { id: worktypeId1 } = await createWorktype( source, @@ -4403,11 +4267,7 @@ describe('deleteWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const { id: worktypeId1 } = await createWorktype( source, @@ -4454,11 +4314,7 @@ describe('deleteWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const { id: worktypeId1 } = await createWorktype( source, @@ -4502,11 +4358,7 @@ describe('deleteWorktype', () => { }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const { id: worktypeId1 } = await createWorktype( source, @@ -4550,11 +4402,7 @@ describe('deleteWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const { id: worktypeId1 } = await createWorktype( source, @@ -4619,11 +4467,7 @@ describe('getOptionItems', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const worktype = await createWorktype(source, account.id, 'worktype1'); const optionItems = await createOptionItems(source, worktype.id); @@ -4666,11 +4510,7 @@ describe('getOptionItems', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const worktype = await createWorktype(source, account.id, 'worktype1'); const optionItems = await createOptionItems(source, worktype.id); @@ -4705,11 +4545,7 @@ describe('getOptionItems', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const worktype = await createWorktype(source, account.id, 'worktype1'); const optionItems = await createOptionItems(source, worktype.id); @@ -4770,11 +4606,7 @@ describe('updateOptionItems', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const worktype = await createWorktype(source, account.id, 'worktype1'); const optionItems = await createOptionItems(source, worktype.id); @@ -4900,11 +4732,7 @@ describe('updateOptionItems', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const worktype = await createWorktype(source, account.id, 'worktype1'); const optionItems = await createOptionItems(source, worktype.id); @@ -4990,11 +4818,7 @@ describe('updateOptionItems', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const worktype = await createWorktype(source, account.id, 'worktype1'); const optionItems = await createOptionItems(source, worktype.id); @@ -5108,11 +4932,7 @@ describe('updateActiveWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const worktype = await createWorktype(source, account.id, 'worktype1'); @@ -5139,11 +4959,7 @@ describe('updateActiveWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const worktype1 = await createWorktype( source, @@ -5181,11 +4997,7 @@ describe('updateActiveWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const worktype1 = await createWorktype( source, @@ -5218,11 +5030,7 @@ describe('updateActiveWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await createWorktype(source, account.id, 'worktype1'); @@ -5255,11 +5063,7 @@ describe('updateActiveWorktype', () => { }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await createWorktype(source, account.id, 'worktype1'); await createWorktype(source, otherAccount.id, 'worktype2'); @@ -5298,11 +5102,7 @@ describe('updateActiveWorktype', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await createWorktype(source, account.id, 'worktype1'); @@ -5390,7 +5190,7 @@ describe('ライセンス発行キャンセル', () => { const service = module.get(AccountsService); await service.cancelIssue( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), tier1Accounts[0].users[0].external_id, poNumber, tier5Accounts.account.id, @@ -5453,7 +5253,7 @@ describe('ライセンス発行キャンセル', () => { const service = module.get(AccountsService); await service.cancelIssue( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), tier2Accounts[0].users[0].external_id, poNumber, tier5Accounts.account.id, @@ -5491,7 +5291,7 @@ describe('ライセンス発行キャンセル', () => { const service = module.get(AccountsService); await expect( service.cancelIssue( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), tier1Accounts[0].users[0].external_id, poNumber, tier5Accounts.account.id, @@ -5537,7 +5337,7 @@ describe('ライセンス発行キャンセル', () => { const service = module.get(AccountsService); await expect( service.cancelIssue( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), tier1Accounts[0].users[0].external_id, poNumber, tier5Accounts.account.id, @@ -5583,7 +5383,7 @@ describe('ライセンス発行キャンセル', () => { const service = module.get(AccountsService); await expect( service.cancelIssue( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), tier1Accounts[0].users[0].external_id, poNumber, tier5Accounts.account.id, @@ -5630,7 +5430,7 @@ describe('ライセンス発行キャンセル', () => { const service = module.get(AccountsService); await expect( service.cancelIssue( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), tier1Accounts[0].users[0].external_id, poNumber, tier5Accounts.account.id, @@ -5749,7 +5549,7 @@ describe('パートナー一覧取得', () => { }); const partners = await service.getPartners( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), tier1Accounts[0].users[0].external_id, 15, 0, @@ -5798,7 +5598,7 @@ describe('パートナー一覧取得', () => { }); const partners = await service.getPartners( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), account.admin.external_id, 15, 0, @@ -5840,7 +5640,7 @@ describe('アカウント情報更新', () => { tier: 5, }); await service.updateAccountInfo( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), tier5Accounts.admin.external_id, tier5Accounts.account.tier, true, @@ -5869,7 +5669,7 @@ describe('アカウント情報更新', () => { role: 'typist', }); await service.updateAccountInfo( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), tier4Accounts[0].users[0].external_id, tier4Accounts[0].account.tier, false, @@ -5899,7 +5699,7 @@ describe('アカウント情報更新', () => { role: 'typist', }); await service.updateAccountInfo( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), tier4Accounts[0].users[0].external_id, tier4Accounts[0].account.tier, false, @@ -5930,7 +5730,7 @@ describe('アカウント情報更新', () => { }); await expect( service.updateAccountInfo( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), tier4Accounts[0].users[0].external_id, tier4Accounts[0].account.tier, false, @@ -5956,7 +5756,7 @@ describe('アカウント情報更新', () => { }); await expect( service.updateAccountInfo( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), tier5Accounts.admin.external_id, tier5Accounts.account.tier, true, @@ -5982,7 +5782,7 @@ describe('アカウント情報更新', () => { }); await expect( service.updateAccountInfo( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), tier5Accounts.admin.external_id, tier5Accounts.account.tier, true, @@ -6027,11 +5827,7 @@ describe('getAccountInfo', () => { }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const accountResponse = await service.getAccountInfo( context, @@ -6110,11 +5906,7 @@ describe('getAuthors', () => { } const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const authors = await service.getAuthors(context, admin.external_id); //実行結果を確認 @@ -6154,11 +5946,7 @@ describe('getAuthors', () => { } const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const authors = await service.getAuthors(context, admin.external_id); //実行結果を確認 @@ -6182,11 +5970,7 @@ describe('getAuthors', () => { } const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const authors = await service.getAuthors(context, admin.external_id); //実行結果を確認 @@ -6202,11 +5986,7 @@ describe('getAuthors', () => { const { admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(AccountsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //DBアクセスに失敗するようにする const usersService = module.get( @@ -6289,7 +6069,7 @@ describe('getTypists', () => { ], }); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); const typists = await service.getTypists(context, admin.external_id); //実行結果を確認 @@ -6317,7 +6097,7 @@ describe('getTypists', () => { overrideAdB2cService(service, { getUsers: async () => [{ id: admin.external_id, displayName: '' }], }); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); const typists = await service.getTypists(context, admin.external_id); //実行結果を確認 @@ -6366,7 +6146,7 @@ describe('getTypists', () => { ], }); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); const typists = await service.getTypists(context, admin.external_id); //実行結果を確認 @@ -6393,7 +6173,7 @@ describe('getTypists', () => { UsersRepositoryService, ); usersService.findTypistUsers = jest.fn().mockRejectedValue('DB failed'); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); //実行結果を確認 try { @@ -6460,11 +6240,7 @@ describe('deleteAccountAndData', () => { account_id: tier5AccountsB.account.id, }); - const context = makeContext( - tier5AccountsA.admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(tier5AccountsA.admin.external_id, 'requestId'); // 第一階層~第五階層までのライセンス注文を作成 await createLicenseOrder( source, @@ -6645,11 +6421,7 @@ describe('deleteAccountAndData', () => { }); const account = account1; const admin = admin1; - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); // 第五階層のアカウント作成 const tier5Accounts = await makeTestAccount(source, { parent_account_id: account.id, @@ -6713,11 +6485,7 @@ describe('deleteAccountAndData', () => { }); const account = account1; const admin = admin1; - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); // 第五階層のアカウント作成 const tier5Accounts = await makeTestAccount(source, { parent_account_id: account.id, @@ -6772,11 +6540,7 @@ describe('deleteAccountAndData', () => { }); const account = account1; const admin = admin1; - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); // 第五階層のアカウント作成 const tier5Accounts = await makeTestAccount(source, { parent_account_id: account.id, @@ -6845,11 +6609,7 @@ describe('getAccountInfoMinimalAccess', () => { const { account, admin } = await makeTestAccount(source, { tier: 5, }); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); // 作成したデータを確認 { @@ -6874,11 +6634,7 @@ describe('getAccountInfoMinimalAccess', () => { const { account, admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); // 作成したデータを確認 { @@ -6903,11 +6659,7 @@ describe('getAccountInfoMinimalAccess', () => { const { account, admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); // 作成したデータを確認 { @@ -6935,11 +6687,7 @@ describe('getAccountInfoMinimalAccess', () => { const { account, admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); // 作成したデータを確認 { @@ -6996,11 +6744,7 @@ describe('getCompanyName', () => { tier: 5, company_name: 'testCompany', }); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const response = await service.getCompanyName(context, account.id); expect({ companyName: 'testCompany' }).toEqual(response); }); @@ -7015,11 +6759,7 @@ describe('getCompanyName', () => { tier: 5, company_name: 'testCompany', }); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); try { await service.getCompanyName(context, 123); } catch (e) { diff --git a/dictation_server/src/features/accounts/accounts.service.ts b/dictation_server/src/features/accounts/accounts.service.ts index 4bfffe5..373e7bc 100644 --- a/dictation_server/src/features/accounts/accounts.service.ts +++ b/dictation_server/src/features/accounts/accounts.service.ts @@ -229,6 +229,7 @@ export class AccountsService { // アカウントと管理者をセットで作成 const { newAccount, adminUser } = await this.accountRepository.createAccount( + context, companyName, country, dealerAccountId, @@ -377,7 +378,7 @@ export class AccountsService { } | params: { accountId: ${accountId}, userId: ${userId} };`, ); try { - await this.accountRepository.deleteAccount(accountId, userId); + await this.accountRepository.deleteAccount(context, accountId, userId); this.logger.log( `[${context.getTrackingId()}] delete account: ${accountId}, user: ${userId}`, ); @@ -801,6 +802,7 @@ export class AccountsService { // アカウントと管理者をセットで作成 const { newAccount, adminUser } = await this.accountRepository.createAccount( + context, companyName, country, myAccountId, diff --git a/dictation_server/src/features/auth/auth.service.spec.ts b/dictation_server/src/features/auth/auth.service.spec.ts index e5aabe9..856f719 100644 --- a/dictation_server/src/features/auth/auth.service.spec.ts +++ b/dictation_server/src/features/auth/auth.service.spec.ts @@ -31,7 +31,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdWVyIiwic3ViIjoic3ViIiwiYXVkIjoiYXVkIiwibm9uY2UiOiJkZWZhdWx0Tm9uY2UiLCJpYXQiOjEwMDAwMDAwMDAsImF1dGhfdGltZSI6MTAwMDAwMDAwMCwiZW1haWxzIjpbInh4eEB4eC5jb20iXSwidGZwIjoic2lnbmluX3VzZXJmbG93In0.RyieW-VHsHPQOjXbbhRc307AYJOc1sq2hrcu4SW1-K0pvLlkplepxvx02a3vCwQrnBYrIP5w6HExG-S_JgW5nYyWr6DeY11mA484n9KA8GeAcAXV37StH1gfWUJvfGb4C8BaMbMM9Ix4Z9NGwKA9vjNwevfmBZnz9lQUePgv6BJNmyvCt8ElJ01O-1WODbZuojJ4xXymA1OqluzfbphPOsqWTSNmTn0emkLjjnlMQf1iwM4C_kvvr8dUCFg0_UGDfQVJnzPEKB38UqnhLnC5WacrddDwQ0kBuGKZgZ_63Q_7fOvqAZivqLK7BPmbPxi6mx3R1S9Eq2ugzpY1LfJOjA'; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); expect(await service.getVerifiedIdToken(context, token)).toEqual( idTokenPayload, ); @@ -43,7 +43,7 @@ describe('AuthService', () => { const service = await makeAuthServiceMock(adb2cParam, configMockValue); const token = 'invalid.id.token'; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E000101'), HttpStatus.UNAUTHORIZED), ); @@ -58,7 +58,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjEwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdWVyIiwic3ViIjoic3ViIiwiYXVkIjoiYXVkIiwibm9uY2UiOiJkZWZhdWx0Tm9uY2UiLCJpYXQiOjEwMDAwMDAwMDAsImF1dGhfdGltZSI6MTAwMDAwMDAwMCwiZW1haWxzIjpbInh4eEB4eC5jb20iXSwidGZwIjoic2lnbmluX3VzZXJmbG93In0.r9x61Mf1S2qFgU_QDKB6tRFBmTQXyOEtpoacOlL_bQzFz1t3GsxMy6SJIvQQ-LtDgylQ1UCdMFiRuy4V8nyLuME0fR-9IkKsboGvwllHB_Isai3XFoja0jpDHMVby1m0B3Z9xOTb7YsaQGyEH-qs1TtnRm6Ny98h4Po80nK8HGefQZHBOlfQN_B1LiHwI3nLXV18NL-4olKXj2NloNRYtnWM0PaqDQcGvZFaSNvtrSYpo9ddD906QWDGVOQ7WvGSUgdNCoxX8Lb3r2-VSj6n84jpb-Y1Fz-GhLluNglAsBhasnJfUIvCIO3iG5pRyTYjHFAVHmzjr8xMOmhS3s41Jw'; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E000102'), HttpStatus.UNAUTHORIZED), ); @@ -73,7 +73,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6OTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdWVyIiwic3ViIjoic3ViIiwiYXVkIjoiYXVkIiwibm9uY2UiOiJkZWZhdWx0Tm9uY2UiLCJpYXQiOjEwMDAwMDAwMDAsImF1dGhfdGltZSI6MTAwMDAwMDAwMCwiZW1haWxzIjpbInh4eEB4eC5jb20iXSwidGZwIjoic2lnbmluX3VzZXJmbG93In0.fX2Gbd7fDPNE3Lw-xbum_5CVqQYqEmMhv_v5u8A-U81pmPD2P5rsJEJx66ns1taFLVaE3j9_OzotxrqjqqQqbACkagGcN5wvA3_ZIxyqmhrKYFJc53ZcO7d0pFWiQlluNBI_pnFNDlSMB2Ut8Th5aiPy2uamBM9wC99bcjo7HkHvTKBf6ljU6rPKoD51qGDWqNxjoH-hdSJ29wprvyxyk_yX6dp-cxXUj5DIgXYQuIZF71rdiPtGlAiyTBns8rS2QlEEXapZVlvYrK4mkpUXVDA7ifD8q6gAC2BStqHeys7CGp2MbV4ZwKCVbAUbMs6Tboh8rADZvQhuTEq7qlhZ-w'; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E000103'), HttpStatus.UNAUTHORIZED), ); @@ -86,7 +86,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdXNlciIsInN1YiI6InN1YiIsImF1ZCI6ImF1ZCIsIm5vbmNlIjoiZGVmYXVsdE5vbmNlIiwiaWF0IjoxMDAwMDAwMDAwLCJhdXRoX3RpbWUiOjEwMDAwMDAwMDAsImVtYWlscyI6WyJ4eHhAeHguY29tIl0sInRmcCI6InNpZ25pbl91c2VyZmxvdyJ9.sign'; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E000104'), HttpStatus.UNAUTHORIZED), ); @@ -101,7 +101,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaW52bGlkX2lzc3VlciIsInN1YiI6InN1YiIsImF1ZCI6ImF1ZCIsIm5vbmNlIjoiZGVmYXVsdE5vbmNlIiwiaWF0IjoxMDAwMDAwMDAwLCJhdXRoX3RpbWUiOjEwMDAwMDAwMDAsImVtYWlscyI6WyJ4eHhAeHguY29tIl0sInRmcCI6InNpZ25pbl91c2VyZmxvdyJ9.0bp3e1mDG78PX3lo8zgOLXGenIqG_Vi6kw7CbwauAQM-cnUZ_aVCoJ_dAv_QmPElOQKcCkRrAvAZ91FwuHDlBGuuDqx8OwqN0VaD-4NPouoAswj-9HNvBm8gUn-pGaXkvWt_72UdCJavZJjDj_RHur8y8kFt5Qeab3mUP2x-uNcV2Q2x3M_IIfcRiIZkRZm_azKfiVIy7tzoUFLDss97y938aR8imMVxazoSQvj7RWIWylgeRr9yVt7qYl18cnEVL0IGtslFbqhfNsiEmRCMsttm5kXs7E9B0bhhUe_xbJW9VumQ6G7dgMrswevp_jRgbpWJoZsgErtqIRl9Tc9ikA'; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E000105'), HttpStatus.UNAUTHORIZED), ); @@ -115,7 +115,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdWVyIiwic3ViIjoic3ViIiwiYXVkIjoiYXVkIiwibm9uY2UiOiJkZWZhdWx0Tm9uY2UiLCJpYXQiOjEwMDAwMDAwMDAsImF1dGhfdGltZSI6MTAwMDAwMDAwMCwiZW1haWxzIjpbInh4eEB4eC5jb20iXSwidGZwIjoic2lnbmluX3VzZXJmbG93In0.RyieW-VHsHPQOjXbbhRc307AYJOc1sq2hrcu4SW1-K0pvLlkplepxvx02a3vCwQrnBYrIP5w6HExG-S_JgW5nYyWr6DeY11mA484n9KA8GeAcAXV37StH1gfWUJvfGb4C8BaMbMM9Ix4Z9NGwKA9vjNwevfmBZnz9lQUePgv6BJNmyvCt8ElJ01O-1WODbZuojJ4xXymA1OqluzfbphPOsqWTSNmTn0emkLjjnlMQf1iwM4C_kvvr8dUCFg0_UGDfQVJnzPEKB38UqnhLnC5WacrddDwQ0kBuGKZgZ_63Q_7fOvqAZivqLK7BPmbPxi6mx3R1S9Eq2ugzpY1LfJOjA'; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -131,7 +131,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdWVyIiwic3ViIjoic3ViIiwiYXVkIjoiYXVkIiwibm9uY2UiOiJkZWZhdWx0Tm9uY2UiLCJpYXQiOjEwMDAwMDAwMDAsImF1dGhfdGltZSI6MTAwMDAwMDAwMCwiZW1haWxzIjpbInh4eEB4eC5jb20iXSwidGZwIjoic2lnbmluX3VzZXJmbG93In0.RyieW-VHsHPQOjXbbhRc307AYJOc1sq2hrcu4SW1-K0pvLlkplepxvx02a3vCwQrnBYrIP5w6HExG-S_JgW5nYyWr6DeY11mA484n9KA8GeAcAXV37StH1gfWUJvfGb4C8BaMbMM9Ix4Z9NGwKA9vjNwevfmBZnz9lQUePgv6BJNmyvCt8ElJ01O-1WODbZuojJ4xXymA1OqluzfbphPOsqWTSNmTn0emkLjjnlMQf1iwM4C_kvvr8dUCFg0_UGDfQVJnzPEKB38UqnhLnC5WacrddDwQ0kBuGKZgZ_63Q_7fOvqAZivqLK7BPmbPxi6mx3R1S9Eq2ugzpY1LfJOjA'; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -150,7 +150,7 @@ describe('AuthService', () => { const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtpZCJ9.eyJleHAiOjkwMDAwMDAwMDAsIm5iZiI6MTAwMDAwMDAwMCwidmVyIjoiMS4wIiwiaXNzIjoiaXNzdWVyIiwic3ViIjoic3ViIiwiYXVkIjoiYXVkIiwibm9uY2UiOiJkZWZhdWx0Tm9uY2UiLCJpYXQiOjEwMDAwMDAwMDAsImF1dGhfdGltZSI6MTAwMDAwMDAwMCwiZW1haWxzIjpbInh4eEB4eC5jb20iXSwidGZwIjoic2lnbmluX3VzZXJmbG93In0.RyieW-VHsHPQOjXbbhRc307AYJOc1sq2hrcu4SW1-K0pvLlkplepxvx02a3vCwQrnBYrIP5w6HExG-S_JgW5nYyWr6DeY11mA484n9KA8GeAcAXV37StH1gfWUJvfGb4C8BaMbMM9Ix4Z9NGwKA9vjNwevfmBZnz9lQUePgv6BJNmyvCt8ElJ01O-1WODbZuojJ4xXymA1OqluzfbphPOsqWTSNmTn0emkLjjnlMQf1iwM4C_kvvr8dUCFg0_UGDfQVJnzPEKB38UqnhLnC5WacrddDwQ0kBuGKZgZ_63Q_7fOvqAZivqLK7BPmbPxi6mx3R1S9Eq2ugzpY1LfJOjA'; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect(service.getVerifiedIdToken(context, token)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -186,7 +186,7 @@ describe('checkIsAcceptedLatestVersion', () => { const { admin } = await makeTestAccount(source, { tier: 5, }); - const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(uuidv4(), 'requestId'); const idToken = { emails: [], @@ -210,7 +210,7 @@ describe('checkIsAcceptedLatestVersion', () => { const { admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(uuidv4(), 'requestId'); const idToken = { emails: [], @@ -234,7 +234,7 @@ describe('checkIsAcceptedLatestVersion', () => { const { admin } = await makeTestAccount(source, { tier: 5, }); - const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(uuidv4(), 'requestId'); const idToken = { emails: [], @@ -258,7 +258,7 @@ describe('checkIsAcceptedLatestVersion', () => { const { admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(uuidv4(), 'requestId'); const idToken = { emails: [], @@ -282,7 +282,7 @@ describe('checkIsAcceptedLatestVersion', () => { const { admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(uuidv4(), 'requestId'); const idToken = { emails: [], @@ -306,7 +306,7 @@ describe('checkIsAcceptedLatestVersion', () => { const { admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(uuidv4(), 'requestId'); const idToken = { emails: [], @@ -361,11 +361,7 @@ describe('generateDelegationRefreshToken', () => { { role: USER_ROLES.NONE }, ); - const context = makeContext( - parentAdmin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(parentAdmin.external_id, 'requestId'); const delegationRefreshToken = await service.generateDelegationRefreshToken( context, @@ -403,11 +399,7 @@ describe('generateDelegationRefreshToken', () => { { role: USER_ROLES.NONE }, ); - const context = makeContext( - parentAdmin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(parentAdmin.external_id, 'requestId'); try { await service.generateDelegationRefreshToken( @@ -445,11 +437,7 @@ describe('generateDelegationRefreshToken', () => { { role: USER_ROLES.NONE }, ); - const context = makeContext( - parentAdmin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(parentAdmin.external_id, 'requestId'); try { await service.generateDelegationRefreshToken( @@ -507,11 +495,7 @@ describe('generateDelegationAccessToken', () => { { role: USER_ROLES.NONE }, ); - const context = makeContext( - parentAdmin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(parentAdmin.external_id, 'requestId'); const delegationRefreshToken = await service.generateDelegationRefreshToken( context, @@ -556,11 +540,7 @@ describe('generateDelegationAccessToken', () => { tier: 4, }); - const context = makeContext( - parentAdmin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(parentAdmin.external_id, 'requestId'); try { await service.generateDelegationAccessToken(context, 'invalid token'); @@ -615,11 +595,7 @@ describe('updateDelegationAccessToken', () => { { role: USER_ROLES.NONE }, ); - const context = makeContext( - parentAdmin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(parentAdmin.external_id, 'requestId'); const delegationRefreshToken = await service.generateDelegationRefreshToken( context, @@ -677,11 +653,7 @@ describe('updateDelegationAccessToken', () => { { role: USER_ROLES.NONE }, ); - const context = makeContext( - parentAdmin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(parentAdmin.external_id, 'requestId'); const delegationRefreshToken = await service.generateDelegationRefreshToken( context, @@ -747,11 +719,7 @@ describe('updateDelegationAccessToken', () => { { role: USER_ROLES.NONE }, ); - const context = makeContext( - parentAdmin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(parentAdmin.external_id, 'requestId'); const delegationRefreshToken = await service.generateDelegationRefreshToken( context, diff --git a/dictation_server/src/features/files/files.service.spec.ts b/dictation_server/src/features/files/files.service.spec.ts index 660b0ba..d32d081 100644 --- a/dictation_server/src/features/files/files.service.spec.ts +++ b/dictation_server/src/features/files/files.service.spec.ts @@ -85,7 +85,7 @@ describe('publishUploadSas', () => { null, null, ); - const context = makeContext(externalId, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(externalId, 'requestId'); const baseUrl = `https://saodmsusdev.blob.core.windows.net/account-${account.id}/${userId}`; //SASトークンを返却する @@ -107,11 +107,7 @@ describe('publishUploadSas', () => { // 第四階層のアカウント作成 const { admin } = await makeTestAccount(source, { tier: 4 }); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //Blobコンテナ存在チェックに失敗するようにする overrideBlobstorageService(service, { @@ -139,11 +135,7 @@ describe('publishUploadSas', () => { // 第四階層のアカウント作成 const { admin } = await makeTestAccount(source, { tier: 4 }); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //BlobのSASトークン生成に失敗するようにする overrideBlobstorageService(service, { @@ -172,11 +164,7 @@ describe('publishUploadSas', () => { // 第五階層のアカウント作成 const { admin } = await makeTestAccount(source, { tier: 5, locked: true }); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); try { await service.publishUploadSas(context, admin.external_id); @@ -222,7 +210,7 @@ describe('publishUploadSas', () => { await expect( service.publishUploadSas( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), externalId, ), ).rejects.toEqual( @@ -283,7 +271,7 @@ describe('publishUploadSas', () => { await expect( service.publishUploadSas( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), externalId, ), ).rejects.toEqual( @@ -366,7 +354,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { NotificationhubService, ); const result = await service.uploadFinished( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), authorExternalId, 'http://blob/url/file.zip', authorAuthorId ?? '', @@ -386,7 +374,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { expect(result).toEqual({ jobNumber: '00000001' }); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), [`user_${typistUserId}`], { authorId: 'AUTHOR_ID', @@ -467,7 +455,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { NotificationhubService, ); const result = await service.uploadFinished( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), authorExternalId, 'http://blob/url/file.zip', authorAuthorId ?? '', @@ -487,7 +475,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { expect(result).toEqual({ jobNumber: '00000002' }); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), [`user_${typistUserId}`], { authorId: 'AUTHOR_ID', @@ -590,7 +578,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { NotificationhubService, ); const result = await service.uploadFinished( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), myExternalId, // API実行者のユーザーIDを設定 'http://blob/url/file.zip', authorAuthorId ?? '', // 音声ファイルの情報には、録音者のAuthorIDが入る @@ -610,7 +598,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { expect(result).toEqual({ jobNumber: '00000001' }); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), [`user_${typistUserId}`], { authorId: 'AUTHOR_ID', @@ -712,7 +700,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { NotificationhubService, ); const result = await service.uploadFinished( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), myExternalId, // API実行者のユーザーIDを設定 'http://blob/url/file.zip', 'XXXXXXXXXX', // 音声ファイルの情報には、録音者のAuthorIDが入る @@ -732,7 +720,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { expect(result).toEqual({ jobNumber: '00000001' }); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), [`user_${typistUserId}`], { authorId: 'XXXXXXXXXX', @@ -781,7 +769,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { const service = module.get(FilesService); const result = await service.uploadFinished( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), authorExternalId, // API実行者のユーザーIDを設定 'http://blob/url/file.zip', authorAuthorId ?? '', // 音声ファイルの情報には、録音者のAuthorIDが入る @@ -837,7 +825,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { await expect( service.uploadFinished( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), authorExternalId, 'http://blob/url/file.zip', authorAuthorId ?? '', @@ -884,7 +872,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { await expect( service.uploadFinished( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), authorExternalId, 'http://blob/url/file.zip', authorAuthorId ?? '', @@ -925,7 +913,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { await expect( service.uploadFinished( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 'authorExternalId', 'http://blob/url/file.zip', 'authorAuthorId', @@ -976,7 +964,7 @@ describe('タスク作成から自動ルーティング(DB使用)', () => { await expect( service.uploadFinished( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), authorExternalId, 'http://blob/url/file.zip', authorAuthorId ?? '', @@ -1061,7 +1049,7 @@ describe('音声ファイルダウンロードURL取得', () => { expect( await service.publishAudioFileDownloadSas( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), externalId, audioFileId, ), @@ -1131,7 +1119,7 @@ describe('音声ファイルダウンロードURL取得', () => { expect( await service.publishAudioFileDownloadSas( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), externalId, audioFileId, ), @@ -1178,7 +1166,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishAudioFileDownloadSas( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), externalId, audioFileId, ), @@ -1232,7 +1220,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('tracking', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('tracking', 'requestId'), externalId, audioFileId, ), @@ -1277,7 +1265,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishAudioFileDownloadSas( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), externalId, audioFileId, ), @@ -1309,7 +1297,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishAudioFileDownloadSas( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), externalId, 1, ), @@ -1358,7 +1346,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishAudioFileDownloadSas( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), externalId, audioFileId, ), @@ -1413,7 +1401,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishAudioFileDownloadSas( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), externalId, audioFileId, ), @@ -1485,7 +1473,7 @@ describe('音声ファイルダウンロードURL取得', () => { await expect( service.publishAudioFileDownloadSas( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), externalId, audioFileId, ), @@ -1553,7 +1541,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { expect( await service.publishTemplateFileDownloadSas( - makeContext('tracking', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('tracking', 'requestId'), externalId, audioFileId, ), @@ -1623,7 +1611,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { expect( await service.publishTemplateFileDownloadSas( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), externalId, audioFileId, ), @@ -1664,7 +1652,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('tracking', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('tracking', 'requestId'), externalId, audioFileId, ), @@ -1714,7 +1702,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('tracking', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('tracking', 'requestId'), externalId, audioFileId, ), @@ -1759,7 +1747,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('tracking', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('tracking', 'requestId'), externalId, audioFileId, ), @@ -1791,7 +1779,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('tracking', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('tracking', 'requestId'), externalId, 1, ), @@ -1839,7 +1827,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('tracking', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('tracking', 'requestId'), externalId, audioFileId, ), @@ -1894,7 +1882,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), externalId, audioFileId, ), @@ -1966,7 +1954,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { await expect( service.publishTemplateFileDownloadSas( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), externalId, audioFileId, ), @@ -2003,11 +1991,7 @@ describe('publishTemplateFileUploadSas', () => { // 第五階層のアカウント作成 const { account, admin } = await makeTestAccount(source, { tier: 5 }); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const baseUrl = `https://saodmsusdev.blob.core.windows.net/account-${account.id}/Templates`; //SASトークンを返却する @@ -2032,11 +2016,7 @@ describe('publishTemplateFileUploadSas', () => { // 第五階層のアカウント作成 const { admin } = await makeTestAccount(source, { tier: 5 }); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //Blobコンテナ存在チェックに失敗するようにする overrideBlobstorageService(service, { @@ -2064,11 +2044,7 @@ describe('publishTemplateFileUploadSas', () => { // 第五階層のアカウント作成 const { admin } = await makeTestAccount(source, { tier: 5 }); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //BlobのSASトークン生成に失敗するようにする overrideBlobstorageService(service, { @@ -2117,11 +2093,7 @@ describe('templateUploadFinished', () => { const service = module.get(FilesService); // 第五階層のアカウント作成 const { account, admin } = await makeTestAccount(source, { tier: 5 }); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const fileName = 'test.docs'; const url = `https://blob.url/account-${account.id}/Templates`; @@ -2155,11 +2127,7 @@ describe('templateUploadFinished', () => { const service = module.get(FilesService); // 第五階層のアカウント作成 const { account, admin } = await makeTestAccount(source, { tier: 5 }); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const fileName = 'test.docs'; const url = `https://blob.url/account-${account.id}/Templates`; @@ -2199,11 +2167,7 @@ describe('templateUploadFinished', () => { const service = module.get(FilesService); // 第五階層のアカウント作成 const { account, admin } = await makeTestAccount(source, { tier: 5 }); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const fileName = 'test.docs'; const url = `https://blob.url/account-${account.id}/Templates`; diff --git a/dictation_server/src/features/licenses/licenses.service.spec.ts b/dictation_server/src/features/licenses/licenses.service.spec.ts index b6eb33b..26efeae 100644 --- a/dictation_server/src/features/licenses/licenses.service.spec.ts +++ b/dictation_server/src/features/licenses/licenses.service.spec.ts @@ -1,4 +1,3 @@ -import { AccessToken } from '../../common/token'; import { CreateOrdersRequest, IssueCardLicensesRequest, @@ -59,7 +58,7 @@ describe('LicensesService', () => { const userId = '0001'; body.orderCount = 1000; body.poNumber = '1'; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); expect( await service.licenseOrders( context, @@ -87,7 +86,7 @@ describe('LicensesService', () => { const userId = ''; body.orderCount = 1000; body.poNumber = '1'; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect( service.licenseOrders(context, userId, body.poNumber, body.orderCount), ).rejects.toEqual( @@ -115,7 +114,7 @@ describe('LicensesService', () => { const userId = '0001'; body.orderCount = 1000; body.poNumber = '1'; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect( service.licenseOrders(context, userId, body.poNumber, body.orderCount), ).rejects.toEqual( @@ -143,7 +142,7 @@ describe('LicensesService', () => { const userId = '0001'; body.orderCount = 1000; body.poNumber = '1'; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect( service.licenseOrders(context, userId, body.poNumber, body.orderCount), ).rejects.toEqual( @@ -181,7 +180,7 @@ describe('LicensesService', () => { 'AEJWRFFSWRQYQQJ6WVLV', ], }; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); expect( await service.issueCardLicenseKeys(context, userId, body.createCount), ).toEqual(issueCardLicensesResponse); @@ -201,7 +200,7 @@ describe('LicensesService', () => { const body = new IssueCardLicensesRequest(); const userId = '0001'; body.createCount = 1000; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect( service.issueCardLicenseKeys(context, userId, body.createCount), ).rejects.toEqual( @@ -225,7 +224,7 @@ describe('LicensesService', () => { const body = new ActivateCardLicensesRequest(); const userId = '0001'; body.cardLicenseKey = 'WZCETXC0Z9PQZ9GKRGGY'; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); expect( await service.activateCardLicenseKey( context, @@ -249,7 +248,7 @@ describe('LicensesService', () => { const body = new ActivateCardLicensesRequest(); const userId = '0001'; body.cardLicenseKey = 'WZCETXC0Z9PQZ9GKRGGY'; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect( service.activateCardLicenseKey(context, userId, body.cardLicenseKey), ).rejects.toEqual( @@ -276,7 +275,7 @@ describe('LicensesService', () => { const body = new ActivateCardLicensesRequest(); const userId = '0001'; body.cardLicenseKey = 'WZCETXC0Z9PQZ9GKRGGY'; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect( service.activateCardLicenseKey(context, userId, body.cardLicenseKey), ).rejects.toEqual( @@ -299,7 +298,7 @@ describe('LicensesService', () => { const body = new ActivateCardLicensesRequest(); const userId = '0001'; body.cardLicenseKey = 'WZCETXC0Z9PQZ9GKRGGY'; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect( service.activateCardLicenseKey(context, userId, body.cardLicenseKey), ).rejects.toEqual( @@ -342,7 +341,7 @@ describe('DBテスト', () => { const service = module.get(LicensesService); const issueCount = 500; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await service.issueCardLicenseKeys(context, externalId, issueCount); const dbSelectResult = await selectCardLicensesCount(source); expect(dbSelectResult.count).toEqual(issueCount); @@ -382,7 +381,7 @@ describe('DBテスト', () => { await createCardLicenseIssue(source, issueId); const service = module.get(LicensesService); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await service.activateCardLicenseKey(context, externalId, cardLicenseKey); const dbSelectResultFromCardLicense = await selectCardLicense( @@ -529,7 +528,7 @@ describe('DBテスト', () => { null, ); const service = module.get(LicensesService); - const context = makeContext('userId', 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext('userId', 'requestId'); const response = await service.getAllocatableLicenses(context, externalId); // 対象外のデータは取得していないことを確認する expect(response.allocatableLicenses.length).toBe(5); @@ -600,7 +599,7 @@ describe('ライセンス割り当て', () => { const expiry_date = new NewAllocatedLicenseExpirationDate(); await service.allocateLicense( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), userId, 1, ); @@ -669,7 +668,7 @@ describe('ライセンス割り当て', () => { const service = module.get(UsersService); await service.allocateLicense( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), userId, 1, ); @@ -748,7 +747,7 @@ describe('ライセンス割り当て', () => { const expiry_date = new NewAllocatedLicenseExpirationDate(); await service.allocateLicense( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), userId, 2, ); @@ -851,7 +850,7 @@ describe('ライセンス割り当て', () => { const service = module.get(UsersService); await service.allocateLicense( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), userId, 2, ); @@ -915,7 +914,7 @@ describe('ライセンス割り当て', () => { const service = module.get(UsersService); await service.allocateLicense( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), userId, 2, ); @@ -979,7 +978,7 @@ describe('ライセンス割り当て', () => { const service = module.get(UsersService); await service.allocateLicense( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), userId, 2, ); @@ -1025,7 +1024,7 @@ describe('ライセンス割り当て', () => { await expect( service.allocateLicense( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), userId, 1, ), @@ -1077,7 +1076,7 @@ describe('ライセンス割り当て', () => { await expect( service.allocateLicense( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), userId, 1, ), @@ -1086,7 +1085,7 @@ describe('ライセンス割り当て', () => { ); await expect( service.allocateLicense( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), userId, 2, ), @@ -1152,7 +1151,7 @@ describe('ライセンス割り当て解除', () => { const service = module.get(UsersService); await service.deallocateLicense( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), userId, ); @@ -1242,10 +1241,7 @@ describe('ライセンス割り当て解除', () => { const service = module.get(UsersService); await expect( - service.deallocateLicense( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), - userId, - ), + service.deallocateLicense(makeContext('trackingId', 'requestId'), userId), ).rejects.toEqual( new HttpException(makeErrorResponse('E010807'), HttpStatus.BAD_REQUEST), ); @@ -1301,7 +1297,7 @@ describe('ライセンス注文キャンセル', () => { const service = module.get(LicensesService); await service.cancelOrder( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), tier2Accounts[0].users[0].external_id, poNumber, ); @@ -1337,7 +1333,7 @@ describe('ライセンス注文キャンセル', () => { const service = module.get(LicensesService); await expect( service.cancelOrder( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), tier2Accounts[0].users[0].external_id, poNumber, ), @@ -1368,7 +1364,7 @@ describe('ライセンス注文キャンセル', () => { const service = module.get(LicensesService); await expect( service.cancelOrder( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), tier2Accounts[0].users[0].external_id, poNumber, ), diff --git a/dictation_server/src/features/notification/notification.service.spec.ts b/dictation_server/src/features/notification/notification.service.spec.ts index 355567f..a13d8b7 100644 --- a/dictation_server/src/features/notification/notification.service.spec.ts +++ b/dictation_server/src/features/notification/notification.service.spec.ts @@ -19,7 +19,7 @@ describe('NotificationService.register', () => { expect( await service.register( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 'external_id', 'apns', 'handler', @@ -38,7 +38,7 @@ describe('NotificationService.register', () => { await expect( service.register( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 'external_id', 'apns', 'handler', @@ -63,7 +63,7 @@ describe('NotificationService.register', () => { await expect( service.register( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 'external_id', 'apns', 'handler', diff --git a/dictation_server/src/features/tasks/tasks.service.spec.ts b/dictation_server/src/features/tasks/tasks.service.spec.ts index ba7f1f4..eaf6e56 100644 --- a/dictation_server/src/features/tasks/tasks.service.spec.ts +++ b/dictation_server/src/features/tasks/tasks.service.spec.ts @@ -63,7 +63,7 @@ describe('TasksService', () => { const direction = 'ASC'; expect( await service.tasksService.getTasks( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), userId, [ADMIN_ROLES.ADMIN, USER_ROLES.NONE], offset, @@ -138,7 +138,7 @@ describe('TasksService', () => { const direction = 'ASC'; await expect( service.tasksService.getTasks( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), userId, [ADMIN_ROLES.ADMIN, USER_ROLES.NONE], offset, @@ -180,7 +180,7 @@ describe('TasksService', () => { const direction = 'ASC'; await expect( service.tasksService.getTasks( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), userId, [ADMIN_ROLES.ADMIN, USER_ROLES.NONE], offset, @@ -266,7 +266,7 @@ describe('TasksService', () => { const direction = 'ASC'; await expect( service.tasksService.getTasks( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), userId, [ADMIN_ROLES.ADMIN, USER_ROLES.NONE], offset, @@ -309,7 +309,7 @@ describe('TasksService', () => { const status = ['Uploaded', 'Backup']; const paramName = 'JOB_NUMBER'; const direction = 'ASC'; - const context = makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext('trackingId', 'requestId'); const result = await service.tasksService.getTasks( context, userId, @@ -394,7 +394,7 @@ describe('TasksService', () => { const direction = 'ASC'; await expect( service.tasksService.getTasks( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), userId, [USER_ROLES.AUTHOR], offset, @@ -438,7 +438,7 @@ describe('TasksService', () => { const status = ['Uploaded', 'Backup']; const paramName = 'JOB_NUMBER'; const direction = 'ASC'; - const context = makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext('trackingId', 'requestId'); const result = await service.tasksService.getTasks( context, userId, @@ -523,7 +523,7 @@ describe('TasksService', () => { const direction = 'ASC'; await expect( service.tasksService.getTasks( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), userId, [USER_ROLES.TYPIST], offset, @@ -565,7 +565,7 @@ describe('TasksService', () => { const direction = 'ASC'; await expect( service.tasksService.getTasks( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), userId, [ADMIN_ROLES.ADMIN, USER_ROLES.NONE], offset, @@ -625,7 +625,7 @@ describe('TasksService', () => { const direction = 'ASC'; const { tasks, total } = await service.getTasks( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), externalId, [ADMIN_ROLES.ADMIN, USER_ROLES.NONE], offset, @@ -683,7 +683,7 @@ describe('TasksService', () => { const direction = 'ASC'; const { tasks, total } = await service.getTasks( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), external_id, [USER_ROLES.AUTHOR], offset, @@ -755,7 +755,7 @@ describe('TasksService', () => { const direction = 'ASC'; const { tasks, total } = await service.getTasks( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), external_id, [USER_ROLES.AUTHOR], offset, @@ -841,7 +841,7 @@ describe('changeCheckoutPermission', () => { NotificationhubService, ); await service.changeCheckoutPermission( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, [{ typistName: 'typist-user-2', typistUserId: typistUserId_2 }], 'author-user-external-id', @@ -858,7 +858,7 @@ describe('changeCheckoutPermission', () => { const resultTask = await getTask(source, taskId); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), [`user_${typistUserId_2}`], { authorId: 'MY_AUTHOR_ID', @@ -924,7 +924,7 @@ describe('changeCheckoutPermission', () => { NotificationhubService, ); await service.changeCheckoutPermission( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, [{ typistName: 'USER_GROUP_B', typistGroupId: userGroupId_2 }], 'author-user-external-id', @@ -942,7 +942,7 @@ describe('changeCheckoutPermission', () => { const resultTask = await getTask(source, taskId); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), [`user_${typistUserId_2}`], { authorId: 'MY_AUTHOR_ID', @@ -994,7 +994,7 @@ describe('changeCheckoutPermission', () => { await createCheckoutPermissions(source, taskId, undefined, userGroupId); const service = module.get(TasksService); await service.changeCheckoutPermission( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, [], 'author-user-external-id', @@ -1047,7 +1047,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, [{ typistName: 'not-exist-user', typistUserId: 999 }], 'author-user-external-id', @@ -1113,7 +1113,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, [{ typistName: 'not-verified-user', typistUserId: typistUserId_2 }], 'author-user-external-id', @@ -1173,7 +1173,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, [{ typistName: 'not-exist-user-group', typistGroupId: 999 }], 'author-user-external-id', @@ -1215,7 +1215,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, [{ typistName: 'typist-user', typistUserId: typistUserId }], 'author-user-external-id', @@ -1267,7 +1267,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, [{ typistName: 'typist-user', typistUserId: typistUserId }], 'author-user-external-id', @@ -1319,7 +1319,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, [{ typistName: 'typist-user', typistUserId: typistUserId }], 'author-user-external-id', @@ -1385,7 +1385,7 @@ describe('changeCheckoutPermission', () => { try { await service.changeCheckoutPermission( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, [{ typistName: 'typist-user-2', typistUserId: typistUserId_2 }], 'author-user-external-id', @@ -1462,7 +1462,7 @@ describe('checkout', () => { const initTask = await getTask(source, taskId); await service.checkout( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, ['typist'], 'typist-user-external-id', @@ -1522,7 +1522,7 @@ describe('checkout', () => { const initTask = await getTask(source, taskId); await service.checkout( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, ['typist'], 'typist-user-external-id', @@ -1575,7 +1575,7 @@ describe('checkout', () => { const initTask = await getTask(source, taskId); await service.checkout( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, ['typist'], 'typist-user-external-id', @@ -1627,7 +1627,7 @@ describe('checkout', () => { const service = module.get(TasksService); try { await service.checkout( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, ['typist'], 'typist-user-external-id', @@ -1674,7 +1674,7 @@ describe('checkout', () => { const service = module.get(TasksService); try { await service.checkout( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, ['typist'], 'typist-user-external-id', @@ -1735,7 +1735,7 @@ describe('checkout', () => { try { await service.checkout( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), audioFileId, ['typist'], 'typist-user-external-id', @@ -1800,7 +1800,7 @@ describe('checkout', () => { const service = module.get(TasksService); await service.checkout( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 2, ['typist'], 'typist-user-external-id2', @@ -1841,7 +1841,7 @@ describe('checkout', () => { const service = module.get(TasksService); expect( await service.checkout( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, ['author'], 'author-user-external-id', @@ -1875,7 +1875,7 @@ describe('checkout', () => { expect( await service.checkout( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, ['author'], 'author-user-external-id', @@ -1898,7 +1898,7 @@ describe('checkout', () => { const service = module.get(TasksService); try { await service.checkout( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, ['author'], 'author-user-external-id', @@ -1939,7 +1939,7 @@ describe('checkout', () => { const service = module.get(TasksService); try { await service.checkout( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, ['author'], 'author-user-external-id', @@ -1970,7 +1970,7 @@ describe('checkout', () => { const service = module.get(TasksService); try { await service.checkout( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, ['none'], 'none-user-external-id', @@ -2045,7 +2045,7 @@ describe('checkin', () => { const initTask = await getTask(source, taskId); await service.checkin( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, 'typist-user-external-id', ); @@ -2092,7 +2092,7 @@ describe('checkin', () => { const service = module.get(TasksService); await expect( service.checkin( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, 'typist-user-external-id', ), @@ -2144,7 +2144,7 @@ describe('checkin', () => { await expect( service.checkin( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, 'typist-user-external-id', ), @@ -2180,7 +2180,7 @@ describe('checkin', () => { await expect( service.checkin( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, 'typist-user-external-id', ), @@ -2245,7 +2245,7 @@ describe('suspend', () => { const service = module.get(TasksService); await service.suspend( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, 'typist-user-external-id', ); @@ -2291,7 +2291,7 @@ describe('suspend', () => { const service = module.get(TasksService); await expect( service.suspend( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, 'typist-user-external-id', ), @@ -2343,7 +2343,7 @@ describe('suspend', () => { await expect( service.checkin( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, 'typist-user-external-id', ), @@ -2379,7 +2379,7 @@ describe('suspend', () => { await expect( service.checkin( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, 'typist-user-external-id', ), @@ -2445,7 +2445,7 @@ describe('cancel', () => { const service = module.get(TasksService); await service.cancel( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, 'typist-user-external-id', ['typist', 'standard'], @@ -2494,7 +2494,7 @@ describe('cancel', () => { const service = module.get(TasksService); await service.cancel( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, 'typist-user-external-id', ['typist', 'standard'], @@ -2546,7 +2546,7 @@ describe('cancel', () => { const service = module.get(TasksService); await service.cancel( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, 'typist-user-external-id', ['admin', 'author'], @@ -2597,7 +2597,7 @@ describe('cancel', () => { const service = module.get(TasksService); await service.cancel( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, 'typist-user-external-id', ['admin', 'author'], @@ -2647,7 +2647,7 @@ describe('cancel', () => { const service = module.get(TasksService); await expect( service.cancel( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, 'typist-user-external-id', ['admin', 'author'], @@ -2700,7 +2700,7 @@ describe('cancel', () => { await expect( service.cancel( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, 'typist-user-external-id', ['typist', 'standard'], @@ -2737,7 +2737,7 @@ describe('cancel', () => { await expect( service.cancel( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, 'typist-user-external-id', ['typist', 'standard'], @@ -2806,7 +2806,7 @@ describe('cancel', () => { NotificationhubService, ); await service.cancel( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, 'typist-user-external-id', ['typist', 'standard'], @@ -2823,7 +2823,7 @@ describe('cancel', () => { expect(permisions[0].user_id).toEqual(typistUserId); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), [`user_${typistUserId}`], { authorId: 'AUTHOR_ID', @@ -2916,7 +2916,7 @@ describe('cancel', () => { NotificationhubService, ); await service.cancel( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, external_id, role.split(' ') as Roles[], @@ -2933,7 +2933,7 @@ describe('cancel', () => { expect(permisions[0].user_id).toEqual(autoRoutingTypistUserId); // 通知処理が想定通りの引数で呼ばれているか確認 expect(NotificationHubService.notify).toHaveBeenCalledWith( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), [`user_${autoRoutingTypistUserId}`], { authorId: 'AUTHOR_ID', @@ -2988,7 +2988,7 @@ describe('cancel', () => { NotificationhubService, ); await service.cancel( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), 1, external_id, role.split(' ') as Roles[], @@ -3062,7 +3062,7 @@ describe('backup', () => { const service = module.get(TasksService); await service.backup( - makeContext(admin.external_id, 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext(admin.external_id, 'requestId'), audioFileId, admin.external_id, ); @@ -3114,7 +3114,7 @@ describe('backup', () => { const service = module.get(TasksService); await service.backup( - makeContext(admin.external_id, 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext(admin.external_id, 'requestId'), audioFileId, admin.external_id, ); @@ -3167,7 +3167,7 @@ describe('backup', () => { try { await service.backup( - makeContext(admin.external_id, 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext(admin.external_id, 'requestId'), audioFileId, admin.external_id, ); @@ -3222,7 +3222,7 @@ describe('backup', () => { try { await service.backup( - makeContext(admin.external_id, 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext(admin.external_id, 'requestId'), 9999, // 存在しないタスクID admin.external_id, ); @@ -3283,7 +3283,7 @@ describe('backup', () => { try { await service.backup( - makeContext(admin.external_id, 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext(admin.external_id, 'requestId'), audioFileId, admin.external_id, ); @@ -3376,11 +3376,7 @@ describe('getNextTask', () => { await createCheckoutPermissions(source, taskId2, typistUserId); const service = module.get(TasksService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const nextAudioFileId = await service.getNextTask( context, @@ -3452,11 +3448,7 @@ describe('getNextTask', () => { await createCheckoutPermissions(source, taskId2, typistUserId); const service = module.get(TasksService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const nextAudioFileId = await service.getNextTask( context, @@ -3528,11 +3520,7 @@ describe('getNextTask', () => { await createCheckoutPermissions(source, taskId2, typistUserId); const service = module.get(TasksService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const nextAudioFileId = await service.getNextTask( context, @@ -3604,11 +3592,7 @@ describe('getNextTask', () => { await createCheckoutPermissions(source, taskId2, typistUserId); const service = module.get(TasksService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const nextAudioFileId = await service.getNextTask( context, @@ -3680,11 +3664,7 @@ describe('getNextTask', () => { await createCheckoutPermissions(source, taskId2, typistUserId); const service = module.get(TasksService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const nextAudioFileId = await service.getNextTask( context, @@ -3732,11 +3712,7 @@ describe('getNextTask', () => { await createCheckoutPermissions(source, taskId1, typistUserId); const service = module.get(TasksService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const nextAudioFileId = await service.getNextTask( context, @@ -3783,11 +3759,7 @@ describe('getNextTask', () => { await createCheckoutPermissions(source, taskId1, typistUserId); const service = module.get(TasksService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); // 実行結果が正しいか確認 try { diff --git a/dictation_server/src/features/templates/templates.service.spec.ts b/dictation_server/src/features/templates/templates.service.spec.ts index 9edeff3..a366b30 100644 --- a/dictation_server/src/features/templates/templates.service.spec.ts +++ b/dictation_server/src/features/templates/templates.service.spec.ts @@ -35,11 +35,7 @@ describe('getTemplates', () => { const service = module.get(TemplatesService); // 第五階層のアカウント作成 const { account, admin } = await makeTestAccount(source, { tier: 5 }); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const template1 = await createTemplateFile( source, @@ -80,11 +76,7 @@ describe('getTemplates', () => { const service = module.get(TemplatesService); // 第五階層のアカウント作成 const { admin } = await makeTestAccount(source, { tier: 5 }); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); const templates = await service.getTemplates(context, admin.external_id); @@ -102,11 +94,7 @@ describe('getTemplates', () => { const service = module.get(TemplatesService); // 第五階層のアカウント作成 const { admin } = await makeTestAccount(source, { tier: 5 }); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //DBアクセスに失敗するようにする const typistGroupService = module.get( diff --git a/dictation_server/src/features/terms/terms.service.spec.ts b/dictation_server/src/features/terms/terms.service.spec.ts index 1f737eb..5950404 100644 --- a/dictation_server/src/features/terms/terms.service.spec.ts +++ b/dictation_server/src/features/terms/terms.service.spec.ts @@ -39,7 +39,7 @@ describe('利用規約取得', () => { await createTermInfo(source, 'DPA', 'v1.0'); await createTermInfo(source, 'DPA', 'v1.2'); - const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(uuidv4(), 'requestId'); const result = await service.getTermsInfo(context); expect(result[0].documentType).toBe('EULA'); @@ -55,7 +55,7 @@ describe('利用規約取得', () => { const module = await makeTestingModule(source); if (!module) fail(); const service = module.get(TermsService); - const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(uuidv4(), 'requestId'); await expect(service.getTermsInfo(context)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -70,7 +70,7 @@ describe('利用規約取得', () => { if (!module) fail(); const service = module.get(TermsService); await createTermInfo(source, 'DPA', 'v1.0'); - const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(uuidv4(), 'requestId'); await expect(service.getTermsInfo(context)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -85,7 +85,7 @@ describe('利用規約取得', () => { if (!module) fail(); const service = module.get(TermsService); await createTermInfo(source, 'PrivacyNotice', 'v1.0'); - const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(uuidv4(), 'requestId'); await expect(service.getTermsInfo(context)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -100,7 +100,7 @@ describe('利用規約取得', () => { if (!module) fail(); const service = module.get(TermsService); await createTermInfo(source, 'EULA', 'v1.0'); - const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(uuidv4(), 'requestId'); await expect(service.getTermsInfo(context)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), diff --git a/dictation_server/src/features/users/users.controller.ts b/dictation_server/src/features/users/users.controller.ts index 3efa943..e854da2 100644 --- a/dictation_server/src/features/users/users.controller.ts +++ b/dictation_server/src/features/users/users.controller.ts @@ -174,6 +174,7 @@ export class UsersController { @Get() async getUsers(@Req() req: Request): Promise { const accessToken = retrieveAuthorizationToken(req); + if (!accessToken) { throw new HttpException( makeErrorResponse('E000107'), diff --git a/dictation_server/src/features/users/users.service.spec.ts b/dictation_server/src/features/users/users.service.spec.ts index f9a08b7..1200def 100644 --- a/dictation_server/src/features/users/users.service.spec.ts +++ b/dictation_server/src/features/users/users.service.spec.ts @@ -97,7 +97,7 @@ describe('UsersService.confirmUser', () => { // account id:1, user id: 2のトークン const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjEsInVzZXJJZCI6MiwiZW1haWwiOiJ4eHhAeHh4Lnh4eCIsImlhdCI6MTAwMDAwMDAwMCwiZXhwIjo5MDAwMDAwMDAwfQ.26L6BdNg-3TbyKT62PswlJ6RPMkcTtHzlDXW2Uo9XbMPVSrl2ObcuS6EcXjFFN2DEfNTKbqX_zevIWMpHOAdLNgGhk528nLrBrNvPASqtTjvW9muxMXpjUdjRVkmVbOylBHWW3YpWL9JEbJQ7rAzWDfaIdPhMovdaxumnZt_UwnlnrdaVPLACW7tkH_laEcAU507iSiM4mqxxG8FuTs34t6PEdwRuzZAQPN2IOPYNSvGNdJYryPacSeSNZ_z1xeBYXLOLQfOBZzyTReYDOhXdikhrNUbxjgnZQlSXBCVMlZ9PH42bHfp-LJIeJzW0yqnF6oLklvJP-fo8eW0k5iDOw'; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await service.confirmUser(context, token); //result const resultUser = await getUser(source, userId); @@ -141,7 +141,7 @@ describe('UsersService.confirmUser', () => { if (!module) fail(); const token = 'invalid.id.token'; const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect(service.confirmUser(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E000101'), HttpStatus.BAD_REQUEST), ); @@ -177,7 +177,7 @@ describe('UsersService.confirmUser', () => { const service = module.get(UsersService); const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjEsInVzZXJJZCI6MiwiZW1haWwiOiJ4eHhAeHh4Lnh4eCIsImlhdCI6MTAwMDAwMDAwMCwiZXhwIjo5MDAwMDAwMDAwfQ.26L6BdNg-3TbyKT62PswlJ6RPMkcTtHzlDXW2Uo9XbMPVSrl2ObcuS6EcXjFFN2DEfNTKbqX_zevIWMpHOAdLNgGhk528nLrBrNvPASqtTjvW9muxMXpjUdjRVkmVbOylBHWW3YpWL9JEbJQ7rAzWDfaIdPhMovdaxumnZt_UwnlnrdaVPLACW7tkH_laEcAU507iSiM4mqxxG8FuTs34t6PEdwRuzZAQPN2IOPYNSvGNdJYryPacSeSNZ_z1xeBYXLOLQfOBZzyTReYDOhXdikhrNUbxjgnZQlSXBCVMlZ9PH42bHfp-LJIeJzW0yqnF6oLklvJP-fo8eW0k5iDOw'; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect(service.confirmUser(context, token)).rejects.toEqual( new HttpException(makeErrorResponse('E010202'), HttpStatus.BAD_REQUEST), ); @@ -189,7 +189,7 @@ describe('UsersService.confirmUser', () => { const service = module.get(UsersService); const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjEsInVzZXJJZCI6MiwiZW1haWwiOiJ4eHhAeHh4Lnh4eCIsImlhdCI6MTAwMDAwMDAwMCwiZXhwIjo5MDAwMDAwMDAwfQ.26L6BdNg-3TbyKT62PswlJ6RPMkcTtHzlDXW2Uo9XbMPVSrl2ObcuS6EcXjFFN2DEfNTKbqX_zevIWMpHOAdLNgGhk528nLrBrNvPASqtTjvW9muxMXpjUdjRVkmVbOylBHWW3YpWL9JEbJQ7rAzWDfaIdPhMovdaxumnZt_UwnlnrdaVPLACW7tkH_laEcAU507iSiM4mqxxG8FuTs34t6PEdwRuzZAQPN2IOPYNSvGNdJYryPacSeSNZ_z1xeBYXLOLQfOBZzyTReYDOhXdikhrNUbxjgnZQlSXBCVMlZ9PH42bHfp-LJIeJzW0yqnF6oLklvJP-fo8eW0k5iDOw'; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect(service.confirmUser(context, token)).rejects.toEqual( new HttpException( makeErrorResponse('E009999'), @@ -246,7 +246,7 @@ describe('UsersService.confirmUserAndInitPassword', () => { 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjEsInVzZXJJZCI6MiwiZW1haWwiOiJ4eHhAeHh4Lnh4eCIsImlhdCI6MTAwMDAwMDAwMCwiZXhwIjo5MDAwMDAwMDAwfQ.26L6BdNg-3TbyKT62PswlJ6RPMkcTtHzlDXW2Uo9XbMPVSrl2ObcuS6EcXjFFN2DEfNTKbqX_zevIWMpHOAdLNgGhk528nLrBrNvPASqtTjvW9muxMXpjUdjRVkmVbOylBHWW3YpWL9JEbJQ7rAzWDfaIdPhMovdaxumnZt_UwnlnrdaVPLACW7tkH_laEcAU507iSiM4mqxxG8FuTs34t6PEdwRuzZAQPN2IOPYNSvGNdJYryPacSeSNZ_z1xeBYXLOLQfOBZzyTReYDOhXdikhrNUbxjgnZQlSXBCVMlZ9PH42bHfp-LJIeJzW0yqnF6oLklvJP-fo8eW0k5iDOw'; expect( await service.confirmUserAndInitPassword( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), token, ), ).toEqual(undefined); @@ -296,7 +296,7 @@ describe('UsersService.confirmUserAndInitPassword', () => { const token = 'invalid.id.token'; await expect( service.confirmUserAndInitPassword( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), token, ), ).rejects.toEqual( @@ -352,7 +352,7 @@ describe('UsersService.confirmUserAndInitPassword', () => { 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjEsInVzZXJJZCI6MiwiZW1haWwiOiJ4eHhAeHh4Lnh4eCIsImlhdCI6MTAwMDAwMDAwMCwiZXhwIjo5MDAwMDAwMDAwfQ.26L6BdNg-3TbyKT62PswlJ6RPMkcTtHzlDXW2Uo9XbMPVSrl2ObcuS6EcXjFFN2DEfNTKbqX_zevIWMpHOAdLNgGhk528nLrBrNvPASqtTjvW9muxMXpjUdjRVkmVbOylBHWW3YpWL9JEbJQ7rAzWDfaIdPhMovdaxumnZt_UwnlnrdaVPLACW7tkH_laEcAU507iSiM4mqxxG8FuTs34t6PEdwRuzZAQPN2IOPYNSvGNdJYryPacSeSNZ_z1xeBYXLOLQfOBZzyTReYDOhXdikhrNUbxjgnZQlSXBCVMlZ9PH42bHfp-LJIeJzW0yqnF6oLklvJP-fo8eW0k5iDOw'; await expect( service.confirmUserAndInitPassword( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), token, ), ).rejects.toEqual( @@ -405,7 +405,7 @@ describe('UsersService.confirmUserAndInitPassword', () => { 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjEsInVzZXJJZCI6MiwiZW1haWwiOiJ4eHhAeHh4Lnh4eCIsImlhdCI6MTAwMDAwMDAwMCwiZXhwIjo5MDAwMDAwMDAwfQ.26L6BdNg-3TbyKT62PswlJ6RPMkcTtHzlDXW2Uo9XbMPVSrl2ObcuS6EcXjFFN2DEfNTKbqX_zevIWMpHOAdLNgGhk528nLrBrNvPASqtTjvW9muxMXpjUdjRVkmVbOylBHWW3YpWL9JEbJQ7rAzWDfaIdPhMovdaxumnZt_UwnlnrdaVPLACW7tkH_laEcAU507iSiM4mqxxG8FuTs34t6PEdwRuzZAQPN2IOPYNSvGNdJYryPacSeSNZ_z1xeBYXLOLQfOBZzyTReYDOhXdikhrNUbxjgnZQlSXBCVMlZ9PH42bHfp-LJIeJzW0yqnF6oLklvJP-fo8eW0k5iDOw'; await expect( service.confirmUserAndInitPassword( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), token, ), ).rejects.toEqual( @@ -491,7 +491,7 @@ describe('UsersService.createUser', () => { expect( await service.createUser( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), adminExternalId, name, role, @@ -579,7 +579,7 @@ describe('UsersService.createUser', () => { expect( await service.createUser( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), adminExternalId, name, role, @@ -670,7 +670,7 @@ describe('UsersService.createUser', () => { expect( await service.createUser( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), adminExternalId, name, role, @@ -758,7 +758,7 @@ describe('UsersService.createUser', () => { expect( await service.createUser( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), adminExternalId, name, role, @@ -851,7 +851,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), adminExternalId, name, role, @@ -871,7 +871,7 @@ describe('UsersService.createUser', () => { // ADB2Cに作成したユーザーを削除するメソッドが呼ばれていることを確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), ); }); @@ -938,7 +938,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), adminExternalId, name, role, @@ -963,7 +963,7 @@ describe('UsersService.createUser', () => { // ADB2Cに作成したユーザーを削除するメソッドが呼ばれていることを確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), ); }); @@ -1019,7 +1019,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), adminExternalId, name, role, @@ -1098,7 +1098,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), adminExternalId, name, role, @@ -1179,7 +1179,7 @@ describe('UsersService.createUser', () => { expect( await service.createUser( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), adminExternalId, name, role, @@ -1220,7 +1220,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), adminExternalId, name, role, @@ -1316,7 +1316,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), adminExternalId, name, role, @@ -1344,7 +1344,7 @@ describe('UsersService.createUser', () => { // ADB2Cに作成したユーザーを削除するメソッドが呼ばれていることを確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), ); }); @@ -1405,7 +1405,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), adminExternalId, name, role, @@ -1431,7 +1431,7 @@ describe('UsersService.createUser', () => { // ADB2Cに作成したユーザーを削除するメソッドが呼ばれていることを確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), ); }); @@ -1497,7 +1497,7 @@ describe('UsersService.createUser', () => { try { await service.createUser( - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), adminExternalId, name, role, @@ -1521,7 +1521,7 @@ describe('UsersService.createUser', () => { // ADB2Cに作成したユーザーを削除するメソッドが呼ばれていることを確認 expect(b2cService.deleteUser).toBeCalledWith( externalId, - makeContext('trackingId', 'xxx-xxx-xxx-xxx', 'requestId'), + makeContext('trackingId', 'requestId'), ); }); }); @@ -1644,7 +1644,7 @@ describe('UsersService.getUsers', () => { }, ]; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); expect(await service.getUsers(context, externalId_author)).toEqual( expectedUsers, ); @@ -1763,7 +1763,7 @@ describe('UsersService.getUsers', () => { }, ]; - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); expect(await service.getUsers(context, external_id1)).toEqual( expectedUsers, ); @@ -1787,7 +1787,7 @@ describe('UsersService.getUsers', () => { prompt: false, }); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); const service = module.get(UsersService); await expect( service.getUsers(context, 'externalId_failed'), @@ -1815,7 +1815,7 @@ describe('UsersService.getUsers', () => { prompt: false, }); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); const service = module.get(UsersService); await expect(service.getUsers(context, externalId_author)).rejects.toEqual( new HttpException(makeErrorResponse('E009999'), HttpStatus.NOT_FOUND), @@ -1840,7 +1840,7 @@ describe('UsersService.updateSortCriteria', () => { configMockValue, sortCriteriaRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); expect( await service.updateSortCriteria( @@ -1871,7 +1871,7 @@ describe('UsersService.updateSortCriteria', () => { configMockValue, sortCriteriaRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect( service.updateSortCriteria(context, 'AUTHOR_ID', 'ASC', 'external_id'), @@ -1903,7 +1903,7 @@ describe('UsersService.updateSortCriteria', () => { configMockValue, sortCriteriaRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect( service.updateSortCriteria(context, 'AUTHOR_ID', 'ASC', 'external_id'), @@ -1933,7 +1933,7 @@ describe('UsersService.getSortCriteria', () => { configMockValue, sortCriteriaRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); expect(await service.getSortCriteria(context, 'external_id')).toEqual({ direction: 'ASC', @@ -1962,7 +1962,7 @@ describe('UsersService.getSortCriteria', () => { configMockValue, sortCriteriaRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect( service.getSortCriteria(context, 'external_id'), @@ -1997,7 +1997,7 @@ describe('UsersService.getSortCriteria', () => { configMockValue, sortCriteriaRepositoryMockValue, ); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect( service.getSortCriteria(context, 'external_id'), @@ -2057,7 +2057,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); expect( await service.updateUser( @@ -2116,7 +2116,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); expect( await service.updateUser( @@ -2175,7 +2175,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); expect( await service.updateUser( @@ -2234,7 +2234,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); expect( await service.updateUser( @@ -2293,7 +2293,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); expect( await service.updateUser( @@ -2352,7 +2352,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect( service.updateUser( @@ -2401,7 +2401,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); expect( await service.updateUser( @@ -2460,7 +2460,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); expect( await service.updateUser( @@ -2519,7 +2519,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect( service.updateUser( @@ -2579,7 +2579,7 @@ describe('UsersService.updateUser', () => { }); const service = module.get(UsersService); - const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(`uuidv4`, 'requestId'); await expect( service.updateUser( @@ -2627,7 +2627,7 @@ describe('UsersService.updateAcceptedVersion', () => { const { admin } = await makeTestAccount(source, { tier: 5, }); - const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(uuidv4(), 'requestId'); const service = module.get(UsersService); await service.updateAcceptedVersion( @@ -2648,7 +2648,7 @@ describe('UsersService.updateAcceptedVersion', () => { const { admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(uuidv4(), 'requestId'); const service = module.get(UsersService); await service.updateAcceptedVersion( @@ -2671,7 +2671,7 @@ describe('UsersService.updateAcceptedVersion', () => { const { admin } = await makeTestAccount(source, { tier: 4, }); - const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(uuidv4(), 'requestId'); const service = module.get(UsersService); await expect( @@ -2714,7 +2714,7 @@ describe('UsersService.getUserName', () => { try { const module = await makeTestingModule(source); if (!module) fail(); - const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(uuidv4(), 'requestId'); const service = module.get(UsersService); await service.getUserName(context, 'external_id'); @@ -2809,7 +2809,7 @@ describe('UsersService.getRelations', () => { expect(workflows[3].author_id).toBe(user2); } - const context = makeContext(external_id, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(external_id, 'requestId'); const service = module.get(UsersService); const relations = await service.getRelations(context, external_id); @@ -2872,7 +2872,7 @@ describe('UsersService.getRelations', () => { expect(workflows[0].author_id).toBe(user2); } - const context = makeContext(external_id, 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(external_id, 'requestId'); const service = module.get(UsersService); const relations = await service.getRelations(context, external_id); @@ -2898,7 +2898,7 @@ describe('UsersService.getRelations', () => { try { const module = await makeTestingModule(source); if (!module) fail(); - const context = makeContext(uuidv4(), 'xxx-xxx-xxx-xxx', 'requestId'); + const context = makeContext(uuidv4(), 'requestId'); const service = module.get(UsersService); await service.getRelations(context, 'external_id'); diff --git a/dictation_server/src/features/users/users.service.ts b/dictation_server/src/features/users/users.service.ts index 1bf2959..e402d5b 100644 --- a/dictation_server/src/features/users/users.service.ts +++ b/dictation_server/src/features/users/users.service.ts @@ -257,7 +257,10 @@ export class UsersService { prompt, ); // ユーザ作成 - newUser = await this.usersRepository.createNormalUser(newUserInfo); + newUser = await this.usersRepository.createNormalUser( + context, + newUserInfo, + ); } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); this.logger.error(`[${context.getTrackingId()}]create user failed`); @@ -352,7 +355,7 @@ export class UsersService { } | params: { userId: ${userId} }`, ); try { - await this.usersRepository.deleteNormalUser(userId); + await this.usersRepository.deleteNormalUser(context, userId); this.logger.log(`[${context.getTrackingId()}] delete user: ${userId}`); } catch (error) { this.logger.error(`[${context.getTrackingId()}] error=${error}`); diff --git a/dictation_server/src/features/workflows/workflows.service.spec.ts b/dictation_server/src/features/workflows/workflows.service.spec.ts index 51c7b2d..177a048 100644 --- a/dictation_server/src/features/workflows/workflows.service.spec.ts +++ b/dictation_server/src/features/workflows/workflows.service.spec.ts @@ -118,11 +118,7 @@ describe('getWorkflows', () => { await createWorkflowTypist(source, workflow3.id, undefined, userGroupId); const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //作成したデータを確認 { @@ -194,11 +190,7 @@ describe('getWorkflows', () => { const { admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); overrideAdB2cService(service, { getUsers: async () => [], @@ -220,11 +212,7 @@ describe('getWorkflows', () => { const { account, admin } = await makeTestAccount(source, { tier: 5 }); const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //DBアクセスに失敗するようにする const templatesService = module.get( @@ -304,11 +292,7 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await service.createWorkflow( context, @@ -373,11 +357,7 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await service.createWorkflow( context, @@ -441,11 +421,7 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await service.createWorkflow( context, @@ -503,11 +479,7 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await service.createWorkflow( context, @@ -571,11 +543,7 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); // 同一AuthorIDのワークフローを作成 await service.createWorkflow( @@ -648,11 +616,7 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //実行結果を確認 try { await service.createWorkflow( @@ -709,11 +673,7 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //実行結果を確認 try { @@ -774,11 +734,7 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //実行結果を確認 try { @@ -838,11 +794,7 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //実行結果を確認 try { @@ -904,11 +856,7 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //実行結果を確認 try { @@ -976,11 +924,7 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //実行結果を確認 try { @@ -1042,11 +986,7 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //実行結果を確認 try { @@ -1117,11 +1057,7 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //実行結果を確認 try { @@ -1188,11 +1124,7 @@ describe('createWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //DBアクセスに失敗するようにする const templatesService = module.get( @@ -1311,11 +1243,7 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await service.updateWorkflow( context, @@ -1405,11 +1333,7 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await service.updateWorkflow( context, @@ -1498,11 +1422,7 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await service.updateWorkflow( context, @@ -1585,11 +1505,7 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await service.updateWorkflow( context, @@ -1692,11 +1608,7 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await service.updateWorkflow( context, @@ -1775,11 +1687,7 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //実行結果を確認 try { @@ -1822,11 +1730,7 @@ describe('updateWorkflow', () => { }); const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //実行結果を確認 try { @@ -1900,11 +1804,7 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //実行結果を確認 try { @@ -1973,11 +1873,7 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //実行結果を確認 try { @@ -2045,11 +1941,7 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //実行結果を確認 try { @@ -2124,11 +2016,7 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //実行結果を確認 try { @@ -2209,11 +2097,7 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //実行結果を確認 try { @@ -2288,11 +2172,7 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //実行結果を確認 try { @@ -2361,11 +2241,7 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //実行結果を確認 try { @@ -2434,11 +2310,7 @@ describe('updateWorkflow', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //DBアクセスに失敗するようにする const workflowsRepositoryService = module.get( @@ -2529,11 +2401,7 @@ describe('deleteWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await service.deleteWorkflow(context, admin.external_id, workflow.id); @@ -2584,11 +2452,7 @@ describe('deleteWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); await service.deleteWorkflow(context, admin.external_id, workflow1.id); @@ -2639,11 +2503,7 @@ describe('deleteWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //実行結果を確認 try { @@ -2718,11 +2578,7 @@ describe('deleteWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //実行結果を確認 try { @@ -2777,11 +2633,7 @@ describe('deleteWorkflows', () => { } const service = module.get(WorkflowsService); - const context = makeContext( - admin.external_id, - 'xxx-xxx-xxx-xxx', - 'requestId', - ); + const context = makeContext(admin.external_id, 'requestId'); //DBアクセスに失敗するようにする const workflowsRepositoryService = module.get( diff --git a/dictation_server/src/gateways/sendgrid/sendgrid.service.ts b/dictation_server/src/gateways/sendgrid/sendgrid.service.ts index 9b1edfd..7874a72 100644 --- a/dictation_server/src/gateways/sendgrid/sendgrid.service.ts +++ b/dictation_server/src/gateways/sendgrid/sendgrid.service.ts @@ -74,7 +74,7 @@ export class SendGridService { .replace( 'VERIFY_LINK_TEXT', `${this.appDomain}${path}?verify=${token}`, - ); + ); const text = this.templateEmailVerifyText .replace('VERIFY_LINK', `${this.appDomain}${path}?verify=${token}`) .replace( diff --git a/dictation_server/src/repositories/accounts/accounts.repository.service.ts b/dictation_server/src/repositories/accounts/accounts.repository.service.ts index be4ce84..bb124f7 100644 --- a/dictation_server/src/repositories/accounts/accounts.repository.service.ts +++ b/dictation_server/src/repositories/accounts/accounts.repository.service.ts @@ -57,12 +57,19 @@ 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 { + insertEntity, + insertEntities, + updateEntity, + deleteEntity, +} from '../../common/repository'; import { Context } from '../../common/log'; @Injectable() export class AccountsRepositoryService { + // クエリログにコメントを出力するかどうか + private readonly isCommentOut = process.env.STAGE !== 'local'; constructor(private dataSource: DataSource) {} - /** * 管理ユーザー無しでアカウントを作成する * @param companyName @@ -72,6 +79,7 @@ export class AccountsRepositoryService { * @returns create */ async create( + context: Context, companyName: string, country: string, dealerAccountId: number | null, @@ -89,7 +97,13 @@ export class AccountsRepositoryService { async (entityManager) => { const repo = entityManager.getRepository(Account); const newAccount = repo.create(account); - const persisted = await repo.save(newAccount); + const persisted = await insertEntity( + Account, + repo, + newAccount, + this.isCommentOut, + context, + ); return persisted; }, ); @@ -101,10 +115,16 @@ export class AccountsRepositoryService { * @param account * @returns update */ - async update(account: Account): Promise { + async update(context: Context, account: Account): Promise { return await this.dataSource.transaction(async (entityManager) => { const repo = entityManager.getRepository(Account); - return await repo.update({ id: account.id }, account); + return await updateEntity( + repo, + { id: account.id }, + account, + this.isCommentOut, + context, + ); }); } @@ -121,6 +141,7 @@ export class AccountsRepositoryService { * @returns account/admin user */ async createAccount( + context: Context, companyName: string, country: string, dealerAccountId: number | undefined, @@ -141,7 +162,13 @@ export class AccountsRepositoryService { } const accountsRepo = entityManager.getRepository(Account); const newAccount = accountsRepo.create(account); - const persistedAccount = await accountsRepo.save(newAccount); + const persistedAccount = await insertEntity( + Account, + accountsRepo, + newAccount, + this.isCommentOut, + context, + ); // 作成されたAccountのIDを使用してユーザーを作成 const user = new User(); @@ -156,14 +183,23 @@ export class AccountsRepositoryService { } const usersRepo = entityManager.getRepository(User); const newUser = usersRepo.create(user); - const persistedUser = await usersRepo.save(newUser); + const persistedUser = await insertEntity( + User, + usersRepo, + newUser, + this.isCommentOut, + context, + ); // アカウントに管理者を設定して更新 persistedAccount.primary_admin_user_id = persistedUser.id; - const result = await accountsRepo.update( + const result = await updateEntity( + accountsRepo, { id: persistedAccount.id }, persistedAccount, + this.isCommentOut, + context, ); // 想定外の更新が行われた場合はロールバックを行った上でエラー送出 @@ -180,7 +216,13 @@ export class AccountsRepositoryService { } const sortCriteriaRepo = entityManager.getRepository(SortCriteria); const newSortCriteria = sortCriteriaRepo.create(sortCriteria); - await sortCriteriaRepo.save(newSortCriteria); + await insertEntity( + SortCriteria, + sortCriteriaRepo, + newSortCriteria, + this.isCommentOut, + context, + ); return { newAccount: persistedAccount, adminUser: persistedUser }; }); @@ -191,19 +233,31 @@ export class AccountsRepositoryService { * @param accountId * @returns delete */ - async deleteAccount(accountId: number, userId: number): Promise { + async deleteAccount( + context: Context, + accountId: number, + userId: number, + ): Promise { await this.dataSource.transaction(async (entityManager) => { const accountsRepo = entityManager.getRepository(Account); const usersRepo = entityManager.getRepository(User); const sortCriteriaRepo = entityManager.getRepository(SortCriteria); // ソート条件を削除 - await sortCriteriaRepo.delete({ - user_id: userId, - }); + await deleteEntity( + sortCriteriaRepo, + { user_id: userId }, + this.isCommentOut, + context, + ); // プライマリ管理者を削除 - await usersRepo.delete({ id: userId }); + await deleteEntity(usersRepo, { id: userId }, this.isCommentOut, context); // アカウントを削除 - await accountsRepo.delete({ id: accountId }); + await deleteEntity( + accountsRepo, + { id: accountId }, + this.isCommentOut, + context, + ); }); } @@ -352,6 +406,7 @@ export class AccountsRepositoryService { status: LICENSE_ALLOCATED_STATUS.ALLOCATED, }, ], + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); // 総ライセンス数のうち、ユーザーに割り当てたことがあるが、現在は割り当て解除され誰にも割り当たっていないライセンス数を取得する @@ -768,18 +823,33 @@ export class AccountsRepositoryService { // 注文を発行待ちに戻す updatedOrder.issued_at = null; updatedOrder.status = LICENSE_ISSUE_STATUS.ISSUE_REQUESTING; - await orderRepo.save(updatedOrder); + await updateEntity( + orderRepo, + { id: targetOrder.id }, + updatedOrder, + this.isCommentOut, + context, + ); + // 発行時に削除したライセンスを未割当に戻す - await licenseRepo.update( + await updateEntity( + licenseRepo, { delete_order_id: targetOrder.id }, { status: LICENSE_ALLOCATED_STATUS.UNALLOCATED, deleted_at: null, delete_order_id: null, }, + this.isCommentOut, + context, ); // 発行時に発行されたライセンスを削除する - await licenseRepo.delete({ order_id: targetOrder.id }); + await deleteEntity( + licenseRepo, + { order_id: targetOrder.id }, + this.isCommentOut, + context, + ); }); } @@ -964,7 +1034,8 @@ export class AccountsRepositoryService { } const accountRepo = entityManager.getRepository(Account); // アカウント情報を更新 - await accountRepo.update( + await updateEntity( + accountRepo, { id: myAccountId }, { parent_account_id: parentAccountId ?? null, @@ -972,6 +1043,8 @@ export class AccountsRepositoryService { primary_admin_user_id: primaryAdminUserId, secondary_admin_user_id: secondryAdminUserId ?? null, }, + this.isCommentOut, + context, ); }); } @@ -1005,9 +1078,12 @@ export class AccountsRepositoryService { } // アカウントのActiveWorktypeIDを更新 - await accountRepo.update( + await updateEntity( + accountRepo, { id: accountId }, { active_worktype_id: id ?? null }, + this.isCommentOut, + context, ); }); } @@ -1030,12 +1106,13 @@ export class AccountsRepositoryService { comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const userArchiveRepo = entityManager.getRepository(UserArchive); - await userArchiveRepo - .createQueryBuilder() - .insert() - .into(UserArchive) - .values(users) - .execute(); + await insertEntities( + UserArchive, + userArchiveRepo, + users, + this.isCommentOut, + context, + ); // 削除対象のライセンスを退避テーブルに退避 const licenses = await this.dataSource.getRepository(License).find({ @@ -1045,12 +1122,13 @@ export class AccountsRepositoryService { comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const licenseArchiveRepo = entityManager.getRepository(LicenseArchive); - await licenseArchiveRepo - .createQueryBuilder() - .insert() - .into(LicenseArchive) - .values(licenses) - .execute(); + await insertEntities( + LicenseArchive, + licenseArchiveRepo, + licenses, + this.isCommentOut, + context, + ); // 削除対象のライセンス割り当て履歴を退避テーブルに退避 const licenseHistories = await this.dataSource @@ -1064,22 +1142,30 @@ export class AccountsRepositoryService { const licenseHistoryArchiveRepo = entityManager.getRepository( LicenseAllocationHistoryArchive, ); - await licenseHistoryArchiveRepo - .createQueryBuilder() - .insert() - .into(LicenseAllocationHistoryArchive) - .values(licenseHistories) - .execute(); + await insertEntities( + LicenseAllocationHistoryArchive, + licenseHistoryArchiveRepo, + licenseHistories, + this.isCommentOut, + context, + ); // アカウントを削除 const accountRepo = entityManager.getRepository(Account); - await accountRepo.delete({ id: accountId }); - + await deleteEntity( + accountRepo, + { id: accountId }, + this.isCommentOut, + context, + ); // ライセンス系(card_license_issue以外)のテーブルのレコードを削除する const orderRepo = entityManager.getRepository(LicenseOrder); - await orderRepo.delete({ - from_account_id: accountId, - }); + await deleteEntity( + orderRepo, + { from_account_id: accountId }, + this.isCommentOut, + context, + ); const licenseRepo = entityManager.getRepository(License); const targetLicenses = await licenseRepo.find({ where: { @@ -1088,18 +1174,27 @@ export class AccountsRepositoryService { comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const cardLicenseRepo = entityManager.getRepository(CardLicense); - await cardLicenseRepo.delete({ - license_id: In(targetLicenses.map((license) => license.id)), - }); - await licenseRepo.delete({ - account_id: accountId, - }); + await deleteEntity( + cardLicenseRepo, + { license_id: In(targetLicenses.map((license) => license.id)) }, + this.isCommentOut, + context, + ); + await deleteEntity( + licenseRepo, + { account_id: accountId }, + this.isCommentOut, + context, + ); const LicenseAllocationHistoryRepo = entityManager.getRepository( LicenseAllocationHistory, ); - await LicenseAllocationHistoryRepo.delete({ - account_id: accountId, - }); + await deleteEntity( + LicenseAllocationHistoryRepo, + { account_id: accountId }, + this.isCommentOut, + context, + ); // ワークタイプ系のテーブルのレコードを削除する const worktypeRepo = entityManager.getRepository(Worktype); @@ -1109,10 +1204,18 @@ export class AccountsRepositoryService { }); const optionItemRepo = entityManager.getRepository(OptionItem); - await optionItemRepo.delete({ - worktype_id: In(taggerWorktypes.map((worktype) => worktype.id)), - }); - await worktypeRepo.delete({ account_id: accountId }); + await deleteEntity( + optionItemRepo, + { worktype_id: In(taggerWorktypes.map((worktype) => worktype.id)) }, + this.isCommentOut, + context, + ); + await deleteEntity( + worktypeRepo, + { account_id: accountId }, + this.isCommentOut, + context, + ); // タスク系のテーブルのレコードを削除する const taskRepo = entityManager.getRepository(Task); @@ -1124,12 +1227,18 @@ export class AccountsRepositoryService { }); const checkoutPermissionRepo = entityManager.getRepository(CheckoutPermission); - await checkoutPermissionRepo.delete({ - task_id: In(targetTasks.map((task) => task.id)), - }); - await taskRepo.delete({ - account_id: accountId, - }); + await deleteEntity( + checkoutPermissionRepo, + { task_id: In(targetTasks.map((task) => task.id)) }, + this.isCommentOut, + context, + ); + await deleteEntity( + taskRepo, + { account_id: accountId }, + this.isCommentOut, + context, + ); // オーディオファイル系のテーブルのレコードを削除する const audioFileRepo = entityManager.getRepository(AudioFile); @@ -1140,12 +1249,20 @@ export class AccountsRepositoryService { comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const audioOptionItemsRepo = entityManager.getRepository(AudioOptionItem); - await audioOptionItemsRepo.delete({ - audio_file_id: In(targetaudioFiles.map((audioFile) => audioFile.id)), - }); - await audioFileRepo.delete({ - account_id: accountId, - }); + await deleteEntity( + audioOptionItemsRepo, + { + audio_file_id: In(targetaudioFiles.map((audioFile) => audioFile.id)), + }, + this.isCommentOut, + context, + ); + await deleteEntity( + audioFileRepo, + { account_id: accountId }, + this.isCommentOut, + context, + ); // ユーザーグループ系のテーブルのレコードを削除する const userGroupRepo = entityManager.getRepository(UserGroup); @@ -1156,28 +1273,47 @@ export class AccountsRepositoryService { comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); const userGroupMemberRepo = entityManager.getRepository(UserGroupMember); - await userGroupMemberRepo.delete({ - user_group_id: In(targetUserGroup.map((userGroup) => userGroup.id)), - }); - await userGroupRepo.delete({ - account_id: accountId, - }); + await deleteEntity( + userGroupMemberRepo, + { + user_group_id: In(targetUserGroup.map((userGroup) => userGroup.id)), + }, + this.isCommentOut, + context, + ); + await deleteEntity( + userGroupRepo, + { account_id: accountId }, + this.isCommentOut, + context, + ); // テンプレートファイルテーブルのレコードを削除する const templateFileRepo = entityManager.getRepository(TemplateFile); - await templateFileRepo.delete({ account_id: accountId }); + await deleteEntity( + templateFileRepo, + { account_id: accountId }, + this.isCommentOut, + context, + ); // ユーザテーブルのレコードを削除する const userRepo = entityManager.getRepository(User); - await userRepo.delete({ - account_id: accountId, - }); + await deleteEntity( + userRepo, + { account_id: accountId }, + this.isCommentOut, + context, + ); // ソート条件のテーブルのレコードを削除する const sortCriteriaRepo = entityManager.getRepository(SortCriteria); - await sortCriteriaRepo.delete({ - user_id: In(users.map((user) => user.id)), - }); + await deleteEntity( + sortCriteriaRepo, + { user_id: In(users.map((user) => user.id)) }, + this.isCommentOut, + context, + ); return users; }); } diff --git a/dictation_server/src/repositories/licenses/licenses.repository.service.ts b/dictation_server/src/repositories/licenses/licenses.repository.service.ts index b761a22..e9f2ad0 100644 --- a/dictation_server/src/repositories/licenses/licenses.repository.service.ts +++ b/dictation_server/src/repositories/licenses/licenses.repository.service.ts @@ -32,10 +32,17 @@ import { DateWithZeroTime, } from '../../features/licenses/types/types'; import { NewAllocatedLicenseExpirationDate } from '../../features/licenses/types/types'; +import { + insertEntity, + insertEntities, + updateEntity, +} from '../../common/repository'; import { Context } from '../../common/log'; @Injectable() export class LicensesRepositoryService { + //クエリログにコメントを出力するかどうか + private readonly isCommentOut = process.env.STAGE !== 'local'; constructor(private dataSource: DataSource) {} private readonly logger = new Logger(LicensesRepositoryService.name); @@ -81,7 +88,13 @@ export class LicensesRepositoryService { const repo = entityManager.getRepository(LicenseOrder); const newLicenseOrder = repo.create(licenseOrder); - const persisted = await repo.save(newLicenseOrder); + const persisted = await insertEntity( + LicenseOrder, + repo, + newLicenseOrder, + this.isCommentOut, + context, + ); return persisted; }, ); @@ -116,19 +129,24 @@ export class LicensesRepositoryService { license.type = LICENSE_TYPE.CARD; licenses.push(license); } - const savedLicenses = await licensesRepo - .createQueryBuilder() - .insert() - .into(License) - .values(licenses) - .execute(); + const savedLicenses = await insertEntities( + License, + licensesRepo, + licenses, + this.isCommentOut, + context, + ); // カードライセンス発行テーブルを作成する const cardLicenseIssue = new CardLicenseIssue(); cardLicenseIssue.issued_at = new Date(); const newCardLicenseIssue = cardLicenseIssueRepo.create(cardLicenseIssue); - const savedCardLicensesIssue = await cardLicenseIssueRepo.save( + const savedCardLicensesIssue = await insertEntity( + CardLicenseIssue, + cardLicenseIssueRepo, newCardLicenseIssue, + this.isCommentOut, + context, ); let isDuplicateKeysExist = true; @@ -173,17 +191,20 @@ export class LicensesRepositoryService { // カードライセンステーブルを作成する(BULK INSERT) for (let i = 0; i < count; i++) { const cardLicense = new CardLicense(); - cardLicense.license_id = savedLicenses.generatedMaps[i].id; // Licenseテーブルの自動採番されたIDを挿入 + cardLicense.license_id = savedLicenses[i].id; // Licenseテーブルの自動採番されたIDを挿入 cardLicense.issue_id = savedCardLicensesIssue.id; // CardLicenseIssueテーブルの自動採番されたIDを挿入 cardLicense.card_license_key = licenseKeys[i]; cardLicenses.push(cardLicense); } - await cardLicenseRepo + //TODO カードライセンステーブルのみPKがidではなかったためInsertEntitiesに置き換えができなかった。 + const query = cardLicenseRepo .createQueryBuilder() .insert() - .into(CardLicense) - .values(cardLicenses) - .execute(); + .into(CardLicense); + if (this.isCommentOut) { + query.comment(`${context.getTrackingId()}_${new Date().toUTCString()}`); + } + query.values(cardLicenses).execute(); }); return licenseKeys; } @@ -275,11 +296,23 @@ export class LicensesRepositoryService { // ライセンステーブルを更新する targetLicense.account_id = accountId; - await licensesRepo.save(targetLicense); + await updateEntity( + licensesRepo, + { id: targetLicense.id }, + targetLicense, + this.isCommentOut, + context, + ); // カードライセンステーブルを更新する targetCardLicense.activated_at = new Date(); - await cardLicenseRepo.save(targetCardLicense); + await updateEntity( + cardLicenseRepo, + { license_id: targetCardLicense.license_id }, + targetCardLicense, + this.isCommentOut, + context, + ); this.logger.log( `activate success. licence_id: ${targetCardLicense.license_id}`, @@ -380,20 +413,24 @@ export class LicensesRepositoryService { return license; }); // ライセンス注文テーブルを更新(注文元) - await licenseOrderRepo.update( + await updateEntity( + licenseOrderRepo, { id: issuingOrder.id }, { issued_at: nowDate, status: LICENSE_ISSUE_STATUS.ISSUED, }, + this.isCommentOut, + context, ); // ライセンステーブルを登録(注文元) - await licenseRepo - .createQueryBuilder() - .insert() - .into(License) - .values(newLicenses) - .execute(); + await insertEntities( + License, + licenseRepo, + newLicenses, + this.isCommentOut, + context, + ); // 第一階層の場合はストックライセンスの概念が存在しないため、ストックライセンス変更処理は行わない if (tier !== TIERS.TIER1) { @@ -422,7 +459,17 @@ export class LicensesRepositoryService { licenseToUpdate.delete_order_id = issuingOrder.id; } // 自身のライセンスを削除(論理削除)する - await licenseRepo.save(licensesToUpdate); + await updateEntity( + licenseRepo, + { id: In(licensesToUpdate.map((l) => l.id)) }, + { + status: LICENSE_ALLOCATED_STATUS.DELETED, + deleted_at: nowDate, + delete_order_id: issuingOrder.id, + }, + this.isCommentOut, + context, + ); } }); } @@ -527,7 +574,13 @@ export class LicensesRepositoryService { allocatedLicense.status = LICENSE_ALLOCATED_STATUS.REUSABLE; allocatedLicense.allocated_user_id = null; - await licenseRepo.save(allocatedLicense); + await updateEntity( + licenseRepo, + { id: allocatedLicense.id }, + allocatedLicense, + this.isCommentOut, + context, + ); // ライセンス割り当て履歴テーブルへ登録 const deallocationHistory = new LicenseAllocationHistory(); @@ -537,7 +590,13 @@ export class LicensesRepositoryService { deallocationHistory.is_allocated = false; deallocationHistory.executed_at = new Date(); deallocationHistory.switch_from_type = SWITCH_FROM_TYPE.NONE; - await licenseAllocationHistoryRepo.save(deallocationHistory); + await insertEntity( + LicenseAllocationHistory, + licenseAllocationHistoryRepo, + deallocationHistory, + this.isCommentOut, + context, + ); } // ライセンス割り当てを実施 @@ -547,7 +606,13 @@ export class LicensesRepositoryService { if (!targetLicense.expiry_date) { targetLicense.expiry_date = new NewAllocatedLicenseExpirationDate(); } - await licenseRepo.save(targetLicense); + await updateEntity( + licenseRepo, + { id: targetLicense.id }, + targetLicense, + this.isCommentOut, + context, + ); // 直近割り当てたライセンス種別を取得 const oldLicenseType = await licenseAllocationHistoryRepo.findOne({ @@ -586,7 +651,13 @@ export class LicensesRepositoryService { // TODO switchFromTypeの値については「PBI1234: 第一階層として、ライセンス数推移情報をCSV出力したい」で正式対応 allocationHistory.switch_from_type = switchFromType; - await licenseAllocationHistoryRepo.save(allocationHistory); + await insertEntity( + LicenseAllocationHistory, + licenseAllocationHistoryRepo, + allocationHistory, + this.isCommentOut, + context, + ); }); } @@ -623,7 +694,13 @@ export class LicensesRepositoryService { // ライセンスの割り当てを解除 allocatedLicense.status = LICENSE_ALLOCATED_STATUS.REUSABLE; allocatedLicense.allocated_user_id = null; - await licenseRepo.save(allocatedLicense); + await updateEntity( + licenseRepo, + { id: allocatedLicense.id }, + allocatedLicense, + this.isCommentOut, + context, + ); // ライセンス割り当て履歴テーブルへ登録 const deallocationHistory = new LicenseAllocationHistory(); @@ -633,7 +710,13 @@ export class LicensesRepositoryService { deallocationHistory.is_allocated = false; deallocationHistory.executed_at = new Date(); deallocationHistory.switch_from_type = SWITCH_FROM_TYPE.NONE; - await licenseAllocationHistoryRepo.save(deallocationHistory); + await insertEntity( + LicenseAllocationHistory, + licenseAllocationHistoryRepo, + deallocationHistory, + this.isCommentOut, + context, + ); }); } @@ -670,7 +753,13 @@ export class LicensesRepositoryService { // 注文キャンセル処理 targetOrder.status = LICENSE_ISSUE_STATUS.CANCELED; targetOrder.canceled_at = new Date(); - await orderRepo.save(targetOrder); + await updateEntity( + orderRepo, + { id: targetOrder.id }, + targetOrder, + this.isCommentOut, + context, + ); }); } 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 99feba1..47c64e0 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 { updateEntity } from '../../common/repository'; import { Context } from '../../common/log'; @Injectable() @@ -23,7 +24,7 @@ export class SortCriteriaRepositoryService { userId: number, parameter: TaskListSortableAttribute, direction: SortDirection, - ): Promise { + ): Promise { this.logger.log( ` ${this.updateSortCriteria.name}; parameter:${parameter}, direction:${direction}`, ); @@ -43,8 +44,13 @@ export class SortCriteriaRepositoryService { targetSortCriteria.parameter = parameter; targetSortCriteria.direction = direction; - const persisted = await repo.save(targetSortCriteria); - return persisted; + await updateEntity( + repo, + { id: targetSortCriteria.id }, + targetSortCriteria, + false, + context, + ); }); } /** diff --git a/dictation_server/src/repositories/tasks/tasks.repository.service.ts b/dictation_server/src/repositories/tasks/tasks.repository.service.ts index eb2be07..9ac0e48 100644 --- a/dictation_server/src/repositories/tasks/tasks.repository.service.ts +++ b/dictation_server/src/repositories/tasks/tasks.repository.service.ts @@ -41,10 +41,18 @@ 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 { + insertEntities, + insertEntity, + updateEntity, + deleteEntity, +} from '../../common/repository'; import { Context } from '../../common/log'; @Injectable() export class TasksRepositoryService { + //クエリログにコメントを出力するかどうか + private readonly isCommentOut = process.env.STAGE !== 'local'; constructor(private dataSource: DataSource) {} /** @@ -252,7 +260,8 @@ export class TasksRepositoryService { // 対象タスクの文字起こし開始日時を現在時刻に更新。割り当てユーザーを自身のユーザーIDに更新 // タスクのステータスがUploaded以外の場合、文字起こし開始時刻は更新しない - await taskRepo.update( + await updateEntity( + taskRepo, { audio_file_id: audio_file_id }, { started_at: @@ -262,18 +271,31 @@ export class TasksRepositoryService { typist_user_id: user_id, status: TASK_STATUS.IN_PROGRESS, }, + this.isCommentOut, + context, ); //対象のタスクに紐づくチェックアウト権限レコードを削除 - await checkoutRepo.delete({ - task_id: task.id, - }); + await deleteEntity( + checkoutRepo, + { + task_id: task.id, + }, + this.isCommentOut, + context, + ); //対象のタスクチェックアウト権限を自身のユーザーIDで作成 - await checkoutRepo.save({ - task_id: task.id, - user_id: user_id, - }); + insertEntity( + CheckoutPermission, + checkoutRepo, + { + task_id: task.id, + user_id: user_id, + }, + this.isCommentOut, + context, + ); }); } @@ -315,12 +337,15 @@ export class TasksRepositoryService { } // 対象タスクの文字起こし終了日時を現在時刻に更新。ステータスをFinishedに更新 - await taskRepo.update( + await updateEntity( + taskRepo, { audio_file_id: audio_file_id }, { finished_at: new Date().toISOString(), status: TASK_STATUS.FINISHED, }, + this.isCommentOut, + context, ); }); } @@ -374,12 +399,15 @@ export class TasksRepositoryService { } // 対象タスクの文字起こし担当をnull,ステータスをUploadedに更新 - await taskRepo.update( + await updateEntity( + taskRepo, { audio_file_id: audio_file_id }, { typist_user_id: null, status: TASK_STATUS.UPLOADED, }, + this.isCommentOut, + context, ); const checkoutPermissionRepo = @@ -388,9 +416,14 @@ export class TasksRepositoryService { // 対象タスクの文字起こし候補を削除 /* 対象タスクがInprogress,Pendingの状態の場合、文字起こし担当者個人指定のレコードのみだが、ユーザーIDの指定はしない (データの不整合があっても問題ないように)*/ - await checkoutPermissionRepo.delete({ - task_id: task.id, - }); + await deleteEntity( + checkoutPermissionRepo, + { + task_id: task.id, + }, + this.isCommentOut, + context, + ); }); } @@ -432,11 +465,14 @@ export class TasksRepositoryService { } // 対象タスクの文字起こし終了日時を現在時刻に更新。ステータスをFinishedに更新 - await taskRepo.update( + await updateEntity( + taskRepo, { audio_file_id: audio_file_id }, { status: TASK_STATUS.PENDING, }, + this.isCommentOut, + context, ); }); } @@ -479,12 +515,15 @@ export class TasksRepositoryService { } // ステータスをバックアップに更新、JobNumberを無効化 - await taskRepo.update( + await updateEntity( + taskRepo, { audio_file_id: audio_file_id }, { status: TASK_STATUS.BACKUP, is_job_number_enabled: false, }, + this.isCommentOut, + context, ); }); } @@ -809,7 +848,13 @@ export class TasksRepositoryService { async (entityManager) => { const audioFileRepo = entityManager.getRepository(AudioFile); const newAudioFile = audioFileRepo.create(audioFile); - const savedAudioFile = await audioFileRepo.save(newAudioFile); + const savedAudioFile = await insertEntity( + AudioFile, + audioFileRepo, + newAudioFile, + this.isCommentOut, + context, + ); task.audio_file_id = savedAudioFile.id; @@ -835,7 +880,13 @@ export class TasksRepositoryService { } task.job_number = newJobNumber; - const persisted = await taskRepo.save(task); + const persisted = await insertEntity( + Task, + taskRepo, + task, + this.isCommentOut, + context, + ); const optionItems = paramOptionItems.map((x) => { return { @@ -847,7 +898,13 @@ export class TasksRepositoryService { const optionItemRepo = entityManager.getRepository(AudioOptionItem); const newAudioOptionItems = optionItemRepo.create(optionItems); - await optionItemRepo.save(newAudioOptionItems); + await insertEntities( + AudioOptionItem, + optionItemRepo, + newAudioOptionItems, + this.isCommentOut, + context, + ); return persisted; }, ); @@ -946,9 +1003,14 @@ export class TasksRepositoryService { // 当該タスクに紐づく既存checkoutPermissionをdelete const checkoutPermissionRepo = entityManager.getRepository(CheckoutPermission); - await checkoutPermissionRepo.delete({ - task_id: taskRecord.id, - }); + await deleteEntity( + checkoutPermissionRepo, + { + task_id: taskRecord.id, + }, + this.isCommentOut, + context, + ); // 当該タスクに紐づく新規checkoutPermissionをinsert const checkoutPermissions: CheckoutPermission[] = assignees.map( @@ -961,7 +1023,13 @@ export class TasksRepositoryService { }, ); - return await checkoutPermissionRepo.save(checkoutPermissions); + return await insertEntities( + CheckoutPermission, + checkoutPermissionRepo, + checkoutPermissions, + this.isCommentOut, + context, + ); }); } @@ -1025,7 +1093,10 @@ export class TasksRepositoryService { const groupMemberRepo = entityManager.getRepository(UserGroupMember); // ユーザーの所属するすべてのグループを列挙 - const groups = await groupMemberRepo.find({ where: { user_id: userId } }); + const groups = await groupMemberRepo.find({ + where: { user_id: userId }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, + }); // ユーザーの所属するすべてのグループIDを列挙 const groupIds = groups.map((member) => member.user_group_id); @@ -1236,11 +1307,14 @@ export class TasksRepositoryService { // タスクのテンプレートIDを更新 const taskRepo = entityManager.getRepository(Task); - await taskRepo.update( + await updateEntity( + taskRepo, { id: task.id }, { template_file_id: template_id, }, + this.isCommentOut, + context, ); // 取得したルーティングルールのタイピストまたはタイピストグループをチェックアウト権限に設定する @@ -1274,9 +1348,14 @@ export class TasksRepositoryService { entityManager.getRepository(CheckoutPermission); // 当該タスクに紐づく既存checkoutPermissionをdelete - await checkoutPermissionRepo.delete({ - task_id: task.id, - }); + await deleteEntity( + checkoutPermissionRepo, + { + task_id: task.id, + }, + this.isCommentOut, + context, + ); // ルーティング候補ユーザーのチェックアウト権限を作成 const typistPermissions = typistUsers.map((typistUser) => { @@ -1293,7 +1372,13 @@ export class TasksRepositoryService { return permission; }); const permissions = [...typistPermissions, ...typistGroupPermissions]; - await checkoutPermissionRepo.save(permissions); + await insertEntities( + CheckoutPermission, + checkoutPermissionRepo, + permissions, + this.isCommentOut, + context, + ); // user_idsとuser_group_idsを返却する return { typistIds: typistIds, 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 69ad434..e3d3319 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,10 +1,14 @@ import { Injectable } from '@nestjs/common'; import { DataSource } from 'typeorm'; import { TemplateFile } from './entity/template_file.entity'; +import { insertEntity, updateEntity } from '../../common/repository'; import { Context } from '../../common/log'; @Injectable() export class TemplateFilesRepositoryService { + //クエリログにコメントを出力するかどうか + private readonly isCommentOut = process.env.STAGE !== 'local'; + constructor(private dataSource: DataSource) {} /** @@ -52,16 +56,25 @@ export class TemplateFilesRepositoryService { // 同名ファイルは同じものとして扱うため、すでにファイルがあれば更新(更新日時の履歴を残しておきたい) if (template) { - await templateFilesRepo.update( + await updateEntity( + templateFilesRepo, { id: template.id }, { file_name: fileName, url: url }, + this.isCommentOut, + context, ); } else { const newTemplate = new TemplateFile(); newTemplate.account_id = accountId; newTemplate.file_name = fileName; newTemplate.url = url; - await templateFilesRepo.save(newTemplate); + await insertEntity( + TemplateFile, + templateFilesRepo, + newTemplate, + this.isCommentOut, + context, + ); } }); } 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 eee2390..eca0bc7 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,10 +5,18 @@ 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 { + insertEntities, + insertEntity, + updateEntity, + deleteEntity, +} from '../../common/repository'; import { Context } from '../../common/log'; @Injectable() export class UserGroupsRepositoryService { + //クエリログにコメントを付与するかどうか + private readonly isCommentOut = process.env.STAGE !== 'local'; constructor(private dataSource: DataSource) {} async getUserGroups( @@ -124,10 +132,16 @@ export class UserGroupsRepositoryService { ); } // userGroupをDBに保存する - const userGroup = await userGroupRepo.save({ - account_id: accountId, - name, - }); + const userGroup = await insertEntity( + UserGroup, + userGroupRepo, + { + name, + account_id: accountId, + }, + this.isCommentOut, + context, + ); const userGroupMembers = userRecords.map((user) => { return { @@ -136,7 +150,13 @@ export class UserGroupsRepositoryService { }; }); // userGroupMembersをDBに保存する - await userGroupMemberRepo.save(userGroupMembers); + await insertEntities( + UserGroupMember, + userGroupMemberRepo, + userGroupMembers, + this.isCommentOut, + context, + ); return userGroup; }); @@ -195,12 +215,23 @@ export class UserGroupsRepositoryService { // 対象のタイピストグループを更新する // ユーザーグループ名を更新する typistGroup.name = typistGroupName; - await userGroupRepo.save(typistGroup); + await updateEntity( + userGroupRepo, + { id: typistGroupId }, + typistGroup, + this.isCommentOut, + context, + ); // user_group_membersテーブルから対象のタイピストグループのユーザーを削除する - await userGroupMemberRepo.delete({ - user_group_id: typistGroupId, - }); + await deleteEntity( + userGroupMemberRepo, + { + user_group_id: typistGroupId, + }, + this.isCommentOut, + context, + ); const typistGroupMembers = userRecords.map((typist) => { return { @@ -208,7 +239,13 @@ export class UserGroupsRepositoryService { user_id: typist.id, }; }); - await userGroupMemberRepo.save(typistGroupMembers); + await insertEntities( + UserGroupMember, + userGroupMemberRepo, + typistGroupMembers, + this.isCommentOut, + context, + ); return typistGroup; }); diff --git a/dictation_server/src/repositories/users/users.repository.service.ts b/dictation_server/src/repositories/users/users.repository.service.ts index 7825073..abaa0d9 100644 --- a/dictation_server/src/repositories/users/users.repository.service.ts +++ b/dictation_server/src/repositories/users/users.repository.service.ts @@ -36,9 +36,18 @@ import { Account } from '../accounts/entity/account.entity'; import { Workflow } from '../workflows/entity/workflow.entity'; import { Worktype } from '../worktypes/entity/worktype.entity'; import { Context } from '../../common/log'; +import { + insertEntity, + insertEntities, + updateEntity, + deleteEntity, +} from '../../common/repository'; @Injectable() export class UsersRepositoryService { + // クエリログにコメントを出力するかどうか + private readonly isCommentOut = process.env.STAGE !== 'local'; + constructor(private dataSource: DataSource) {} /** @@ -46,7 +55,7 @@ export class UsersRepositoryService { * @param user * @returns User */ - async createNormalUser(user: newUser): Promise { + async createNormalUser(context: Context, user: newUser): Promise { const { account_id: accountId, external_id: externalUserId, @@ -80,7 +89,13 @@ export class UsersRepositoryService { async (entityManager) => { const repo = entityManager.getRepository(User); const newUser = repo.create(userEntity); - const persisted = await repo.save(newUser); + const persisted = await insertEntity( + User, + repo, + newUser, + this.isCommentOut, + context, + ); // ユーザーのタスクソート条件を作成 const sortCriteria = new SortCriteria(); @@ -91,7 +106,13 @@ export class UsersRepositoryService { } const sortCriteriaRepo = entityManager.getRepository(SortCriteria); const newSortCriteria = sortCriteriaRepo.create(sortCriteria); - await sortCriteriaRepo.save(newSortCriteria); + await insertEntity( + SortCriteria, + sortCriteriaRepo, + newSortCriteria, + this.isCommentOut, + context, + ); return persisted; }, @@ -256,7 +277,13 @@ export class UsersRepositoryService { targetUser.license_alert = licenseAlart; targetUser.notification = notification; - const result = await repo.update({ id: id }, targetUser); + const result = await updateEntity( + repo, + { id: id }, + targetUser, + this.isCommentOut, + context, + ); // 想定外の更新が行われた場合はロールバックを行った上でエラー送出 if (result.affected !== 1) { @@ -295,7 +322,13 @@ export class UsersRepositoryService { targetUser.email_verified = true; - return await repo.update({ id: targetUser.id }, targetUser); + return await updateEntity( + repo, + { id: targetUser.id }, + targetUser, + this.isCommentOut, + context, + ); }); } @@ -331,7 +364,13 @@ export class UsersRepositoryService { targetUser.email_verified = true; - await userRepo.update({ id: targetUser.id }, targetUser); + await updateEntity( + userRepo, + { id: targetUser.id }, + targetUser, + this.isCommentOut, + context, + ); // トライアルライセンス100件を作成する const licenseRepo = entityManager.getRepository(License); @@ -349,12 +388,13 @@ export class UsersRepositoryService { licenses.push(license); } - await licenseRepo - .createQueryBuilder() - .insert() - .into(License) - .values(licenses) - .execute(); + await insertEntities( + License, + licenseRepo, + licenses, + this.isCommentOut, + context, + ); }); } @@ -457,16 +497,19 @@ export class UsersRepositoryService { * @param userId * @returns delete */ - async deleteNormalUser(userId: number): Promise { + async deleteNormalUser(context: Context, userId: number): Promise { await this.dataSource.transaction(async (entityManager) => { const usersRepo = entityManager.getRepository(User); const sortCriteriaRepo = entityManager.getRepository(SortCriteria); // ソート条件を削除 - await sortCriteriaRepo.delete({ - user_id: userId, - }); + await deleteEntity( + sortCriteriaRepo, + { user_id: userId }, + this.isCommentOut, + context, + ); // プライマリ管理者を削除 - await usersRepo.delete({ id: userId }); + await deleteEntity(usersRepo, { id: userId }, this.isCommentOut, context); }); } @@ -599,7 +642,13 @@ export class UsersRepositoryService { user.accepted_privacy_notice_version = privacyNoticeVersion ?? user.accepted_privacy_notice_version; user.accepted_dpa_version = dpaVersion ?? user.accepted_dpa_version; - await userRepo.update({ id: user.id }, user); + await updateEntity( + userRepo, + { id: user.id }, + user, + this.isCommentOut, + context, + ); }); } diff --git a/dictation_server/src/repositories/workflows/workflows.repository.service.ts b/dictation_server/src/repositories/workflows/workflows.repository.service.ts index 397956f..b945380 100644 --- a/dictation_server/src/repositories/workflows/workflows.repository.service.ts +++ b/dictation_server/src/repositories/workflows/workflows.repository.service.ts @@ -15,10 +15,18 @@ import { AuthorIdAndWorktypeIdPairAlreadyExistsError, WorkflowNotFoundError, } from './errors/types'; +import { + insertEntities, + insertEntity, + deleteEntity, +} from '../../common/repository'; import { Context } from '../../common/log'; @Injectable() export class WorkflowsRepositoryService { + // クエリログにコメントを出力するかどうか + private readonly isCommentOut = process.env.STAGE !== 'local'; + constructor(private dataSource: DataSource) {} /** @@ -165,7 +173,13 @@ export class WorkflowsRepositoryService { templateId, ); - await workflowRepo.save(newWorkflow); + await insertEntity( + Workflow, + workflowRepo, + newWorkflow, + this.isCommentOut, + context, + ); // ルーティング候補のデータ作成 const workflowTypists = typists.map((typist) => @@ -177,7 +191,13 @@ export class WorkflowsRepositoryService { ); const workflowTypistsRepo = entityManager.getRepository(DbWorkflowTypist); - await workflowTypistsRepo.save(workflowTypists); + await insertEntities( + DbWorkflowTypist, + workflowTypistsRepo, + workflowTypists, + this.isCommentOut, + context, + ); }); } @@ -290,8 +310,18 @@ export class WorkflowsRepositoryService { const workflowTypistsRepo = entityManager.getRepository(DbWorkflowTypist); // 既存データの削除 - await workflowTypistsRepo.delete({ workflow_id: workflowId }); - await workflowRepo.delete(workflowId); + await deleteEntity( + workflowTypistsRepo, + { workflow_id: workflowId }, + this.isCommentOut, + context, + ); + await deleteEntity( + workflowRepo, + { id: workflowId }, + this.isCommentOut, + context, + ); { // ワークフローの重複確認 @@ -318,7 +348,13 @@ export class WorkflowsRepositoryService { templateId, ); - await workflowRepo.save(newWorkflow); + await insertEntity( + Workflow, + workflowRepo, + newWorkflow, + this.isCommentOut, + context, + ); // ルーティング候補のデータ作成 const workflowTypists = typists.map((typist) => @@ -329,7 +365,13 @@ export class WorkflowsRepositoryService { ), ); - await workflowTypistsRepo.save(workflowTypists); + await insertEntities( + DbWorkflowTypist, + workflowTypistsRepo, + workflowTypists, + this.isCommentOut, + context, + ); }); } @@ -358,9 +400,18 @@ export class WorkflowsRepositoryService { `workflow not found. id: ${workflowId}`, ); } - - await workflowTypistsRepo.delete({ workflow_id: workflowId }); - await workflowRepo.delete(workflowId); + await deleteEntity( + workflowTypistsRepo, + { workflow_id: workflowId }, + this.isCommentOut, + context, + ); + await deleteEntity( + workflowRepo, + { id: workflowId }, + this.isCommentOut, + context, + ); }); } diff --git a/dictation_server/src/repositories/worktypes/worktypes.repository.service.ts b/dictation_server/src/repositories/worktypes/worktypes.repository.service.ts index 6c489f7..f647288 100644 --- a/dictation_server/src/repositories/worktypes/worktypes.repository.service.ts +++ b/dictation_server/src/repositories/worktypes/worktypes.repository.service.ts @@ -17,10 +17,19 @@ 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 { + insertEntities, + insertEntity, + updateEntity, + deleteEntity, +} from '../../common/repository'; import { Context } from '../../common/log'; @Injectable() export class WorktypesRepositoryService { + // クエリログにコメントを出力するかどうか + private readonly isCommentOut = process.env.STAGE !== 'local'; + constructor(private dataSource: DataSource) {} /** @@ -101,11 +110,17 @@ export class WorktypesRepositoryService { } // ワークタイプを作成 - const worktype = await worktypeRepo.save({ - account_id: accountId, - custom_worktype_id: worktypeId, - description: description, - }); + const worktype = await insertEntity( + Worktype, + worktypeRepo, + { + account_id: accountId, + custom_worktype_id: worktypeId, + description: description ?? null, + }, + this.isCommentOut, + context, + ); // ワークタイプに紐づくオプションアイテムを10件作成 const newOptionItems = Array.from({ length: OPTION_ITEM_NUM }, () => { @@ -118,7 +133,13 @@ export class WorktypesRepositoryService { return optionItem; }); - await optionItemRepo.save(newOptionItems); + await insertEntities( + OptionItem, + optionItemRepo, + newOptionItems, + this.isCommentOut, + context, + ); }); } @@ -168,7 +189,13 @@ export class WorktypesRepositoryService { // ワークタイプを更新 worktype.custom_worktype_id = worktypeId; worktype.description = description ?? null; - await worktypeRepo.save(worktype); + await updateEntity( + worktypeRepo, + { id: id }, + { custom_worktype_id: worktypeId, description: description ?? null }, + this.isCommentOut, + context, + ); }); } @@ -203,9 +230,12 @@ export class WorktypesRepositoryService { }); if (account?.active_worktype_id === id) { - await accountRepo.update( + await updateEntity( + accountRepo, { id: accountId }, { active_worktype_id: null }, + this.isCommentOut, + context, ); } @@ -224,10 +254,15 @@ export class WorktypesRepositoryService { // ワークタイプに紐づくオプションアイテムを削除 const optionItemRepo = entityManager.getRepository(OptionItem); - await optionItemRepo.delete({ worktype_id: id }); + await deleteEntity( + optionItemRepo, + { worktype_id: id }, + this.isCommentOut, + context, + ); // ワークタイプを削除 - await worktypeRepo.delete({ id: id }); + await deleteEntity(worktypeRepo, { id: id }, this.isCommentOut, context); }); } @@ -307,8 +342,19 @@ export class WorktypesRepositoryService { }); // ワークタイプに紐づくオプションアイテムを削除してから再登録 - await optionItemRepo.delete({ worktype_id: worktypeId }); - await optionItemRepo.save(optionItems); + await deleteEntity( + optionItemRepo, + { worktype_id: worktypeId }, + this.isCommentOut, + context, + ); + await insertEntities( + OptionItem, + optionItemRepo, + optionItems, + this.isCommentOut, + context, + ); }); } } From 5b97b619668e0805c70882dcf852c3e46880bc56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B0=B4=E6=9C=AC=20=E7=A5=90=E5=B8=8C?= Date: Wed, 13 Dec 2023 02:04:16 +0000 Subject: [PATCH 13/51] =?UTF-8?q?Merged=20PR=20619:=20API=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=EF=BC=88License=20Inventory=E3=81=AE=E8=A8=88?= =?UTF-8?q?=E7=AE=97=E5=A4=89=E6=9B=B4=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3270: API修正(License Inventoryの計算変更)](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3270) - 何をどう変更したか、追加したライブラリなど License Inventoryの計算方法を変更 →割り当て済みライセンスは件数に含まれないようにする(未使用と再利用可能ライセンスのみ) ## レビューポイント 特になし ## 動作確認状況 - ローカルで確認、ユニットテスト ## 補足 LicenseSummaryのユニットテストが旧式であったため、新しい方式でテストを追加しました。 --- .../accounts/accounts.service.spec.ts | 290 ++++++------------ .../src/features/accounts/test/utility.ts | 3 +- .../accounts/accounts.repository.service.ts | 20 +- 3 files changed, 119 insertions(+), 194 deletions(-) diff --git a/dictation_server/src/features/accounts/accounts.service.spec.ts b/dictation_server/src/features/accounts/accounts.service.spec.ts index a21f1d6..023d046 100644 --- a/dictation_server/src/features/accounts/accounts.service.spec.ts +++ b/dictation_server/src/features/accounts/accounts.service.spec.ts @@ -1581,39 +1581,6 @@ describe('createPartnerAccount', () => { }); describe('AccountsService', () => { - it('アカウントに紐づくライセンス情報を取得する', async () => { - const accountId = 1; - const usersRepositoryMockValue = makeDefaultUsersRepositoryMockValue(); - const userGroupsRepositoryMockValue = - makeDefaultUserGroupsRepositoryMockValue(); - const adb2cParam = makeDefaultAdB2cMockValue(); - const accountsRepositoryMockValue = - makeDefaultAccountsRepositoryMockValue(); - const configMockValue = makeDefaultConfigValue(); - const sendGridMockValue = makeDefaultSendGridlValue(); - const blobStorageMockValue = makeBlobStorageServiceMockValue(); - const licensesRepositoryMockValue = - makeDefaultLicensesRepositoryMockValue(); - const worktypesRepositoryMockValue = - makeDefaultWorktypesRepositoryMockValue(); - - const service = await makeAccountsServiceMock( - accountsRepositoryMockValue, - usersRepositoryMockValue, - userGroupsRepositoryMockValue, - adb2cParam, - configMockValue, - sendGridMockValue, - blobStorageMockValue, - licensesRepositoryMockValue, - worktypesRepositoryMockValue, - ); - const context = makeContext(`uuidv4`, 'requestId'); - expect(await service.getLicenseSummary(context, accountId)).toEqual( - expectedAccountLisenceCounts, - ); - }); - it('ライセンス情報が取得できない場合、エラーとなる', async () => { const accountId = 1; const usersRepositoryMockValue = makeDefaultUsersRepositoryMockValue(); @@ -1861,21 +1828,7 @@ describe('AccountsService', () => { }); }); -const expectedAccountLisenceCounts = { - totalLicense: 1, - allocatedLicense: 2, - reusableLicense: 3, - freeLicense: 4, - expiringWithin14daysLicense: 5, - issueRequesting: 6, - numberOfRequesting: 7, - shortage: 0, - storageSize: 0, - usedSize: 0, - isStorageAvailable: false, -}; - -describe('getPartnerAccount', () => { +describe('getLicenseSummary', () => { let source: DataSource | null = null; beforeEach(async () => { source = new DataSource({ @@ -1893,173 +1846,132 @@ describe('getPartnerAccount', () => { await source.destroy(); source = null; }); - - it('パラメータのアカウント自身と子アカウントに紐つくライセンス情報を取得する', async () => { + it('第五階層のライセンス情報を取得する', async () => { if (!source) fail(); const module = await makeTestingModule(source); if (!module) fail(); - // 親アカウントと子アカウント2つ作成 + // 親アカウントと子アカウント2つ作成 const { id: parentAccountId } = ( await makeTestAccount(source, { parent_account_id: 0, - tier: 1, + tier: 4, company_name: 'PARENTCORP', }) ).account; - const { id: childAccountId1 } = ( await makeTestAccount(source, { parent_account_id: parentAccountId, - tier: 2, + tier: 5, company_name: 'CHILDCORP1', }) ).account; - const { id: childAccountId2 } = ( await makeTestAccount(source, { parent_account_id: parentAccountId, - tier: 2, + tier: 5, company_name: 'CHILDCORP2', }) ).account; - // 第二にリクエストを投げる用の第三を作成 - const { id: childAccountId3 } = ( - await makeTestAccount(source, { - parent_account_id: childAccountId1, - tier: 3, - company_name: 'CHILDCORP3', - }) - ).account; - const { id: childAccountId4 } = ( - await makeTestAccount(source, { - parent_account_id: childAccountId2, - tier: 3, - company_name: 'CHILDCORP4', - }) - ).account; + // 有効期限が14日後のライセンスを追加(5ライセンス) + const expiryDate = new Date(); + expiryDate.setDate(expiryDate.getDate() + 14); + expiryDate.setHours(23, 59, 59, 999); + for (let i = 0; i < 5; i++) { + await createLicenseSetExpiryDateAndStatus( + source, + childAccountId1, + expiryDate, + 'Allocated', + 1, + ); + await createLicenseSetExpiryDateAndStatus( + source, + childAccountId2, + expiryDate, + 'Allocated', + 1, + ); + } - // 所有ライセンスを追加(親:3、子1:1、子2:2) - await createLicense( - source, - 1, - null, - parentAccountId, - LICENSE_TYPE.NORMAL, - LICENSE_ALLOCATED_STATUS.UNALLOCATED, - null, - 1, - null, - null, - ); - await createLicense( - source, - 2, - null, - parentAccountId, - LICENSE_TYPE.NORMAL, - LICENSE_ALLOCATED_STATUS.UNALLOCATED, - null, - 1, - null, - null, - ); - await createLicense( - source, - 3, - null, - parentAccountId, - LICENSE_TYPE.NORMAL, - LICENSE_ALLOCATED_STATUS.UNALLOCATED, - null, - 1, - null, - null, - ); - await createLicense( - source, - 4, - null, - childAccountId1, - LICENSE_TYPE.NORMAL, - LICENSE_ALLOCATED_STATUS.UNALLOCATED, - null, - 2, - null, - null, - ); + // 有効期限が迫っていないライセンスを追加(子1:各ステータスのライセンスを1つずつ、計4つ) + const status = ['Unallocated', 'Allocated', 'Reusable', 'Deleted']; + status.forEach(async (element) => { + if (!source) fail(); + await createLicenseSetExpiryDateAndStatus( + source, + childAccountId1, + new Date(2500, 1, 1, 23, 59, 59), + element, + 1, + ); + }); - await createLicense( - source, - 5, - null, - childAccountId2, - LICENSE_TYPE.NORMAL, - LICENSE_ALLOCATED_STATUS.UNALLOCATED, - null, - 3, - null, - null, - ); - await createLicense( - source, - 6, - null, - childAccountId2, - LICENSE_TYPE.NORMAL, - LICENSE_ALLOCATED_STATUS.UNALLOCATED, - null, - 3, - null, - null, - ); + // 有効期限が迫っていないライセンスを追加(子2:Unallocatedを10件) + for (let i = 0; i < 10; i++) { + await createLicenseSetExpiryDateAndStatus( + source, + childAccountId2, + new Date(2500, 1, 1, 23, 59, 59), + 'Unallocated', + ); + } - // ライセンス注文を追加(子1→親:10ライセンス、子2→親:5ライセンス) - await createLicenseOrder( + // 有効期限未設定のライセンスを1件追加(子1) + await createLicenseSetExpiryDateAndStatus( source, childAccountId1, - parentAccountId, - 10, - 'TEST222', + null, + 'Unallocated', ); - await createLicenseOrder(source, childAccountId2, parentAccountId, 5); - - // ライセンス注文を追加(子3→子1:10ライセンス、子4→子2:10ライセンス) - await createLicenseOrder(source, childAccountId3, childAccountId1, 10); - await createLicenseOrder(source, childAccountId4, childAccountId2, 10); + // childAccountId1にallocatedLicenseを追加 + await createLicenseSetExpiryDateAndStatus( + source, + childAccountId1, + null, + 'Allocated', + 1, + ); + // childAccountId1からライセンスの注文を100件を追加 + await createLicenseOrder(source, childAccountId1, parentAccountId, 100); const service = module.get(AccountsService); - const accountId = parentAccountId; - const offset = 0; - const limit = 20; - - const context = makeContext(`uuidv4`, 'requestId'); - const response = await service.getPartnerLicenses( + const context = makeContext(`uuidv4`, 'xxx-xxx-xxx-xxx', 'requestId'); + const resultChild1 = await service.getLicenseSummary( context, - limit, - offset, - accountId, + childAccountId1, ); - - expect(response.total).toBe(2); - - expect(response.ownPartnerLicense.companyName).toBe('PARENTCORP'); - expect(response.ownPartnerLicense.tier).toBe(1); - expect(response.ownPartnerLicense.stockLicense).toBe(3); - expect(response.ownPartnerLicense.issuedRequested).toBe(15); - expect(response.ownPartnerLicense.shortage).toBe(12); - - expect(response.childrenPartnerLicenses[0].companyName).toBe('CHILDCORP1'); - expect(response.childrenPartnerLicenses[0].tier).toBe(2); - expect(response.childrenPartnerLicenses[0].stockLicense).toBe(1); - expect(response.childrenPartnerLicenses[0].issueRequesting).toBe(10); - expect(response.childrenPartnerLicenses[0].shortage).toBe(9); - - expect(response.childrenPartnerLicenses[1].companyName).toBe('CHILDCORP2'); - expect(response.childrenPartnerLicenses[1].tier).toBe(2); - expect(response.childrenPartnerLicenses[1].stockLicense).toBe(2); - expect(response.childrenPartnerLicenses[1].shortage).toBe(8); + const resultChild2 = await service.getLicenseSummary( + context, + childAccountId2, + ); + expect(resultChild1).toEqual({ + totalLicense: 3, + allocatedLicense: 7, + reusableLicense: 1, + freeLicense: 2, + expiringWithin14daysLicense: 5, + issueRequesting: 100, + numberOfRequesting: 1, + storageSize: 0, + usedSize: 0, + shortage: 2, + isStorageAvailable: false, + }); + expect(resultChild2).toEqual({ + totalLicense: 10, + allocatedLicense: 5, + reusableLicense: 0, + freeLicense: 10, + expiringWithin14daysLicense: 5, + issueRequesting: 0, + numberOfRequesting: 0, + storageSize: 0, + usedSize: 0, + shortage: 0, + isStorageAvailable: false, + }); }); }); @@ -2189,17 +2101,17 @@ describe('getPartnerAccount', () => { accountId, ); - // 有効期限間近(5件)+ 有効期限間近でない(3件)'Unallocated', 'Allocated', 'Reusable'+ 有効期限未設定(1件) → 9件 - expect(response.childrenPartnerLicenses[0].stockLicense).toBe(9); + // 有効期限間近(5件)+ 有効期限間近でない(3件)'Unallocated', 'Allocated', 'Reusable'+ 有効期限未設定(1件) → 3件 + expect(response.childrenPartnerLicenses[0].stockLicense).toBe(3); // 有効期限間近(5件) - {有効期限間近でない未割当(2件)'Unallocated', 'Reusable'+ 有効期限未設定(1件)} → 2件 expect(response.childrenPartnerLicenses[0].shortage).toBe(2); - // 有効期限間近(5件)+ 有効期限間近でない(10件) → 15件 - expect(response.childrenPartnerLicenses[1].stockLicense).toBe(15); + // 有効期限間近(5件)+ 有効期限間近でない(10件) → 10件 + expect(response.childrenPartnerLicenses[1].stockLicense).toBe(10); // 有効期限間近(5件)- (有効期限間近でない未割当(10件)'Unallocated' + 有効期限未設定(1件)) → -5件 → 0件 expect(response.childrenPartnerLicenses[1].shortage).toBe(0); - - expect(response.childrenPartnerLicenses[2].stockLicense).toBe(1); + // 有効期限が15日後のライセンス(1件)'Allocated' + expect(response.childrenPartnerLicenses[2].stockLicense).toBe(0); // 有効期限が15日後のものはshortageにカウントされない expect(response.childrenPartnerLicenses[2].shortage).toBe(0); }); @@ -6755,7 +6667,7 @@ describe('getCompanyName', () => { if (!module) fail(); const service = module.get(AccountsService); // 第五階層のアカウント作成 - const { account, admin } = await makeTestAccount(source, { + const { admin } = await makeTestAccount(source, { tier: 5, company_name: 'testCompany', }); diff --git a/dictation_server/src/features/accounts/test/utility.ts b/dictation_server/src/features/accounts/test/utility.ts index b52a186..e658d9b 100644 --- a/dictation_server/src/features/accounts/test/utility.ts +++ b/dictation_server/src/features/accounts/test/utility.ts @@ -56,13 +56,14 @@ export const createLicenseSetExpiryDateAndStatus = async ( accountId: number, expiryDate: Date | null, status: string, + allocated_user_id?: number | null, ): Promise => { const { identifiers } = await datasource.getRepository(License).insert({ expiry_date: expiryDate, account_id: accountId, type: 'NORMAL', status: status, - allocated_user_id: null, + allocated_user_id: allocated_user_id, order_id: null, deleted_at: null, delete_order_id: null, diff --git a/dictation_server/src/repositories/accounts/accounts.repository.service.ts b/dictation_server/src/repositories/accounts/accounts.repository.service.ts index bb124f7..872e22a 100644 --- a/dictation_server/src/repositories/accounts/accounts.repository.service.ts +++ b/dictation_server/src/repositories/accounts/accounts.repository.service.ts @@ -379,12 +379,18 @@ export class AccountsRepositoryService { { account_id: id, expiry_date: MoreThanOrEqual(currentDate), - status: Not(LICENSE_ALLOCATED_STATUS.DELETED), + status: In([ + LICENSE_ALLOCATED_STATUS.REUSABLE, + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + ]), }, { account_id: id, expiry_date: IsNull(), - status: Not(LICENSE_ALLOCATED_STATUS.DELETED), + status: In([ + LICENSE_ALLOCATED_STATUS.REUSABLE, + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + ]), }, ], comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, @@ -530,12 +536,18 @@ export class AccountsRepositoryService { { account_id: id, expiry_date: MoreThanOrEqual(currentDate), - status: Not(LICENSE_ALLOCATED_STATUS.DELETED), + status: In([ + LICENSE_ALLOCATED_STATUS.REUSABLE, + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + ]), }, { account_id: id, expiry_date: IsNull(), - status: Not(LICENSE_ALLOCATED_STATUS.DELETED), + status: In([ + LICENSE_ALLOCATED_STATUS.REUSABLE, + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + ]), }, ], comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, From 0f35789b91e482ef79ba6360434020b74056587a Mon Sep 17 00:00:00 2001 From: "saito.k" Date: Wed, 13 Dec 2023 12:56:55 +0900 Subject: [PATCH 14/51] =?UTF-8?q?IP=E3=82=A2=E3=83=89=E3=83=AC=E3=82=B9?= =?UTF-8?q?=E3=83=AD=E3=82=B0=E5=87=BA=E5=8A=9B=E3=81=AB=E4=BC=B4=E3=81=86?= =?UTF-8?q?=E5=A4=89=E6=9B=B4=E3=81=AE=E6=BC=8F=E3=82=8C=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/features/accounts/accounts.controller.ts | 6 +++--- dictation_server/src/features/auth/auth.controller.ts | 8 ++++---- dictation_server/src/features/terms/terms.controller.ts | 2 +- dictation_server/src/features/users/users.controller.ts | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/dictation_server/src/features/accounts/accounts.controller.ts b/dictation_server/src/features/accounts/accounts.controller.ts index 5750071..e8a8ecd 100644 --- a/dictation_server/src/features/accounts/accounts.controller.ts +++ b/dictation_server/src/features/accounts/accounts.controller.ts @@ -141,7 +141,7 @@ export class AccountsController { ); } - const context = makeContext('anonymous', ip, requestId); + const context = makeContext('anonymous', requestId); this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.accountService.createAccount( @@ -1102,7 +1102,7 @@ export class AccountsController { ); } - const context = makeContext('anonymous', ip, requestId); + const context = makeContext('anonymous', requestId); this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); return await this.accountService.getDealers(context); @@ -1984,7 +1984,7 @@ export class AccountsController { HttpStatus.INTERNAL_SERVER_ERROR, ); } - const context = makeContext('anonymous', ip, requestId); + const context = makeContext('anonymous', requestId); this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); // IDトークンの検証 diff --git a/dictation_server/src/features/auth/auth.controller.ts b/dictation_server/src/features/auth/auth.controller.ts index a243192..09763fc 100644 --- a/dictation_server/src/features/auth/auth.controller.ts +++ b/dictation_server/src/features/auth/auth.controller.ts @@ -86,7 +86,7 @@ export class AuthController { ); } - const context = makeContext('anonymous', ip, requestId); + const context = makeContext('anonymous', requestId); this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const idToken = await this.authService.getVerifiedIdToken( @@ -190,7 +190,7 @@ export class AuthController { ); } - const context = makeContext('anonymous', ip, requestId); + const context = makeContext('anonymous', requestId); this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const accessToken = await this.authService.generateAccessToken( @@ -272,7 +272,7 @@ export class AuthController { } const { userId } = decodedAccessToken as AccessToken; - const context = makeContext('anonymous', ip, requestId); + const context = makeContext('anonymous', requestId); this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const refreshToken = await this.authService.generateDelegationRefreshToken( @@ -345,7 +345,7 @@ export class AuthController { } const { userId, delegateUserId } = decodedRefreshToken as RefreshToken; - const context = makeContext('anonymous', ip, requestId); + const context = makeContext('anonymous', requestId); this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const accessToken = await this.authService.updateDelegationAccessToken( diff --git a/dictation_server/src/features/terms/terms.controller.ts b/dictation_server/src/features/terms/terms.controller.ts index 6c9e8ac..5d668a7 100644 --- a/dictation_server/src/features/terms/terms.controller.ts +++ b/dictation_server/src/features/terms/terms.controller.ts @@ -51,7 +51,7 @@ export class TermsController { HttpStatus.INTERNAL_SERVER_ERROR, ); } - const context = makeContext('anonymous', ip, requestId); + const context = makeContext('anonymous', requestId); this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const termsInfo = await this.termsService.getTermsInfo(context); diff --git a/dictation_server/src/features/users/users.controller.ts b/dictation_server/src/features/users/users.controller.ts index e854da2..036e609 100644 --- a/dictation_server/src/features/users/users.controller.ts +++ b/dictation_server/src/features/users/users.controller.ts @@ -101,7 +101,7 @@ export class UsersController { HttpStatus.INTERNAL_SERVER_ERROR, ); } - const context = makeContext('anonymous', ip, requestId); + const context = makeContext('anonymous', requestId); this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.usersService.confirmUser(context, body.token); @@ -144,7 +144,7 @@ export class UsersController { HttpStatus.INTERNAL_SERVER_ERROR, ); } - const context = makeContext('anonymous', ip, requestId); + const context = makeContext('anonymous', requestId); this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); await this.usersService.confirmUserAndInitPassword(context, body.token); return {}; @@ -833,7 +833,7 @@ export class UsersController { HttpStatus.INTERNAL_SERVER_ERROR, ); } - const context = makeContext('anonymous', ip, requestId); + const context = makeContext('anonymous', requestId); this.logger.log(`[${context.getTrackingId()}] ip : ${ip}`); const verifiedIdToken = await this.authService.getVerifiedIdToken( From 63892bad83230cfcceade4a338bc22d9b0a1666f Mon Sep 17 00:00:00 2001 From: "makabe.t" Date: Wed, 13 Dec 2023 08:08:58 +0000 Subject: [PATCH 15/51] =?UTF-8?q?Merged=20PR=20620:=20=E3=83=86=E3=83=B3?= =?UTF-8?q?=E3=83=97=E3=83=AC=E3=83=BC=E3=83=88=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E3=83=80=E3=82=A6=E3=83=B3=E3=83=AD=E3=83=BC=E3=83=89?= =?UTF-8?q?=E3=82=92Typist=E3=81=AE=E3=81=BF=E3=81=8C=E5=AE=9F=E8=A1=8C?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3291: テンプレートファイルダウンロードをTypistのみが実行可能にする](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3291) - テンプレートファイルダウンロード先要求APIを実行できるユーザーをTypistのみに修正しました。 - Authorが実行できないようにしました。 ## レビューポイント - ガードでTypistのみにしたので内部のロールでの分岐処理を削除しましたが問題ないでしょうか? ## UIの変更 - なし ## 動作確認状況 - ローカルで確認 --- .../src/features/files/files.controller.ts | 4 +- .../src/features/files/files.service.spec.ts | 293 ++++++++---------- .../src/features/files/files.service.ts | 38 +-- 3 files changed, 137 insertions(+), 198 deletions(-) diff --git a/dictation_server/src/features/files/files.controller.ts b/dictation_server/src/features/files/files.controller.ts index af41275..f8b4328 100644 --- a/dictation_server/src/features/files/files.controller.ts +++ b/dictation_server/src/features/files/files.controller.ts @@ -338,9 +338,7 @@ export class FilesController { }) @ApiBearerAuth() @UseGuards(AuthGuard) - @UseGuards( - RoleGuard.requireds({ roles: [USER_ROLES.AUTHOR, USER_ROLES.TYPIST] }), - ) + @UseGuards(RoleGuard.requireds({ roles: [USER_ROLES.TYPIST] })) async downloadTemplateLocation( @Req() req: Request, @Query() body: TemplateDownloadLocationRequest, diff --git a/dictation_server/src/features/files/files.service.spec.ts b/dictation_server/src/features/files/files.service.spec.ts index d32d081..89c9f68 100644 --- a/dictation_server/src/features/files/files.service.spec.ts +++ b/dictation_server/src/features/files/files.service.spec.ts @@ -34,7 +34,12 @@ import { TasksRepositoryService } from '../../repositories/tasks/tasks.repositor import { NotificationhubService } from '../../gateways/notificationhub/notificationhub.service'; import { getCheckoutPermissions, getTask } from '../tasks/test/utility'; import { DateWithZeroTime } from '../licenses/types/types'; -import { LICENSE_ALLOCATED_STATUS, LICENSE_TYPE } from '../../constants'; +import { + LICENSE_ALLOCATED_STATUS, + LICENSE_TYPE, + TASK_STATUS, + USER_ROLES, +} from '../../constants'; describe('publishUploadSas', () => { let source: DataSource | null = null; @@ -1505,15 +1510,11 @@ describe('テンプレートファイルダウンロードURL取得', () => { it('ダウンロードSASトークンが乗っているURLを取得できる', async () => { if (!source) fail(); const { id: accountId } = await makeTestSimpleAccount(source); - const { external_id: externalId, author_id: authorId } = await makeTestUser( - source, - { - account_id: accountId, - external_id: 'author-user-external-id', - role: 'author', - author_id: 'AUTHOR_ID', - }, - ); + const { external_id: externalId, id: userId } = await makeTestUser(source, { + account_id: accountId, + external_id: 'typist-user-external-id', + role: USER_ROLES.TYPIST, + }); const url = `https://saodmsusdev.blob.core.windows.net/account-${accountId}/Templates`; const { audioFileId } = await createTask( @@ -1521,9 +1522,9 @@ describe('テンプレートファイルダウンロードURL取得', () => { accountId, url, 'test.zip', - 'InProgress', - undefined, - authorId ?? '', + TASK_STATUS.IN_PROGRESS, + userId, + 'AUTHOR_ID', ); const blobParam = makeBlobstorageServiceMockValue(); @@ -1539,13 +1540,12 @@ describe('テンプレートファイルダウンロードURL取得', () => { if (!module) fail(); const service = module.get(FilesService); - expect( - await service.publishTemplateFileDownloadSas( - makeContext('tracking', 'requestId'), - externalId, - audioFileId, - ), - ).toEqual(`${url}?sas-token`); + const resultUrl = await service.publishTemplateFileDownloadSas( + makeContext('tracking', 'requestId'), + externalId, + audioFileId, + ); + expect(resultUrl).toBe(`${url}?sas-token`); }); it('ダウンロードSASトークンが乗っているURLを取得できる(第五階層の場合ライセンスのチェックを行う)', async () => { if (!source) fail(); @@ -1557,15 +1557,10 @@ describe('テンプレートファイルダウンロードURL取得', () => { parent_account_id: tier4Accounts[0].account.id, tier: 5, }); - const { - external_id: externalId, - id: userId, - author_id: authorId, - } = await makeTestUser(source, { + const { external_id: externalId, id: userId } = await makeTestUser(source, { account_id: tier5Accounts.account.id, - external_id: 'author-user-external-id', - role: 'author', - author_id: 'AUTHOR_ID', + external_id: 'typist-user-external-id', + role: USER_ROLES.TYPIST, }); // 本日の日付を作成 let yesterday = new Date(); @@ -1591,9 +1586,9 @@ describe('テンプレートファイルダウンロードURL取得', () => { tier5Accounts.account.id, url, 'test.zip', - 'InProgress', - undefined, - authorId ?? '', + TASK_STATUS.IN_PROGRESS, + userId, + 'AUTHOR_ID', ); const blobParam = makeBlobstorageServiceMockValue(); @@ -1609,22 +1604,20 @@ describe('テンプレートファイルダウンロードURL取得', () => { if (!module) fail(); const service = module.get(FilesService); - expect( - await service.publishTemplateFileDownloadSas( - makeContext('trackingId', 'requestId'), - externalId, - audioFileId, - ), - ).toEqual(`${url}?sas-token`); + const resultUrl = await service.publishTemplateFileDownloadSas( + makeContext('trackingId', 'requestId'), + externalId, + audioFileId, + ); + expect(resultUrl).toBe(`${url}?sas-token`); }); - it('Typistの場合、タスクのステータスが[Inprogress,Pending]以外でエラー', async () => { + it('タスクのステータスが[Inprogress,Pending]以外でエラー', async () => { if (!source) fail(); const { id: accountId } = await makeTestSimpleAccount(source); const { external_id: externalId, id: userId } = await makeTestUser(source, { account_id: accountId, external_id: 'typist-user-external-id', - role: 'typist', - author_id: undefined, + role: USER_ROLES.TYPIST, }); const url = `https://saodmsusdev.blob.core.windows.net/account-${accountId}/Templates`; @@ -1633,7 +1626,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { accountId, url, 'test.zip', - 'Finished', + TASK_STATUS.FINISHED, userId, ); @@ -1650,31 +1643,35 @@ describe('テンプレートファイルダウンロードURL取得', () => { if (!module) fail(); const service = module.get(FilesService); - await expect( - service.publishTemplateFileDownloadSas( + try { + await service.publishTemplateFileDownloadSas( makeContext('tracking', 'requestId'), externalId, audioFileId, - ), - ).rejects.toEqual( - new HttpException(makeErrorResponse('E010603'), HttpStatus.BAD_REQUEST), - ); + ); + fail(); + } catch (e) { + if (e instanceof HttpException) { + expect(e.getStatus()).toBe(HttpStatus.BAD_REQUEST); + expect(e.getResponse()).toEqual(makeErrorResponse('E010603')); + } else { + fail(); + } + } }); - it('Typistの場合、自身が担当するタスクでない場合エラー', async () => { + it('自身が担当するタスクでない場合エラー', async () => { if (!source) fail(); const { id: accountId } = await makeTestSimpleAccount(source); const { external_id: externalId } = await makeTestUser(source, { account_id: accountId, external_id: 'typist-user-external-id', - role: 'typist', - author_id: undefined, + role: USER_ROLES.TYPIST, }); const { id: otherId } = await makeTestUser(source, { account_id: accountId, external_id: 'other-typist-user-external-id', - role: 'typist', - author_id: undefined, + role: USER_ROLES.TYPIST, }); const url = `https://saodmsusdev.blob.core.windows.net/account-${accountId}/Templates`; @@ -1683,7 +1680,7 @@ describe('テンプレートファイルダウンロードURL取得', () => { accountId, url, 'test.zip', - 'InProgress', + TASK_STATUS.IN_PROGRESS, otherId, ); @@ -1700,60 +1697,21 @@ describe('テンプレートファイルダウンロードURL取得', () => { if (!module) fail(); const service = module.get(FilesService); - await expect( - service.publishTemplateFileDownloadSas( + try { + await service.publishTemplateFileDownloadSas( makeContext('tracking', 'requestId'), externalId, audioFileId, - ), - ).rejects.toEqual( - new HttpException(makeErrorResponse('E010603'), HttpStatus.BAD_REQUEST), - ); - }); - - it('Authorの場合、自身が登録したタスクでない場合エラー', async () => { - if (!source) fail(); - const { id: accountId } = await makeTestSimpleAccount(source); - const { external_id: externalId } = await makeTestUser(source, { - account_id: accountId, - external_id: 'author-user-external-id', - role: 'author', - author_id: 'AUTHOR_ID', - }); - const url = `https://saodmsusdev.blob.core.windows.net/account-${accountId}/Templates`; - - const { audioFileId } = await createTask( - source, - accountId, - url, - 'test.zip', - 'InProgress', - undefined, - 'OTHOR_ID', - ); - - const blobParam = makeBlobstorageServiceMockValue(); - blobParam.publishDownloadSas = `${url}?sas-token`; - blobParam.fileExists = true; - - const notificationParam = makeDefaultNotificationhubServiceMockValue(); - const module = await makeTestingModuleWithBlobAndNotification( - source, - blobParam, - notificationParam, - ); - if (!module) fail(); - const service = module.get(FilesService); - - await expect( - service.publishTemplateFileDownloadSas( - makeContext('tracking', 'requestId'), - externalId, - audioFileId, - ), - ).rejects.toEqual( - new HttpException(makeErrorResponse('E010603'), HttpStatus.BAD_REQUEST), - ); + ); + fail(); + } catch (e) { + if (e instanceof HttpException) { + expect(e.getStatus()).toBe(HttpStatus.BAD_REQUEST); + expect(e.getResponse()).toEqual(makeErrorResponse('E010603')); + } else { + fail(); + } + } }); it('Taskが存在しない場合はエラーとなる', async () => { @@ -1761,9 +1719,8 @@ describe('テンプレートファイルダウンロードURL取得', () => { const { id: accountId } = await makeTestSimpleAccount(source); const { external_id: externalId } = await makeTestUser(source, { account_id: accountId, - external_id: 'author-user-external-id', - role: 'author', - author_id: 'AUTHOR_ID', + external_id: 'typist-user-external-id', + role: USER_ROLES.TYPIST, }); const blobParam = makeBlobstorageServiceMockValue(); @@ -1777,29 +1734,31 @@ describe('テンプレートファイルダウンロードURL取得', () => { if (!module) fail(); const service = module.get(FilesService); - await expect( - service.publishTemplateFileDownloadSas( + try { + await service.publishTemplateFileDownloadSas( makeContext('tracking', 'requestId'), externalId, 1, - ), - ).rejects.toEqual( - new HttpException(makeErrorResponse('E010603'), HttpStatus.BAD_REQUEST), - ); + ); + fail(); + } catch (e) { + if (e instanceof HttpException) { + expect(e.getStatus()).toBe(HttpStatus.BAD_REQUEST); + expect(e.getResponse()).toEqual(makeErrorResponse('E010603')); + } else { + fail(); + } + } }); it('blobストレージにファイルが存在しない場合はエラーとなる', async () => { if (!source) fail(); const { id: accountId } = await makeTestSimpleAccount(source); - const { external_id: externalId, author_id: authorId } = await makeTestUser( - source, - { - account_id: accountId, - external_id: 'author-user-external-id', - role: 'author', - author_id: 'AUTHOR_ID', - }, - ); + const { external_id: externalId, id: userId } = await makeTestUser(source, { + account_id: accountId, + external_id: 'typist-user-external-id', + role: USER_ROLES.TYPIST, + }); const url = `https://saodmsusdev.blob.core.windows.net/account-${accountId}/Templates`; const { audioFileId } = await createTask( @@ -1807,9 +1766,9 @@ describe('テンプレートファイルダウンロードURL取得', () => { accountId, url, 'test.zip', - 'InProgress', - undefined, - authorId ?? '', + TASK_STATUS.IN_PROGRESS, + userId, + 'AUTHOR_ID', ); const blobParam = makeBlobstorageServiceMockValue(); @@ -1825,15 +1784,21 @@ describe('テンプレートファイルダウンロードURL取得', () => { if (!module) fail(); const service = module.get(FilesService); - await expect( - service.publishTemplateFileDownloadSas( + try { + await service.publishTemplateFileDownloadSas( makeContext('tracking', 'requestId'), externalId, audioFileId, - ), - ).rejects.toEqual( - new HttpException(makeErrorResponse('E010701'), HttpStatus.BAD_REQUEST), - ); + ); + fail(); + } catch (e) { + if (e instanceof HttpException) { + expect(e.getStatus()).toBe(HttpStatus.BAD_REQUEST); + expect(e.getResponse()).toEqual(makeErrorResponse('E010701')); + } else { + fail(); + } + } }); it('ダウンロード時にユーザーにライセンスが未割当の場合エラーとなる(第五階層限定)', async () => { if (!source) fail(); @@ -1845,15 +1810,10 @@ describe('テンプレートファイルダウンロードURL取得', () => { parent_account_id: tier4Accounts[0].account.id, tier: 5, }); - const { - external_id: externalId, - id: userId, - author_id: authorId, - } = await makeTestUser(source, { + const { external_id: externalId, id: userId } = await makeTestUser(source, { account_id: tier5Accounts.account.id, - external_id: 'author-user-external-id', - role: 'author', - author_id: 'AUTHOR_ID', + external_id: 'typist-user-external-id', + role: USER_ROLES.TYPIST, }); const url = `https://saodmsusdev.blob.core.windows.net/account-${tier5Accounts.account.id}/${userId}`; @@ -1862,9 +1822,9 @@ describe('テンプレートファイルダウンロードURL取得', () => { tier5Accounts.account.id, url, 'test.zip', - 'InProgress', + TASK_STATUS.IN_PROGRESS, undefined, - authorId ?? '', + 'AUTHOR_ID', ); const blobParam = makeBlobstorageServiceMockValue(); @@ -1880,15 +1840,21 @@ describe('テンプレートファイルダウンロードURL取得', () => { if (!module) fail(); const service = module.get(FilesService); - await expect( - service.publishTemplateFileDownloadSas( + try { + await service.publishTemplateFileDownloadSas( makeContext('trackingId', 'requestId'), externalId, audioFileId, - ), - ).rejects.toEqual( - new HttpException(makeErrorResponse('E010812'), HttpStatus.BAD_REQUEST), - ); + ); + fail(); + } catch (e) { + if (e instanceof HttpException) { + expect(e.getStatus()).toBe(HttpStatus.BAD_REQUEST); + expect(e.getResponse()).toEqual(makeErrorResponse('E010812')); + } else { + fail(); + } + } }); it('ダウンロード時にユーザーに割り当てられたライセンスが有効期限切れの場合エラー(第五階層限定)', async () => { if (!source) fail(); @@ -1900,15 +1866,10 @@ describe('テンプレートファイルダウンロードURL取得', () => { parent_account_id: tier4Accounts[0].account.id, tier: 5, }); - const { - external_id: externalId, - id: userId, - author_id: authorId, - } = await makeTestUser(source, { + const { external_id: externalId, id: userId } = await makeTestUser(source, { account_id: tier5Accounts.account.id, - external_id: 'author-user-external-id', - role: 'author', - author_id: 'AUTHOR_ID', + external_id: 'typist-user-external-id', + role: USER_ROLES.TYPIST, }); // 昨日の日付を作成 let yesterday = new Date(); @@ -1934,9 +1895,9 @@ describe('テンプレートファイルダウンロードURL取得', () => { tier5Accounts.account.id, url, 'test.zip', - 'InProgress', + TASK_STATUS.IN_PROGRESS, undefined, - authorId ?? '', + 'AUTHOR_ID', ); const blobParam = makeBlobstorageServiceMockValue(); @@ -1952,15 +1913,21 @@ describe('テンプレートファイルダウンロードURL取得', () => { if (!module) fail(); const service = module.get(FilesService); - await expect( - service.publishTemplateFileDownloadSas( + try { + await service.publishTemplateFileDownloadSas( makeContext('trackingId', 'requestId'), externalId, audioFileId, ), - ).rejects.toEqual( - new HttpException(makeErrorResponse('E010805'), HttpStatus.BAD_REQUEST), - ); + fail(); + } catch (e) { + if (e instanceof HttpException) { + expect(e.getStatus()).toBe(HttpStatus.BAD_REQUEST); + expect(e.getResponse()).toEqual(makeErrorResponse('E010805')); + } else { + fail(); + } + } }); }); diff --git a/dictation_server/src/features/files/files.service.ts b/dictation_server/src/features/files/files.service.ts index 8e73b0a..6c1b558 100644 --- a/dictation_server/src/features/files/files.service.ts +++ b/dictation_server/src/features/files/files.service.ts @@ -474,7 +474,7 @@ export class FilesService { // ユーザーがTypistの場合、自身が担当したタスクでない場合はエラー if (isTypist && task.typist_user_id !== userId) { - throw new AuthorUserNotMatchError( + throw new TypistUserNotFoundError( `task typist is not match. audio_file_id:${audioFileId}, task.typist_user_id:${task.typist_user_id}, userId:${userId}`, ); } @@ -563,8 +563,6 @@ export class FilesService { let accountId: number; let userId: number; let country: string; - let isTypist: boolean; - let authorId: string | undefined; try { const user = await this.usersRepository.findUserByExternalId( context, @@ -590,8 +588,6 @@ export class FilesService { accountId = user.account_id; userId = user.id; country = user.account.country; - isTypist = user.role === USER_ROLES.TYPIST; - authorId = user.author_id ?? undefined; } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); this.logger.log( @@ -619,27 +615,13 @@ export class FilesService { } try { - const status = isTypist - ? [TASK_STATUS.IN_PROGRESS, TASK_STATUS.PENDING] - : Object.values(TASK_STATUS); - const task = await this.tasksRepository.getTaskAndAudioFile( context, audioFileId, accountId, - status, + [TASK_STATUS.IN_PROGRESS, TASK_STATUS.PENDING], ); - const { file } = task; - - // タスクに紐づく音声ファイルだけが消される場合がある。 - // その場合はダウンロード不可なので不在エラーとして扱う - if (!file) { - throw new AudioFileNotFoundError( - `Audio file is not exists in DB. audio_file_id:${audioFileId}`, - ); - } - - const template_file = task.template_file; + const { template_file } = task; // タスクに紐づくテンプレートファイルがない場合がある。 // その場合はダウンロード不可なので不在エラーとして扱う @@ -649,16 +631,9 @@ export class FilesService { ); } - // ユーザーがAuthorの場合、自身が追加したタスクでない場合はエラー - if (!isTypist && file.author_id !== authorId) { - throw new AuthorUserNotMatchError( - `task author is not match. audio_file_id:${audioFileId}, task.file.author_id:${file.author_id}, authorId:${authorId}`, - ); - } - - // ユーザーがTypistの場合、自身が担当したタスクでない場合はエラー - if (isTypist && task.typist_user_id !== userId) { - throw new AuthorUserNotMatchError( + // ユーザー自身が担当したタスクでない場合はエラー + if (task.typist_user_id !== userId) { + throw new TypistUserNotFoundError( `task typist is not match. audio_file_id:${audioFileId}, task.typist_user_id:${task.typist_user_id}, userId:${userId}`, ); } @@ -693,7 +668,6 @@ export class FilesService { case TasksNotFoundError: case AccountNotMatchError: case StatusNotMatchError: - case AuthorUserNotMatchError: case TypistUserNotFoundError: throw new HttpException( makeErrorResponse('E010603'), From ad715285c61b2bb59e0fcedebaa027c314a96b90 Mon Sep 17 00:00:00 2001 From: "makabe.t" Date: Wed, 13 Dec 2023 08:27:00 +0000 Subject: [PATCH 16/51] =?UTF-8?q?Merged=20PR=20613:=20=E5=A4=96=E9=83=A8?= =?UTF-8?q?=E9=80=A3=E6=90=BAAPI=E3=81=AE=E3=83=90=E3=83=AA=E3=83=87?= =?UTF-8?q?=E3=83=BC=E3=82=BF=E8=A6=8B=E7=9B=B4=E3=81=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3279: files配下APIの対応](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3279) - 外部連携API(以下のAPIが対象)のバリデータを修正しました。 - ~~音声ファイルアップロード要求API~~ - ~~GET /files/audio/upload-location~~ - 音声ファイルアップロード完了API(タスク追加API) - POST /files/audio/upload-finished - タスクチェックアウトAPI - POST /tasks/{audioFileId}/checkout - タスクペンディングAPI - POST /tasks/{audioFileId}/suspend - タスクキャンセルAPI - POST /tasks/{audioFileId}/cancel - タスクチェックインAPI - POST /tasks/{audioFileId}/checkin - 音声ファイルダウンロード先取得API - GET /files/audio/download-location - テンプレートファイルダウンロード先要求API - GET /files/template/download-location - 次ファイル情報取得要求API - GET /tasks/next - 認証情報作成API - POST /auth/token - 通知登録API - POST /notification/register ## レビューポイント - 対象APIに漏れはないでしょうか。 - バリデータの制約は適切でしょうか? ## UIの変更 - なし ## 動作確認状況 - ローカルで確認 --- .../src/features/accounts/types/types.ts | 18 ++++----- .../src/features/auth/types/types.ts | 6 ++- .../src/features/files/types/types.ts | 39 ++++++++++++++++++- .../src/features/notification/types/types.ts | 4 +- .../src/features/tasks/types/types.ts | 3 +- .../src/features/workflows/types/types.ts | 16 ++++---- 6 files changed, 63 insertions(+), 23 deletions(-) diff --git a/dictation_server/src/features/accounts/types/types.ts b/dictation_server/src/features/accounts/types/types.ts index 6e45d8e..c587255 100644 --- a/dictation_server/src/features/accounts/types/types.ts +++ b/dictation_server/src/features/accounts/types/types.ts @@ -184,7 +184,7 @@ export class GetTypistGroupRequest { @ApiProperty() @Type(() => Number) @IsInt() - @Min(0) + @Min(1) typistGroupId: number; } export class GetTypistGroupResponse { @@ -203,7 +203,7 @@ export class CreateTypistGroupRequest { @ArrayMinSize(1) @IsArray() @IsInt({ each: true }) - @Min(0, { each: true }) + @Min(1, { each: true }) @IsUnique() typistIds: number[]; } @@ -219,7 +219,7 @@ export class UpdateTypistGroupRequest { @ArrayMinSize(1) @IsArray() @IsInt({ each: true }) - @Min(0, { each: true }) + @Min(1, { each: true }) @IsUnique() typistIds: number[]; } @@ -227,7 +227,7 @@ export class UpdateTypistGroupRequestParam { @ApiProperty() @Type(() => Number) @IsInt() - @Min(0) + @Min(1) typistGroupId: number; } export class UpdateTypistGroupResponse {} @@ -463,7 +463,7 @@ export class GetOptionItemsRequestParam { @ApiProperty({ description: 'Worktypeの内部ID' }) @Type(() => Number) @IsInt() - @Min(0) + @Min(1) id: number; } @@ -487,7 +487,7 @@ export class UpdateOptionItemsRequestParam { @ApiProperty({ description: 'Worktypeの内部ID' }) @Type(() => Number) @IsInt() - @Min(0) + @Min(1) id: number; } @@ -495,7 +495,7 @@ export class UpdateWorktypeRequestParam { @ApiProperty({ description: 'Worktypeの内部ID' }) @Type(() => Number) @IsInt() - @Min(0) + @Min(1) id: number; } @@ -503,7 +503,7 @@ export class DeleteWorktypeRequestParam { @ApiProperty({ description: 'Worktypeの内部ID' }) @Type(() => Number) @IsInt() - @Min(0) + @Min(1) id: number; } @@ -517,7 +517,7 @@ export class PostActiveWorktypeRequest { @IsOptional() @Type(() => Number) @IsInt() - @Min(0) + @Min(1) id?: number; } diff --git a/dictation_server/src/features/auth/types/types.ts b/dictation_server/src/features/auth/types/types.ts index c031508..023a982 100644 --- a/dictation_server/src/features/auth/types/types.ts +++ b/dictation_server/src/features/auth/types/types.ts @@ -1,10 +1,14 @@ import { ApiProperty } from '@nestjs/swagger'; -import { IsInt } from 'class-validator'; +import { IsIn, IsInt, IsNotEmpty, IsString } from 'class-validator'; export class TokenRequest { @ApiProperty() + @IsString() + @IsNotEmpty() idToken: string; @ApiProperty({ description: 'web or mobile or desktop' }) + @IsIn(['web', 'mobile', 'desktop'], { message: 'invalid type' }) + @IsNotEmpty() type: string; } export class TokenResponse { diff --git a/dictation_server/src/features/files/types/types.ts b/dictation_server/src/features/files/types/types.ts index 2fda838..3545a20 100644 --- a/dictation_server/src/features/files/types/types.ts +++ b/dictation_server/src/features/files/types/types.ts @@ -1,6 +1,17 @@ import { ApiProperty } from '@nestjs/swagger'; import { Type } from 'class-transformer'; -import { IsInt, Min } from 'class-validator'; +import { + ArrayMaxSize, + ArrayMinSize, + IsArray, + IsIn, + IsInt, + IsNotEmpty, + IsNumberString, + MaxLength, + Min, + MinLength, +} from 'class-validator'; export class AudioUploadLocationRequest {} @@ -13,6 +24,9 @@ export class AudioUploadLocationResponse { export class AudioDownloadLocationRequest { @ApiProperty({ description: 'ODMSCloud上で管理する音声ファイルのID' }) + @Type(() => Number) + @Min(1) + @IsInt() audioFileId: number; } @@ -26,7 +40,7 @@ export class AudioDownloadLocationResponse { export class TemplateDownloadLocationRequest { @ApiProperty({ description: '文字起こし対象の音声ファイルID' }) @Type(() => Number) - @Min(0) + @Min(1) @IsInt() audioFileId: number; } @@ -43,40 +57,58 @@ export class TemplateUploadLocationResponse { export class AudioOptionItem { @ApiProperty({ minLength: 1, maxLength: 16 }) + @MinLength(1) + @MaxLength(16) optionItemLabel: string; @ApiProperty({ minLength: 1, maxLength: 20 }) + @MinLength(1) + @MaxLength(20) optionItemValue: string; } export class AudioUploadFinishedRequest { @ApiProperty({ description: 'アップロード先Blob Storage(ファイル名含む)' }) + @IsNotEmpty() url: string; @ApiProperty({ description: '自分自身(ログイン認証)したAuthorID' }) + @IsNotEmpty() authorId: string; @ApiProperty({ description: '音声ファイル名' }) + @IsNotEmpty() fileName: string; @ApiProperty({ description: '音声ファイルの録音時間(ミリ秒の整数値)', }) + @IsNumberString() + @IsNotEmpty() duration: string; @ApiProperty({ description: '音声ファイルの録音作成日時(開始日時)(yyyy-mm-ddThh:mm:ss.sss)', }) + @IsNotEmpty() createdDate: string; @ApiProperty({ description: '音声ファイルの録音作成終了日時(yyyy-mm-ddThh:mm:ss.sss)', }) + @IsNotEmpty() finishedDate: string; @ApiProperty({ description: '音声ファイルのアップロード日時(yyyy-mm-ddThh:mm:ss.sss)', }) + @IsNotEmpty() uploadedDate: string; @ApiProperty({ description: '音声ファイルのファイルサイズ(Byte)' }) + @Type(() => Number) + @IsInt() + @IsNotEmpty() fileSize: number; @ApiProperty({ description: '優先度 "00":Normal / "01":High' }) + @IsIn(['00', '01'], { message: 'invalid priority' }) + @IsNotEmpty() priority: string; @ApiProperty({ description: '録音形式: DSS/DS2(SP)/DS2(QP)' }) + @IsNotEmpty() audioFormat: string; @ApiProperty() comment: string; @@ -88,6 +120,9 @@ export class AudioUploadFinishedRequest { minItems: 10, description: '音声ファイルに紐づくOption Itemの一覧(10個固定)', }) + @IsArray() + @ArrayMinSize(10) + @ArrayMaxSize(10) optionItemList: AudioOptionItem[]; @ApiProperty() isEncrypted: boolean; diff --git a/dictation_server/src/features/notification/types/types.ts b/dictation_server/src/features/notification/types/types.ts index b19bf08..433ea59 100644 --- a/dictation_server/src/features/notification/types/types.ts +++ b/dictation_server/src/features/notification/types/types.ts @@ -1,5 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; -import { IsIn } from 'class-validator'; +import { IsIn, IsNotEmpty, IsString } from 'class-validator'; import { PNS } from '../../../constants'; export class RegisterRequest { @@ -9,6 +9,8 @@ export class RegisterRequest { }) pns: string; @ApiProperty({ description: 'wnsのチャネルURI or apnsのデバイストークン' }) + @IsString() + @IsNotEmpty() handler: string; } diff --git a/dictation_server/src/features/tasks/types/types.ts b/dictation_server/src/features/tasks/types/types.ts index 80cff57..69b7c1d 100644 --- a/dictation_server/src/features/tasks/types/types.ts +++ b/dictation_server/src/features/tasks/types/types.ts @@ -22,7 +22,6 @@ export class TasksRequest { }) @IsInt() @Min(0) - @Type(() => Number) @IsOptional() @Type(() => Number) limit: number; @@ -35,7 +34,6 @@ export class TasksRequest { }) @IsInt() @Min(0) - @Type(() => Number) @IsOptional() @Type(() => Number) offset: number; @@ -192,6 +190,7 @@ export class AudioNextRequest { @ApiProperty({ description: '文字起こし完了したタスクの音声ファイルID' }) @Type(() => Number) @IsInt() + @Min(1) endedFileId: number; } diff --git a/dictation_server/src/features/workflows/types/types.ts b/dictation_server/src/features/workflows/types/types.ts index 87f77c0..e3e34df 100644 --- a/dictation_server/src/features/workflows/types/types.ts +++ b/dictation_server/src/features/workflows/types/types.ts @@ -53,19 +53,19 @@ export class CreateWorkflowsRequest { @ApiProperty({ description: 'Authorの内部ID' }) @Type(() => Number) @IsInt() - @Min(0) + @Min(1) authorId: number; @ApiProperty({ description: 'Worktypeの内部ID', required: false }) @IsOptional() @Type(() => Number) @IsInt() - @Min(0) + @Min(1) worktypeId?: number; @ApiProperty({ description: 'テンプレートの内部ID', required: false }) @IsOptional() @Type(() => Number) @IsInt() - @Min(0) + @Min(1) templateId?: number; @ApiProperty({ description: 'ルーティング候補のタイピストユーザー/タイピストグループ', @@ -84,7 +84,7 @@ export class UpdateWorkflowRequestParam { @ApiProperty({ description: 'ワークフローの内部ID' }) @Type(() => Number) @IsInt() - @Min(0) + @Min(1) workflowId: number; } @@ -92,19 +92,19 @@ export class UpdateWorkflowRequest { @ApiProperty({ description: 'Authorの内部ID' }) @Type(() => Number) @IsInt() - @Min(0) + @Min(1) authorId: number; @ApiProperty({ description: 'Worktypeの内部ID', required: false }) @IsOptional() @Type(() => Number) @IsInt() - @Min(0) + @Min(1) worktypeId?: number; @ApiProperty({ description: 'テンプレートの内部ID', required: false }) @IsOptional() @Type(() => Number) @IsInt() - @Min(0) + @Min(1) templateId?: number; @ApiProperty({ description: 'ルーティング候補のタイピストユーザー/タイピストグループ', @@ -123,7 +123,7 @@ export class DeleteWorkflowRequestParam { @ApiProperty({ description: 'ワークフローの内部ID' }) @Type(() => Number) @IsInt() - @Min(0) + @Min(1) workflowId: number; } From 1c39555bfccf53e7b03d9b5f6d4cb71f6864887f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B9=AF=E6=9C=AC=20=E9=96=8B?= Date: Fri, 15 Dec 2023 05:56:09 +0000 Subject: [PATCH 17/51] =?UTF-8?q?Merged=20PR=20632:=20=E3=83=A9=E3=82=A4?= =?UTF-8?q?=E3=82=BB=E3=83=B3=E3=82=B9=E3=82=AA=E3=83=BC=E3=83=80=E3=83=BC?= =?UTF-8?q?=E3=81=AE=E3=82=AD=E3=83=A3=E3=83=B3=E3=82=BB=E3=83=AB=E5=8F=97?= =?UTF-8?q?=E4=BB=98=E9=80=9A=E7=9F=A5=20[U-106]=C2=A0=E3=81=AE=E5=AE=9F?= =?UTF-8?q?=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3303: ライセンスオーダーのキャンセル受付通知 [U-106] の実装](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3303) - オーダーキャンセルが完了時にメールを送信する処理を追加 - SendGridServiceにテンプレートメールを送信するメソッドを追加 - Adb2cUserからメールアドレスを取得する方法が分散して実装してあったので、取り出す用のメソッドを定義してそれを使用するよう修正 ## レビュー対象外 - 実際のメール送信処理部分は未実装なので対象外 ## レビューポイント - SendGridServiceに`sendTtemplateMailWithU{番号}`というメソッドを用意してメール送信を行う形式で問題ないか - from/toやCC等もメールの種別毎に異なるので、SendGridService側に具体的にどんなメールを送るかの責任を持たせる方針でいいか - `sendMailWithU106` の引数に不足や認識間違いはないか - キャンセルを行った本人へのメールだけで本当によいか?(他の管理者には知らせないでいいか)等 - to/cc等も考慮してチェックお願いします - **特にMISOチーム向け** 依存関係の追加で壊れたテストを削除したが、別途DBテストを追加しないで問題なさそうか? - 問題ありそうでれば、別途テスト実装タスクを作る想定 ## 動作確認状況 - npm run testが通るところまで確認 --- .../src/features/accounts/accounts.service.ts | 7 +- .../src/features/licenses/licenses.module.ts | 4 + .../licenses/licenses.service.spec.ts | 265 ------------------ .../src/features/licenses/licenses.service.ts | 119 +++++++- .../src/features/users/users.service.ts | 9 +- .../src/gateways/adb2c/utils/utils.ts | 12 + .../src/gateways/sendgrid/sendgrid.service.ts | 32 +++ .../licenses/licenses.repository.service.ts | 38 ++- .../users/users.repository.service.ts | 42 ++- 9 files changed, 251 insertions(+), 277 deletions(-) diff --git a/dictation_server/src/features/accounts/accounts.service.ts b/dictation_server/src/features/accounts/accounts.service.ts index 373e7bc..ba76c63 100644 --- a/dictation_server/src/features/accounts/accounts.service.ts +++ b/dictation_server/src/features/accounts/accounts.service.ts @@ -71,6 +71,7 @@ import { WorktypeIdMaxCountError, WorktypeIdNotFoundError, } from '../../repositories/worktypes/errors/types'; +import { getUserNameAndMailAddress } from '../../gateways/adb2c/utils/utils'; @Injectable() export class AccountsService { @@ -1930,10 +1931,8 @@ export class AccountsService { ); } - const primaryAdmin = adb2cUser.displayName; - const mail = adb2cUser.identities?.find( - (identity) => identity.signInType === ADB2C_SIGN_IN_TYPE.EMAILADDRESS, - )?.issuerAssignedId; + const { displayName: primaryAdmin, emailAddress: mail } = + getUserNameAndMailAddress(adb2cUser); if (!mail) { throw new Error( `adb2c user mail not found. externalId: ${db.primaryAccountExternalId}`, diff --git a/dictation_server/src/features/licenses/licenses.module.ts b/dictation_server/src/features/licenses/licenses.module.ts index d3a69a4..b18272a 100644 --- a/dictation_server/src/features/licenses/licenses.module.ts +++ b/dictation_server/src/features/licenses/licenses.module.ts @@ -4,12 +4,16 @@ import { LicensesService } from './licenses.service'; import { UsersRepositoryModule } from '../../repositories/users/users.repository.module'; import { AccountsRepositoryModule } from '../../repositories/accounts/accounts.repository.module'; import { LicensesRepositoryModule } from '../../repositories/licenses/licenses.repository.module'; +import { AdB2cModule } from '../../gateways/adb2c/adb2c.module'; +import { SendGridModule } from '../../gateways/sendgrid/sendgrid.module'; @Module({ imports: [ UsersRepositoryModule, AccountsRepositoryModule, LicensesRepositoryModule, + AdB2cModule, + SendGridModule, ], controllers: [LicensesController], providers: [LicensesService], diff --git a/dictation_server/src/features/licenses/licenses.service.spec.ts b/dictation_server/src/features/licenses/licenses.service.spec.ts index 26efeae..f7d0e49 100644 --- a/dictation_server/src/features/licenses/licenses.service.spec.ts +++ b/dictation_server/src/features/licenses/licenses.service.spec.ts @@ -42,271 +42,6 @@ import { makeTestUser, } from '../../common/test/utility'; -describe('LicensesService', () => { - it('ライセンス注文が完了する', async () => { - const lisencesRepositoryMockValue = - makeDefaultLicensesRepositoryMockValue(); - const usersRepositoryMockValue = makeDefaultUsersRepositoryMockValue(); - const accountsRepositoryMockValue = - makeDefaultAccountsRepositoryMockValue(); - const service = await makeLicensesServiceMock( - lisencesRepositoryMockValue, - usersRepositoryMockValue, - accountsRepositoryMockValue, - ); - const body = new CreateOrdersRequest(); - const userId = '0001'; - body.orderCount = 1000; - body.poNumber = '1'; - const context = makeContext(`uuidv4`, 'requestId'); - expect( - await service.licenseOrders( - context, - userId, - body.poNumber, - body.orderCount, - ), - ).toEqual(undefined); - }); - it('ユーザID取得できなかった場合、エラーとなる', async () => { - const lisencesRepositoryMockValue = - makeDefaultLicensesRepositoryMockValue(); - const usersRepositoryMockValue = makeDefaultUsersRepositoryMockValue(); - usersRepositoryMockValue.findUserByExternalId = new Error( - 'User not Found Error.', - ); - const accountsRepositoryMockValue = - makeDefaultAccountsRepositoryMockValue(); - const service = await makeLicensesServiceMock( - lisencesRepositoryMockValue, - usersRepositoryMockValue, - accountsRepositoryMockValue, - ); - const body = new CreateOrdersRequest(); - const userId = ''; - body.orderCount = 1000; - body.poNumber = '1'; - const context = makeContext(`uuidv4`, 'requestId'); - await expect( - service.licenseOrders(context, userId, body.poNumber, body.orderCount), - ).rejects.toEqual( - new HttpException( - makeErrorResponse('E009999'), - HttpStatus.INTERNAL_SERVER_ERROR, - ), - ); - }); - it('親ユーザID取得できなかった場合、エラーとなる', async () => { - const lisencesRepositoryMockValue = - makeDefaultLicensesRepositoryMockValue(); - const usersRepositoryMockValue = makeDefaultUsersRepositoryMockValue(); - usersRepositoryMockValue.findUserByExternalId = new Error( - 'Account not Found Error.', - ); - const accountsRepositoryMockValue = - makeDefaultAccountsRepositoryMockValue(); - const service = await makeLicensesServiceMock( - lisencesRepositoryMockValue, - usersRepositoryMockValue, - accountsRepositoryMockValue, - ); - const body = new CreateOrdersRequest(); - const userId = '0001'; - body.orderCount = 1000; - body.poNumber = '1'; - const context = makeContext(`uuidv4`, 'requestId'); - await expect( - service.licenseOrders(context, userId, body.poNumber, body.orderCount), - ).rejects.toEqual( - new HttpException( - makeErrorResponse('E009999'), - HttpStatus.INTERNAL_SERVER_ERROR, - ), - ); - }); - it('POナンバー重複時、エラーとなる', async () => { - const lisencesRepositoryMockValue = - makeDefaultLicensesRepositoryMockValue(); - lisencesRepositoryMockValue.order = new PoNumberAlreadyExistError( - `This PoNumber already used`, - ); - const usersRepositoryMockValue = makeDefaultUsersRepositoryMockValue(); - const accountsRepositoryMockValue = - makeDefaultAccountsRepositoryMockValue(); - const service = await makeLicensesServiceMock( - lisencesRepositoryMockValue, - usersRepositoryMockValue, - accountsRepositoryMockValue, - ); - const body = new CreateOrdersRequest(); - const userId = '0001'; - body.orderCount = 1000; - body.poNumber = '1'; - const context = makeContext(`uuidv4`, 'requestId'); - await expect( - service.licenseOrders(context, userId, body.poNumber, body.orderCount), - ).rejects.toEqual( - new HttpException( - makeErrorResponse('E010401'), - HttpStatus.INTERNAL_SERVER_ERROR, - ), - ); - }); - it('カードライセンス発行が完了する', async () => { - const lisencesRepositoryMockValue = - makeDefaultLicensesRepositoryMockValue(); - const usersRepositoryMockValue = makeDefaultUsersRepositoryMockValue(); - const accountsRepositoryMockValue = - makeDefaultAccountsRepositoryMockValue(); - const service = await makeLicensesServiceMock( - lisencesRepositoryMockValue, - usersRepositoryMockValue, - accountsRepositoryMockValue, - ); - const body = new IssueCardLicensesRequest(); - const userId = '0001'; - body.createCount = 10; - const issueCardLicensesResponse: IssueCardLicensesResponse = { - cardLicenseKeys: [ - 'WZCETXC0Z9PQZ9GKRGGY', - 'F0JD7EZEDBH4PQRQ83YF', - 'H0HXBP5K9RW7T7JSVDJV', - 'HKIWX54EESYL4X132223', - '363E81JR460UBHXGFXFI', - '70IKAPV9K6YMEVLTOXBY', - '1RJY1TRRYYTGF1LL9WLU', - 'BXM0HKFO7IULTL0A1B36', - 'XYLEWNY2LR6Q657CZE41', - 'AEJWRFFSWRQYQQJ6WVLV', - ], - }; - const context = makeContext(`uuidv4`, 'requestId'); - expect( - await service.issueCardLicenseKeys(context, userId, body.createCount), - ).toEqual(issueCardLicensesResponse); - }); - it('カードライセンス発行に失敗した場合、エラーになる', async () => { - const lisencesRepositoryMockValue = - makeDefaultLicensesRepositoryMockValue(); - lisencesRepositoryMockValue.createCardLicenses = new Error('DB failed'); - const usersRepositoryMockValue = makeDefaultUsersRepositoryMockValue(); - const accountsRepositoryMockValue = - makeDefaultAccountsRepositoryMockValue(); - const service = await makeLicensesServiceMock( - lisencesRepositoryMockValue, - usersRepositoryMockValue, - accountsRepositoryMockValue, - ); - const body = new IssueCardLicensesRequest(); - const userId = '0001'; - body.createCount = 1000; - const context = makeContext(`uuidv4`, 'requestId'); - await expect( - service.issueCardLicenseKeys(context, userId, body.createCount), - ).rejects.toEqual( - new HttpException( - makeErrorResponse('E009999'), - HttpStatus.INTERNAL_SERVER_ERROR, - ), - ); - }); - it('カードライセンス取り込みが完了する', async () => { - const lisencesRepositoryMockValue = - makeDefaultLicensesRepositoryMockValue(); - const usersRepositoryMockValue = makeDefaultUsersRepositoryMockValue(); - const accountsRepositoryMockValue = - makeDefaultAccountsRepositoryMockValue(); - const service = await makeLicensesServiceMock( - lisencesRepositoryMockValue, - usersRepositoryMockValue, - accountsRepositoryMockValue, - ); - const body = new ActivateCardLicensesRequest(); - const userId = '0001'; - body.cardLicenseKey = 'WZCETXC0Z9PQZ9GKRGGY'; - const context = makeContext(`uuidv4`, 'requestId'); - expect( - await service.activateCardLicenseKey( - context, - userId, - body.cardLicenseKey, - ), - ).toEqual(undefined); - }); - it('カードライセンス取り込みに失敗した場合、エラーになる(DBエラー)', async () => { - const lisencesRepositoryMockValue = - makeDefaultLicensesRepositoryMockValue(); - lisencesRepositoryMockValue.activateCardLicense = new Error('DB failed'); - const usersRepositoryMockValue = makeDefaultUsersRepositoryMockValue(); - const accountsRepositoryMockValue = - makeDefaultAccountsRepositoryMockValue(); - const service = await makeLicensesServiceMock( - lisencesRepositoryMockValue, - usersRepositoryMockValue, - accountsRepositoryMockValue, - ); - const body = new ActivateCardLicensesRequest(); - const userId = '0001'; - body.cardLicenseKey = 'WZCETXC0Z9PQZ9GKRGGY'; - const context = makeContext(`uuidv4`, 'requestId'); - await expect( - service.activateCardLicenseKey(context, userId, body.cardLicenseKey), - ).rejects.toEqual( - new HttpException( - makeErrorResponse('E009999'), - HttpStatus.INTERNAL_SERVER_ERROR, - ), - ); - }); - it('カードライセンス取り込みに失敗した場合、エラーになる(ライセンスが存在しないエラー)', async () => { - const lisencesRepositoryMockValue = - makeDefaultLicensesRepositoryMockValue(); - lisencesRepositoryMockValue.activateCardLicense = new LicenseNotExistError( - `License not exist`, - ); - const usersRepositoryMockValue = makeDefaultUsersRepositoryMockValue(); - const accountsRepositoryMockValue = - makeDefaultAccountsRepositoryMockValue(); - const service = await makeLicensesServiceMock( - lisencesRepositoryMockValue, - usersRepositoryMockValue, - accountsRepositoryMockValue, - ); - const body = new ActivateCardLicensesRequest(); - const userId = '0001'; - body.cardLicenseKey = 'WZCETXC0Z9PQZ9GKRGGY'; - const context = makeContext(`uuidv4`, 'requestId'); - await expect( - service.activateCardLicenseKey(context, userId, body.cardLicenseKey), - ).rejects.toEqual( - new HttpException(makeErrorResponse('E010801'), HttpStatus.BAD_REQUEST), - ); - }); - it('カードライセンス取り込みに失敗した場合、エラーになる(ライセンスが既に取り込まれているエラー)', async () => { - const lisencesRepositoryMockValue = - makeDefaultLicensesRepositoryMockValue(); - lisencesRepositoryMockValue.activateCardLicense = - new LicenseKeyAlreadyActivatedError(`License already activated`); - const usersRepositoryMockValue = makeDefaultUsersRepositoryMockValue(); - const accountsRepositoryMockValue = - makeDefaultAccountsRepositoryMockValue(); - const service = await makeLicensesServiceMock( - lisencesRepositoryMockValue, - usersRepositoryMockValue, - accountsRepositoryMockValue, - ); - const body = new ActivateCardLicensesRequest(); - const userId = '0001'; - body.cardLicenseKey = 'WZCETXC0Z9PQZ9GKRGGY'; - const context = makeContext(`uuidv4`, 'requestId'); - await expect( - service.activateCardLicenseKey(context, userId, body.cardLicenseKey), - ).rejects.toEqual( - new HttpException(makeErrorResponse('E010802'), HttpStatus.BAD_REQUEST), - ); - }); -}); - describe('DBテスト', () => { let source: DataSource | null = null; beforeEach(async () => { diff --git a/dictation_server/src/features/licenses/licenses.service.ts b/dictation_server/src/features/licenses/licenses.service.ts index 17e61bd..5e981df 100644 --- a/dictation_server/src/features/licenses/licenses.service.ts +++ b/dictation_server/src/features/licenses/licenses.service.ts @@ -16,6 +16,10 @@ import { IssueCardLicensesResponse, } from './types/types'; import { Context } from '../../common/log'; +import { SendGridService } from '../../gateways/sendgrid/sendgrid.service'; +import { AdB2cService } from '../../gateways/adb2c/adb2c.service'; +import { getUserNameAndMailAddress } from '../../gateways/adb2c/utils/utils'; +import { LICENSE_ISSUE_STATUS } from '../../constants'; @Injectable() export class LicensesService { @@ -23,6 +27,8 @@ export class LicensesService { private readonly usersRepository: UsersRepositoryService, private readonly accountsRepository: AccountsRepositoryService, private readonly licensesRepository: LicensesRepositoryService, + private readonly adb2cService: AdB2cService, + private readonly sendgridService: SendGridService, ) {} private readonly logger = new Logger(LicensesService.name); @@ -325,7 +331,71 @@ export class LicensesService { await this.usersRepository.findUserByExternalId(context, externalId) ).account_id; // 注文キャンセル処理 - await this.licensesRepository.cancelOrder(context, myAccountId, poNumber); + const { canceledOrderId } = await this.licensesRepository.cancelOrder(context, myAccountId, poNumber); + + // メール送信処理 + try { + // 注文キャンセルを実行したカスタマー企業の管理者情報を取得する + const customerAccountId = myAccountId; + + // カスタマー企業の企業名と管理者情報を取得する + const { + companyName: customerCompanyName, + adminEmails: customerAdminEmails, + } = await this.getAccountInformation(context, customerAccountId); + + // ディーラー企業を特定する + const { parent_account_id: dealerAccountId } = + await this.accountsRepository.findAccountById( + context, + customerAccountId, + ); + // ライセンス発行が行われているので、ディーラーは必ず存在するはず + if (dealerAccountId == null) { + throw new Error('dealerAccountId is null'); + } + + // ディーラー企業の企業名と管理者情報を取得する + const { + companyName: dealerCompanyName, + adminEmails: dealerAdminEmails, + } = await this.getAccountInformation(context, dealerAccountId); + + // キャンセル済みの注文をID指定して取得する + const order = await this.licensesRepository.getLicenseOrder( + context, + customerAccountId, + poNumber, + canceledOrderId + ); + + if (order == null) { + throw new Error( + `cancel target order not found. fromAccountId: ${customerAccountId}, poNumber:${poNumber}`, + ); + } + if (order.status !== LICENSE_ISSUE_STATUS.CANCELED) { + throw new Error( + `target order is not canceled. fromAccountId: ${order.from_account_id}, poNumber:${order.po_number}, status:${order.status}, id:${order.id}`, + ); + } + + const { quantity } = order; + + // 注文キャンセルが成功した旨をメール送信する + await this.sendgridService.sendMailWithU106( + context, + customerAdminEmails, + customerCompanyName, + quantity, + poNumber, + dealerAdminEmails, + dealerCompanyName, + ); + } catch (e) { + this.logger.error(`[${context.getTrackingId()}] error=${e}`); + // メール送信に関する例外はログだけ出して握りつぶす + } } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); switch (e.constructor) { @@ -352,4 +422,51 @@ export class LicensesService { } return; } + + /** + * アカウントIDを指定して、アカウント情報と管理者情報を取得する + * @param context + * @param accountId 対象アカウントID + * @returns 企業名/管理者メールアドレス + */ + private async getAccountInformation( + context: Context, + accountId: number, + ): Promise<{ + companyName: string; + adminEmails: string[]; + }> { + // アカウントIDから企業名を取得する + const { company_name } = await this.accountsRepository.findAccountById( + context, + accountId, + ); + + // 管理者一覧を取得 + const admins = await this.usersRepository.findAdminUsers( + context, + accountId, + ); + const adminExternalIDs = admins.map((x) => x.external_id); + + // ADB2Cから管理者IDを元にメールアドレスを取得する + const usersInfo = await this.adb2cService.getUsers( + context, + adminExternalIDs, + ); + + // 生のAzure AD B2Cのユーザー情報からメールアドレスを抽出する + const adminEmails = usersInfo.map((x) => { + const { emailAddress } = getUserNameAndMailAddress(x); + if (emailAddress == null) { + throw new Error('dealer admin email-address is not found'); + } + return emailAddress; + }); + + return { + companyName: company_name, + adminEmails: adminEmails, + }; + } } diff --git a/dictation_server/src/features/users/users.service.ts b/dictation_server/src/features/users/users.service.ts index e402d5b..9221ead 100644 --- a/dictation_server/src/features/users/users.service.ts +++ b/dictation_server/src/features/users/users.service.ts @@ -50,6 +50,7 @@ import { LicenseUnavailableError, } from '../../repositories/licenses/errors/types'; import { AccountNotFoundError } from '../../repositories/accounts/errors/types'; +import { getUserNameAndMailAddress } from '../../gateways/adb2c/utils/utils'; @Injectable() export class UsersService { @@ -570,10 +571,12 @@ export class UsersService { (user) => user.id === dbUser.external_id, ); + if (adb2cUser == null) { + throw new Error('mail not found.'); // TODO: リファクタ時に挙動を変更しないようエラー文面をmail not foundのまま据え置き。影響がない事が確認できたらエラー文面を変更する。 + } + // メールアドレスを取得する - const mail = adb2cUser?.identities?.find( - (identity) => identity.signInType === ADB2C_SIGN_IN_TYPE.EMAILADDRESS, - )?.issuerAssignedId; + const { emailAddress: mail } = getUserNameAndMailAddress(adb2cUser); //メールアドレスが取得できない場合はエラー if (!mail) { diff --git a/dictation_server/src/gateways/adb2c/utils/utils.ts b/dictation_server/src/gateways/adb2c/utils/utils.ts index 1d3b4a9..dfeb4c7 100644 --- a/dictation_server/src/gateways/adb2c/utils/utils.ts +++ b/dictation_server/src/gateways/adb2c/utils/utils.ts @@ -1,3 +1,6 @@ +import { ADB2C_SIGN_IN_TYPE } from "../../../constants"; +import { AdB2cUser } from "../types/types"; + export const isPromiseRejectedResult = ( data: unknown, ): data is PromiseRejectedResult => { @@ -8,3 +11,12 @@ export const isPromiseRejectedResult = ( 'reason' in data ); }; + +// 生のAdB2cUserのレスポンスから表示名とメールアドレスを取得する +export const getUserNameAndMailAddress = (user: AdB2cUser) => { + const { displayName, identities } = user; + const emailAddress = identities?.find( + (identity) => identity.signInType === ADB2C_SIGN_IN_TYPE.EMAILADDRESS, + )?.issuerAssignedId; + return { displayName, emailAddress }; +} \ No newline at end of file diff --git a/dictation_server/src/gateways/sendgrid/sendgrid.service.ts b/dictation_server/src/gateways/sendgrid/sendgrid.service.ts index 7874a72..dbb7776 100644 --- a/dictation_server/src/gateways/sendgrid/sendgrid.service.ts +++ b/dictation_server/src/gateways/sendgrid/sendgrid.service.ts @@ -137,6 +137,38 @@ export class SendGridService { }; } + /** + * U-106のテンプレートを使用したメールを送信する + * @param context + * @param cancelUserEmailAddress 注文キャンセルを行ったアカウントの管理者(primary/secondary)のメールアドレス + * @param customerAccountName 送信対象の企業名 + * @param lisenceCount 注文キャンセルを行った対象の注文の内容(ライセンス数) + * @param poNumber 注文キャンセルを行った対象の注文の内容(PO番号) + * @param dealerEmails 問題発生時に問い合わせする先の上位のディーラーの管理者(primary/secondary)のメールアドレス + * @param dealerAccountName 問題発生時に問い合わせする先の上位のディーラー名(会社名) + * @returns mail with u106 + */ + async sendMailWithU106( + context: Context, + customerMails: string[], + customerAccountName: string, + lisenceCount: number, + poNumber: string, + dealerEmails: string[], + dealerAccountName: string, + ): Promise { + this.logger.log( + `[IN] [${context.getTrackingId()}] ${this.sendMailWithU106.name}`, + ); + try { + // NOT IMPLEMENT + } finally { + this.logger.log( + `[OUT] [${context.getTrackingId()}] ${this.sendMailWithU106.name}`, + ); + } + } + /** * メールを送信する * @param context diff --git a/dictation_server/src/repositories/licenses/licenses.repository.service.ts b/dictation_server/src/repositories/licenses/licenses.repository.service.ts index e9f2ad0..523f004 100644 --- a/dictation_server/src/repositories/licenses/licenses.repository.service.ts +++ b/dictation_server/src/repositories/licenses/licenses.repository.service.ts @@ -1,5 +1,5 @@ import { Injectable, Logger } from '@nestjs/common'; -import { DataSource, In } from 'typeorm'; +import { DataSource, EntityManager, In, Not } from 'typeorm'; import { LicenseOrder, License, @@ -101,6 +101,36 @@ export class LicensesRepositoryService { return createdEntity; } + /** + * オーダーIDとPO番号と依頼元アカウントIDを元にライセンス注文を取得する + * @param context context + * @param fromAccountId ライセンス注文を行ったアカウントのID + * @param poNumber PO番号 + * @param orderId LicenseOrderのID + * @returns license order + */ + async getLicenseOrder( + context: Context, + fromAccountId: number, + poNumber: string, + orderId: number, + ): Promise { + return await this.dataSource.transaction(async (entityManager) => { + const repo = entityManager.getRepository(LicenseOrder); + + // ステータスは問わず、指定したIDのランセンス注文を取得する + const entity = repo.findOne({ + where: { + id: orderId, + po_number: poNumber, + from_account_id: fromAccountId, + }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, + }); + return entity; + }); + } + /** * カードライセンスを発行する * @param accountId @@ -729,8 +759,8 @@ export class LicensesRepositoryService { context: Context, accountId: number, poNumber: string, - ): Promise { - await this.dataSource.transaction(async (entityManager) => { + ): Promise<{ canceledOrderId: number }> { + return await this.dataSource.transaction(async (entityManager) => { const orderRepo = entityManager.getRepository(LicenseOrder); // キャンセル対象の注文を取得 @@ -760,6 +790,8 @@ export class LicensesRepositoryService { this.isCommentOut, context, ); + + return { canceledOrderId: targetOrder.id }; }); } diff --git a/dictation_server/src/repositories/users/users.repository.service.ts b/dictation_server/src/repositories/users/users.repository.service.ts index abaa0d9..ca46c20 100644 --- a/dictation_server/src/repositories/users/users.repository.service.ts +++ b/dictation_server/src/repositories/users/users.repository.service.ts @@ -1,6 +1,12 @@ import { Injectable } from '@nestjs/common'; import { User, newUser } from './entity/user.entity'; -import { DataSource, IsNull, Not, UpdateResult } from 'typeorm'; +import { + DataSource, + FindOptionsWhere, + IsNull, + Not, + UpdateResult, +} from 'typeorm'; import { SortCriteria } from '../sort_criteria/entity/sort_criteria.entity'; import { getDirection, @@ -169,6 +175,40 @@ export class UsersRepositoryService { return user; } + /** + * 指定したアカウントIDを持つアカウントのプライマリ管理者とセカンダリ管理者を取得する + * @param context context + * @param accountId アカウントID + * @throws AccountNotFoundError + * @returns admin users + */ + async findAdminUsers(context: Context, accountId: number): Promise { + return this.dataSource.transaction(async (entityManager) => { + const account = await entityManager.getRepository(Account).findOne({ + where: { + id: accountId, + }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, + }); + if (account == null) { + throw new AccountNotFoundError('account not found'); + } + const primaryAdminId = account.primary_admin_user_id; + const secondaryAdminId = account.secondary_admin_user_id; + + // IDが有効なユーザーだけを検索対象とする + const targets = [primaryAdminId, secondaryAdminId] + .flatMap((x) => (x == null ? [] : [x])) + .map((x): FindOptionsWhere => ({ id: x })); + + const users = await entityManager.getRepository(User).find({ + where: targets, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, + }); + return users; + }); + } + /** * AuthorIdが既に存在するか確認する * @param user From 9380d9bfc6a930e92061b60c63251390cd16a2ba Mon Sep 17 00:00:00 2001 From: "saito.k" Date: Mon, 18 Dec 2023 00:58:50 +0000 Subject: [PATCH 18/51] =?UTF-8?q?Merged=20PR=20629:=20STG=E3=81=AE?= =?UTF-8?q?=E3=83=91=E3=82=A4=E3=83=97=E3=83=A9=E3=82=A4=E3=83=B3=E3=81=AB?= =?UTF-8?q?=E7=92=B0=E5=A2=83=E5=A4=89=E6=95=B0=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3326: STG、PRODのパイプラインに環境変数を追加する](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3326) - StagingのPipelineに環境変数を追加 ## レビューポイント ## UIの変更 - Before/Afterのスクショなど - スクショ置き場 ## 動作確認状況 ## 補足 - 相談、参考資料などがあれば --- azure-pipelines-staging.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-pipelines-staging.yml b/azure-pipelines-staging.yml index d2759b7..86f970d 100644 --- a/azure-pipelines-staging.yml +++ b/azure-pipelines-staging.yml @@ -87,6 +87,7 @@ jobs: REDIS_PORT: 0 REDIS_PASSWORD: xxxxxxxxxxxx ADB2C_CACHE_TTL: 0 + STAGE: local - task: Docker@0 displayName: build inputs: From afa05f381c4b192199740eac70197e2dd06ac55c Mon Sep 17 00:00:00 2001 From: "maruyama.t" Date: Mon, 18 Dec 2023 04:07:03 +0000 Subject: [PATCH 19/51] =?UTF-8?q?Merged=20PR=20628:=20=E7=AC=AC=EF=BC=95?= =?UTF-8?q?=E9=9A=8E=E5=B1=A4=E3=81=A7=E8=A6=8F=E7=B4=84=E5=90=8C=E6=84=8F?= =?UTF-8?q?=E7=94=BB=E9=9D=A2=E3=82=92=E8=A1=A8=E7=A4=BA=E3=81=99=E3=82=8B?= =?UTF-8?q?=E9=9A=9B=E3=81=AB=E3=80=81DPA=E3=81=AB=E5=90=8C=E6=84=8F?= =?UTF-8?q?=E3=81=8C=E4=B8=80=E7=9E=AC=E8=A1=A8=E7=A4=BA=E3=81=95=E3=82=8C?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3281: 【Commit諸作業終わったら優先対応】第5階層で規約同意画面を表示する際に、DPAに同意が一瞬表示される](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3281) selectorから別途tierの値が入っているかをselectIsTierLoadingで取得し、まだ入っていない場合(tier===0)Loadingの表示を行うようにした。 ``` export const selectIsTierLoading = (state: RootState) => state.terms.domain.tier === 0; ``` ## レビューポイント - とくになし ## UIの変更 https://ndstokyo.sharepoint.com/:f:/r/sites/Piranha/Shared%20Documents/General/OMDS/%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%B7%E3%83%A7%E3%83%83%E3%83%88/Task3281?csf=1&web=1&e=D9t5di ## 動作確認状況 - ローカルで確認 ## 補足 - 相談、参考資料などがあれば --- dictation_client/src/features/terms/selectors.ts | 3 +++ dictation_client/src/features/terms/termsSlice.ts | 7 ------- dictation_client/src/pages/TermsPage/index.tsx | 13 +++++++++++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/dictation_client/src/features/terms/selectors.ts b/dictation_client/src/features/terms/selectors.ts index 75f45b9..2716c88 100644 --- a/dictation_client/src/features/terms/selectors.ts +++ b/dictation_client/src/features/terms/selectors.ts @@ -22,3 +22,6 @@ export const selectTermVersions = (state: RootState) => { }; export const selectTier = (state: RootState) => state.terms.domain.tier; + +export const selectIsLoading = (state: RootState) => + state.terms.apps.isLoading === true; diff --git a/dictation_client/src/features/terms/termsSlice.ts b/dictation_client/src/features/terms/termsSlice.ts index 7f88271..242692e 100644 --- a/dictation_client/src/features/terms/termsSlice.ts +++ b/dictation_client/src/features/terms/termsSlice.ts @@ -39,16 +39,9 @@ export const termsSlice = createSlice({ builder.addCase(getAccountInfoMinimalAccessAsync.rejected, (state) => { state.apps.isLoading = false; }); - builder.addCase(getTermsInfoAsync.pending, (state) => { - state.apps.isLoading = true; - }); builder.addCase(getTermsInfoAsync.fulfilled, (state, actions) => { - state.apps.isLoading = false; state.domain.termsInfo = actions.payload.termsInfo; }); - builder.addCase(getTermsInfoAsync.rejected, (state) => { - state.apps.isLoading = false; - }); builder.addCase(updateAcceptedVersionAsync.pending, (state) => { state.apps.isLoading = true; }); diff --git a/dictation_client/src/pages/TermsPage/index.tsx b/dictation_client/src/pages/TermsPage/index.tsx index 777a115..0082cfd 100644 --- a/dictation_client/src/pages/TermsPage/index.tsx +++ b/dictation_client/src/pages/TermsPage/index.tsx @@ -13,6 +13,7 @@ import { getTermsInfoAsync, updateAcceptedVersionAsync, selectTier, + selectIsLoading, selectTermVersions, } from "features//terms"; import { selectLocalStorageKeyforIdToken } from "features/login"; @@ -27,7 +28,7 @@ const TermsPage: React.FC = (): JSX.Element => { selectLocalStorageKeyforIdToken ); const tier = useSelector(selectTier); - + const isLoading = useSelector(selectIsLoading); const [isCheckedEula, setIsCheckedEula] = useState(false); const [isCheckedPrivacyNotice, setIsCheckedPrivacyNotice] = useState(false); const [isCheckedDpa, setIsCheckedDpa] = useState(false); @@ -88,7 +89,15 @@ const TermsPage: React.FC = (): JSX.Element => { tier, dispatch, ]); - + if (isLoading) { + return ( + <> +
+

loading ...

+