Browse Source

still fleshing out main structure, documentation

master
Brandon Nolet 1 year ago
parent
commit
bfe7d08d2b
4 changed files with 145 additions and 46 deletions
  1. +45
    -44
      app.js
  2. +39
    -0
      docs/Database Schema
  3. +58
    -0
      package-lock.json
  4. +3
    -2
      package.json

+ 45
- 44
app.js View File

@@ -2,58 +2,59 @@ const express = require('express')
const app = express()
const bodyParser = require('body-parser')
const logger = require('morgan')
const mongoose = require('mongoose')
const MongoClient = require('mongodb').MongoClient
const singleLine = require('single-line-log').stdout

app.use(bodyParser.json())

const dbUrl = 'mongodb://localhost:27017/generalist'

const Task = mongoose.model('Task', {
task: String,
inbox: Boolean,
done: Boolean,
priority: Number,
category: Object,
label: Array,
comment: String,
dateCreated: {type: Date, default: Date.now},
dateDue: Date,

})

const Category = mongoose.model('Category', {
name: String,
tasks: Array,
color: {type: String, min: 3, max: 6},
description: String,
subcategories: Array,
archived: Boolean
})

const Label = mongoose.model('Category', {
name: String,
color: {type: String, min: 3, max: 6}
MongoClient.connect(dbUrl, { useNewUrlParser: true},function(err, db){
if (err) throw err
const dbo = db.db('generalist')
var firstTask = { task: "the fuck", inbox: true, done: false, priority: 5, category: "Shopping", label: [], comment: "Fuck you", dateCreated: Date.now(), dateDue: null }
dbo.collection('tasks').insertOne(firstTask, function(err, res) {
if (err) throw err
console.log('Document inserted')
db.close
})

dbo.collection('tasks').estimatedDocumentCount({}, function(err, res) {
console.log(res)
})
})

if (process.env.NODE_ENV === 'dev')
app.use(logger('dev'))
console.log('Cauting: running in development mode')

app.get('/', (req, res) => {
console.log('get')
res.sendStatus(200)
})

app.post('/tasks', (req, res) => {
var task = new Task(req.body)
var savedTask = Task.save()

console.log('task saved')
})

app.put('/tasks', (req, res) => {
var taskID = JSON.parse(req.body)._id
Task.updateOne({_id: taskID}, { })
app.put('/tasks/', (req, res) => {
dbo.collection('tasks').insertOne(req.body, function(err, res) {
if (err) throw err
console.log('Document inserted')
db.close
})
})

app.listen(3000, function() { console.log('Listening on port: ' + this.address().port)})
app.listen(3000, function() {
console.log('Listening on port: ' + this.address().port)
if (process.env.NODE_ENV === 'dev') {

app.use(logger('dev'))
console.log('Cauting: running in development mode')
console.log('If you wish to keep all collections in the GeneraList database, please press Ctrl+C (10 seconds)')
setTimeout(function() {
MongoClient.connect(dbUrl, { useNewUrlParser: true},function(err, db){
const dbo = db.db('generalist')
dbo.dropDatabase()
console.log('Dropped all collections')
})
}, 10020)
var i = 10
setInterval(function() {
if (i > 0 ) {i--; singleLine(i)}
if (i === 0) {
console.log()
clearInterval(this)
}
}, 1000)
}
})

+ 39
- 0
docs/Database Schema View File

@@ -0,0 +1,39 @@
# Database Schema

Below are a brief overview of the schema used for the GeneraList MongoDB database.

`//todo: explanation of schema choices`

## Tasks

Each task has the following schema

* task: String
* inbox: Boolean
* done: Boolean
* priority: Number
* category: Object
* label: Array
* comment: String
* dateCreated: {type: Date, default: Date.now},
* dateDue: Date


## Categories

Each category has the following schema

* name: String,
* tasks: Array,
* color: {type: String, min: 3, max: 6},
* description: String,
* subcategories: Array,
* archived: Boolean


## Labels

Each label has the following schema

* name: String,
* color: {type: String, min: 3, max: 6}

+ 58
- 0
package-lock.json View File

@@ -376,6 +376,12 @@
"integrity": "sha1-T6kXw+WclKAEzWH47lCdplFocUM=",
"dev": true
},
"code-point-at": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz",
"integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=",
"dev": true
},
"collection-visit": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/collection-visit/-/collection-visit-1.0.0.tgz",
@@ -2112,6 +2118,12 @@
"path-key": "^2.0.0"
}
},
"number-is-nan": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz",
"integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=",
"dev": true
},
"object-copy": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/object-copy/-/object-copy-0.1.0.tgz",
@@ -2549,6 +2561,52 @@
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=",
"dev": true
},
"single-line-log": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/single-line-log/-/single-line-log-1.1.2.tgz",
"integrity": "sha1-wvg/Jzo+GhbtsJlWYdoO1e8DM2Q=",
"dev": true,
"requires": {
"string-width": "^1.0.1"
},
"dependencies": {
"ansi-regex": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=",
"dev": true
},
"is-fullwidth-code-point": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz",
"integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=",
"dev": true,
"requires": {
"number-is-nan": "^1.0.0"
}
},
"string-width": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
"integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
"dev": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
"strip-ansi": "^3.0.0"
}
},
"strip-ansi": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"dev": true,
"requires": {
"ansi-regex": "^2.0.0"
}
}
}
},
"sliced": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/sliced/-/sliced-1.0.1.tgz",


+ 3
- 2
package.json View File

@@ -5,7 +5,7 @@
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "NODE_ENV='dev' nodemon app.js"
"dev": "NODE_ENV='dev' node-dev app.js"
},
"repository": {
"type": "git",
@@ -25,6 +25,7 @@
},
"devDependencies": {
"morgan": "^1.9.1",
"nodemon": "^1.18.11"
"nodemon": "^1.18.11",
"single-line-log": "^1.1.2"
}
}

Loading…
Cancel
Save