Nik Atlas 6 жил өмнө
parent
commit
c2078b8f08

+ 9 - 1
database/index.js

@@ -1,5 +1,13 @@
+const db = require('./db.js');
 const UserRepo = require('./repositories/users');
 
+
+db.init();
+
+let Repositories = {
+	Users: UserRepo
+};
+
 module.exports = {
-	UserRepo
+	Repositories	
 };

+ 6 - 0
helpers/JSONError.js

@@ -0,0 +1,6 @@
+const JSONError = (msg) => {
+	return {
+		msg
+	};
+}
+module.exports = JSONError;

+ 5 - 0
helpers/index.js

@@ -0,0 +1,5 @@
+var JSONError = require('./JSONError.js');
+
+module.exports = {
+	JSONError
+};

+ 0 - 0
mydb/000017.log


+ 1 - 0
mydb/CURRENT

@@ -0,0 +1 @@
+MANIFEST-000016

+ 0 - 0
mydb/LOCK


+ 3 - 0
mydb/LOG

@@ -0,0 +1,3 @@
+2018/01/28-15:17:03.122 1684 Recovering log #15
+2018/01/28-15:17:03.128 1684 Delete type=0 #15
+2018/01/28-15:17:03.129 1684 Delete type=3 #14

+ 3 - 0
mydb/LOG.old

@@ -0,0 +1,3 @@
+2018/01/28-15:15:59.244 23a8 Recovering log #13
+2018/01/28-15:15:59.251 23a8 Delete type=0 #13
+2018/01/28-15:15:59.251 23a8 Delete type=3 #12

BIN
mydb/MANIFEST-000016


+ 5 - 0
package-lock.json

@@ -1487,6 +1487,11 @@
       "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz",
       "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo="
     },
+    "supervisor": {
+      "version": "0.12.0",
+      "resolved": "https://registry.npmjs.org/supervisor/-/supervisor-0.12.0.tgz",
+      "integrity": "sha1-3n5jNwFbKRhRwQ81OMSn8EkX7ME="
+    },
     "tar-fs": {
       "version": "1.16.0",
       "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-1.16.0.tgz",

+ 3 - 2
package.json

@@ -3,7 +3,7 @@
   "version": "0.0.0",
   "private": true,
   "scripts": {
-    "start": "node ./bin/www"
+    "start": "supervisor ./bin/www"
   },
   "dependencies": {
     "body-parser": "~1.18.2",
@@ -18,6 +18,7 @@
     "levelup": "^2.0.1",
     "morgan": "~1.9.0",
     "pug": "2.0.0-beta11",
-    "serve-favicon": "~2.4.5"
+    "serve-favicon": "~2.4.5",
+    "supervisor": "^0.12.0"
   }
 }

+ 21 - 0
routes/users.js

@@ -1,9 +1,30 @@
 var express = require('express');
 var router = express.Router();
 
+let JSONError = require('../helpers').JSONError;
+let Users = require('../database').Repositories.Users;
+
 /* GET users listing. */
 router.get('/', function(req, res, next) {
   res.send('respond with a resource');
 });
 
+
+/* GET users listing. */
+router.post('/login', function(req, res, next) {
+  const params = {...req.body};
+  const {
+  	username,
+  	password
+  } = params;
+
+  Users.login({username, password}).
+  then((user) => res.send(user)).
+  catch((e) => {
+  	console.log(e);
+  	res.status(400);
+  	res.send(JSONError("Bad Credentials"));
+  });
+});
+
 module.exports = router;