Merged PR 347: 割り当て可能ライセンス取得APIをQueryBuilderでの実装に戻す

## 概要
[Task2466: 割り当て可能ライセンス取得APIをQueryBuilderでの実装に戻す](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2466)

- 元PBI or タスクへのリンク(内容・目的などはそちらにあるはず)
- 何をどう変更したか、追加したライブラリなど
  - EntityManegarで実装した部分について、レビューバック後のPOSTMANによる確認が漏れていました。
結果、MySQLにクエリを投入する際に、typeORMでNULLS FIRSTを使用できない旨のエラーが出てしまいました。
よって、暫定的にQueryBuilderを使用しての実装にしています。
EntityManagarを使用するか、QueryBuilderを使用するかは別途開発メンバで相談して、修正する場合は別タスクで追って対応いたします。
[タスク 2465: QueryBuilderのままにするか、service層でソートするか検討する]()
  - ライセンス種別の取得について、結果0件時の考慮が出来ていなかったので修正しています
- このPull Requestでの対象/対象外
- 影響範囲(他の機能にも影響があるか)

## レビューポイント
- 特にレビューしてほしい箇所
- 軽微なものや自明なものは記載不要
- 修正範囲が大きい場合などに記載
- 全体的にや仕様を満たしているか等は本当に必要な時のみ記載

## UIの変更
- Before/Afterのスクショなど
- スクショ置き場

## 動作確認状況
- ローカルで確認

## 補足
- 相談、参考資料などがあれば
This commit is contained in:
maruyama.t 2023-08-22 12:22:47 +00:00
parent f1425bc509
commit 249689a40e

View File

@ -409,42 +409,28 @@ export class LicensesRepositoryService {
myAccountId: number, myAccountId: number,
): Promise<AllocatableLicenseInfo[]> { ): Promise<AllocatableLicenseInfo[]> {
const nowDate = new DateWithZeroTime(); const nowDate = new DateWithZeroTime();
const licenseRepo = this.dataSource.getRepository(License);
return await this.dataSource.transaction(async (entityManager) => { const queryBuilder = licenseRepo
const licenseRepo = entityManager.getRepository(License); .createQueryBuilder('license')
const allocatableLicenses = await licenseRepo.find({ .where('license.account_id = :accountId', { accountId: myAccountId })
where: [ .andWhere('license.status IN (:...statuses)', {
{ statuses: [
account_id: myAccountId, LICENSE_ALLOCATED_STATUS.UNALLOCATED,
status: In([ LICENSE_ALLOCATED_STATUS.REUSABLE,
LICENSE_ALLOCATED_STATUS.UNALLOCATED,
LICENSE_ALLOCATED_STATUS.REUSABLE,
]),
expiry_date: MoreThanOrEqual(nowDate),
},
{
account_id: myAccountId,
status: In([
LICENSE_ALLOCATED_STATUS.UNALLOCATED,
LICENSE_ALLOCATED_STATUS.REUSABLE,
]),
expiry_date: IsNull(),
},
], ],
order: { })
expiry_date: { .andWhere(
direction: 'DESC', 'license.expiry_date >= :nowDate OR license.expiry_date IS NULL',
nulls: 'FIRST', { nowDate },
}, )
id: 'ASC', .orderBy('license.expiry_date IS NULL', 'DESC')
}, .addOrderBy('license.expiry_date', 'DESC')
}); .addOrderBy('license.id', 'ASC');
const allocatableLicenses = await queryBuilder.getMany();
return allocatableLicenses.map((license) => ({ return allocatableLicenses.map((license) => ({
licenseId: license.id, licenseId: license.id,
expiryDate: license.expiry_date, expiryDate: license.expiry_date,
})); }));
});
} }
/** /**
* *
@ -527,16 +513,20 @@ export class LicensesRepositoryService {
}); });
let switchFromType = ''; let switchFromType = '';
switch (oldLicenseType.license.type) { if (oldLicenseType) {
case LICENSE_TYPE.CARD: switch (oldLicenseType.license.type) {
switchFromType = SWITCH_FROM_TYPE.CARD; case LICENSE_TYPE.CARD:
break; switchFromType = SWITCH_FROM_TYPE.CARD;
case LICENSE_TYPE.TRIAL: break;
switchFromType = SWITCH_FROM_TYPE.TRIAL; case LICENSE_TYPE.TRIAL:
break; switchFromType = SWITCH_FROM_TYPE.TRIAL;
default: break;
switchFromType = SWITCH_FROM_TYPE.NONE; default:
break; switchFromType = SWITCH_FROM_TYPE.NONE;
break;
}
} else {
switchFromType = SWITCH_FROM_TYPE.NONE;
} }
// ライセンス割り当て履歴テーブルへ登録 // ライセンス割り当て履歴テーブルへ登録