Skip to content

Commit 78ba17f

Browse files
committed
UpdownVote added again
1 parent 28881fa commit 78ba17f

File tree

4 files changed

+24
-75
lines changed

4 files changed

+24
-75
lines changed

controller/profile.controller.js

Lines changed: 19 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -50,76 +50,26 @@ module.exports = {
5050
res.redirect('/profile/profileview/' + req.user.Eid);
5151
});
5252
},
53-
upvote: function(req, res) {
54-
var p = 0;
55-
56-
var check = 0;
57-
var comment = ' ';
58-
for (var q = 0; q < proj.downvote.length; q++) {
59-
if (req.body.client == proj.downvote[q]) {
60-
comment = 'Cannot upvote and downvote a post ';
61-
check = 1;
62-
break;
63-
}
64-
}
65-
66-
if (check == 1) {
67-
res.send({ proj, comment });
68-
} else {
69-
for (var v = 0; v < proj.upvote.length; v++) {
70-
if (req.body.client == proj.upvote[v]) {
71-
p = 1;
72-
proj.upvote.pop(req.body.client);
73-
proj.save();
74-
console.log('already present');
75-
break;
76-
}
77-
}
78-
79-
if (p == 0) {
80-
proj.upvote.push(req.body.client);
81-
proj.save();
82-
}
83-
84-
res.send({ comment, proj });
85-
}
86-
},
87-
downvote: function(req, res) {
88-
proj.findOne({ proid: req.body.project }).then(function(proj) {
89-
var p = 0;
90-
var check = 0;
91-
var comment = '';
92-
93-
for (var q = 0; q < proj.upvote.length; q++) {
94-
if (req.body.client == proj.upvote[q]) {
95-
comment = 'Cannot do upvote downvote at same post';
96-
check = 1;
97-
break;
53+
upDownVote: function (req,res) {
54+
proj.findOne({proid: req.body.project}).then((pro)=>{
55+
if(pro.upDownVote.get(req.body.client)){
56+
if(pro.upDownVote.get(req.body.client)=="-1"){
57+
pro.upDownVote.set(req.body.client,"+1")
58+
return pro.save()
59+
60+
}else{
61+
pro.upDownVote.set(req.body.client,"-1")
62+
return pro.save()
63+
64+
}
65+
}else{
66+
pro.upDownVote.set(req.body.client,req.body.vote)
67+
return pro.save()
9868
}
99-
}
100-
101-
if (check == 1) {
102-
res.send({ comment, proj });
103-
} else {
104-
for (var v = 0; v < proj.downvote.length; v++) {
105-
if (req.body.client == proj.downvote[v]) {
106-
p = 1;
107-
proj.downvote.pop(req.body.client);
108-
proj.save();
109-
console.log('already present');
110-
break;
111-
}
112-
}
113-
114-
if (p == 0) {
115-
proj.downvote.push(req.body.client);
116-
proj.save();
117-
}
118-
119-
res.send({ comment, proj });
120-
}
121-
});
122-
},
69+
}).catch((err)=>{
70+
return err
71+
})
72+
},
12373
ch2: function(req, res) {
12474
res.render('main-landing', { sign: req.user });
12575
},

routes/profile.routes.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ route.get('/profileview/:sd', auth, url, profileController.profileViewSd);
2424

2525
route.post('/publish', auth, url, profileController.publish);
2626

27-
route.post('/upvote', auth, url, jsonParser, profileController.upvote);
28-
route.post('/downvote', auth, url, jsonParser, profileController.downvote);
27+
route.post('/upDownVote', auth,url, jsonParser,profileController.upDownVote);
28+
29+
2930

3031
route.get('/ch2', auth, profileController.ch2);
3132

views/other-landing.ejs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<meta http-equiv="x-ua-compatible" content="ie=edge">
99
<title>Codeuino</title>
1010
<!-- Font Awesome -->
11-
<link rel="stylesheet" type="text/css" href="/vendor/fontawesome-free/css/fontawesome.min.css">
1211
<!-- Bootstrap core CSS -->
1312
<link href="/vendor/bootstrap/css/bootstrap.min.css" type="text/css" rel="stylesheet">
1413
<!-- Material Design Bootstrap -->
@@ -231,13 +230,14 @@
231230
</div>
232231
</main>
233232

234-
233+
<script type="text/javascript" src="/vendor/jquery/jquery.min.js"></script>
235234
<script>
236235
$(document).ready(function(){
237236
238237
$('.ch1').click(function(e){
239238
e.preventDefault();
240239
var z=$(this).attr('id');
240+
console.log($(this))
241241
$.ajax({
242242
243243
url:'/profile/upDownVote',
@@ -281,7 +281,6 @@
281281
})
282282
})
283283
</script>
284-
<script type="text/javascript" src="/vendor/jquery/jquery.min.js"></script>
285284
<!-- Bootstrap tooltips -->
286285
<script type="text/javascript" src="/vendor/bootstrap/js/popper.min.js"></script>
287286
<!-- Bootstrap core JavaScript -->

views/vendor/fontawesome-free/svgs/solid/hourglass.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)