Skip to content

Commit

Permalink
updates to the api for keelan
Browse files Browse the repository at this point in the history
  • Loading branch information
springdo committed Feb 13, 2020
1 parent 648f5f7 commit d573932
Show file tree
Hide file tree
Showing 3 changed files with 1,036 additions and 267 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ jspm_packages


# Out put dir for built functions
lamda
lamda
*.csv
60 changes: 48 additions & 12 deletions functions/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,36 @@ const BASE_API_URL =
const OPL_BASE_URL = 'https://openpracticelibrary.com/practice/'


const fields = [
'title',
'subtitle',
'area',
'people',
'time',
'difficulty',
'participants',
'url'
];
const fields = [{
label: 'title',
value: 'title',
default: ''
}, {
label: 'subtitle',
value: 'subtitle',
default: ''
}, {
label: '@area',
value: 'area',
default: ''
}, {
label: 'time',
value: 'time',
default: ''
}, {
label: 'difficulty',
value: 'difficulty',
default: ''
}, {
label: 'participants',
value: 'participants',
default: ''
}, {
label: '#url',
value: 'url',
default: ''
}];

const opts = {
fields
};
Expand Down Expand Up @@ -64,18 +84,34 @@ router.get('/data', (req, res) => {
);
let content = fm(fileContent);
// trim extra stuff from the metadata
// FRONT OF CARD
let frontArea = `front-${content.attributes.area}.ai`;
let backArea = `back-${content.attributes.area}.ai`;
content.attributes.area = frontArea;
delete content.attributes.date;
delete content.attributes.authors;
delete content.attributes.people;
delete content.attributes.icon;
delete content.attributes.jumbotron;
delete content.attributes.jumbotronAlt;
delete content.attributes.perspectives;
content.attributes.participants = content.attributes.participants ?
content.attributes.participants.join('#') :
'';
let name = allFileLocations[index].name.substring(0, allFileLocations[index].name.length - 3)
content.attributes.url = `${OPL_BASE_URL}${name}/`;
const backOfCard = Object.assign({}, content.attributes);


response.push(content.attributes);

// BACK OF CARD
let name = allFileLocations[index].name.substring(0, allFileLocations[index].name.length - 3)
backOfCard.url = `${OPL_BASE_URL}${name}/`;
delete backOfCard.subtitle;
backOfCard.area = backArea;
delete backOfCard.time;
delete backOfCard.difficulty;
delete backOfCard.participants;
response.push(backOfCard);
});
// TODO - add parser for CSV
const csv = parse(response, opts);
Expand Down
Loading

0 comments on commit d573932

Please sign in to comment.