post todos route and refactor mongoose

This commit is contained in:
Tyrel Souza 2017-11-29 22:52:44 -05:00
parent cad31aa449
commit eac8779435
6 changed files with 545 additions and 3 deletions

478
package-lock.json generated
View File

@ -4,31 +4,260 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"accepts": {
"version": "1.3.4",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.4.tgz",
"integrity": "sha1-hiRnWMfdbSGmR0/whKR0DsBesh8=",
"requires": {
"mime-types": "2.1.17",
"negotiator": "0.6.1"
}
},
"array-flatten": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
},
"async": {
"version": "1.5.2",
"resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz",
"integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo="
},
"bluebird": {
"version": "2.10.2",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-2.10.2.tgz",
"integrity": "sha1-AkpVFylTCIV/FPkfEQb8O1VfRGs="
},
"body-parser": {
"version": "1.15.2",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.15.2.tgz",
"integrity": "sha1-11eM9PHRHV9uqATO813Hp/9trmc=",
"requires": {
"bytes": "2.4.0",
"content-type": "1.0.4",
"debug": "2.2.0",
"depd": "1.1.1",
"http-errors": "1.5.1",
"iconv-lite": "0.4.13",
"on-finished": "2.3.0",
"qs": "6.2.0",
"raw-body": "2.1.7",
"type-is": "1.6.15"
}
},
"bson": {
"version": "0.5.7",
"resolved": "https://registry.npmjs.org/bson/-/bson-0.5.7.tgz",
"integrity": "sha1-DRH+CTbB/uAp4R9wY/XQqyQi6j4="
},
"bytes": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-2.4.0.tgz",
"integrity": "sha1-fZcZb51br39pNeJZhVSe3SpsIzk="
},
"content-disposition": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.1.tgz",
"integrity": "sha1-h0dsamfI2qh+Muh2Ft+IO6f7Bxs="
},
"content-type": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
"integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA=="
},
"cookie": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz",
"integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s="
},
"cookie-signature": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw="
},
"core-util-is": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"debug": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.2.0.tgz",
"integrity": "sha1-+HBX6ZWxofauaklgZkE3vFbwOdo=",
"requires": {
"ms": "0.7.1"
}
},
"depd": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz",
"integrity": "sha1-V4O04cRZ8G+lyif5kfPQbnoxA1k="
},
"destroy": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
},
"ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
},
"encodeurl": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.1.tgz",
"integrity": "sha1-eePVhlU0aQn+bw9Fpd5oEDspTSA="
},
"es6-promise": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.0.2.tgz",
"integrity": "sha1-AQ1YWEI6XxGJeWZfRkhqlcbuK7Y="
},
"escape-html": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
"integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg="
},
"etag": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/etag/-/etag-1.7.0.tgz",
"integrity": "sha1-A9MLX2fdbmMtKUXTDWZScxo01dg="
},
"express": {
"version": "4.14.0",
"resolved": "https://registry.npmjs.org/express/-/express-4.14.0.tgz",
"integrity": "sha1-we4/Qs3Ikfs9xlCoki1R7IR9DWY=",
"requires": {
"accepts": "1.3.4",
"array-flatten": "1.1.1",
"content-disposition": "0.5.1",
"content-type": "1.0.4",
"cookie": "0.3.1",
"cookie-signature": "1.0.6",
"debug": "2.2.0",
"depd": "1.1.1",
"encodeurl": "1.0.1",
"escape-html": "1.0.3",
"etag": "1.7.0",
"finalhandler": "0.5.0",
"fresh": "0.3.0",
"merge-descriptors": "1.0.1",
"methods": "1.1.2",
"on-finished": "2.3.0",
"parseurl": "1.3.2",
"path-to-regexp": "0.1.7",
"proxy-addr": "1.1.5",
"qs": "6.2.0",
"range-parser": "1.2.0",
"send": "0.14.1",
"serve-static": "1.11.2",
"type-is": "1.6.15",
"utils-merge": "1.0.0",
"vary": "1.1.2"
}
},
"finalhandler": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-0.5.0.tgz",
"integrity": "sha1-6VCKvs6bbbqHGmlCodeRG5GRGsc=",
"requires": {
"debug": "2.2.0",
"escape-html": "1.0.3",
"on-finished": "2.3.0",
"statuses": "1.3.1",
"unpipe": "1.0.0"
},
"dependencies": {
"statuses": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz",
"integrity": "sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4="
}
}
},
"forwarded": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
"integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ="
},
"fresh": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.3.0.tgz",
"integrity": "sha1-ZR+DjiJCTnVm3hYdg1jKoZn4PU8="
},
"hooks-fixed": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/hooks-fixed/-/hooks-fixed-1.2.0.tgz",
"integrity": "sha1-DSdy1NfWhf+SRHJKnwtbJVmqyWs="
},
"http-errors": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.5.1.tgz",
"integrity": "sha1-eIwNLB3iyBuebowBhDtrl+uSB1A=",
"requires": {
"inherits": "2.0.3",
"setprototypeof": "1.0.2",
"statuses": "1.4.0"
}
},
"iconv-lite": {
"version": "0.4.13",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.13.tgz",
"integrity": "sha1-H4irpKsLFQjoMSrMOTRfNumS4vI="
},
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
},
"ipaddr.js": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.4.0.tgz",
"integrity": "sha1-KWrKh4qCGBbluF0KKFqZvP9FgvA="
},
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"kareem": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/kareem/-/kareem-1.1.3.tgz",
"integrity": "sha1-CHdhDYh5w42mLR26/eThfyaS8EE="
},
"media-typer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
"integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g="
},
"merge-descriptors": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
"integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E="
},
"methods": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
"integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4="
},
"mime": {
"version": "1.3.4",
"resolved": "https://registry.npmjs.org/mime/-/mime-1.3.4.tgz",
"integrity": "sha1-EV+eO2s9rylZmDyzjxSaLUDrXVM="
},
"mime-db": {
"version": "1.30.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.30.0.tgz",
"integrity": "sha1-dMZD2i3Z1qRTmZY0ZbJtXKfXHwE="
},
"mime-types": {
"version": "2.1.17",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.17.tgz",
"integrity": "sha1-Cdejk/A+mVp5+K+Fe3Cp4KsWVXo=",
"requires": {
"mime-db": "1.30.0"
}
},
"mongodb": {
"version": "2.2.5",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-2.2.5.tgz",
@ -48,6 +277,141 @@
"require_optional": "1.0.1"
}
},
"mongoose": {
"version": "4.5.9",
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-4.5.9.tgz",
"integrity": "sha1-T2laSWw1mrpFPcZRonzu6cspYdg=",
"requires": {
"async": "1.5.2",
"bson": "0.4.23",
"hooks-fixed": "1.2.0",
"kareem": "1.1.3",
"mongodb": "2.1.18",
"mpath": "0.2.1",
"mpromise": "0.5.5",
"mquery": "1.11.0",
"ms": "0.7.1",
"muri": "1.1.0",
"regexp-clone": "0.0.1",
"sliced": "1.0.1"
},
"dependencies": {
"bson": {
"version": "0.4.23",
"resolved": "https://registry.npmjs.org/bson/-/bson-0.4.23.tgz",
"integrity": "sha1-5louPHUH/63kEJvHV1p25Q+NqRU="
},
"mongodb": {
"version": "2.1.18",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-2.1.18.tgz",
"integrity": "sha1-KNQLUVsr5NWmn/3UxTXw30MuQJc=",
"requires": {
"es6-promise": "3.0.2",
"mongodb-core": "1.3.18",
"readable-stream": "1.0.31"
}
},
"mongodb-core": {
"version": "1.3.18",
"resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-1.3.18.tgz",
"integrity": "sha1-kGhLO3xzVtZa41Y5HTCw8kiATHo=",
"requires": {
"bson": "0.4.23",
"require_optional": "1.0.1"
}
}
}
},
"mpath": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/mpath/-/mpath-0.2.1.tgz",
"integrity": "sha1-Ok6Ck1mAHeljCcJ6ay4QLon56W4="
},
"mpromise": {
"version": "0.5.5",
"resolved": "https://registry.npmjs.org/mpromise/-/mpromise-0.5.5.tgz",
"integrity": "sha1-9bJCWddjrMIlewoMjG2Gb9UXMuY="
},
"mquery": {
"version": "1.11.0",
"resolved": "https://registry.npmjs.org/mquery/-/mquery-1.11.0.tgz",
"integrity": "sha1-4MZd7bEDftv2z7iCYud3/uI1Udk=",
"requires": {
"bluebird": "2.10.2",
"debug": "2.2.0",
"regexp-clone": "0.0.1",
"sliced": "0.0.5"
},
"dependencies": {
"sliced": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/sliced/-/sliced-0.0.5.tgz",
"integrity": "sha1-XtwETKTrb3gW1Qui/GPiXY/kcH8="
}
}
},
"ms": {
"version": "0.7.1",
"resolved": "https://registry.npmjs.org/ms/-/ms-0.7.1.tgz",
"integrity": "sha1-nNE8A62/8ltl7/3nzoZO6VIBcJg="
},
"muri": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/muri/-/muri-1.1.0.tgz",
"integrity": "sha1-o6bXTmiogPQzokmnSWnLtmXMCt0="
},
"negotiator": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz",
"integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk="
},
"on-finished": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
"integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=",
"requires": {
"ee-first": "1.1.1"
}
},
"parseurl": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz",
"integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M="
},
"path-to-regexp": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
},
"proxy-addr": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-1.1.5.tgz",
"integrity": "sha1-ccDuOxAt4/IC87ZPYI0XP8uhqRg=",
"requires": {
"forwarded": "0.1.2",
"ipaddr.js": "1.4.0"
}
},
"qs": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.2.0.tgz",
"integrity": "sha1-O3hIwDwt7OaalSKw+ujEEm10Xzs="
},
"range-parser": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz",
"integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4="
},
"raw-body": {
"version": "2.1.7",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.1.7.tgz",
"integrity": "sha1-rf6s4uT7MJgFgBTQjActzFl1h3Q=",
"requires": {
"bytes": "2.4.0",
"iconv-lite": "0.4.13",
"unpipe": "1.0.0"
}
},
"readable-stream": {
"version": "1.0.31",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.31.tgz",
@ -59,6 +423,11 @@
"string_decoder": "0.10.31"
}
},
"regexp-clone": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-0.0.1.tgz",
"integrity": "sha1-p8LgmJH9vzj7sQ03b7cwA+aKxYk="
},
"require_optional": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz",
@ -78,10 +447,119 @@
"resolved": "https://registry.npmjs.org/semver/-/semver-5.4.1.tgz",
"integrity": "sha512-WfG/X9+oATh81XtllIo/I8gOiY9EXRdv1cQdyykeXK17YcUW3EXUAi2To4pcH6nZtJPr7ZOpM5OMyWJZm+8Rsg=="
},
"send": {
"version": "0.14.1",
"resolved": "https://registry.npmjs.org/send/-/send-0.14.1.tgz",
"integrity": "sha1-qVSYQyU5L1FTKndgdg5FlZjIn3o=",
"requires": {
"debug": "2.2.0",
"depd": "1.1.1",
"destroy": "1.0.4",
"encodeurl": "1.0.1",
"escape-html": "1.0.3",
"etag": "1.7.0",
"fresh": "0.3.0",
"http-errors": "1.5.1",
"mime": "1.3.4",
"ms": "0.7.1",
"on-finished": "2.3.0",
"range-parser": "1.2.0",
"statuses": "1.3.1"
},
"dependencies": {
"statuses": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz",
"integrity": "sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4="
}
}
},
"serve-static": {
"version": "1.11.2",
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.11.2.tgz",
"integrity": "sha1-LPmIm9RDWjIMw2iVyapXvWYuasc=",
"requires": {
"encodeurl": "1.0.1",
"escape-html": "1.0.3",
"parseurl": "1.3.2",
"send": "0.14.2"
},
"dependencies": {
"ms": {
"version": "0.7.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-0.7.2.tgz",
"integrity": "sha1-riXPJRKziFodldfwN4aNhDESR2U="
},
"send": {
"version": "0.14.2",
"resolved": "https://registry.npmjs.org/send/-/send-0.14.2.tgz",
"integrity": "sha1-ObBDiz9RC+Xcb2Z6EfcWiTaM3u8=",
"requires": {
"debug": "2.2.0",
"depd": "1.1.1",
"destroy": "1.0.4",
"encodeurl": "1.0.1",
"escape-html": "1.0.3",
"etag": "1.7.0",
"fresh": "0.3.0",
"http-errors": "1.5.1",
"mime": "1.3.4",
"ms": "0.7.2",
"on-finished": "2.3.0",
"range-parser": "1.2.0",
"statuses": "1.3.1"
}
},
"statuses": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz",
"integrity": "sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4="
}
}
},
"setprototypeof": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.2.tgz",
"integrity": "sha1-gaVSFB7BBLiOic44MQOtXGZWTQg="
},
"sliced": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/sliced/-/sliced-1.0.1.tgz",
"integrity": "sha1-CzpmK10Ewxd7GSa+qCsD+Dei70E="
},
"statuses": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz",
"integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew=="
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
},
"type-is": {
"version": "1.6.15",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.15.tgz",
"integrity": "sha1-yrEPtJCeRByChC6v4a1kbIGARBA=",
"requires": {
"media-typer": "0.3.0",
"mime-types": "2.1.17"
}
},
"unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
"integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw="
},
"utils-merge": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.0.tgz",
"integrity": "sha1-ApT7kiu5N1FTVBxPcJYjHyh8ivg="
},
"vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
"integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
}
}
}

