diff --git a/.eslintrc.js b/.eslintrc.js
index 8a81087..5635ec9 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -1,7 +1,4 @@
module.exports = {
- "extends": "airbnb-base",
- "rules": {
- "linebreak-style": ["error", "windows"]
- }
+ "extends": "airbnb-base"
};
/*eslint linebreak-style: ["error", "windows"]*/
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index d2f3209..8d78f3c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1 +1,7 @@
-language: node_js
\ No newline at end of file
+language: node_js
+node_js:
+ - "5.5.0"
+install:
+ - npm install
+script:
+ - npm test
diff --git a/Middleware/index.js b/Middleware/index.js
index c28de99..69c6b64 100644
--- a/Middleware/index.js
+++ b/Middleware/index.js
@@ -7,7 +7,7 @@ import express from 'express';
const Middleware = (app) => {
app.use(bodyParser.json());
//public the view
- app.use(express.static('View'));
+ //app.use(express.static('View'));
//initialise routes
app.use('/api/v1', user);
app.use('/api/v1', driver);
diff --git a/View/css/style.css b/View/css/style.css
deleted file mode 100644
index 6363961..0000000
--- a/View/css/style.css
+++ /dev/null
@@ -1,734 +0,0 @@
-@import url('https://fonts.googleapis.com/css?family=Roboto:400,500,700,900');
-*, *:before, *:after {
- box-sizing: inherit;
-}
-a{
- text-decoration: none;
- color: #000;
-}
-ul{
- list-style-type: none;
-}
-hr{
- background: #555;
-}
-input[type=text], input[type=password],input[type=date]{
- padding: 1%;
- width: 50%;
- font-size: 80%;
- text-align: left;
- color: #999;
- font-weight: 400;
- font-style: inherit;
-}
-.dr-e{
- display: none;
-}
-.search-form{
- display: none;
-}
-.pg-gig,.dr-gig{
- padding: 5px 10px;
- width: 90%;
- display: none;
-}
-body{
- background: #d5d4d2;
-}
-.ds{
- color: #555 !important;
-}
-.dropdown{
- background: #fff;
- right: 42px;
- top: 70%;
- display: none;
- z-index: 10;
- position: absolute;
- /*visibility: hidden;*/
- opacity: 100;
- transition: all .2s linear;
- border-radius: 0 0 3px 3px;
- -webkit-transition: all .2s linear;
- border: 1px #ddd solid;
- box-shadow: 0 0 5px 1px rgba(0,0,0,.05);
-}
-.dropdown>ul{
- min-width: 100px;
- padding: 0 15px;
-}
-.dropdown>ul li{
- white-space: nowrap;
- padding: 2px 0;
- text-align: left;
- font-family: 'Roboto', sans-serif;
- font-size: 14px;
- position: relative;
- color: #555;
-}
-#dropdown-toggle,.dropdown-item,.notify,.toggle-bar,.unbox-content-foot>p>a{
- cursor: pointer;
-}
-.toggle-bar{
- padding: 3px 0px;
-}
-#sec2{
- display: none;
-}
-.center{
- left: 15%;
- right: 15%;
- text-align: center;
-}
-.btn,.btn:visited{
- background: none;
- padding: 10px;
- text-align: center;
- vertical-align: middle;
- cursor: pointer;
- display: inline-block;
- border: 2px solid transparent;
-}
-.btn-non{
- border: 0;
-}
-.btn-open{
- border: solid 2px;
-}
-.btn-tap{
- background-color: #00b22d;
- border: #00b22d;
- /*border-radius: 0 3px 3px 0;*/
- box-sizing: border-box;
- background: linear-gradient(#35c350,#03b525);
- padding: 1.1% 1.8%;
- font-size: 80%;
- margin: 0;
- color: #fff;
-}
-.top{
- position: fixed;
- width: 100%;
- z-index: 1;
- left: 0;
- top: 0;
-}
-.sect{
- margin-left: -18%;
-}
-.sect input[type=text]{
- font-size: 110%;
-}
-.title{
- font-weight: bold;
- font-size: 160%;
- color: #000;
- width: 30% !important;
- padding: 3% 4% !important;
-}
-.bar{
- width: 100%;
- display: block;
- color: #000!important;
- padding: 0.3% 0 5% 0 !important;
-}
-.box{
- width: 100%;
- padding: 25px;
- background-color: coral;
- color: white;
- font-size: 25px;
-}
-.unbox{
- display: none; /* Hidden by default */
- position: fixed; /* Stay in place */
- z-index: 1; /* Sit on top */
- left: 0;
- top: 0;
- width: 100%; /* Full width */
- height: 100%; /* Full height */
- overflow: auto; /* Enable scroll if needed */
- background-color: rgb(0,0,0); /* Fallback color */
- background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
-}
-.unbox-content {
- border-radius: 5px !important;
- box-shadow: 0 0 8px rgba(0,0,0,0.4);
- background-color: #fefefe;
- margin: 10% auto; /* 15% from the top and centered */
- padding: 2%;
- border: 1px solid #888;
- width: 60%; /* Could be more or less, depending on screen size */
-}
-.unbox-content-body{
- width: 100%;
- margin: 0 auto;
- text-align: center;
- padding: 10px 0;
- font-style: inherit;
-}
-.unbox-content-body>p{
- text-align: left;
- color: #555;
-}
-.unbox-content-foot{
- border-top: 2px solid #dddddd;
- padding: 3px 0 !important;
- display: block;
- text-align: center;
- width: 100%;
-}
-.close {
- color: #aaa;
- float: right;
- font-size: 20px;
- font-weight: bold;
- margin: 0;
-}
-
-.close:hover,
-.close:focus {
- color: black;
- text-decoration: none;
- cursor: pointer;
-}
-.bar-right{
- float: right !important;
- list-style-type: none;
- display: block;
- margin-right: 0%;
- width: 14%;
- margin-top: 3%;
-}
-.bar-item{
- display: block;
- font-family: 'Roboto', sans-serif;
- float: left;
- width: auto;
- padding: 3% 5%;
- color: #fff ;
- margin-right: 0%;
- word-wrap: nowrap;
-}
-.head-text{
- display: block;
- position: absolute;
- text-align: center;
- left: 15%;
- right: 15%;
- z-index: 1;
- bottom: 32%;
- padding-top: 20px;
- width:70%;
- padding-bottom: 20px;
-}
-.head-text-h{
- font-weight: 600;
- font-size: 300%;
- color: #fff!important;
- line-height: 110%;
- letter-spacing: -.3px;
-
- text-transform: capitalize!important;
-}
-.body{
- padding-top: 30px;
- background: #d5d4d2;
- width: 100%;
- padding-bottom: 30px;
- height: auto;
-}
-.body-plate{
- width: 100%;
- margin: 0 auto;
- box-sizing: border-box;
- font-family: 'Roboto', sans-serif;
-}
-.body-plate-h{
- color: #0e0e0f;
- font-weight: 600;
- font-size: 180%;
- line-height: 120%;
- letter-spacing: -.3px;
- text-transform: capitalize!important;
- margin: 0;
- padding: 0;
- border: 0;
- outline: 0;
- vertical-align: baseline;
- background: 0 0;
-}
-.body-plate p{
- line-height: 120%;
- color: #0e0e0f;
- padding: 0;
- font-size: 150%;
-}
-.body-dish ul li{
- display: inline-block;
- width: 32.5%;
- text-align: center;
- padding: 6% 0;
- font-size: 160%;
-}
-.form{
- margin: 0 auto;
- width: 100%
- display: block;
- padding: 10px 0;
- font-style: inherit;
-}
-.form-element, .form-element:hover, .form-element:active,.form-new{
- border: 0px;
- border-bottom: 1px solid #00b22d !important;
- display: block;
- width: 100% !important;
- padding: 10px 0 !important;
- text-align: center !important;
- margin-bottom: 15px;
- font-size: 1.3em;
-}
-.form .btn-tap{
- padding: 15px 0%;
- width: 100%;
- margin-bottom: 10px;
-}
-.form input[type=checkbox]{
- text-align: left !important;
-}
-.unbox a{
- color: #00b22d;
-}
-.search{
- background: #353537;
- display: none;
- overflow: hidden;
-}
-.search-bar{
- display: none;
-}
-.search-h{
- text-align: center;
- font-size: 2em;
- color: #fff;
-}
-.search-result{
- margin: 0 auto;
- width: 80%;
- text-align: center;
-}
-.search-result .btn{
- margin-bottom: 10%;
-}
-.result{
- width: 60%;
- text-align: center;
- margin: 5% auto;
- border-radius: 5px;
- box-shadow: 0 0 8px rgba(0,0,0,0.4);
-}
-.result-img{
- border-radius: 35px;
- width: 90%;
-}
-.result table tr td{
- text-align: left;
-}
-.result-h{
- width: 14%;
-}
-.result-content{
- width: 58%;
- color: #fff;
-}
-.result-content p,.result-content h3{
- padding: 0 !important;
- margin: 0;
-}
-.result-btn{
- width: 28%;
-}
-.result-btn .btn{
- padding: 10% 20%;
-}
-.headup{
- font-style: inherit;
- font-size: 1.3em;
-}
-.search-u{
- width: 70% !important;
- size: 20px !important;
- font-size: 1.1em;
- font-style: inherit;
- border: 1px solid #999;
- border-radius: 3px 0 0 3px;
-}
-.search-u-btn{
- font-size: 1.1em;
- width: 25%;
- padding: 3.9px 0;
- margin-left: -5px;
- margin-top: -2px;
- border-radius: 0 3px 3px 0;
-
-}
-.ds img{
- width: 30px;
- border-radius: 35px;
- margin-top: 0;
- padding: 0;
-}
-.white{
- background: #fff !important;
- height: 30px !important;
-}
-.dashboard{
- margin-top: 90px;
- width: 100%;
-}
-.dashboard-h{
- font-size: 1.6em;
-}
-.dashboard-content{
- margin-top: 0;
- width: 100%;
-}
-.horizon-box{
- display: block;
- float: left;
- width: 62%;
-}
-.horizon-box-h{
- width: 100%;
- height: 60px;
- background: #fff;
- padding: 20px 10px 0 10px;
- margin: 0;
-}
-.vertic-box{
- float: right;
- display: block;
- background: #fff;
- width: 30%;
-}
-.topic{
- width: auto;
- font-size: 160%;
- float: left;
- display: block;
- margin-left: 20px;
- color: #555;
-}
-.attached{
- width: auto;
- float: right;
- display: block;
- margin: 2% 2% 0 0;
- color: #fff !important;
- border-radius: 35px;
-}
-.gig-profile{
- width: 100%;
- text-align: center;
-}
-.gig-profile-img, .gig-profile-p{
- text-align: center;
-}
-.gig-profile-img{
- margin-top: 70px;
-}
-.gig-profile-img>img{
- width: 20%;
- border-radius: 60px;
- text-align: center;
-}
-.gig-profile-p>p{
- color: #222;
- font-weight: 400;
- font-size: 1.1em;
-}
-.pg-ride{
- display: none;
-}
-.ride-offers{
- display: none;
-}
-.ride{
- width: 90%;
- display: block;
- padding: 20px;
-}
-.ride>p{
- float: left;
- width: auto;
- color: #555;
- margin-top: 0;
- cursor: pointer;
-}
-.horizon-box-content{
- width: 100%;
- margin-top: 20px;
- margin-left: 10px;
-}
-.ride-offer,.ride-offer{
- width: 100%;
-}
-#ride-offer-accept,#ride-offer-pending{
- display: none;
-}
-.offer{
- width: 98.6%;
- background: #fff;
- padding: 5px 10px;
- margin: 5px 0;
- height: 80px;
- border-bottom: 2px solid #00b22d;
-}
-.offer-details{
- width: 60%;
- float: left;
- margin: 0;
- padding: 10px 0;
- color: #555;
-}
-.offer-details p,.offer-details h3{
- padding: 0 0 5px 0;
- margin: 0;
-}
-.offer-response{
- float: right;
- margin: 30px 50px 0 0;
- padding: 0;
- display: block;
-}
-.offer-response>button{
- padding: 7px 12px;
- border: 1px solid #555;
- border-radius: 35px;
- background: #fff;
- color: #555;
-}
-.response{
- padding: 7px 20px !important;
- border-radius: 0 !important;
- color: #fff !important;
- background: #00b22d !important;
- box-sizing: border-box;
- background: linear-gradient(#35c350,#03b525);
- border: #00b22d !important;
-}
-.offer-pass{
- width: 100%;
- margin-top: 10px;
- display: none;
-}
-.pass-success{
- border-left: 4px solid #00b22d;
-}
-.pass-pending{
- border-left: 4px solid #c04d00;
-}
-.pass{
- width: 99.5%;
- background: #fff;
- padding: 8px 4px;
-}
-.pass-name{
- float: left;
- width: 70%;
-}
-.pass-response{
- margin-top: 10px;
-}
-.s-badge{
- border-radius: 35px;
- padding: 2px;
- font-size: 0.8em;
-}
-
-.badge{
- float: right;
- border-radius: 35px;
-}
-.red{
- background: #a80026 !important;
-}
-.yellow{
- background: #c04d00 !important;
-}
-.blue{
- background: #15569f !important;
-}
-.gray{
- background: #888 !important;
-}
-.name{
- color: #00b22d !important;
-}
-.add-new{
- text-align: left !important;
-}
-.form-new{
- text-align: left !important;
- font-size: 12px !important;
-}
-.profile{
- margin: 0 auto;
- left: 10%;
- right: 10%;
- width: 80%;
- text-align: center;
-}
-.settings{
- width: 100%;
-}
-.settings-tab{
- float: left;
- width: 30%;
- margin: 0;
-}
-.settings-content{
- width: 70%;
- float: right;
- text-align: left;
- border-radius: 5px !important;
- box-shadow: 0 0 8px rgba(0,0,0,0.4);
- background-color: #fefefe;
-}
-.settings-content-bar{
- padding: 30px;
-}
-
-.foot{
- display: block;
- float: left;
- margin-top: 20px;
- width: 100%;
-}
-.foot-bag{
- background-color: #fff;
- padding: 20px 0;
-}
-@media screen and (max-width: 420px){
- body{
- width: 100%;
- }
- .title{
- font-size: 100%;
- }
- .bar-right{
- width: 40% !important;
- }
- .btn-tap{
- padding: 1.78% 1.8%;
- }
- .sect{
- display: none;
- }
- .topic{
- font-size: 120%;
- }
- .offer{
- width: 94.8%;
- }
- .offer-details{
- width: 70%;
- }
- .offer-details h3{
- font-size: 100%;
- }
- .offer-details p{
- font-size: 80%;
- padding: 0 1%;
- }
- .offer-response{
- width: 20%;
- margin-right: 0;
- }
- .response{
- padding: 7% 9% !important;
- }
- .gig-profile-img{
- margin-top: 50%;
- }
- .gig-profile-img img{
- width: 30%;
- }
- .gig-profile-p p{
- font-size: 100%;
- }
- .notify{
- font-size: 70%;
- }
- .gig{
- padding: 2% 0%;
- }
- .ride{
- padding: 2%;
- width: 100%;
- }
- .ride p{
- font-size: 80%;
- }
- .ride button{
- display: block;
- float: left;
- text-align: center;
- margin-left: 40%;
- }
- .profile{
- left:0%;
- width: 100%;
- }
- .settings-tab{
- width: 20%;
- }
- .settings-content{
- width: 78%;
- }
- .add-new p{
- font-size: 80%;
- }
- ul{
- padding-left: 0;
- }
- label{
- font-size: 80%;
- }
-}
-@media screen and (max-width: 642px){
- .ride button{
- display: block;
- float: left;
- text-align: center;
- margin-left: 40%;
- }
- .bar-right{
- width: 26%;
- }
- .offer-details h3{
- font-size: 100%;
- }
- .offer-details p{
- font-size: 80%;
- padding: 0 1%;
- }
- .offer-response{
- width: 20%;
- margin-right: 0;
- }
- .response{
- padding: 7% 9% !important;
- }
-}
-@media screen and (max-width: 754px){
- .sect{
- display: none;
- }
- .bar-right{
- width: 22%;
- }
-}
-@media screen and (max-width: 578px){
-
-}
\ No newline at end of file
diff --git a/View/dashboard.html b/View/dashboard.html
deleted file mode 100644
index 2e957e2..0000000
--- a/View/dashboard.html
+++ /dev/null
@@ -1,318 +0,0 @@
-
-
-
- Ride My Way | My Profile
-
-
-
-
-
-
-
-
-
-
Dashboard
-
-
-
-
-
-
Ride Offer
-
-
-
-
-
-
-
-
Lorem ipsum - Duis aute
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
-
-
-
-
-
-
![](images/mails.png)
-
-
-
34 new response(s)
-
-
-
-
Total Ride Offer
-
-
-
-
Present Ride Offer
-
-
-
-
Active Ride Offer
-
-
-
-
Expired Ride Offer
-
-
-
-
-
-
Accepted ride Offer
-
-
-
-
Pending Ride Offer
-
-
-
-
-
-
-
-
-
-
-
-
×
-
-
please fill in all the required info to add a new ride offer.
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/View/images/Koala.jpg b/View/images/Koala.jpg
deleted file mode 100644
index 78704a0..0000000
Binary files a/View/images/Koala.jpg and /dev/null differ
diff --git a/View/images/Thumbs.db b/View/images/Thumbs.db
deleted file mode 100644
index d1f0b43..0000000
Binary files a/View/images/Thumbs.db and /dev/null differ
diff --git a/View/images/mails.png b/View/images/mails.png
deleted file mode 100644
index 12b0903..0000000
Binary files a/View/images/mails.png and /dev/null differ
diff --git a/View/images/page1.jpg b/View/images/page1.jpg
deleted file mode 100644
index 6c243bb..0000000
Binary files a/View/images/page1.jpg and /dev/null differ
diff --git a/View/images/pp.jpg b/View/images/pp.jpg
deleted file mode 100644
index 2d272ca..0000000
Binary files a/View/images/pp.jpg and /dev/null differ
diff --git a/View/images/world-map.png b/View/images/world-map.png
deleted file mode 100644
index e893458..0000000
Binary files a/View/images/world-map.png and /dev/null differ
diff --git a/View/index.html b/View/index.html
deleted file mode 100644
index 51f1649..0000000
--- a/View/index.html
+++ /dev/null
@@ -1,197 +0,0 @@
-
-
-
- Ride My Way | Home
-
-
-
-
-
-
-
-
-
Search Result
-
-
-
-
- ![](images/mails.png) |
-
- deserunt laborum
- Date: 24/06/2018
- Time: 4:50pm
- Location - Destination
- |
-
-
- |
-
-
-
-
-
-
- ![](images/mails.png) |
-
- deserunt laborum
- Date: 24/06/2018
- Time: 4:50pm
- Location - Destination
- |
-
-
- |
-
-
-
-
-
-
- ![](images/mails.png) |
-
- deserunt laborum
- Date: 24/06/2018
- Time: 4:50pm
- Location - Destination
- |
-
-
- |
-
-
-
-
-
-
-
-
Avaliable Ride Offer
-
All around the world
-
-
-
- - Europe
- - Africa
- - Asia
- - North America
- - South America
- - Australia
- - Antarctica
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/View/js/dashboard.js b/View/js/dashboard.js
deleted file mode 100644
index a5d00b2..0000000
--- a/View/js/dashboard.js
+++ /dev/null
@@ -1,122 +0,0 @@
-document.addEventListener("DOMContentLoaded", () =>{
- let key = window.localStorage.getItem("key");
- fetch('/api/v1/getusers/'+key)
- .then(res => res.json())
- .then(data => {
- localStorage.setItem("name",data.name);
- localStorage.setItem("picture",data.picture);
- localStorage.setItem("usertype",data.userType);
- })
- .catch(err => console.log(err));
- let pp =localStorage.getItem("picture");
- let name = localStorage.getItem("name");
- let usertype = localStorage.getItem("usertype");
- get('#user').innerHTML = name;
- get('#pageuser').innerHTML = name;
- get('#userpic').src = pp;
- get('#pagepic').src = pp;
- if(usertype == "driver"){
- get('#ride-add').type = "button";
- get('#myprofile').href = "dashboard.html";
- get('.ride-offers').style.display = "block";
- get('.pg-ride').style.display ="none !important";
- get('.dr-gig').style.display = "block";
- get('.search-form').style.display = "none !important";
- get('.pg-gig').style.display = "none !important";
- // fetch('/api/v1/getusers/'+key)
- // .then(res => res.json())
- // .then(data => {
-
- // })
- // .catch(err => console.log(err));
-
- }else{
- get('#myprofile').href = "dashboard.html";
- get('#ride-add').type = "hidden";
- get('.ride-offers').style.display = "none !important";
- get('.pg-ride').style.display ="block";
- get('.search-form').style.display = "block";
- get('.pg-gig').style.display = "block";
- get('.dr-gig').style.display = "none !important";
- }
-
-});
-get('#create-ride').onclick = (e) => {
- e.preventDefault();
- let loc = get('input[name="Location"]').value;
- let dec = get('input[name="destination"]').value;
- let dat = get('input[name="date"]').value;
- let time = get('input[name="time"]').value;
-
- fetch('/api/v1/rides', {
- method: 'POST',
- headers: {
- 'user-agent': 'Mozilla/4.0 MDN Example',
- 'content-type': 'application/json'
- },
- body:JSON.stringify({
- "id": window.localStorage.getItem("key"),
- "location": loc,
- "destination": dec,
- "date": dat,
- "time": time
- })
- })
- .then(res => res.json())
- .then(data => console.log(data))
- .catch(err => console.log(err));
-}
-let add = get('#add');
-let offer = get('#offer123');
-let rideOfferAc = get('#ride-offer-accept');
-let rideOfferPd = get('#ride-offer-pending');
-let rideAv = get('#ride-offer');
-get('#ride-add').onclick = () =>{
- add.style.display = "block";
-}
-get('.close').onclick = () =>{
- add.style.display = "none";
-}
-get('#accept').onclick = () =>{
- rideOfferAc.style.display = "block";
- rideOfferPd.style.display = "none";
- rideAv.style.display = "none";
- topic.innerHTML = "Accepted Ride Offer";
-
-}
-get('#pending').onclick = () =>{
- rideOfferPd.style.display = "block";
- rideAv.style.display = "none";
- rideOfferAc.style.display ="none";
- topic.innerHTML = "Pending Ride Offer";
-}
-
-window.onclick = e => {
- if (e.target == add) {
- add.style.display = "none";
- }
-}
-let toggle = (word,classname) =>{
- let id = document.getElementsByClassName(classname);
- if(id.length > 0){
- for (let i = 0; i < id.length; i++) {
- document.getElementById(id[i].id).onclick = () =>{
- if(document.getElementById(word+id[i].id).style.display == "block"){
- document.getElementById(word+(id[i].id)).style.display = "none";
- }else{
- document.getElementById(word+id[i].id).style.display = "block";
- }
- }
-
- }
- }
-}
-toggle('offer','offer-response-b');
-get('#logout').onclick = (e) => {
- e.preventDefault();
- localStorage.removeItem('key');
- localStorage.removeItem('name');
- localStorage.removeItem('picture');
- localStorage.removeItem('usertype');
- window.location.href = "index.html";
-}
\ No newline at end of file
diff --git a/View/js/dropdown.js b/View/js/dropdown.js
deleted file mode 100644
index bb5c5a2..0000000
--- a/View/js/dropdown.js
+++ /dev/null
@@ -1,22 +0,0 @@
-let dropdown = document.getElementById('dropdown');
-let search = document.getElementById('search-bar');
-let topic = document.getElementById('topic');
-document.getElementById('dropdown-toggle').onclick = () =>{
- let n = dropdown.style.display == "block"? dropdown.style.display = "none" : dropdown.style.display = "block";
- // dropdown.style.display = "block";
-}
-if(document.getElementById('search') !== null){
- document.getElementById('search').onclick = () => {
- let destination = document.getElementById('search-box').value;
- if(destination !== ""){
- document.getElementById('ride-offer').style.display = "none";
- search.style.display = "block";
- topic.innerHTML = "Search Result";
- }
- }
-}
-window.onclick = e => {
- if (e.target == dropdown){
- dropdown.style.display = "none";
- }
-}
\ No newline at end of file
diff --git a/View/js/get.js b/View/js/get.js
deleted file mode 100644
index 72b086d..0000000
--- a/View/js/get.js
+++ /dev/null
@@ -1,5 +0,0 @@
-let get = item => {
- if(document.querySelector(item) !== null){
- return document.querySelector(item);
- }
-}
\ No newline at end of file
diff --git a/View/js/home.js b/View/js/home.js
deleted file mode 100644
index 823536f..0000000
--- a/View/js/home.js
+++ /dev/null
@@ -1,206 +0,0 @@
-let signin = get('#on');
-let signup = get('#off');
-let caution = get('#switch');
-let search = get('#search-bar');
-let drive = get('#drive-info');
-let x;
-let pau;
-let id;
-get('#userdr').onclick = () => {
- caution.style.display = "none";
- drive.style.display = "block";
- get('input[name="usertype"]').value = "driver";
-}
-get('#signin1').onclick = () => {
- signup.style.display = "none";
- signin.style.display = "block";
-}
-get('#signup1').onclick = () => {
- signin.style.display = "none";
- signup.style.display = "block";
-}
-get('#search').onclick = () => {
- let destination = get('#search-box').value;
- if(destination !== ""){
- search.style.display = "block";
- }
-}
-get('.close').onclick = () => {
- signin.style.display = "none";
-}
-get('.close').onclick = () => {
- signup.style.display = "none";
-}
-get('#signin').onclick = () => {
- signin.style.display = "block";
-}
-get('#signup').onclick = () => {
- signup.style.display = "block";
-}
-get('#pass').onchange = () => {
- let pass = get('#pass').value;
- let n = validation(pass);
- pau = pass;
- x = (n >= 75)? true : false;
-}
-get('#continue').onclick = () => {
- if(x & pau == get('#confirm').value){
- signup.style.display = "none";
- caution.style.display = "block";
- }else{
- get('#error1').innerHTML = "Please enter the correct password to confirm";
- }
-}
-window.onclick = e => {
- if (e.target == signin) {
- signin.style.display = "none";
- }else if(e.target == signup){
- signup.style.display = "none";
- }else if(e.target == caution){
- caution.style.display = "none";
- }else if(e.target == drive){
- drive.style.display = "none";
- }
-}
-let validation = (word) =>{
- if(word.length >= 6 & word.length <= 12){
- let n = 0;
- n = word.match(/[A-Z]/g)? n+=25 : n+=0;
- n = word.match(/[a-z]/g)? n+=25 : n+=0;
- n = word.match(/[0-9]/g)? n+=25 : n+=0;
- n = word.match(/[$@#&!]/g)? n+=25 : n+=0;
- if (n == 25) {
- get('#error').innerHTML = "password is poor!";
- get('#pass').value = "";
- }else if (n == 50) {
- get('#error').innerHTML = "password is fair!";
- get('#pass').value = "";
- }else if (n == 75) {
- get('#error').innerHTML = "password is good!";
- }else if (n == 100) {
- get('#error').innerHTML = "password is strong!"
- }
- return n;
- }else if(word.length < 6){
- get('#error').innerHTML = "Minimum password length is 6";
- }else{
- get('#error').innerHTML = "Maximum password length is 12";
- }
-}
-let redirect = (url) => {
- window.location = url;
-}
-get('#drisignup').onclick = (event) => {
- event.preventDefault();
- let name = get('#first').value+" "+get('#last').value;
- let email = get('#email').value;
- let gender = get('input[name="gender"]:checked').value;
- let dob = get('#date').value;
- let pass = get('#pass').value;
- let usertype = get('input[name="usertype"]').value;
- let pic = get('#p-image').value;
- let vrn = get('#vrn').value;
-
- fetch('/api/v1/users', {
- method: 'POST',
- redirect: 'error',
- headers: {
- 'user-agent': 'Mozilla/4.0 MDN Example',
- 'content-type': 'application/json'
- },
- body:JSON.stringify({
- "name": name,
- "email": email,
- "gender": gender,
- "dob": dob,
- "picture": "/images/Koala.jpg",
- "password": pass,
- "userType": usertype
- })
- })
- .then(res => res.json())
- .then(data => {
- id = data.key;
- fetch('/api/v1/drivers', {
- method: 'POST',
- redirect: 'error',
- headers: {
- 'user-agent': 'Mozilla/4.0 MDN Example',
- 'content-type': 'application/json'
- },
- body:JSON.stringify({
- "id": id,
- "driver-license": pic,
- "VRN": vrn
- })
- }).then(re => re.json())
- .then(res => console.log(res))
- .catch(err => console.log(err));
- localStorage.setItem("key", id);
- window.location.href = "dashboard.html";
- }).catch(err => console.log(err));
-}
-get('#passignup').onclick = (event) => {
- event.preventDefault();
- get('input[name="usertype"]').value = "passenger";
- let name = get('#first').value+" "+get('#last').value;
- let email = get('#email').value;
- let gender = get('input[name="gender"]:checked').value;
- let dob = get('#date').value;
- let pass = get('#pass').value;
- let usertype = get('input[name="usertype"]').value;
- let pic = get('#p-image').value;
- let vrn = get('#vrn').value;
-
- fetch('/api/v1/users', {
- method: 'POST',
- redirect: 'error',
- headers: {
- 'user-agent': 'Mozilla/4.0 MDN Example',
- 'content-type': 'application/json'
- },
- body:JSON.stringify({
- "name": name,
- "email": email,
- "gender": gender,
- "dob": dob,
- "picture": "/images/Koala.jpg",
- "password": pass,
- "userType": usertype
- })
- }).then(data => data.json())
- .then(data => {
- id = data.key;
- })
- .catch(err => console.log(err));
- localStorage.setItem("key", id);
- window.location.href = "dashboard.html";
-}
-get('#log').onclick = (event) => {
- event.preventDefault();
- let email = get('input[name="logemail"]').value;
- let passw = get('input[name="logpass"]').value;
- fetch('/api/v1/authusers', {
- method: 'POST',
- redirect: 'error',
- headers: {
- 'user-agent': 'Mozilla/4.0 MDN Example',
- 'content-type': 'application/json'
- },
- body:JSON.stringify({
- "user": email,
- "pass": passw,
- })
- }).then(res => res.json())
- .then(data => {
- id = data.key;
- if(typeof data.key == "undefined" & typeof data.key == "null"){
- get('#logerr').innerHTML = " Username/Password incorrect !";
- }else if(typeof data.key !== "undefined" & typeof data.key !=="null"){
- localStorage.setItem("key", id);
- if(localStorage.getItem("key") !== "undefined"){
- window.location.href = "dashboard.html";
- }
- }
- }).catch(err => console.log(err));
-}
\ No newline at end of file
diff --git a/View/js/profile.js b/View/js/profile.js
deleted file mode 100644
index 5b9295f..0000000
--- a/View/js/profile.js
+++ /dev/null
@@ -1,79 +0,0 @@
-document.addEventListener("DOMContentLoaded", () =>{
- let key = localStorage.getItem("key");
- fetch('/api/v1/getusers/'+key)
- .then(res => res.json())
- .then(data => {
- localStorage.setItem("name",data.name);
- localStorage.setItem("picture",data.picture);
- localStorage.setItem("email",data.email);
- localStorage.setItem("gender",data.gender);
- localStorage.setItem("dob",data.dob);
- localStorage.setItem("password",data.password);
- localStorage.setItem("usertype",data.userType);
- })
- .catch(err => console.log(err));
- let pp =localStorage.getItem("picture");
- let name = localStorage.getItem("name");
- let email = localStorage.getItem("email");
- let gender = localStorage.getItem("gender");
- let dob = localStorage.getItem("dob");
- let pass = localStorage.getItem("password");
- let usertype = localStorage.getItem("usertype");
- get('#user').innerHTML = name;
- get('#userpic').src = pp;
- get('#myprofile').href = "dashboard.html";
- get('input[name="name"]').value = name;
- get('input[name="email"]').value = email;
- //get('input[name="gender"]').options[get('input[name="gender"]').selectedIndex].value = gender;
- get('input[name="pic"]').value = pp;
- if(usertype == "driver"){
- get('.dr-e').style.display = "block";
- }else{
- get('.dr-e').style.display = "none";
- }
-});
-let acct = document.getElementById('acc1');
-let secu = document.getElementById('sec2');
-document.getElementById('acct').onclick = () =>{
- secu.style.display = "none";
- acct.style.display = "block";
-
-}
-document.getElementById('secu').onclick = () =>{
- acct.style.display = "none";
- secu.style.display = "block";
-}
-get('#accut').onclick = (e) => {
- e.preventDefault();
- let cname = get('input[name="name"]').value;
- let cmail = get('input[name="email"]').value;
- let cgen = get('input[name="gender"]').value;
- let cpic = get('input[name="pic"]').value;
- fetch('/api/v1/users/'+key, {
- method: 'PUT',
- redirect: 'error',
- headers: {
- 'user-agent': 'Mozilla/4.0 MDN Example',
- 'content-type': 'application/json'
- },
- body:JSON.stringify({
- "name": cname,
- "email": cmail,
- "gender": cgen,
- "dob": dob,
- "picture": cpic,
- "password": pass,
- "userType": usertype
- })
- }).then(res => res.json())
- .then(data => console.log(data))
- .catch(err => console.log(err));
-}
-get('#logout').onclick = (e) => {
- e.preventDefault();
- localStorage.removeItem('key');
- localStorage.removeItem('name');
- localStorage.removeItem('picture');
- localStorage.removeItem('usertype');
- window.location.href = "index.html";
-}
\ No newline at end of file
diff --git a/View/passenger-dashboard.html b/View/passenger-dashboard.html
deleted file mode 100644
index b12e4b0..0000000
--- a/View/passenger-dashboard.html
+++ /dev/null
@@ -1,198 +0,0 @@
-
-
-
- Ride My Way | Passenger Dashboard
-
-
-
-
-
-
-
-
-
-
Dashboard
-
-
-
-
-
-
Available Ride Offer
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
Location - Destination
-
Date: 4/06/2018
-
Time: 4:50pm
-
-
-
-
-
-
-
-
-
-
-
-
-
![](images/mails.png)
-
-
-
34 new response(s)
-
-
-
-
Accepted ride Offer
-
-
-
-
Pending Ride Offer
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/View/profile.html b/View/profile.html
deleted file mode 100644
index d1edf41..0000000
--- a/View/profile.html
+++ /dev/null
@@ -1,108 +0,0 @@
-
-
-
- Ride My Way | Settings
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/helper/blowFish.js b/helper/blowFish.js
index 00f1d1e..c6ba970 100644
--- a/helper/blowFish.js
+++ b/helper/blowFish.js
@@ -1,9 +1,10 @@
import crypto from 'crypto';
-const blowFish = (text,key) => {
- let decipher = crypto.createCipheriv('bf-cbc', key, 'ridewayway');
- let encrypted = decipher.update(text, 'utf-8', "base64");
- return encrypted += decipher.final('base64');
-}
+const blowFish = (text, key) => {
+ const decipher = crypto.createCipheriv('bf-cbc', key, 'ridewayway');
+ let encrypted = decipher.update(text, 'utf-8', 'base64');
+ encrypted += decipher.final('base64');
+ return encrypted;
+};
-export default blowFish;
\ No newline at end of file
+export default blowFish;
diff --git a/helper/md5.js b/helper/md5.js
index f91173f..730bb79 100644
--- a/helper/md5.js
+++ b/helper/md5.js
@@ -1,7 +1,7 @@
import crypto from 'crypto';
-const md5 = (data) => {
- return crypto.createHash('md5').update(data).digest("hex");
-}
+const md5 = data => (
+ crypto.createHash('md5').update(data).digest('hex')
+);
-export default md5;
\ No newline at end of file
+export default md5;
diff --git a/helper/saveToJson.js b/helper/saveToJson.js
index 7108971..ee870ca 100644
--- a/helper/saveToJson.js
+++ b/helper/saveToJson.js
@@ -1,7 +1,8 @@
import fs from 'fs';
+import path from 'path';
-const saveToJson = (jsonName,dbname,callback){
- fs.writeFile('../Database/'+dbname+'.json', JSON.stringify(jsonName),callback);
-}
+const saveToJson = (jsonName, dbname, callback) => {
+ fs.writeFile(path.join(__dirname, '/../Database/index.json'), JSON.stringify(jsonName), callback);
+};
-export default saveToJson;
\ No newline at end of file
+export default saveToJson;
diff --git a/helper/userValidate.js b/helper/userValidate.js
index 8700e37..3f73174 100644
--- a/helper/userValidate.js
+++ b/helper/userValidate.js
@@ -1,12 +1,13 @@
const userValidate = (obj, mail, pass) => {
- if(typeof obj !== "undefined" & typeof mail !== "undefined" & typeof pass !== "undefined"){
- for (let i = 1; i <= Object.keys(obj).length; i++) {
- if(obj['user'+ i].email == mail & obj['user'+ i].password == pass){
- return 'user'+i;
- break;
- }
- }
- }
-}
+ if (typeof obj !== 'undefined' && typeof mail !== 'undefined' && typeof pass !== 'undefined') {
+ for (let i = 1; i <= Object.keys(obj).length; i += 1) {
+ if (obj[i].email === mail && obj[i].password === pass) {
+ return obj[i];
+ }
+ }
+ } else {
+ return -1;
+ }
+};
-export default userValidate;
\ No newline at end of file
+export default userValidate;
diff --git a/index.js b/index.js
index e78db07..3ecf637 100644
--- a/index.js
+++ b/index.js
@@ -2,9 +2,10 @@ import express from 'express';
import Middleware from './Middleware/index';
const app = express();
-//connecting Middleware
+
+// connecting Middleware
Middleware(app);
-//add listen port for server
+// add listen port for server
app.listen(process.env.PORT || 4000, () => {
- console.log('listening now');
-});
\ No newline at end of file
+
+});
diff --git a/model/user.js b/model/user.js
index 425cd80..8e22b1d 100644
--- a/model/user.js
+++ b/model/user.js
@@ -1,36 +1,36 @@
import mongoose from 'mongoose';
const Schema = mongoose.Schema;
-const userSet= new Schema({
- name: {
- type: String,
- required: [true,'Name field is required']
- },
- email: {
- type: String,
- required: [true, 'Email field is required']
- },
- gender: {
- type: String,
- required: [true,'User type is required']
- },
- dob: {
- type: String,
- required: [true,'User type is required']
- },
- picture: {
- type: String,
- required: [false]
- },
- password: {
- type: String,
- required: [true,'User type is required']
- },
- userType: {
- type: String,
- required: [true,'User type is required']
- }
+const userSet = new Schema({
+ name: {
+ type: String,
+ required: [true, 'Name field is required'],
+ },
+ email: {
+ type: String,
+ required: [true, 'Email field is required'],
+ },
+ gender: {
+ type: String,
+ required: [true, 'User type is required'],
+ },
+ dob: {
+ type: String,
+ required: [true, 'User type is required'],
+ },
+ picture: {
+ type: String,
+ required: [false],
+ },
+ password: {
+ type: String,
+ required: [true, 'User type is required'],
+ },
+ userType: {
+ type: String,
+ required: [true, 'User type is required'],
+ },
});
-const user = mongoose.model('user',userSet);
+const user = mongoose.model('user', userSet);
-export default user;
\ No newline at end of file
+export default user;
diff --git a/route/driver.js b/route/driver.js
index 5a46e18..f11ac82 100644
--- a/route/driver.js
+++ b/route/driver.js
@@ -1,38 +1,38 @@
import express from 'express';
import fs from 'fs';
+import path from 'path';
const driver = express.Router();
-//get the list of driv
-driver.get('/drivers', (req,res) => {
- res.send({type: 'GET'});
+// get the list of driver
+driver.get('/drivers', (req, res) => {
+ res.send({ type: 'GET' });
});
-//add a driver
-driver.post('/drivers', (req,res) => {
- fs.readFile(__dirname+'/../Database/index.json','utf8', (err, data) => {
- if (err){
- console.log(err);
- } else {
- let obj = JSON.parse(data);
- console.log("drivers = "+ req.body.id);
- //let id = "user" + (Object.keys(obj.users).length + 1);
- obj.drivers[req.body.id] = req.body;
- console.log("driver id = "+obj.drivers[req.body.id]);
- let json = JSON.stringify(obj);
- fs.writeFile(__dirname+'/../Database/index.json', json, 'utf8', err => {
- if(err) throw err;
- console.log("file has been saved");
- });
- res.send(req.body.id);
- }
- });
+// add a driver
+driver.post('/drivers', (req, res) => {
+ fs.readFile(path.json(__dirname, '/../Database/index.json'), 'utf8', (err, data) => {
+ if (err) {
+ console.log(err);
+ } else {
+ const obj = JSON.parse(data);
+ // let id = "user" + (Object.keys(obj.users).length + 1);
+ obj.drivers[req.body.id] = req.body;
+ console.log(obj.drivers[req.body.id]);
+ const json = JSON.stringify(obj);
+ fs.writeFile(path.join(__dirname, '/../Database/index.json'), json, 'utf8', (er) => {
+ if (er) throw er;
+ console.log('file has been saved');
+ });
+ res.json(req.body.id);
+ }
+ });
});
-//update a driver
-driver.put('/drivers/:id', (req,res) => {
- res.send({type: 'PUT'});
-});
-//delete a driver
-driver.delete('/drivers/:id', (req,res) => {
- res.send({type: 'DELETE'});
+// update a driver
+driver.put('/drivers/:id', (req, res) => {
+ res.send({ type: 'PUT' });
+});
+// delete a driver
+driver.delete('/drivers/:id', (req, res) => {
+ res.send({ type: 'DELETE' });
});
-export default driver;
\ No newline at end of file
+export default driver;
diff --git a/route/ride.js b/route/ride.js
index 3d61cea..11e7eee 100644
--- a/route/ride.js
+++ b/route/ride.js
@@ -1,57 +1,52 @@
import express from 'express';
-import userValidate from '../helper/userValidate';
import fs from 'fs';
+import path from 'path';
const ride = express.Router();
-//get the list of ride
-ride.get('/rides', (req,res) => {
- fs.readFile(__dirname+'/../Database/index.json','utf8', (err,data) => {
- let obj = JSON.parse(data);
- res.send(obj.rides);
- });
+// get the list of ride
+ride.get('/rides', (req, res) => {
+ fs.readFile(path.join(__dirname, '/../Database/index.json'), 'utf8', (data) => {
+ const obj = JSON.parse(data);
+ res.json(obj.rides);
+ });
});
-ride.get('/rides/:id', (req,res) => {
- fs.readFile(__dirname+'/../Database/index.json','utf8', (err,data) => {
- let obj = JSON.parse(data);
- let user = obj.rides[req.params.id];
- console.log( user );
- res.end(JSON.stringify(user));
- });
+ride.get('/rides/:id', (req, res) => {
+ fs.readFile(path.join(__dirname, '/../Database/index.json'), 'utf8', (data) => {
+ const obj = JSON.parse(data);
+ res.json(JSON.stringify(obj.rides[req.params.id]));
+ });
});
//
-//add a ride
-ride.post('/rides', (req,res) => {
- fs.readFile(__dirname+'/../Database/index.json','utf8', (err, data) => {
- if (err){
- console.log(err);
- } else {
- let obj = JSON.parse(data);
- let id = "ride" + (Object.keys(obj.ride[req.body.id]).length + 1);
- obj.ride[req.body.id].ride[id] = {
- "location": req.body.location,
- "destination": req.body.destination,
- "date": req.body.date,
- "time": req.body.time
- };
- console.log("rides ="+req.body);
- let json = JSON.stringify(obj);
- fs.writeFile(__dirname+'/../Database/index.json', json, 'utf8', err => {
- if(err) throw err;
- console.log("file has been saved");
- console.log(id);
- });
- res.send({key : id});
- }
- });
+// add a ride
+ride.post('/rides', (req, res) => {
+ fs.readFile(path.join(__dirname, '/../Database/index.json'), 'utf8', (err, data) => {
+ if (err) {
+ console.log(err);
+ } else {
+ const obj = JSON.parse(data);
+ const id = Object.keys(obj.rides).length + 1;
+ obj.ride[req.body.id].ride[id] = {
+ location: req.body.location,
+ destination: req.body.destination,
+ date: req.body.date,
+ time: req.body.time,
+ };
+ const json = JSON.stringify(obj);
+ fs.writeFile(path.join(__dirname, '/../Database/index.json'), json, 'utf8', (er) => {
+ if (er) throw er;
+ });
+ res.json({ key: id });
+ }
+ });
});
-//update a ride
-ride.put('/rides/:id', (req,res) => {
- res.send({type: 'PUT'});
-});
-//delete a ride
-ride.delete('/rides/:id', (req,res) => {
- console.log(req.params.id);
- res.send({type: 'DELETE'});
+// update a ride
+ride.put('/rides/:id', (req, res) => {
+ res.send({ type: 'PUT' });
+});
+// delete a ride
+ride.delete('/rides/:id', (req, res) => {
+ console.log(req.params.id);
+ res.json({ type: 'DELETE' });
});
-export default ride;
\ No newline at end of file
+export default ride;
diff --git a/route/user.js b/route/user.js
index 3846f72..a9feb73 100644
--- a/route/user.js
+++ b/route/user.js
@@ -1,76 +1,66 @@
import express from 'express';
-import userValidate from '../helper/userValidate';
import fs from 'fs';
+import path from 'path';
+import userValidate from '../helper/userValidate';
+
const user = express.Router();
-//get the list of user
-user.get('/users', (req,res) => {
- fs.readFile(__dirname+'/../Database/index.json','utf8', (err,data) => {
- let obj = JSON.parse(data);
- res.send(obj.users);
- });
+// get the list of user
+user.get('/users', (req, res) => {
+ fs.readFile(path.join(__dirname, '/../Database/index.json'), 'utf8', (err, data) => {
+ const obj = JSON.parse(data);
+ res.send(obj.users);
+ });
+});
+user.get('/getusers/:id', (req, res) => {
+ fs.readFile(path.join(__dirname, '/../Database/index.json'), 'utf8', (err, data) => {
+ const obj = JSON.parse(data);
+ res.status().end(JSON.stringify(obj.users[req.params.id]));
+ });
});
-user.get('/getusers/:id', (req,res) => {
- fs.readFile(__dirname+'/../Database/index.json','utf8', (err,data) => {
- let obj = JSON.parse(data);
- let user = obj.users[req.params.id];
- console.log(user);
- res.end(JSON.stringify(user));
- });
+// add a user
+user.post('/users', (req, res) => {
+ fs.readFile(path.join(__dirname, '/../Database/index.json'), 'utf8', (err, data) => {
+ if (err) {
+ console.log(err);
+ } else {
+ const obj = JSON.parse(data);
+ const id = Object.keys(obj.users).length + 1;
+ obj.users[id] = req.body;
+ const json = JSON.stringify(obj);
+ fs.writeFile(path.join(__dirname, '/../Database/index.json'), json, 'utf8', (er) => {
+ if (er) throw er;
+ });
+ res.json({ key: id });
+ }
+ });
});
-//
-//add a user
-user.post('/users', (req,res) => {
- fs.readFile(__dirname+'/../Database/index.json','utf8', (err, data) => {
- if (err){
- console.log(err);
- } else {
- let obj = JSON.parse(data);
- let id = "user" + (Object.keys(obj.users).length + 1);
- obj.users[id] = req.body;
- console.log("users ="+req.body);
- let json = JSON.stringify(obj);
- fs.writeFile(__dirname+'/../Database/index.json', json, 'utf8', err => {
- if(err) throw err;
- console.log("file has been saved");
- console.log(id);
- });
- res.send({key : id});
- }
- });
+user.post('/authusers', (req, res) => {
+ fs.readFile(path.join(__dirname, '/../Database/index.json'), 'utf8', (err, data) => {
+ const obj = JSON.parse(data);
+ const n = userValidate(obj.users, req.body.user, req.body.pass);
+ res.json({ key: n });
+ });
});
-user.post('/authusers', (req,res) => {
- fs.readFile(__dirname+'/../Database/index.json','utf8', (err,data) => {
- let obj = JSON.parse(data);
- console.log(req.body);
- let n = userValidate(obj.users, req.body.user, req.body.pass);
- console.log(n);
- res.send({key : n});
- });
+// update a user
+user.put('/users/:id', (req, res) => {
+ fs.readFile(path.join(__dirname, '/../Database/index.json'), 'utf8', (err, data) => {
+ if (err) {
+ console.log(err);
+ } else {
+ const obj = JSON.parse(data);
+ obj.users[req.params.id] = req.body;
+ const json = JSON.stringify(obj);
+ fs.writeFile(path.join(__dirname, '/../Database/index.json'), json, 'utf8', (er) => {
+ if (er) throw er;
+ });
+ res.json({ key: req.params.id });
+ }
+ });
});
-//update a user
-user.put('/users/:id', (req,res) => {
- fs.readFile(__dirname+'/../Database/index.json','utf8', (err, data) => {
- if (err){
- console.log(err);
- } else {
- let obj = JSON.parse(data);
- obj.users[req.params.id] = req.body;
- console.log("users ="+req.body);
- let json = JSON.stringify(obj);
- fs.writeFile(__dirname+'/../Database/index.json', json, 'utf8', err => {
- if(err) throw err;
- console.log("file has been saved");
- console.log(id);
- });
- res.send({key : id});
- }
- });
-});
-//delete a user
-user.delete('/users/:id', (req,res) => {
- console.log(req.params.id);
- res.send({type: 'DELETE'});
+// delete a user
+user.delete('/users/:id', (req, res) => {
+ res.json({ type: 'DELETE' });
});
-export default user;
\ No newline at end of file
+export default user;