Skip to content

Commit 776d6ad

Browse files
committed
fixed merge conflicts and tested code
2 parents 0e9aff7 + 1d7a23e commit 776d6ad

File tree

6 files changed

+25
-88
lines changed

6 files changed

+25
-88
lines changed

controller/profile.controller.js

Lines changed: 16 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -36,79 +36,24 @@ module.exports = {
3636
res.redirect('/profile/profileview/' + req.user.Eid);
3737
});
3838
},
39-
upvote: function (req, res) {
40-
41-
var p = 0;
42-
43-
var check = 0;
44-
var comment = ' ';
45-
for (var q = 0; q < proj.downvote.length; q++) {
46-
if (req.body.client == proj.downvote[q]) {
47-
comment = 'Cannot upvote and downvote a post ';
48-
check = 1;
49-
break;
50-
}
51-
52-
}
53-
54-
if (check == 1) {
55-
res.send({ proj, comment });
56-
}
57-
else {
58-
for (var v = 0; v < proj.upvote.length; v++) {
59-
if (req.body.client == proj.upvote[v]) {
60-
p = 1;
61-
proj.upvote.pop(req.body.client);
62-
proj.save();
63-
console.log('already present');
64-
break;
65-
}
66-
}
67-
68-
if (p == 0) {
69-
proj.upvote.push(req.body.client);
70-
proj.save();
71-
}
72-
73-
res.send({ comment, proj });
74-
}
75-
},
76-
downvote: function(req,res){
77-
proj.findOne({ proid: req.body.project }).then(function (proj) {
78-
79-
var p = 0;
80-
var check = 0;
81-
var comment = '';
82-
83-
for (var q = 0; q < proj.upvote.length; q++) {
84-
if (req.body.client == proj.upvote[q]) {
85-
comment = 'Cannot do upvote downvote at same post';
86-
check = 1;
87-
break;
88-
}
89-
}
90-
91-
if (check == 1) {
92-
res.send({ comment, proj });
93-
}
94-
else {
95-
for (var v = 0; v < proj.downvote.length; v++) {
96-
if (req.body.client == proj.downvote[v]) {
97-
p = 1;
98-
proj.downvote.pop(req.body.client);
99-
proj.save();
100-
console.log('already present');
101-
break;
102-
}
39+
upDownVote: function (req,res) {
40+
proj.findOne({proid: req.body.project}).then((pro)=>{
41+
if(pro.upDownVote.get(req.body.client)){
42+
if(pro.upDownVote.get(req.body.client)=='-1'){
43+
pro.upDownVote.set(req.body.client,'+1');
44+
return pro.save();
45+
46+
}else{
47+
pro.upDownVote.set(req.body.client,'-1');
48+
return pro.save();
49+
10350
}
104-
105-
if (p == 0) {
106-
proj.downvote.push(req.body.client);
107-
proj.save();
108-
}
109-
110-
res.send({ comment, proj });
51+
}else{
52+
pro.upDownVote.set(req.body.client,req.body.vote);
53+
return pro.save();
11154
}
55+
}).catch((err)=>{
56+
return err;
11257
});
11358
},
11459
ch2 : function(req,res){

routes/login.routes.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ const route = express.Router();
88

99
//get request
1010

11-
12-
1311
route.get('/google', passport.authenticate('google', { scope: ['profile'] }));
1412

1513
route.get('/google/redirect', passport.authenticate('google'), function (req, res) {
@@ -47,7 +45,6 @@ route.post('/login', url, function (req, res) {
4745
}
4846
});
4947

50-
5148
});
5249
route.get('/logout', function (req, res) {
5350
req.logout();

schema/project.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const mongoose = require('mongoose');
2-
const schema = mongoose.Schema;
3-
const project = new schema({
1+
const mongoose=require('mongoose');
2+
const schema=mongoose.Schema;
3+
const project=new schema({
44
pname:{
55
type:String
66
},
@@ -16,11 +16,9 @@ const project = new schema({
1616
content:{
1717
type:String
1818
},
19-
upvote:{
20-
type:[String]
21-
},
22-
downvote:{
23-
type:[String]
19+
upDownVote:{
20+
type:Map,
21+
of: String,
2422
},
2523
proid:{
2624
type:Number

server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ app.use(passport.session());
3434
app.use(indexRoutes);
3535

3636

37-
var ser = app.listen(3000, function () {
37+
const ser = app.listen(3000, function () {
3838
console.log('Running');
3939
});
4040

views/js/codeuino.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@
7373
$('#loginModal').addClass('displayOff');
7474

7575
});
76-
77-
78-
79-
76+
8077
$(window).scroll(navbarCollapse);
8178

8279
})(jQuery);

views/js/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $('.tab a').on('click', function(e) {
99
.siblings()
1010
.removeClass('active');
1111

12-
var target = $(this).attr('href');
12+
const target = $(this).attr('href');
1313

1414
$('.tab-content > div')
1515
.not(target)

0 commit comments

Comments
 (0)