Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated acknowledgment table #2586

Merged
merged 2 commits into from
Mar 15, 2022
Merged
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
61 changes: 7 additions & 54 deletions verification/curator-service/api/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,45 +133,6 @@ paths:
tags: [Source]
summary: Lists sources for acknowledgments table
operationId: listSourcesForTable
parameters:
- name: page
in: query
description: The pages of sources to skip before starting to collect the result set
required: false
schema:
type: integer
format: int32
minimum: 1
default: 1
- name: limit
in: query
description: The number of sources to return
required: false
schema:
type: integer
format: int32
minimum: 0
maximum: 100
default: 10
- name: orderBy
in: query
description: Field to be sorted by
required: false
schema:
type: string
enum:
- dataContributor
- originDataSource
- license
- name: order
in: query
description: Sorting order
required: false
schema:
type: string
enum:
- asc
- desc
responses:
'200':
$ref: '#/components/responses/200AcknowledgmentSource'
Expand Down Expand Up @@ -1349,6 +1310,10 @@ components:
origin:
type: object
properties:
providerName:
type: string
providerWebsiteUrl:
type: string
url:
type: string
example: https://opendata.digilugu.ee/opendata_covid19_test_results.csv
Expand All @@ -1357,11 +1322,6 @@ components:
type: string
example: MIT
description: The license under which we have the right to ingest the data. Ideally a SPDX identifier (https://spdx.org/licenses/).
countryCodes:
type: array
description: An array of country codes that this source relates to
items:
type: string
SourceArray:
type: object
properties:
Expand All @@ -1376,16 +1336,9 @@ components:
items:
$ref: '#/components/schemas/Source'
AcknowledgmentSourcesArray:
type: object
properties:
sources:
type: array
items:
$ref: '#/components/schemas/AcknowledgmentSource'
nextPage:
type: integer
total:
type: integer
type: array
items:
$ref: '#/components/schemas/AcknowledgmentSource'
Case:
description: A single line-list case.
properties:
Expand Down
81 changes: 14 additions & 67 deletions verification/curator-service/api/src/controllers/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Source, SourceDocument } from '../model/source';
import AwsBatchClient from '../clients/aws-batch-client';
import AwsEventsClient from '../clients/aws-events-client';
import EmailClient from '../clients/email-client';
import { logger } from '../util/logger';

/**
* Email notification that should be sent on any update to a source.
Expand Down Expand Up @@ -90,76 +91,22 @@ export default class SourcesController {
/**
* Get sources for the acknowledgement table
* This is a public endpoint because acknowledgement table needs to
* be accessible in iframe
* be accessible without logging in
*/
listSourcesForTable = async (
req: Request,
res: Response,
): Promise<void> => {
const page = Number(req.query.page) ?? 1;
const limit = Number(req.query.limit) ?? 10;
const orderBy = String(req.query.orderBy);
const order = String(req.query.order);
if (page < 1) {
res.status(422).json({ message: 'page must be > 0' });
return;
}
// Allow for 0 value for fetching all sources
if (limit < 0) {
res.status(422).json({ message: 'limit must be >= 0' });
return;
}

// When limit is set as 0 in the request that means that all data
// should be fetched without any limit
const skipValue = limit === 0 ? 0 : limit * (page - 1);
const limitValue = limit === 0 ? 0 : limit + 1;

// Map values that come from ui to mongo Schema
let sortByKeyword = '';
switch (orderBy) {
case 'dataContributor':
sortByKeyword = 'name';
break;
case 'originDataSource':
sortByKeyword = 'origin.url';
break;
case 'license':
sortByKeyword = 'origin.license';
break;
default:
sortByKeyword = 'name';
break;
}

const sourcesQuery = Source.find(
{},
{
name: 1,
'origin.url': 1,
'origin.license': 1,
},
).sort({ [sortByKeyword]: order !== 'undefined' ? order : 'asc' });

listSourcesForTable = async (req: Request, res: Response) => {
try {
const [sources, total] = await Promise.all([
sourcesQuery.skip(skipValue).limit(limitValue),
Source.countDocuments({}),
]);
const sources = await Source.find(
{},
{
name: 1,
'origin.providerName': 1,
'origin.providerWebsiteUrl': 1,
'origin.url': 1,
'origin.license': 1,
},
);

// If we have more items than limit, add a response param
// indicating that there is more to fetch on the next page.
if (sources.length === limit + 1) {
sources.splice(limit);
res.json({
sources,
nextPage: page + 1,
total: total,
});
return;
}
// If we fetched all available data, just return it.
res.json({ sources, total: total });
return res.json(sources);
} catch (err) {
if (err.name === 'ValidationError') {
res.status(422).json(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,81 +5,100 @@
"name": "USA",
"origin": {
"url": "https://test.com",
"license": "MIT"
"license": "MIT",
"providerName": "USA",
"providerWebsiteUrl": "https://test.com"
}
},
{
"_id": "2",
"name": "Germany",
"origin": {
"url": "https://test.com",
"license": "MIT"
"license": "MIT",
"providerWebsiteUrl": "https://test.com"
}
},
{
"_id": "3",
"name": "Poland",
"origin": {
"url": "https://test.com",
"license": "MIT"
"license": "MIT",
"providerName": "Poland",
"providerWebsiteUrl": "https://test.com"
}
},
{
"_id": "4",
"name": "Argentina",
"origin": {
"url": "https://test.com",
"license": "MIT"
"license": "MIT",
"providerName": "Argentina",
"providerWebsiteUrl": "https://test.com"
}
},
{
"_id": "5",
"name": "Peru",
"origin": {
"url": "https://test.com",
"license": "MIT"
"license": "MIT",
"providerName": "Peru",
"providerWebsiteUrl": "https://test.com"
}
},
{
"_id": "6",
"name": "United Kingdom",
"origin": {
"url": "https://test.com",
"license": "MIT"
"license": "MIT",
"providerName": "United Kingdom",
"providerWebsiteUrl": "https://test.com"
}
},
{
"_id": "7",
"name": "Brazil",
"origin": {
"url": "https://test.com",
"license": "MIT"
"license": "MIT",
"providerName": "Brazil",
"providerWebsiteUrl": "https://test.com"
}
},
{
"_id": "8",
"name": "China",
"origin": {
"url": "https://test.com",
"license": "MIT"
"license": "MIT",
"providerName": "China",
"providerWebsiteUrl": "https://test.com"
}
},
{
"_id": "9",
"name": "Canada",
"origin": {
"url": "https://test.com",
"license": "MIT"
"license": "MIT",
"providerName": "Canada",
"providerWebsiteUrl": "https://test.com"
}
},
{
"_id": "10",
"name": "Spain",
"origin": {
"url": "https://test.com",
"license": "MIT"
"license": "MIT",
"providerName": "Spain",
"providerWebsiteUrl": "https://test.com"
}
}
],
"total": 11
"total": 10
}
Loading