Skip to content

Commit c0de0b5

Browse files
committed
Fix deplyment and count articles
1 parent 27e7816 commit c0de0b5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

serverless.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ service: realworld
22

33
provider:
44
name: aws
5-
runtime: nodejs8.10
5+
runtime: nodejs14.x
66
region: us-east-1
77
environment:
88
DYNAMODB_NAMESPACE: ${opt:stage, "dev"}

src/Article.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ module.exports = {
268268
}
269269
return Util.envelop({
270270
articles: await queryEnoughArticles(queryParams, authenticatedUser,
271-
limit, offset)
271+
limit, offset),
272+
articlesCount: await countArticles(queryParams, authenticatedUser)
272273
});
273274
},
274275

@@ -317,6 +318,7 @@ module.exports = {
317318
return Util.envelop({
318319
articles: await queryEnoughArticles(queryParams, authenticatedUser,
319320
limit, offset),
321+
articlesCount: await countArticles(queryParams, authenticatedUser)
320322
});
321323
},
322324

@@ -379,6 +381,20 @@ async function queryEnoughArticles(queryParams, authenticatedUser,
379381
return articles;
380382
}
381383

384+
/**
385+
* Given queryParams, return the number of articles that match.
386+
*/
387+
async function countArticles(queryParams, authenticatedUser,
388+
limit, offset) {
389+
390+
const countQueryParams = Object.assign({}, queryParams, { Select: "COUNT" })
391+
392+
const queryResult = await Util.DocumentClient.query(countQueryParams)
393+
.promise();
394+
395+
return queryResult.Count;
396+
}
397+
382398
/**
383399
* Given an article retrieved from table,
384400
* decorate it with extra information like author, favorite, following etc.

0 commit comments

Comments
 (0)