diff --git a/models/Article.js b/models/Article.js index 500e04e..7140dd7 100644 --- a/models/Article.js +++ b/models/Article.js @@ -20,7 +20,11 @@ const ArticleSchema = new Schema({ type: String, required: true }, - identifier: { + category: { + type: String, + required: true + }, + criteria: { type: String, required: true }, diff --git a/public/app.js b/public/app.js index 2e2f1de..70b593d 100644 --- a/public/app.js +++ b/public/app.js @@ -1,9 +1,12 @@ // grab articles from db based on localstorage terms -console.log(localStorage.getItem('category')); -console.log(localStorage.getItem('criteria')); +// console.log(localStorage.getItem('category')); +// console.log(localStorage.getItem('criteria')); if ( localStorage.getItem('category') != null ) { + + console.log('getting data!'); $.getJSON(`/articles/${localStorage.getItem('category')}/${localStorage.getItem('criteria')}`, data => { + console.log(data); // append articles to page on load for (var i = 0; i < data.length; i++) { $("#articles").append(`

${data[i].title}
Link to Ad
${data[i].price}

`); @@ -16,7 +19,7 @@ checkCategory = category => { let searchCategory; if (category === null) { searchCategory = ''; - } else if (category === 'Motorycles') { + } else if (category === 'Motorcycles') { searchCategory = 'mca'; } else if (category === 'Furniture') { searchCategory = 'fua'; @@ -28,13 +31,9 @@ checkCategory = category => { // ajax request for scraping craigslist $('#srch-submit').on('click', () => { - console.log('button clicked!'); event.preventDefault(); - console.log($('#srch-category').val()); const category = checkCategory($('#srch-category').val()); const criteria = $('#srch-criteria').val(); - console.log(`category is ${category}`); - console.log(criteria); // set localstorage values so when page reloads, ajax request gets search fields from db localStorage.setItem('category', category);