Merged PR 338: トライアルライセンスの期限が30日後になっていないので対応

## 概要
[Task2442: トライアルライセンスの期限が30日後になっていないので対応](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2442)

- トライアルライセンスの有効期限をライセンス割り当てと同様にDateのラップクラス内で設定するように修正しました。

## レビューポイント
- 修正内容は適切か

## UIの変更
- なし

## 動作確認状況
- ローカルで確認
This commit is contained in:
makabe.t 2023-08-21 06:24:53 +00:00
parent 493dbadb8e
commit 5690b66e41
3 changed files with 22 additions and 12 deletions

View File

@ -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[]) {

View File

@ -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'

View File

@ -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;