Skip to content

Commit c1df08c

Browse files
Merge pull request #141 from lakshyabatman/development
Small bugs in other-landing.ejs solved
2 parents 2a8db7b + 4935fdb commit c1df08c

File tree

5 files changed

+59
-95
lines changed

5 files changed

+59
-95
lines changed

controller/profile.controller.js

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

routes/profile.routes.js

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

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

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

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

views/other-landing.ejs

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
<meta http-equiv="x-ua-compatible" content="ie=edge">
99
<title>Codeuino</title>
1010
<!-- Font Awesome -->
11-
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
1211
<!-- Bootstrap core CSS -->
13-
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
12+
<link href="/vendor/bootstrap/css/bootstrap.min.css" type="text/css" rel="stylesheet">
1413
<!-- Material Design Bootstrap -->
15-
<link href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.5.4/css/mdb.min.css" rel="stylesheet">
14+
<link href="/vendor/mdbootstrap/mdb.min.css" type="text/css" rel="stylesheet">
15+
1616
<!-- Your custom styles (optional) -->
1717
<link href="../../css/other-landing.css" type="text/css" rel="stylesheet">
1818
</head>
@@ -174,8 +174,8 @@
174174
</div>
175175
<div class="container">
176176
<div class="row">
177-
<div class="form-group grey-border btn-rounded">
178-
<textarea class="form-control z-depth-1 btn-rounded" rows="3" placeholder="Reply"></textarea>
177+
<div class="form-group grey-border btn-rounded w-100 pr-2">
178+
<textarea class="form-control z-depth-1 btn-rounded reply" rows="3" placeholder="Reply"></textarea>
179179
</div>
180180
</div>
181181
</div>
@@ -227,19 +227,15 @@
227227
</div>
228228
</div>
229229
</main>
230-
<!--Main Layout-->
231-
232-
<!-- SCRIPTS -->
233-
<!-- JQuery -->
234-
235-
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
230+
231+
<script type="text/javascript" src="/vendor/jquery/jquery.min.js"></script>
236232
<script>
237233
$(document).ready(function(){
238234
239235
$('.ch').click(function(e){
240236
e.preventDefault();
241237
var z=$(this).attr('id');
242-
alert(z);
238+
243239
$.ajax({
244240
245241
url:'/profile/upvote',
@@ -250,23 +246,36 @@
250246
console.log(res);
251247
}
252248
})
249+
});
253250
254251
255252
253+
$('.ch2').click(function(e){
254+
e.preventDefault();
255+
var z=$(this).attr('id');
256+
$.ajax({
256257
257-
});
258-
258+
url:'/profile/upDownVote',
259+
method:'POST',
260+
contentType:'application/json',
261+
data:JSON.stringify({'project':z,client:'<%=sign.Eid%>','vote':'-1'}),
262+
success:function(res){
263+
console.log("Sucess")
264+
//Frontend code can be implemented
265+
},
266+
error:function (res) {
267+
console.log(res)
268+
console.log("Error")
269+
//Frontend code can be implemented
270+
}
271+
});
272+
})
259273
})
260-
261-
262-
263-
</script>
264-
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
274+
</script>
265275
<!-- Bootstrap tooltips -->
266-
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.13.0/umd/popper.min.js"></script>
276+
<script type="text/javascript" src="/vendor/bootstrap/js/popper.min.js"></script>
267277
<!-- Bootstrap core JavaScript -->
268-
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/js/bootstrap.min.js"></script>
269-
<!-- MDB core JavaScript -->
270-
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.5.4/js/mdb.min.js"></script>
278+
<script type="text/javascript" src="/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
279+
271280
</body>
272281
</html>

0 commit comments

Comments
 (0)