diff --git a/vue-app/codexia/relevant.js b/vue-app/codexia/relevant.js index 43e0bae..8a0dad1 100644 --- a/vue-app/codexia/relevant.js +++ b/vue-app/codexia/relevant.js @@ -1,31 +1,22 @@ -const bigCompany = [ - 'facebook', - 'google', - 'microsoft', - 'dotnet', - 'ibm', - 'oracle', - 'intel', - 'alibaba', - 'aws', - 'pivotal', - 'mozilla', - 'uber', - 'netflix', - 'spring', - 'apache', - 'azure', - 'amazon', - 'airbnb', - 'linkedin' -] +const firebase = require('../data/firebase') + +let bigCompanies = [] +let isLoaded = false + +async function load() { + if (isLoaded) return + bigCompanies = await firebase.getBigCompanies() + isLoaded = true +} + /** * @param {string} repoName */ -function notRelevant(repoName) { - return bigCompany.some(company => +async function notRelevant(repoName) { + if (!isLoaded) await load() + return bigCompanies.some(company => repoName.toLowerCase().startsWith(company.toLowerCase()) ) } -module.exports = { notRelevant } +module.exports = { notRelevant, load } diff --git a/vue-app/data/firebase.js b/vue-app/data/firebase.js index b0520fd..a747475 100644 --- a/vue-app/data/firebase.js +++ b/vue-app/data/firebase.js @@ -120,6 +120,28 @@ function findRepoByName(repoName, db) { .then(snap => console.log(repoName + ' found:' + snap.val())) } +/** + * Fetch big companies list from firebase + * @param {firebase.database.Database} db + * @returns {Promise} + */ +async function getBigCompanies(db = _db()) { + const ref = db.ref('bigCompanies') + const snap = await ref.once('value') + let companies = snap.val() + if (companies == null) companies = [] + return companies +} + +/** + * Save a big company name to firebase + * @param {String} company + * @param {firebase.database.Database} db + */ +async function saveBigCompany(company, db = _db()) { + return db.ref('bigCompanies').child(company.toLowerCase()).set(company) +} + console.log('loading module: firebase') module.exports = { app: _app, @@ -131,5 +153,7 @@ module.exports = { saveSubmittedRepos, getSubmittedRepos, removeSubmittedFromRelevant, - run + run, + getBigCompanies, + saveBigCompany }