From 4f1a9b01d900583aa0a0cd5de8e5c155ce589ff7 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 3 May 2020 17:50:06 -0400 Subject: [PATCH] function for updating all existing accounts --- src/functions/existingLimitsSetup.ts | 26 ++++++++++++++++++++++++++ src/functions/index.ts | 1 + 2 files changed, 27 insertions(+) create mode 100644 src/functions/existingLimitsSetup.ts diff --git a/src/functions/existingLimitsSetup.ts b/src/functions/existingLimitsSetup.ts new file mode 100644 index 0000000..5b7a572 --- /dev/null +++ b/src/functions/existingLimitsSetup.ts @@ -0,0 +1,26 @@ +import { Client } from '..'; + +export default async function existingLimitsSetup(client: Client): Promise { + const tier1 = await client.db.Tier.findOne({ id: 1 }); + const tier2 = await client.db.Tier.findOne({ id: 2 }); + const tier3 = await await client.db.Tier.findOne({ id: 3 }); + + const accounts = await client.db.Account.find(); + let numOfAccountsUpdated = 0; + + for (const account of accounts) { + if (account.tier === 1) { + account.updateOne({ $set: { ramLimitNotification: tier1.resourceLimits.ram - 20 } }); + numOfAccountsUpdated += 1; + } + if (account.tier === 2) { + account.updateOne({ $set: { ramLimitNotification: tier2.resourceLimits.ram - 20 } }); + numOfAccountsUpdated += 1; + } + if (account.tier === 3) { + account.updateOne({ $set: { ramLimitNotification: tier3.resourceLimits.ram - 20 } }); + numOfAccountsUpdated += 1; + } + } + return numOfAccountsUpdated; +} diff --git a/src/functions/index.ts b/src/functions/index.ts index 8c3a5ac..b933c35 100644 --- a/src/functions/index.ts +++ b/src/functions/index.ts @@ -1,4 +1,5 @@ export { default as checkLock, clear as clearLock } from '../intervals/checkLock'; export { default as dataConversion } from './dataConversion'; +export { default as existingLimitsSetup } from './existingLimitsSetup'; // export { default as checkSS, clear as clearSS } from './checkSS'; export { default as parseCertificate, Certificate } from './parseCertificate';