Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f643200

Browse files
author
Sashko Stubailo
committed
Formatting
1 parent 3a5b0bc commit f643200

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

api/sql/models.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ function handleNullScoreInRow({ score, ...rest }) {
1616
};
1717
}
1818

19-
function convertNullScoresToZero(query) {
19+
// Given a Knex query promise, resolve it and then format one or more rows
20+
function formatRows(query) {
2021
return query.then((rows) => {
2122
if (rows.map) {
2223
return rows.map(handleNullScoreInRow);
@@ -31,6 +32,7 @@ export class Comments {
3132
.where({ id });
3233
return query.then(([row]) => row);
3334
}
35+
3436
getCommentsByRepoName(name) {
3537
const query = knex('comments')
3638
.where({ repository_name: name })
@@ -39,6 +41,7 @@ export class Comments {
3941
rows || []
4042
));
4143
}
44+
4245
getCommentCount(name) {
4346
const query = knex('comments')
4447
.where({ repository_name: name })
@@ -49,6 +52,7 @@ export class Comments {
4952
))
5053
));
5154
}
55+
5256
submitComment(repoFullName, username, content) {
5357
return knex.transaction((trx) => (
5458
trx('comments')
@@ -62,7 +66,6 @@ export class Comments {
6266
}
6367
}
6468
export class Entries {
65-
6669
getForFeed(type, offset, limit) {
6770
const query = knex('entries')
6871
.modify(addSelectToEntryQuery);
@@ -81,7 +84,7 @@ export class Entries {
8184

8285
query.limit(limit);
8386

84-
return convertNullScoresToZero(query);
87+
return formatRows(query);
8588
}
8689

8790
getByRepoFullName(name) {
@@ -93,7 +96,7 @@ export class Entries {
9396
})
9497
.first();
9598

96-
return convertNullScoresToZero(query);
99+
return formatRows(query);
97100
}
98101

99102
voteForEntry(repoFullName, voteValue, username) {

0 commit comments

Comments
 (0)