diff --git a/client/src/components/NoteDeleteButtonComponent.vue b/client/src/components/NoteDeleteButtonComponent.vue index 76edd1d..4b8a3bc 100644 --- a/client/src/components/NoteDeleteButtonComponent.vue +++ b/client/src/components/NoteDeleteButtonComponent.vue @@ -26,7 +26,7 @@ this.click++ }, actuallyDelete(){ - axios.post('/api/notes/delete', {'noteId':this.noteId}).then(response => { + axios.post('/api/note/delete', {'noteId':this.noteId}).then(response => { if(response.data == true){ this.$bus.$emit('note_deleted') } diff --git a/client/src/components/NoteInputPanel.vue b/client/src/components/NoteInputPanel.vue index f75d700..21a0066 100644 --- a/client/src/components/NoteInputPanel.vue +++ b/client/src/components/NoteInputPanel.vue @@ -143,7 +143,7 @@ let vm = this //Component is activated with NoteId in place, lookup text with associated ID if(this.$store.getters.getLoggedIn){ - axios.post('/api/notes/get', {'noteId': noteId}) + axios.post('/api/note/get', {'noteId': noteId}) .then(response => { //Set up local data @@ -248,7 +248,7 @@ this.saveDebounce = setTimeout(() => { //Only notify user if saving - may help with debugging in the future vm.statusText = 'Saving' - axios.post('/api/notes/update', postData).then( response => { + axios.post('/api/note/update', postData).then( response => { vm.statusText = 'Saved' vm.updated = Math.round((+new Date)/1000) diff --git a/client/src/components/NoteTagEdit.vue b/client/src/components/NoteTagEdit.vue index c372f2e..f2a7742 100644 --- a/client/src/components/NoteTagEdit.vue +++ b/client/src/components/NoteTagEdit.vue @@ -45,7 +45,7 @@ getTags(){ //Get Note Tags -> /api/tags/get let vm = this - axios.post('/api/tags/get', {'noteId': this.noteId}) + axios.post('/api/tag/get', {'noteId': this.noteId}) .then(response => { //Set up local data vm.tags = response.data @@ -105,7 +105,7 @@ 'noteId':vm.noteId } - axios.post('/api/tags/suggest', postData) + axios.post('/api/tag/suggest', postData) .then(response => { vm.suggestions = response.data @@ -130,7 +130,7 @@ 'noteId':this.noteId } let vm = this - axios.post('/api/tags/addtonote', postData) + axios.post('/api/tag/addtonote', postData) .then(response => { vm.newTagInput = '' vm.clearSuggestions() @@ -155,7 +155,7 @@ 'noteId':this.noteId } let vm = this - axios.post('/api/tags/removefromnote', postData) + axios.post('/api/tag/removefromnote', postData) .then(response => { vm.getTags() }) diff --git a/client/src/pages/NotesPage.vue b/client/src/pages/NotesPage.vue index 091b428..6665cdb 100644 --- a/client/src/pages/NotesPage.vue +++ b/client/src/pages/NotesPage.vue @@ -196,7 +196,7 @@ } //Perform search let vm = this - axios.post('/api/notes/search', postData). + axios.post('/api/note/search', postData). then(response => { console.log('Notes and Tags') console.log(response.data) @@ -217,7 +217,7 @@ const title = '' let vm = this - axios.post('/api/notes/create', {title}) + axios.post('/api/note/create', {title}) .then(response => { if(response.data && response.data.id){ diff --git a/server/index.js b/server/index.js index fe7c672..9beddae 100644 --- a/server/index.js +++ b/server/index.js @@ -37,16 +37,16 @@ app.use(function(req, res, next){ app.get(prefix, (req, res) => res.send('The api is running')) //Init user endpoint -var user = require('@routes/user') +var user = require('@routes/userController') app.use(prefix+'/user', user) //Init notes endpoint -var notes = require('@routes/notesController') -app.use(prefix+'/notes', notes) +var notes = require('@routes/noteController') +app.use(prefix+'/note', notes) //Init tags endpoint -var tags = require('@routes/tagsController') -app.use(prefix+'/tags', tags) +var tags = require('@routes/tagController') +app.use(prefix+'/tag', tags) //Output running status app.listen(port, () => console.log(`Listening on port ${port}!`)) \ No newline at end of file diff --git a/server/models/Notes.js b/server/models/Note.js similarity index 94% rename from server/models/Notes.js rename to server/models/Note.js index 2efb144..57e839e 100644 --- a/server/models/Notes.js +++ b/server/models/Note.js @@ -1,12 +1,12 @@ let db = require('@config/database') -let Tags = require('@models/Tags') +let Tags = require('@models/Tag') let Attachment = require('@models/Attachment') var rp = require('request-promise'); var SolrNode = require('solr-node'); -let Notes = module.exports = {} +let Note = module.exports = {} // Create client var client = new SolrNode({ @@ -16,7 +16,7 @@ var client = new SolrNode({ protocol: 'http' }); -Notes.create = (userId, noteText) => { +Note.create = (userId, noteText) => { return new Promise((resolve, reject) => { if(userId == null || userId < 10){ reject('User Id required to create note') } @@ -32,7 +32,7 @@ Notes.create = (userId, noteText) => { }) } -Notes.update = (userId, noteId, noteText, fancyInput, color) => { +Note.update = (userId, noteId, noteText, fancyInput, color) => { return new Promise((resolve, reject) => { const now = Math.round((+new Date)/1000) @@ -73,7 +73,7 @@ Notes.update = (userId, noteId, noteText, fancyInput, color) => { }) } -Notes.delete = (userId, noteId) => { +Note.delete = (userId, noteId) => { return new Promise((resolve, reject) => { // DELETE FROM notes WHERE notes.id = 290 AND notes.user = 61; // DELETE FROM attachment WHERE attachment.note_id = 290 AND attachment.user_id = 61; @@ -92,7 +92,7 @@ Notes.delete = (userId, noteId) => { }) } -Notes.get = (userId, noteId) => { +Note.get = (userId, noteId) => { return new Promise((resolve, reject) => { db.promise() .query('SELECT text, updated, raw_input, color FROM notes WHERE user = ? AND id = ? LIMIT 1', [userId,noteId]) @@ -103,7 +103,7 @@ Notes.get = (userId, noteId) => { }) } -Notes.getLatest = (userId) => { +Note.getLatest = (userId) => { return new Promise((resolve, reject) => { db.promise() .query('SELECT id, SUBSTRING(text, 1, 100) as text FROM notes WHERE user = ? ORDER BY updated DESC, created DESC', [userId]) @@ -114,7 +114,7 @@ Notes.getLatest = (userId) => { }) } -Notes.solrQuery = (userId, searchQuery, searchTags) => { +Note.solrQuery = (userId, searchQuery, searchTags) => { return new Promise((resolve, reject) => { if(searchQuery != '' && searchQuery != null){ @@ -140,7 +140,7 @@ Notes.solrQuery = (userId, searchQuery, searchTags) => { }) } -Notes.search = (userId, searchQuery, searchTags) => { +Note.search = (userId, searchQuery, searchTags) => { return new Promise((resolve, reject) => { @@ -152,7 +152,7 @@ Notes.search = (userId, searchQuery, searchTags) => { } - Notes.solrQuery(userId, searchQuery, searchTags).then( solrResult => { + Note.solrQuery(userId, searchQuery, searchTags).then( solrResult => { let highlights = solrResult.highlighting diff --git a/server/models/Tags.js b/server/models/Tag.js similarity index 84% rename from server/models/Tags.js rename to server/models/Tag.js index 85e0e6d..e150fa5 100644 --- a/server/models/Tags.js +++ b/server/models/Tag.js @@ -1,9 +1,9 @@ let db = require('@config/database') -let Tags = module.exports = {} +let Tag = module.exports = {} -Tags.removeTagFromNote = (userId, tagId) => { +Tag.removeTagFromNote = (userId, tagId) => { return new Promise((resolve, reject) => { db.promise() .query(`DELETE FROM notes_tags WHERE id = ? AND user_id = ? LIMIT 1;`, [tagId, userId]) @@ -14,19 +14,19 @@ Tags.removeTagFromNote = (userId, tagId) => { }) } -Tags.addToNote = (userId, noteId, tagText) => { +Tag.addToNote = (userId, noteId, tagText) => { return new Promise((resolve, reject) => { //Lookup tag - Tags.lookup(tagText) + Tag.lookup(tagText) .then( lookup => { //Tag does not exist, insert new tag, then associate it with a note if(lookup.length == 0){ //Insert new tag - Tags.add(tagText) + Tag.add(tagText) .then( newTagId => { - Tags.associateWithNote(userId, noteId, newTagId) + Tag.associateWithNote(userId, noteId, newTagId) .then( result => { resolve(result) }) @@ -35,7 +35,7 @@ Tags.addToNote = (userId, noteId, tagText) => { //Tag already exists, associate it with a note if(lookup.length > 0){ - Tags.associateWithNote(userId, noteId, lookup[0].id) + Tag.associateWithNote(userId, noteId, lookup[0].id) .then( result => { resolve(result) }) @@ -45,7 +45,7 @@ Tags.addToNote = (userId, noteId, tagText) => { }) } -Tags.associateWithNote = (userId, noteId, tagId) => { +Tag.associateWithNote = (userId, noteId, tagId) => { return new Promise((resolve, reject) => { //Check if tag already exists on note before adding note @@ -72,7 +72,7 @@ Tags.associateWithNote = (userId, noteId, tagId) => { }) } -Tags.add = (tagText) => { +Tag.add = (tagText) => { return new Promise((resolve, reject) => { db.promise() .query(`INSERT INTO tags (text, hash) VALUES (?,?);`, [tagText,0]) @@ -83,7 +83,7 @@ Tags.add = (tagText) => { }) } -Tags.get = (userId, noteId) => { +Tag.get = (userId, noteId) => { return new Promise((resolve, reject) => { db.promise() .query(`SELECT notes_tags.id, tags.text FROM notes_tags @@ -96,9 +96,9 @@ Tags.get = (userId, noteId) => { }) } -Tags.string = (userId, noteId) => { +Tag.string = (userId, noteId) => { return new Promise((resolve, reject) => { - Tags.get(userId, noteId).then(tagArray => { + Tag.get(userId, noteId).then(tagArray => { let tagString = '' tagArray.forEach( (tag, i) => { @@ -112,7 +112,7 @@ Tags.string = (userId, noteId) => { }) } -Tags.lookup = (tagText) => { +Tag.lookup = (tagText) => { return new Promise((resolve, reject) => { db.promise() .query(`SELECT * FROM tags WHERE text = ?;`, [tagText]) @@ -124,7 +124,7 @@ Tags.lookup = (tagText) => { } //Suggest note tags - don't suggest tags already on note -Tags.suggest = (userId, noteId, tagText) => { +Tag.suggest = (userId, noteId, tagText) => { tagText += '%' diff --git a/server/models/Users.js b/server/models/User.js similarity index 99% rename from server/models/Users.js rename to server/models/User.js index 41f5d81..361ace9 100644 --- a/server/models/Users.js +++ b/server/models/User.js @@ -1,4 +1,3 @@ - var crypto = require('crypto') let db = require('@config/database') diff --git a/server/routes/notesController.js b/server/routes/noteController.js similarity index 83% rename from server/routes/notesController.js rename to server/routes/noteController.js index e4963b3..c9012f5 100644 --- a/server/routes/notesController.js +++ b/server/routes/noteController.js @@ -1,7 +1,7 @@ var express = require('express') var router = express.Router() -let Notes = require('@models/Notes'); +let Notes = require('@models/Note'); let userId = null // middleware that is specific to this router @@ -13,12 +13,6 @@ router.use(function setUserId (req, res, next) { next() }) -//Get the latest notes the user has created -router.post('/latest', function (req, res) { - Notes.getLatest(userId) - .then( data => res.send(data) ) -}) - router.post('/get', function (req, res) { Notes.get(userId, req.body.noteId) .then( data => res.send(data) ) diff --git a/server/routes/tagsController.js b/server/routes/tagController.js similarity index 96% rename from server/routes/tagsController.js rename to server/routes/tagController.js index d4fffe0..44639b5 100644 --- a/server/routes/tagsController.js +++ b/server/routes/tagController.js @@ -1,7 +1,7 @@ var express = require('express') var router = express.Router() -let Tags = require('@models/Tags'); +let Tags = require('@models/Tag'); let userId = null // middleware that is specific to this router diff --git a/server/routes/user.js b/server/routes/userController.js similarity index 96% rename from server/routes/user.js rename to server/routes/userController.js index 1f2a4a5..84774a7 100644 --- a/server/routes/user.js +++ b/server/routes/userController.js @@ -1,7 +1,7 @@ var express = require('express') var router = express.Router() -let User = require('@models/Users'); +let User = require('@models/User'); // middleware that is specific to this router router.use(function timeLog (req, res, next) {