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';