@@ -16,7 +16,8 @@ function handleNullScoreInRow({ score, ...rest }) {
16
16
} ;
17
17
}
18
18
19
- function convertNullScoresToZero ( query ) {
19
+ // Given a Knex query promise, resolve it and then format one or more rows
20
+ function formatRows ( query ) {
20
21
return query . then ( ( rows ) => {
21
22
if ( rows . map ) {
22
23
return rows . map ( handleNullScoreInRow ) ;
@@ -31,6 +32,7 @@ export class Comments {
31
32
. where ( { id } ) ;
32
33
return query . then ( ( [ row ] ) => row ) ;
33
34
}
35
+
34
36
getCommentsByRepoName ( name ) {
35
37
const query = knex ( 'comments' )
36
38
. where ( { repository_name : name } )
@@ -39,6 +41,7 @@ export class Comments {
39
41
rows || [ ]
40
42
) ) ;
41
43
}
44
+
42
45
getCommentCount ( name ) {
43
46
const query = knex ( 'comments' )
44
47
. where ( { repository_name : name } )
@@ -49,6 +52,7 @@ export class Comments {
49
52
) )
50
53
) ) ;
51
54
}
55
+
52
56
submitComment ( repoFullName , username , content ) {
53
57
return knex . transaction ( ( trx ) => (
54
58
trx ( 'comments' )
@@ -62,7 +66,6 @@ export class Comments {
62
66
}
63
67
}
64
68
export class Entries {
65
-
66
69
getForFeed ( type , offset , limit ) {
67
70
const query = knex ( 'entries' )
68
71
. modify ( addSelectToEntryQuery ) ;
@@ -81,7 +84,7 @@ export class Entries {
81
84
82
85
query . limit ( limit ) ;
83
86
84
- return convertNullScoresToZero ( query ) ;
87
+ return formatRows ( query ) ;
85
88
}
86
89
87
90
getByRepoFullName ( name ) {
@@ -93,7 +96,7 @@ export class Entries {
93
96
} )
94
97
. first ( ) ;
95
98
96
- return convertNullScoresToZero ( query ) ;
99
+ return formatRows ( query ) ;
97
100
}
98
101
99
102
voteForEntry ( repoFullName , voteValue , username ) {
0 commit comments