Skip to content

Instantly share code, notes, and snippets.

@leomonteiro92
Last active May 4, 2020 20:24
Show Gist options
  • Save leomonteiro92/e7c632e009c8c405896bbf87c19baa27 to your computer and use it in GitHub Desktop.
Save leomonteiro92/e7c632e009c8c405896bbf87c19baa27 to your computer and use it in GitHub Desktop.
Update Fee
/**
* Visit https://cloud.google.com/docs/authentication/getting-started and
* follow the steps to generate a service account, by the end you have a json or p2
* file downloaded.
* Export the path so that you have access to the datastore
* export GOOGLE_APPLICATION_CREDENTIALS="/path/to/file.json"
*
* npm init --yes
* npm install firebase-admin
* node index.js <PROJECT_ID>
*/
const firebase = require('firebase-admin');
const feesRef = "/appRevenue/creditCardPayment/fees";
(async () => {
const args = process.argv.slice(2);
if (!args.some(Boolean)) {
throw new Error("ProjectId cannot be null");
}
const [projectId] = args;
firebase.initializeApp({ projectId });
const NEW_INTEREST_FEE = 0.01; //Change it here
const firestore = firebase.firestore();
const feeRef = await firestore
.collection(feesRef)
.where('interestFee', '>', 0.01)
.get();
feeRef.forEach(async doc => {
console.info(`Atualizando ${doc.id}...`);
await doc.ref.update({ interestFee: NEW_INTEREST_FEE });
});
console.log('Taxas atualizada');
})().then(console.info)
.catch(console.error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment