Updated vue CLI to latest version
Added cycle tracking base
This commit is contained in:
		| @@ -1,7 +1,12 @@ | ||||
| //Set up environmental variables, pulled from .env file used as process.env.DB_HOST | ||||
| //Set up environmental variables, pulled from ~/.env file used as process.env.DB_HOST | ||||
| const os = require('os') //Used to get path of home directory | ||||
| const result = require('dotenv').config({ path:(os.homedir()+'/.env') }) | ||||
|  | ||||
| const ports = { | ||||
| 	express: 3000, | ||||
| 	socketIo: 3001 | ||||
| } | ||||
|  | ||||
| //Allow user of @ in in require calls. Config in package.json | ||||
| require('module-alias/register') | ||||
|  | ||||
| @@ -15,7 +20,6 @@ const helmet = require('helmet') | ||||
| const express = require('express') | ||||
| const app = express() | ||||
| app.use( helmet() ) | ||||
| const port = 3000 | ||||
|  | ||||
|  | ||||
| // | ||||
| @@ -230,8 +234,8 @@ io.on('connection', function(socket){ | ||||
| }); | ||||
|  | ||||
|  | ||||
| http.listen(3001, function(){ | ||||
| 	console.log('socket.io liseting on port 3001'); | ||||
| http.listen(ports.socketIo, function(){ | ||||
| 	console.log(`Socke.io: Listening on port ${ports.socketIo}!`) | ||||
| }); | ||||
|  | ||||
| //Enable json body parsing in requests. Allows me to post data in ajax calls | ||||
| @@ -285,7 +289,7 @@ UserTest.keyPairTest('genMan30', '1', printResults) | ||||
| }) | ||||
|  | ||||
| //Test  | ||||
| app.get('/api', (req, res) => res.send('Solidscribe API is up and running')) | ||||
| app.get('/api', (req, res) => res.send('Solidscribe /API is up and running')) | ||||
|  | ||||
| //Serve up uploaded files | ||||
| app.use('/api/static', express.static( __dirname+'/../staticFiles' )) | ||||
| @@ -314,9 +318,13 @@ app.use('/api/attachment', attachment) | ||||
| var quickNote = require('@routes/quicknoteController') | ||||
| app.use('/api/quick-note', quickNote) | ||||
|  | ||||
| //cycle tracking endpoint | ||||
| var cycleTracking = require('@routes/cycletrackingController') | ||||
| app.use('/api/cycle-tracking', cycleTracking) | ||||
|  | ||||
| //Output running status | ||||
| app.listen(port, () => {  | ||||
| 	console.log(`Listening on port ${port}!`) | ||||
| app.listen(ports.express, () => {  | ||||
| 	console.log(`Express: Listening on port ${ports.express}!`) | ||||
| }) | ||||
|  | ||||
| // | ||||
|   | ||||
							
								
								
									
										66
									
								
								server/models/CycleTracking.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								server/models/CycleTracking.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,66 @@ | ||||
| let db = require('@config/database') | ||||
|  | ||||
| let Note = require('@models/Note') | ||||
|  | ||||
| let CycleTracking = module.exports = {} | ||||
|  | ||||
|  | ||||
| CycleTracking.get = (userId, masterKey) => { | ||||
| 	return new Promise((resolve, reject) => { | ||||
|  | ||||
| 		db.promise() | ||||
| 		.query(` | ||||
| 			SELECT note.id FROM note WHERE quick_note = 2 AND user_id = ? LIMIT 1`, [userId]) | ||||
| 		.then((rows, fields) => { | ||||
|  | ||||
| 			//Quick Note is set, return note object | ||||
| 			if(rows[0][0] != undefined){ | ||||
|  | ||||
| 				let noteId = rows[0][0].id | ||||
| 				const note = Note.get(userId, noteId, masterKey) | ||||
| 				.then(noteData => { | ||||
| 					return resolve(noteData) | ||||
| 				}) | ||||
|  | ||||
| 			} else { | ||||
| 				//Or create a new note | ||||
| 				let finalId = null | ||||
| 				return Note.create(userId, 'Cycle Tracking', '', masterKey) | ||||
| 				.then(insertedId => { | ||||
| 					finalId = insertedId | ||||
| 					db.promise().query('UPDATE note SET quick_note = 2 WHERE id = ? AND user_id = ?',[insertedId, userId]) | ||||
| 					.then((rows, fields) => { | ||||
|  | ||||
| 						const note = Note.get(userId, finalId, masterKey) | ||||
| 						.then(noteData => { | ||||
| 							return resolve(noteData) | ||||
| 						}) | ||||
|  | ||||
| 					}) | ||||
| 				}) | ||||
| 				 | ||||
| 			} | ||||
|  | ||||
| 			 | ||||
| 		}) | ||||
| 		.catch(console.log) | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| CycleTracking.save = (userId, cycleData, masterKey) => { | ||||
| 	return new Promise((resolve, reject) => { | ||||
|  | ||||
| 		let finalId = null | ||||
|  | ||||
| 		CycleTracking.get(userId, masterKey) | ||||
| 		.then(noteObject => { | ||||
|  | ||||
| 			return Note.update(userId, noteObject.id, cycleData, noteObject.title, noteObject.color, noteObject.pinned, noteObject.archived, null, masterKey) | ||||
| 			 | ||||
| 		}) | ||||
| 		.then( saveResults => { | ||||
| 			return resolve(saveResults) | ||||
| 		}) | ||||
| 	}) | ||||
|  | ||||
| } | ||||
							
								
								
									
										41
									
								
								server/routes/cycletrackingController.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								server/routes/cycletrackingController.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,41 @@ | ||||
| // | ||||
| // /api/cycle-tracking | ||||
| // | ||||
|  | ||||
| var express = require('express') | ||||
| var router = express.Router() | ||||
|  | ||||
| let CycleTracking = require('@models/CycleTracking'); | ||||
|  | ||||
| let userId = null | ||||
| let masterKey = null | ||||
|  | ||||
| // middleware that is specific to this router | ||||
| router.use(function setUserId (req, res, next) { | ||||
|  | ||||
| 	//Session key is required to continue | ||||
| 	if(!req.headers.sessionId){ | ||||
| 		next('Unauthorized') | ||||
| 	} | ||||
|  | ||||
| 	if(req.headers.userId){ | ||||
| 		userId = req.headers.userId | ||||
| 		masterKey = req.headers.masterKey | ||||
| 		next() | ||||
| 	} | ||||
| }) | ||||
|  | ||||
| //Get quick note text | ||||
| router.post('/get', function (req, res) { | ||||
| 	CycleTracking.get(userId, masterKey) | ||||
| 	.then( data => res.send(data) ) | ||||
| }) | ||||
|  | ||||
| //Push text to quick note | ||||
| router.post('/save', function (req, res) { | ||||
| 	CycleTracking.save(userId, req.body.cycleData, masterKey) | ||||
| 	.then( data => res.send(data) ) | ||||
| }) | ||||
|  | ||||
|  | ||||
| module.exports = router | ||||
		Reference in New Issue
	
	Block a user