View File

@ -1,8 +1,8 @@
{
"name": "node-todo-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"description": "yeahhh",
"main": "server/server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
@ -10,6 +10,9 @@
"author": "",
"license": "ISC",
"dependencies": {
"mongodb": "^2.2.5"
"body-parser": "^1.15.2",
"express": "^4.14.0",
"mongodb": "^2.2.5",
"mongoose": "^4.5.9"
}
}

5
server/db/mongoose.js Normal file
View File

@ -0,0 +1,5 @@
var mongoose = require('mongoose');
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://127.0.0.1:27017/TodoApp');
module.exports = { mongoose }

18
server/models/todo.js Normal file
View File

@ -0,0 +1,18 @@
var mongoose = require('mongoose')
var Todo = mongoose.model('Todo', {
text: {
type: String,
required: true,
minlength: 1,
trim: true,
},
completed: {
type: Boolean,
default: false
},
completedAt:{
type: Number,
default: null
}
});
module.exports = {Todo}

10
server/models/user.js Normal file
View File

@ -0,0 +1,10 @@
var mongoose = require('mongoose')
var User = mongoose.model('User', {
email: {
type: String,
required: true,
minlength: 1,
trim: true,
},
});

28
server/server.js Normal file
View File

@ -0,0 +1,28 @@
var express = require('express')
var bodyParser = require('body-parser')
var {mongoose} = require('./db/mongoose')
// models
var {User} = require('./models/user')
var {Todo} = require('./models/todo')
var app = express();
app.use(bodyParser.json());
app.post('/todos', (req, res) => {
var todo = new Todo({
text: req.body.text
});
todo.save().then((doc) => {
res.send(doc)
}, (e) => {
res.status(400).send(e);
})
})
app.listen(3000, () => {
console.log("Started on port 3000");
});