Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Commit

Permalink
added documentation for two more GET requests
Browse files Browse the repository at this point in the history
  • Loading branch information
harumhelmy committed Jul 29, 2020
1 parent 6a361ce commit 9785e52
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/components/api-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export default function APISection({
APISection.propTypes = {
id: PropTypes.oneOf([
'get-preprints',
'get-reviews',
'get-review',
'get-request',
'post-request',
Expand Down
28 changes: 28 additions & 0 deletions src/components/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,34 @@ export default function API() {
curl https://outbreaksci.prereview.org/api/preprint?q=name%3ACOVID-19&include_docs=true&limit=2
</code>
</p>
<p>
Example to return many preprints, sorted by date of last review:
<br />
<code>
curl https://outbreaksci.prereview.org/api/preprint/?q=*:*&sort=[%22-dateLastReview%3Cnumber%3E%22%2C%22-score%3Cnumber%3E%22%2C%22-datePosted%3Cnumber%3E%22]&include_docs=true
</code>
</p>
</APISection>

<APISection
id="get-reviews"
title={
<Fragment>
GET <code>/api/action?q=@type:RapidPREreviewAction</code>
</Fragment>
}
>
<p>
Get all reviews, sorted from oldest to newest.
</p>
<p>
Example to retrieve all reviews, including its associated preprint:
<br />
<code>
curl https://outbreaksci.prereview.org/api/action?q=@type:RapidPREreviewAction&include_docs=true
</code>
</p>

</APISection>

<APISection
Expand Down
22 changes: 21 additions & 1 deletion src/routes/api-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@ router.get(
parseQuery,
cache(req => req.query.key),
async (req, res, next) => {
console.log('in async.....');
switch (req.query.key) {
case 'demo:get-preprints': {
try {
Expand All @@ -452,6 +451,27 @@ router.get(
break;
}

case 'demo:get-reviews': {
try {
const body = await req.db.docs.view('ddoc-docs', 'byType', {
key: 'RapidPREreviewAction',
include_docs: true,
reduce: false
});
const row = body.rows[0];
if (!row) {
return next(createError(404));
}

const payload = row.doc;
req.cache(payload);
res.json(payload);
} catch (err) {
return next(err);
}
break;
}

case 'demo:get-review': {
try {
const body = await req.db.docs.view('ddoc-docs', 'byType', {
Expand Down

0 comments on commit 9785e52

Please sign in to comment.