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