diff --git a/dictation_server/src/repositories/accounts/accounts.repository.service.ts b/dictation_server/src/repositories/accounts/accounts.repository.service.ts index 8c582f0..65fe99d 100644 --- a/dictation_server/src/repositories/accounts/accounts.repository.service.ts +++ b/dictation_server/src/repositories/accounts/accounts.repository.service.ts @@ -327,27 +327,52 @@ export class AccountsRepositoryService { // 有効な総ライセンス数のうち、ユーザーに割り当て済みのライセンス数を取得する const allocatedLicense = await license.count({ - where: { - account_id: id, - allocated_user_id: Not(IsNull()), - status: LICENSE_ALLOCATED_STATUS.ALLOCATED, - }, + where: [ + { + account_id: id, + allocated_user_id: Not(IsNull()), + expiry_date: MoreThanOrEqual(currentDate), + status: LICENSE_ALLOCATED_STATUS.ALLOCATED, + }, + { + account_id: id, + allocated_user_id: Not(IsNull()), + expiry_date: IsNull(), + status: LICENSE_ALLOCATED_STATUS.ALLOCATED, + }, + ], }); // 総ライセンス数のうち、ユーザーに割り当てたことがあるが、現在は割り当て解除され誰にも割り当たっていないライセンス数を取得する const reusableLicense = await license.count({ - where: { - account_id: id, - status: LICENSE_ALLOCATED_STATUS.REUSABLE, - }, + where: [ + { + account_id: id, + expiry_date: MoreThanOrEqual(currentDate), + status: LICENSE_ALLOCATED_STATUS.REUSABLE, + }, + { + account_id: id, + expiry_date: IsNull(), + status: LICENSE_ALLOCATED_STATUS.REUSABLE, + }, + ], }); // 総ライセンス数のうち、一度もユーザーに割り当てたことのないライセンス数を取得する const freeLicense = await license.count({ - where: { - account_id: id, - status: LICENSE_ALLOCATED_STATUS.UNALLOCATED, - }, + where: [ + { + account_id: id, + expiry_date: MoreThanOrEqual(currentDate), + status: LICENSE_ALLOCATED_STATUS.UNALLOCATED, + }, + { + account_id: id, + expiry_date: IsNull(), + status: LICENSE_ALLOCATED_STATUS.UNALLOCATED, + }, + ], }); // 有効期限が現在日付からしきい値以内のライセンス数を取得する