Skip to content

Commit 6e72fb3

Browse files
committed
more clean up, more comments, plus fixed a bug in the generation of ddKeys in dd2queries.js
1 parent dc3f3c6 commit 6e72fb3

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

api/v2/lib/dd2queries.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,14 @@ const calcQuery = function(ddKeys, queryGroup, query, queryObject, matchTables,
119119
const offset = queryObject.offset || query.offset || 0;
120120

121121
if (matchTables.length) {
122+
122123
tables.push(...matchTables);
123124
}
124125

125126
if (queryGroup !== 'taxonStats' && queryGroup !== 'related') {
127+
126128
if (addedConstraint.length) {
129+
127130
constraint.push(...addedConstraint);
128131
}
129132
}
@@ -134,11 +137,13 @@ const calcQuery = function(ddKeys, queryGroup, query, queryObject, matchTables,
134137
// now, figure out the sort params, if applicable
135138
let [sortcol, sortdir] = ['', ''];
136139
if (queryObject.sortBy && Object.keys(sortBy).length) {
140+
137141
[sortcol, sortdir] = calcSortParams(sortBy, queryObject);
138142
sql += ` ORDER BY ${sortcol} ${sortdir}`;
139143
}
140144

141145
if (group && Object.keys(group).length) {
146+
142147
sql += ` GROUP BY ${group.join(' ')}`;
143148
}
144149

@@ -180,7 +185,11 @@ const getDdKeys = function() {
180185
table: f.table || false,
181186
resourceId: f.resourceId ? f.plaziName : false
182187
}
188+
}
189+
190+
if (f.resourceId) {
183191

192+
byResourceIds[resource] = f.plaziName
184193
}
185194

186195
}
@@ -219,13 +228,11 @@ const dd2queries = function(queryObject) {
219228
const doGroups = ['essential'];
220229

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

232+
doGroups.push(...[ 'related', 'taxonStats' ]);
226233
}
227234
else {
228-
console.log('no pk');
235+
229236
if (queryObject.facets) doGroups.push('facets');
230237
if (queryObject.stats) doGroups.push('stats');
231238
}

