This repository was archived by the owner on Mar 3, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +36
-6
lines changed Expand file tree Collapse file tree 5 files changed +36
-6
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ module.exports = {
17
17
"func-names" : 0 ,
18
18
"object-property-newline" : 0 ,
19
19
"no-unused-vars" : 1 ,
20
+ "no-confusing-arrow" : 0 ,
21
+ "no-continue" : 0 ,
22
+ "no-await-in-loop" : 0
20
23
} ,
21
24
"plugins" : [
22
25
"flowtype"
Original file line number Diff line number Diff line change @@ -63,20 +63,43 @@ Comment.readComment = async function (commentId: string) {
63
63
}
64
64
} ;
65
65
66
+ Comment . getChildrenOf = function ( id ) {
67
+ return Comment . findAll ( {
68
+ include : [ { model : User , attributes : [ 'username' ] } ] ,
69
+ where : {
70
+ reply_to : id ,
71
+ } ,
72
+ } ) ;
73
+ } ;
74
+
66
75
Comment . listComments = async function ( postId : string ) {
67
76
try {
68
77
const data = await Comment . findAll ( {
69
78
include : [ { model : User , attributes : [ 'username' ] } ] ,
70
79
where : {
71
80
fk_post_id : postId ,
81
+ level : 0 ,
72
82
} ,
73
83
order : [
74
84
[ 'created_at' , 'DESC' ] ,
75
85
] ,
76
86
limit : 20 ,
77
87
} ) ;
78
88
if ( ! data ) return [ ] ;
79
- return data . map ( this . serialize ) ;
89
+ const comments = data . map ( c => c . toJSON ( ) ) ;
90
+ for ( let i = 0 ; i < comments . length ; i ++ ) {
91
+ if ( ! comments [ i ] . has_replies ) continue ;
92
+ const c2 = ( await Comment . getChildrenOf ( comments [ i ] . id ) )
93
+ . map ( c => c . toJSON ( ) ) ;
94
+ comments [ i ] . children = c2 . map ( c => c . toJSON ( ) ) ;
95
+ for ( let j = 0 ; j < c2 . length ; j ++ ) {
96
+ if ( c2 [ j ] . has_replies ) continue ;
97
+ const c3 = ( await Comment . getChildrenOf ( c2 [ j ] . id ) )
98
+ . map ( c => c . toJSON ( ) ) ;
99
+ c2 [ j ] . children = c3 ;
100
+ }
101
+ }
102
+ return comments ;
80
103
} catch ( e ) {
81
104
throw e ;
82
105
}
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ export const writeComment: Middleware = async (ctx: Context) => {
31
31
if ( replyTo ) {
32
32
// check that it exists
33
33
try {
34
- const c = await Comment . findById ( replyTo , { raw : true } ) ;
34
+ const c = await Comment . findById ( replyTo ) ;
35
35
if ( ! c ) {
36
36
ctx . status = 404 ;
37
37
ctx . body = {
@@ -46,6 +46,10 @@ export const writeComment: Middleware = async (ctx: Context) => {
46
46
processedReplyTo = c . reply_to ;
47
47
}
48
48
// TODO: update hasReply
49
+ c . has_reply = true ;
50
+ await c . update ( {
51
+ has_replies : true ,
52
+ } ) ;
49
53
} catch ( e ) {
50
54
ctx . throw ( 500 , e ) ;
51
55
}
Original file line number Diff line number Diff line change 114
114
"eslint-plugin-import" : " ^2.8.0" ,
115
115
"eslint-plugin-jsx-a11y" : " ^6.0.3" ,
116
116
"eslint-plugin-react" : " ^7.5.1" ,
117
- "flow-bin" : " ^0.61.0 "
117
+ "flow-bin" : " ^0.67.1 "
118
118
},
119
119
"proxy" : " http://localhost:4000/"
120
120
}
Original file line number Diff line number Diff line change @@ -2676,9 +2676,9 @@ flatten@^1.0.2:
2676
2676
version "1.0.2"
2677
2677
resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782"
2678
2678
2679
- flow-bin@^0.61.0 :
2680
- version "0.61.0 "
2681
- resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.61.0 .tgz#d0473a8c35dbbf4de573823f4932124397d32d35 "
2679
+ flow-bin@^0.67.1 :
2680
+ version "0.67.1 "
2681
+ resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.67.1 .tgz#eabb7197cce870ac9442cfd04251c7ddc30377db "
2682
2682
2683
2683
follow-redirects@^1.2.5 :
2684
2684
version "1.2.6"
You can’t perform that action at this time.
0 commit comments