Skip to content

Commit

Permalink
more clean up, more comments, plus fixed a bug in the generation of d…
Browse files Browse the repository at this point in the history
…dKeys in dd2queries.js
  • Loading branch information
punkish committed Apr 27, 2020
1 parent dc3f3c6 commit 6e72fb3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
15 changes: 11 additions & 4 deletions api/v2/lib/dd2queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,14 @@ const calcQuery = function(ddKeys, queryGroup, query, queryObject, matchTables,
const offset = queryObject.offset || query.offset || 0;

if (matchTables.length) {

tables.push(...matchTables);
}

if (queryGroup !== 'taxonStats' && queryGroup !== 'related') {

if (addedConstraint.length) {

constraint.push(...addedConstraint);
}
}
Expand All @@ -134,11 +137,13 @@ const calcQuery = function(ddKeys, queryGroup, query, queryObject, matchTables,
// now, figure out the sort params, if applicable
let [sortcol, sortdir] = ['', ''];
if (queryObject.sortBy && Object.keys(sortBy).length) {

[sortcol, sortdir] = calcSortParams(sortBy, queryObject);
sql += ` ORDER BY ${sortcol} ${sortdir}`;
}

if (group && Object.keys(group).length) {

sql += ` GROUP BY ${group.join(' ')}`;
}

Expand Down Expand Up @@ -180,7 +185,11 @@ const getDdKeys = function() {
table: f.table || false,
resourceId: f.resourceId ? f.plaziName : false
}
}

if (f.resourceId) {

byResourceIds[resource] = f.plaziName
}

}
Expand Down Expand Up @@ -219,13 +228,11 @@ const dd2queries = function(queryObject) {
const doGroups = ['essential'];

if (queryObject[pk]) {
console.log(`pk key: ${pk}`);
console.log(`pk val: ${queryObject[pk]}`);
doGroups.push(...[ 'related', 'taxonStats' ]);

doGroups.push(...[ 'related', 'taxonStats' ]);
}
else {
console.log('no pk');

if (queryObject.facets) doGroups.push('facets');
if (queryObject.stats) doGroups.push('stats');
}
Expand Down
19 changes: 11 additions & 8 deletions api/v2/lib/qparts.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ const queryParts = {
tables: ['materialsCitations'],
constraint: [
'deleted = 0',
'latitude != ""',
'longitude != ""',
"latitude != ''",
"longitude != ''",
'treatmentId = @treatmentId'
],
sortBy: {},
Expand All @@ -232,7 +232,10 @@ const queryParts = {
'thumbnailUri'
],
tables: ['figureCitations'],
constraint: ['deleted = 0', 'treatmentId = @treatmentId'],
constraint: [
'deleted = 0',
'treatmentId = @treatmentId'
],
sortBy: {},
group: []
}
Expand Down Expand Up @@ -444,7 +447,7 @@ const queryParts = {
'treatments.id',
'treatments.treatmentId AS treatmentId',
'treatmentTitle',
'authorityName || ". " || authorityYear || ". <i>" || articleTitle || ".</i> " || journalTitle || ", " || journalYear || ", pp. " || pages || ", vol. " || journalVolume || ", issue " || journalIssue AS context'
"authorityName || '. ' || authorityYear || '. <i>' || articleTitle || '.</i> ' || journalTitle || ', ' || journalYear || ', pp. ' || pages || ', vol. ' || journalVolume || ', issue ' || journalIssue AS context"
],
tables: [
'treatments',
Expand Down Expand Up @@ -509,7 +512,7 @@ const queryParts = {
'treatments.id',
'treatments.treatmentId AS treatmentId',
'treatmentTitle',
'authorityName || ". " || authorityYear || ". <i>" || articleTitle || ".</i> " || journalTitle || ", " || journalYear || ", pp. " || pages || ", vol. " || journalVolume || ", issue " || journalIssue AS context'
"authorityName || '. ' || authorityYear || '. <i>' || articleTitle || '.</i> ' || journalTitle || ', ' || journalYear || ', pp. ' || pages || ', vol. ' || journalVolume || ', issue ' || journalIssue AS context"
],
tables: [
'treatments',
Expand Down Expand Up @@ -565,7 +568,7 @@ const queryParts = {
'treatments.id',
'treatments.treatmentId AS treatmentId',
'treatmentTitle',
'authorityName || ". " || authorityYear || ". <i>" || articleTitle || ".</i> " || journalTitle || ", " || journalYear || ", pp. " || pages || ", vol. " || journalVolume || ", issue " || journalIssue AS context'
"authorityName || '. ' || authorityYear || '. <i>' || articleTitle || '.</i> ' || journalTitle || ', ' || journalYear || ', pp. ' || pages || ', vol. ' || journalVolume || ', issue ' || journalIssue AS context"
],
tables: [
'treatments',
Expand Down Expand Up @@ -629,7 +632,7 @@ const queryParts = {
'treatments.id',
'treatments.treatmentId AS treatmentId',
'treatmentTitle',
'authorityName || ". " || authorityYear || ". <i>" || articleTitle || ".</i> " || journalTitle || ", " || journalYear || ", pp. " || pages || ", vol. " || journalVolume || ", issue " || journalIssue AS context'
"authorityName || '. ' || authorityYear || '. <i>' || articleTitle || '.</i> ' || journalTitle || ', ' || journalYear || ', pp. ' || pages || ', vol. ' || journalVolume || ', issue ' || journalIssue AS context"
],
tables: [
'treatments',
Expand Down Expand Up @@ -726,7 +729,7 @@ const queryParts = {
'treatments.id',
'treatments.treatmentId AS treatmentId',
'treatmentTitle',
'authorityName || ". " || authorityYear || ". <i>" || articleTitle || ".</i> " || journalTitle || ", " || journalYear || ", pp. " || pages || ", vol. " || journalVolume || ", issue " || journalIssue AS context'
"authorityName || '. ' || authorityYear || '. <i>' || articleTitle || '.</i> ' || journalTitle || ', ' || journalYear || ', pp. ' || pages || ', vol. ' || journalVolume || ', issue ' || journalIssue AS context"
],
tables: [
'treatments',
Expand Down
3 changes: 3 additions & 0 deletions api/v2/lib/zenodeo.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,16 @@ const getOneRecord = function(queryObject) {

// We are done if no records found
if (! data['num-of-records']) {

timer = process.hrtime(timer);
return Utils.dataForDelivery(timer, data, debug);
}

// more data from beyond the database
if (queryObject.resource === 'treatments') {

if (queryObject.xml && queryObject.xml === 'true') {

data.records[0].xml = getXml(queryObject.treatmentId);
}

Expand Down
17 changes: 14 additions & 3 deletions api/v2/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,21 @@ module.exports = {

halify: function({records, uri, resource, id}) {
records.forEach(row => {
row._links = this.makeSelfLink({
// row._links = this.makeLink({
// uri: uri,
// path: resource.toLowerCase(),
// queryString: `${id}=${row[id]}`
// })
row._links = {};
row._links.self = this.makeLink({
uri: uri,
path: resource.toLowerCase(),
queryString: `${id}=${row[id]}`
params: {
path: resource.toLowerCase(),
resourceId: {
key: id,
val: row[id]
}
}
})
});

Expand Down

0 comments on commit 6e72fb3

Please sign in to comment.