Backend update renamed controllers and models to be singular

This commit is contained in:
Max G 2019-07-30 19:21:12 +00:00
parent 7806a206b2
commit 0d86aa4ff9
11 changed files with 41 additions and 48 deletions

View File

@ -26,7 +26,7 @@
this.click++ this.click++
}, },
actuallyDelete(){ 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){ if(response.data == true){
this.$bus.$emit('note_deleted') this.$bus.$emit('note_deleted')
} }

View File

@ -143,7 +143,7 @@
let vm = this let vm = this
//Component is activated with NoteId in place, lookup text with associated ID //Component is activated with NoteId in place, lookup text with associated ID
if(this.$store.getters.getLoggedIn){ if(this.$store.getters.getLoggedIn){
axios.post('/api/notes/get', {'noteId': noteId}) axios.post('/api/note/get', {'noteId': noteId})
.then(response => { .then(response => {
//Set up local data //Set up local data
@ -248,7 +248,7 @@
this.saveDebounce = setTimeout(() => { this.saveDebounce = setTimeout(() => {
//Only notify user if saving - may help with debugging in the future //Only notify user if saving - may help with debugging in the future
vm.statusText = 'Saving' vm.statusText = 'Saving'
axios.post('/api/notes/update', postData).then( response => { axios.post('/api/note/update', postData).then( response => {
vm.statusText = 'Saved' vm.statusText = 'Saved'
vm.updated = Math.round((+new Date)/1000) vm.updated = Math.round((+new Date)/1000)

View File

@ -45,7 +45,7 @@
getTags(){ getTags(){
//Get Note Tags -> /api/tags/get //Get Note Tags -> /api/tags/get
let vm = this let vm = this
axios.post('/api/tags/get', {'noteId': this.noteId}) axios.post('/api/tag/get', {'noteId': this.noteId})
.then(response => { .then(response => {
//Set up local data //Set up local data
vm.tags = response.data vm.tags = response.data
@ -105,7 +105,7 @@
'noteId':vm.noteId 'noteId':vm.noteId
} }
axios.post('/api/tags/suggest', postData) axios.post('/api/tag/suggest', postData)
.then(response => { .then(response => {
vm.suggestions = response.data vm.suggestions = response.data
@ -130,7 +130,7 @@
'noteId':this.noteId 'noteId':this.noteId
} }
let vm = this let vm = this
axios.post('/api/tags/addtonote', postData) axios.post('/api/tag/addtonote', postData)
.then(response => { .then(response => {
vm.newTagInput = '' vm.newTagInput = ''
vm.clearSuggestions() vm.clearSuggestions()
@ -155,7 +155,7 @@
'noteId':this.noteId 'noteId':this.noteId
} }
let vm = this let vm = this
axios.post('/api/tags/removefromnote', postData) axios.post('/api/tag/removefromnote', postData)
.then(response => { .then(response => {
vm.getTags() vm.getTags()
}) })

View File

@ -196,7 +196,7 @@
} }
//Perform search //Perform search
let vm = this let vm = this
axios.post('/api/notes/search', postData). axios.post('/api/note/search', postData).
then(response => { then(response => {
console.log('Notes and Tags') console.log('Notes and Tags')
console.log(response.data) console.log(response.data)
@ -217,7 +217,7 @@
const title = '' const title = ''
let vm = this let vm = this
axios.post('/api/notes/create', {title}) axios.post('/api/note/create', {title})
.then(response => { .then(response => {
if(response.data && response.data.id){ if(response.data && response.data.id){

View File

@ -37,16 +37,16 @@ app.use(function(req, res, next){
app.get(prefix, (req, res) => res.send('The api is running')) app.get(prefix, (req, res) => res.send('The api is running'))
//Init user endpoint //Init user endpoint
var user = require('@routes/user') var user = require('@routes/userController')
app.use(prefix+'/user', user) app.use(prefix+'/user', user)
//Init notes endpoint //Init notes endpoint
var notes = require('@routes/notesController') var notes = require('@routes/noteController')
app.use(prefix+'/notes', notes) app.use(prefix+'/note', notes)
//Init tags endpoint //Init tags endpoint
var tags = require('@routes/tagsController') var tags = require('@routes/tagController')
app.use(prefix+'/tags', tags) app.use(prefix+'/tag', tags)
//Output running status //Output running status
app.listen(port, () => console.log(`Listening on port ${port}!`)) app.listen(port, () => console.log(`Listening on port ${port}!`))

View File

@ -1,12 +1,12 @@
let db = require('@config/database') let db = require('@config/database')
let Tags = require('@models/Tags') let Tags = require('@models/Tag')
let Attachment = require('@models/Attachment') let Attachment = require('@models/Attachment')
var rp = require('request-promise'); var rp = require('request-promise');
var SolrNode = require('solr-node'); var SolrNode = require('solr-node');
let Notes = module.exports = {} let Note = module.exports = {}
// Create client // Create client
var client = new SolrNode({ var client = new SolrNode({
@ -16,7 +16,7 @@ var client = new SolrNode({
protocol: 'http' protocol: 'http'
}); });
Notes.create = (userId, noteText) => { Note.create = (userId, noteText) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if(userId == null || userId < 10){ reject('User Id required to create note') } 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) => { return new Promise((resolve, reject) => {
const now = Math.round((+new Date)/1000) 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) => { return new Promise((resolve, reject) => {
// DELETE FROM notes WHERE notes.id = 290 AND notes.user = 61; // DELETE FROM notes WHERE notes.id = 290 AND notes.user = 61;
// DELETE FROM attachment WHERE attachment.note_id = 290 AND attachment.user_id = 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) => { return new Promise((resolve, reject) => {
db.promise() db.promise()
.query('SELECT text, updated, raw_input, color FROM notes WHERE user = ? AND id = ? LIMIT 1', [userId,noteId]) .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) => { return new Promise((resolve, reject) => {
db.promise() db.promise()
.query('SELECT id, SUBSTRING(text, 1, 100) as text FROM notes WHERE user = ? ORDER BY updated DESC, created DESC', [userId]) .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) => { return new Promise((resolve, reject) => {
if(searchQuery != '' && searchQuery != null){ 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) => { 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 let highlights = solrResult.highlighting

View File

@ -1,9 +1,9 @@
let db = require('@config/database') 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) => { return new Promise((resolve, reject) => {
db.promise() db.promise()
.query(`DELETE FROM notes_tags WHERE id = ? AND user_id = ? LIMIT 1;`, [tagId, userId]) .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) => { return new Promise((resolve, reject) => {
//Lookup tag //Lookup tag
Tags.lookup(tagText) Tag.lookup(tagText)
.then( lookup => { .then( lookup => {
//Tag does not exist, insert new tag, then associate it with a note //Tag does not exist, insert new tag, then associate it with a note
if(lookup.length == 0){ if(lookup.length == 0){
//Insert new tag //Insert new tag
Tags.add(tagText) Tag.add(tagText)
.then( newTagId => { .then( newTagId => {
Tags.associateWithNote(userId, noteId, newTagId) Tag.associateWithNote(userId, noteId, newTagId)
.then( result => { .then( result => {
resolve(result) resolve(result)
}) })
@ -35,7 +35,7 @@ Tags.addToNote = (userId, noteId, tagText) => {
//Tag already exists, associate it with a note //Tag already exists, associate it with a note
if(lookup.length > 0){ if(lookup.length > 0){
Tags.associateWithNote(userId, noteId, lookup[0].id) Tag.associateWithNote(userId, noteId, lookup[0].id)
.then( result => { .then( result => {
resolve(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) => { return new Promise((resolve, reject) => {
//Check if tag already exists on note before adding note //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) => { return new Promise((resolve, reject) => {
db.promise() db.promise()
.query(`INSERT INTO tags (text, hash) VALUES (?,?);`, [tagText,0]) .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) => { return new Promise((resolve, reject) => {
db.promise() db.promise()
.query(`SELECT notes_tags.id, tags.text FROM notes_tags .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) => { return new Promise((resolve, reject) => {
Tags.get(userId, noteId).then(tagArray => { Tag.get(userId, noteId).then(tagArray => {
let tagString = '' let tagString = ''
tagArray.forEach( (tag, i) => { tagArray.forEach( (tag, i) => {
@ -112,7 +112,7 @@ Tags.string = (userId, noteId) => {
}) })
} }
Tags.lookup = (tagText) => { Tag.lookup = (tagText) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.promise() db.promise()
.query(`SELECT * FROM tags WHERE text = ?;`, [tagText]) .query(`SELECT * FROM tags WHERE text = ?;`, [tagText])
@ -124,7 +124,7 @@ Tags.lookup = (tagText) => {
} }
//Suggest note tags - don't suggest tags already on note //Suggest note tags - don't suggest tags already on note
Tags.suggest = (userId, noteId, tagText) => { Tag.suggest = (userId, noteId, tagText) => {
tagText += '%' tagText += '%'

View File

@ -1,4 +1,3 @@
var crypto = require('crypto') var crypto = require('crypto')
let db = require('@config/database') let db = require('@config/database')

View File

@ -1,7 +1,7 @@
var express = require('express') var express = require('express')
var router = express.Router() var router = express.Router()
let Notes = require('@models/Notes'); let Notes = require('@models/Note');
let userId = null let userId = null
// middleware that is specific to this router // middleware that is specific to this router
@ -13,12 +13,6 @@ router.use(function setUserId (req, res, next) {
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) { router.post('/get', function (req, res) {
Notes.get(userId, req.body.noteId) Notes.get(userId, req.body.noteId)
.then( data => res.send(data) ) .then( data => res.send(data) )

View File

@ -1,7 +1,7 @@
var express = require('express') var express = require('express')
var router = express.Router() var router = express.Router()
let Tags = require('@models/Tags'); let Tags = require('@models/Tag');
let userId = null let userId = null
// middleware that is specific to this router // middleware that is specific to this router

View File

@ -1,7 +1,7 @@
var express = require('express') var express = require('express')
var router = express.Router() var router = express.Router()
let User = require('@models/Users'); let User = require('@models/User');
// middleware that is specific to this router // middleware that is specific to this router
router.use(function timeLog (req, res, next) { router.use(function timeLog (req, res, next) {