api/v2/lib/qparts.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ const queryParts = {
215215
tables: ['materialsCitations'],
216216
constraint: [
217217
'deleted = 0',
218-
'latitude != ""',
219-
'longitude != ""',
218+
"latitude != ''",
219+
"longitude != ''",
220220
'treatmentId = @treatmentId'
221221
],
222222
sortBy: {},
@@ -232,7 +232,10 @@ const queryParts = {
232232
'thumbnailUri'
233233
],
234234
tables: ['figureCitations'],
235-
constraint: ['deleted = 0', 'treatmentId = @treatmentId'],
235+
constraint: [
236+
'deleted = 0',
237+
'treatmentId = @treatmentId'
238+
],
236239
sortBy: {},
237240
group: []
238241
}
@@ -444,7 +447,7 @@ const queryParts = {
444447
'treatments.id',
445448
'treatments.treatmentId AS treatmentId',
446449
'treatmentTitle',
447-
'authorityName || ". " || authorityYear || ". <i>" || articleTitle || ".</i> " || journalTitle || ", " || journalYear || ", pp. " || pages || ", vol. " || journalVolume || ", issue " || journalIssue AS context'
450+
"authorityName || '. ' || authorityYear || '. <i>' || articleTitle || '.</i> ' || journalTitle || ', ' || journalYear || ', pp. ' || pages || ', vol. ' || journalVolume || ', issue ' || journalIssue AS context"
448451
],
449452
tables: [
450453
'treatments',
@@ -509,7 +512,7 @@ const queryParts = {
509512
'treatments.id',
510513
'treatments.treatmentId AS treatmentId',
511514
'treatmentTitle',
512-
'authorityName || ". " || authorityYear || ". <i>" || articleTitle || ".</i> " || journalTitle || ", " || journalYear || ", pp. " || pages || ", vol. " || journalVolume || ", issue " || journalIssue AS context'
515+
"authorityName || '. ' || authorityYear || '. <i>' || articleTitle || '.</i> ' || journalTitle || ', ' || journalYear || ', pp. ' || pages || ', vol. ' || journalVolume || ', issue ' || journalIssue AS context"
513516
],
514517
tables: [
515518
'treatments',
@@ -565,7 +568,7 @@ const queryParts = {
565568
'treatments.id',
566569
'treatments.treatmentId AS treatmentId',
567570
'treatmentTitle',
568-
'authorityName || ". " || authorityYear || ". <i>" || articleTitle || ".</i> " || journalTitle || ", " || journalYear || ", pp. " || pages || ", vol. " || journalVolume || ", issue " || journalIssue AS context'
571+
"authorityName || '. ' || authorityYear || '. <i>' || articleTitle || '.</i> ' || journalTitle || ', ' || journalYear || ', pp. ' || pages || ', vol. ' || journalVolume || ', issue ' || journalIssue AS context"
569572
],
570573
tables: [
571574
'treatments',
@@ -629,7 +632,7 @@ const queryParts = {
629632
'treatments.id',
630633
'treatments.treatmentId AS treatmentId',
631634
'treatmentTitle',
632-
'authorityName || ". " || authorityYear || ". <i>" || articleTitle || ".</i> " || journalTitle || ", " || journalYear || ", pp. " || pages || ", vol. " || journalVolume || ", issue " || journalIssue AS context'
635+
"authorityName || '. ' || authorityYear || '. <i>' || articleTitle || '.</i> ' || journalTitle || ', ' || journalYear || ', pp. ' || pages || ', vol. ' || journalVolume || ', issue ' || journalIssue AS context"
633636
],
634637
tables: [
635638
'treatments',
@@ -726,7 +729,7 @@ const queryParts = {
726729
'treatments.id',
727730
'treatments.treatmentId AS treatmentId',
728731
'treatmentTitle',
729-
'authorityName || ". " || authorityYear || ". <i>" || articleTitle || ".</i> " || journalTitle || ", " || journalYear || ", pp. " || pages || ", vol. " || journalVolume || ", issue " || journalIssue AS context'
732+
"authorityName || '. ' || authorityYear || '. <i>' || articleTitle || '.</i> ' || journalTitle || ', ' || journalYear || ', pp. ' || pages || ', vol. ' || journalVolume || ', issue ' || journalIssue AS context"
730733
],
731734
tables: [
732735
'treatments',

api/v2/lib/zenodeo.js

+3
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,16 @@ const getOneRecord = function(queryObject) {
167167

168168
// We are done if no records found
169169
if (! data['num-of-records']) {
170+
170171
timer = process.hrtime(timer);
171172
return Utils.dataForDelivery(timer, data, debug);
172173
}
173174

174175
// more data from beyond the database
175176
if (queryObject.resource === 'treatments') {
177+
176178
if (queryObject.xml && queryObject.xml === 'true') {
179+
177180
data.records[0].xml = getXml(queryObject.treatmentId);
178181
}
179182

api/v2/utils.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,21 @@ module.exports = {
250250

251251
halify: function({records, uri, resource, id}) {
252252
records.forEach(row => {
253-
row._links = this.makeSelfLink({
253+
// row._links = this.makeLink({
254+
// uri: uri,
255+
// path: resource.toLowerCase(),
256+
// queryString: `${id}=${row[id]}`
257+
// })
258+
row._links = {};
259+
row._links.self = this.makeLink({
254260
uri: uri,
255-
path: resource.toLowerCase(),
256-
queryString: `${id}=${row[id]}`
261+
params: {
262+
path: resource.toLowerCase(),
263+
resourceId: {
264+
key: id,
265+
val: row[id]
266+
}
267+
}
257268
})
258269
});
259270

0 commit comments

Comments
 (0)