(orgId: string, subscriptionId: string, usageCacheManager: UsageCacheManager)
| 20 | ] |
| 21 | |
| 22 | export const getCurrentUsage = async (orgId: string, subscriptionId: string, usageCacheManager: UsageCacheManager) => { |
| 23 | try { |
| 24 | if (!usageCacheManager || !subscriptionId || !orgId) return |
| 25 | |
| 26 | const currentStorageUsage = (await usageCacheManager.get(`storage:${orgId}`)) || 0 |
| 27 | const currentPredictionsUsage = (await usageCacheManager.get(`predictions:${orgId}`)) || 0 |
| 28 | |
| 29 | const quotas = await usageCacheManager.getQuotas(subscriptionId) |
| 30 | const storageLimit = quotas[LICENSE_QUOTAS.STORAGE_LIMIT] |
| 31 | const predLimit = quotas[LICENSE_QUOTAS.PREDICTIONS_LIMIT] |
| 32 | |
| 33 | return { |
| 34 | predictions: { |
| 35 | usage: currentPredictionsUsage, |
| 36 | limit: predLimit |
| 37 | }, |
| 38 | storage: { |
| 39 | usage: currentStorageUsage, |
| 40 | limit: storageLimit |
| 41 | } |
| 42 | } |
| 43 | } catch (error) { |
| 44 | logger.error(`[getCurrentUsage] Error getting usage: ${error}`) |
| 45 | throw error |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | // For usage that doesn't renew per month, we just get the count from database and check |
| 50 | export const checkUsageLimit = async ( |
no test coverage detected