Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ service: realworld

provider:
name: aws
runtime: nodejs8.10
runtime: nodejs14.x
region: us-east-1
environment:
DYNAMODB_NAMESPACE: ${opt:stage, "dev"}
Expand Down
18 changes: 17 additions & 1 deletion src/Article.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ module.exports = {
}
return Util.envelop({
articles: await queryEnoughArticles(queryParams, authenticatedUser,
limit, offset)
limit, offset),
articlesCount: await countArticles(queryParams, authenticatedUser)
});
},

Expand Down Expand Up @@ -317,6 +318,7 @@ module.exports = {
return Util.envelop({
articles: await queryEnoughArticles(queryParams, authenticatedUser,
limit, offset),
articlesCount: await countArticles(queryParams, authenticatedUser)
});
},

Expand Down Expand Up @@ -379,6 +381,20 @@ async function queryEnoughArticles(queryParams, authenticatedUser,
return articles;
}

/**
* Given queryParams, return the number of articles that match.
*/
async function countArticles(queryParams, authenticatedUser,
limit, offset) {

const countQueryParams = Object.assign({}, queryParams, { Select: "COUNT" })

const queryResult = await Util.DocumentClient.query(countQueryParams)
.promise();

return queryResult.Count;
}

/**
* Given an article retrieved from table,
* decorate it with extra information like author, favorite, following etc.
Expand Down