Browse Source
Merge branch 'master' into deployment-api-usage
pull/679/head
Martin McKeaveney
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
5 additions and
2 deletions
-
packages/server/src/utilities/usageQuota.js
|
|
|
@ -69,13 +69,16 @@ exports.update = async (apiKey, property, usage) => { |
|
|
|
try { |
|
|
|
await apiKeyTable.update(buildUpdateParams(apiKey, property, usage)) |
|
|
|
} catch (err) { |
|
|
|
// conditional check means the condition failed, need to check why
|
|
|
|
if (err.code === "ConditionalCheckFailedException") { |
|
|
|
// get the API key so we can check it
|
|
|
|
const keyObj = await apiKeyTable.get({ primary: apiKey }) |
|
|
|
// the usage quota or usage limits didn't exist
|
|
|
|
if (keyObj && (keyObj.usageQuota == null || keyObj.usageLimits == null)) { |
|
|
|
keyObj.usageQuota = DEFAULT_USAGE |
|
|
|
keyObj.usageLimits = DEFAULT_PLAN |
|
|
|
keyObj.usageQuota = |
|
|
|
keyObj.usageQuota == null ? DEFAULT_USAGE : keyObj.usageQuota |
|
|
|
keyObj.usageLimits = |
|
|
|
keyObj.usageLimits == null ? DEFAULT_PLAN : keyObj.usageLimits |
|
|
|
keyObj.quotaReset = getNewQuotaReset() |
|
|
|
await apiKeyTable.put({ item: keyObj }) |
|
|
|
return |
|
|
|
|