@@ -5,7 +5,6 @@ var path = require('path');
5
5
var client = require ( path . resolve ( './lib/elasticsearch' ) ) ;
6
6
7
7
exports . renderComments = function ( req , res ) {
8
- console . log ( "I am rendering Comments" )
9
8
var postID = req . query . postID ;
10
9
var search ;
11
10
@@ -22,14 +21,13 @@ exports.renderComments = function(req, res) {
22
21
search . body . sort = { "created_at" : { "order" : "desc" } } ;
23
22
24
23
client . search ( search ) . then ( function ( results ) {
25
- console . log ( "in !postID" )
26
24
res . send ( results . hits . hits ) ;
27
25
} ) ;
28
26
} else {
29
27
search = { } ;
30
28
search . index = 'comments' ;
31
29
search . type = 'comment' ;
32
- search . size = 10 ;
30
+ search . size = 1000 ;
33
31
search . body = { } ;
34
32
search . body . query = { } ;
35
33
search . body . query . match = { } ;
@@ -42,11 +40,9 @@ exports.renderComments = function(req, res) {
42
40
43
41
client . search ( search ) . then ( function ( result ) {
44
42
var hits = result . hits . hits ;
45
- console . log ( hits ) ;
46
43
for ( var i = 0 ; i < hits . length ; i ++ ) {
47
44
hits [ i ] . votes = hits [ i ] . _source . upvotes . length - hits [ i ] . _source . downvotes . length ;
48
45
}
49
- console . log ( "hits === " , hits ) ;
50
46
res . json ( hits ) ;
51
47
} ) ;
52
48
}
@@ -88,55 +84,55 @@ exports.storeComment = function(req, res) {
88
84
} ;
89
85
90
86
exports . upvoteComment = function ( req , res ) {
91
- console . log ( "req.comment ==== " , req . comment )
87
+
92
88
var comment = req . comment ;
93
- if ( ! comment . upvotes ) {
94
- comment . upvotes = [ ] ;
89
+ if ( ! comment . _source . upvotes ) {
90
+ comment . _source . upvotes = [ ] ;
95
91
}
96
- if ( ! comment . downvotes ) {
97
- comment . downvotes = [ ] ;
92
+ if ( ! comment . _source . downvotes ) {
93
+ comment . _source . downvotes = [ ] ;
98
94
}
99
- if ( comment . downvotes . indexOf ( req . session . user . id ) > - 1 ) {
100
- comment . downvotes . splice ( comment . downvotes . indexOf ( req . session . user . id ) , 1 ) ;
95
+ if ( comment . _source . downvotes . indexOf ( req . session . user . id ) > - 1 ) {
96
+ comment . _source . downvotes . splice ( comment . _source . downvotes . indexOf ( req . session . user . id ) , 1 ) ;
101
97
}
102
- if ( comment . upvotes . indexOf ( req . session . user . id ) === - 1 ) {
103
- comment . upvotes . push ( req . session . user . id ) ;
98
+ if ( comment . _source . upvotes . indexOf ( req . session . user . id ) === - 1 ) {
99
+ comment . _source . upvotes . push ( req . session . user . id ) ;
104
100
}
105
101
var update = { } ;
106
102
update . index = 'comments' ;
107
103
update . type = 'comment' ;
108
104
update . id = comment . _id ;
109
105
update . body = { } ;
110
106
update . body . doc = { } ;
111
- update . body . upvotes = comment . upvotes ;
112
- update . body . downvotes = comment . downvotes ;
107
+ update . body . doc . upvotes = comment . _source . upvotes ;
108
+ update . body . doc . downvotes = comment . _source . downvotes ;
113
109
client . update ( update ) . then ( function ( result ) {
114
110
res . send ( result ) ;
115
111
} ) ;
116
112
} ;
117
113
118
114
exports . downvoteComment = function ( req , res ) {
119
115
var comment = req . comment ;
120
- if ( ! comment . downvotes ) {
121
- comment . downvotes = [ ] ;
116
+ if ( ! comment . _source . downvotes ) {
117
+ comment . _source . downvotes = [ ] ;
122
118
}
123
- if ( ! comment . upvotes ) {
124
- comment . upvotes = [ ] ;
119
+ if ( ! comment . _source . upvotes ) {
120
+ comment . _source . upvotes = [ ] ;
125
121
}
126
- if ( comment . upvotes . indexOf ( req . session . user . id ) > - 1 ) {
127
- comment . upvotes . splice ( comment . upvotes . indexOf ( req . session . user . id ) , 1 ) ;
122
+ if ( comment . _source . upvotes . indexOf ( req . session . user . id ) > - 1 ) {
123
+ comment . _source . upvotes . splice ( comment . _source . upvotes . indexOf ( req . session . user . id ) , 1 ) ;
128
124
}
129
- if ( comment . downvotes . indexOf ( req . session . user . id ) === - 1 ) {
130
- comment . downvotes . push ( req . session . user . id ) ;
125
+ if ( comment . _source . downvotes . indexOf ( req . session . user . id ) === - 1 ) {
126
+ comment . _source . downvotes . push ( req . session . user . id ) ;
131
127
}
132
128
var update = { } ;
133
129
update . index = 'comments' ;
134
130
update . type = 'comment' ;
135
131
update . id = comment . _id ;
136
132
update . body = { } ;
137
133
update . body . doc = { } ;
138
- update . body . upvotes = comment . upvotes ;
139
- update . body . downvotes = comment . downvotes ;
134
+ update . body . doc . upvotes = comment . _source . upvotes ;
135
+ update . body . doc . downvotes = comment . _source . downvotes ;
140
136
client . update ( update ) . then ( function ( result ) {
141
137
res . send ( result ) ;
142
138
} ) ;
0 commit comments