diff --git a/dictation_server/src/features/licenses/types/types.ts b/dictation_server/src/features/licenses/types/types.ts index d5e2fce..e0fce77 100644 --- a/dictation_server/src/features/licenses/types/types.ts +++ b/dictation_server/src/features/licenses/types/types.ts @@ -3,6 +3,7 @@ import { IsInt, Matches, Max, Min, Length } from 'class-validator'; import { LICENSE_EXPIRATION_DAYS, LICENSE_EXPIRATION_THRESHOLD_DAYS, + TRIAL_LICENSE_EXPIRATION_DAYS, } from '../../../constants'; export class CreateOrdersRequest { @@ -79,6 +80,20 @@ export class ExpirationThresholdDate extends Date { } } +// 新規トライアルライセンス発行時の有効期限算出用に、30日後の日付を取得する +export class NewTrialLicenseExpirationDate extends Date { + constructor(...args: any[]) { + if (args.length === 0) { + super(); // 引数がない場合、現在の日付で初期化 + } else { + super(...(args as [string])); // 引数がある場合、引数をそのままDateクラスのコンストラクタに渡す + } + this.setDate(this.getDate() + TRIAL_LICENSE_EXPIRATION_DAYS); + this.setHours(23, 59, 59); // 時分秒を"23:59:59"に固定 + this.setMilliseconds(0); + } +} + // 新規ライセンス割り当て時の有効期限算出用に、365日後の日付を取得する export class NewAllocatedLicenseExpirationDate extends Date { constructor(...args: any[]) { diff --git a/dictation_server/src/features/users/users.service.spec.ts b/dictation_server/src/features/users/users.service.spec.ts index 609dabe..1c2ee84 100644 --- a/dictation_server/src/features/users/users.service.spec.ts +++ b/dictation_server/src/features/users/users.service.spec.ts @@ -28,7 +28,6 @@ import { LICENSE_ALLOCATED_STATUS, LICENSE_EXPIRATION_THRESHOLD_DAYS, LICENSE_TYPE, - TRIAL_LICENSE_EXPIRATION_DAYS, USER_LICENSE_STATUS, USER_ROLES, } from '../../constants'; @@ -39,7 +38,7 @@ import { overrideSendgridService, overrideUsersRepositoryService, } from '../../common/test/overrides'; -import { ExpirationThresholdDate } from '../licenses/types/types'; +import { NewTrialLicenseExpirationDate } from '../licenses/types/types'; import { License } from '../../repositories/licenses/entity/license.entity'; describe('UsersService.confirmUser', () => { @@ -93,11 +92,9 @@ describe('UsersService.confirmUser', () => { //result const resultUser = await getUser(source, userId); const resultLicenses = await getLicenses(source, accountId); - const today = new Date(); + // トライアルライセンスは有効期限は今日を起算日として30日後の日付が変わるまで - const expiryDate = new ExpirationThresholdDate( - today.setDate(today.getDate() + TRIAL_LICENSE_EXPIRATION_DAYS), - ); + const expiryDate = new NewTrialLicenseExpirationDate(); const resultLicensesCheckParam: Omit< License, 'deleted_at' | 'created_by' | 'created_at' | 'updated_at' | 'updated_by' diff --git a/dictation_server/src/repositories/users/users.repository.service.ts b/dictation_server/src/repositories/users/users.repository.service.ts index d27fe3e..2dce6a3 100644 --- a/dictation_server/src/repositories/users/users.repository.service.ts +++ b/dictation_server/src/repositories/users/users.repository.service.ts @@ -16,12 +16,11 @@ import { import { LICENSE_ALLOCATED_STATUS, LICENSE_TYPE, - TRIAL_LICENSE_EXPIRATION_DAYS, TRIAL_LICENSE_ISSUE_NUM, USER_ROLES, } from '../../constants'; import { License } from '../licenses/entity/license.entity'; -import { ExpirationThresholdDate } from '../../features/licenses/types/types'; +import { NewTrialLicenseExpirationDate } from '../../features/licenses/types/types'; @Injectable() export class UsersRepositoryService { @@ -301,11 +300,10 @@ export class UsersRepositoryService { // トライアルライセンス100件を作成する const licenseRepo = entityManager.getRepository(License); const licenses: License[] = []; - const today = new Date(); + // トライアルライセンスの有効期限は今日を起算日として30日後の日付が変わるまで - const expiryDate = new ExpirationThresholdDate( - today.setDate(today.getDate() + TRIAL_LICENSE_EXPIRATION_DAYS), - ); + const expiryDate = new NewTrialLicenseExpirationDate(); + for (let i = 0; i < TRIAL_LICENSE_ISSUE_NUM; i++) { const license = new License(); license.expiry_date = expiryDate;