-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
95 lines (70 loc) · 2.05 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const express = require("express");
const app = express();
app.use(express.static("React/build"));
var bodyParser = require("body-parser");
app.use(bodyParser.json());
let allVotesServer = [{id:"1",score:1}];
app.post("/Get-setVotePoints", (req, res) => {
let check = null;
let num;
const {allVotes} = req.body;
let temp = JSON.parse(allVotes);
if(temp !== null){
for (let index = 0; index < temp.length; index++) {
for (let index1 = 0; index1 < allVotesServer.length; index1++) {
if(temp[index].voteUpOrDown === "Up") { num = 1;}
else if(temp[index].voteUpOrDown === "Down") {num = -1}
check = null;
if(temp[index].id === allVotesServer[index1].id){
check = true;
allVotesServer[index1].score = allVotesServer[index1].score + num ;
break;
}
else{
check = false;
}
}
if(check === false || check === null ){
allVotesServer.push({id:temp[index].id , score: num});
}}
}
console.log(allVotesServer)
})
app.get('/getVotePoints',(req, res)=>{
res.send(allVotesServer);
})
const port = process.env.PORT || 3000;
app.listen(port, function () {
console.log("listening", port);
});
/*
const listOfEmails=[
{email:'[email protected]'},
{email:'[email protected]'},
{email:'[email protected]'},
{email:'[email protected]'},
{email:'[email protected]'},
{email:'[email protected]'},
]
const LoginUsers =[
{user:"tal" , password:"tal123"}
]
app.get('/get-emails',(req, res)=>{
res.send(listOfEmails)
})
app.post('/add-email',(req,res)=>{
const {email} = req.body;
if(listOfEmails.findIndex(emaili => emaili.email === email) === -1){
listOfEmails.push({email:email});
res.send(listOfEmails)
}
})
app.post('/login',(req, res)=>{
console.log("arrived")
const { user, password } = req.body;
const index = LoginUsers.findIndex(login => login.user === user && login.password === password);
if (index === -1) {
res.send({ login: false })
}
res.send({ login: true })
})*/