Skip to content
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
21 changes: 5 additions & 16 deletions lib/querier.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,9 @@ function getProperties(params) {
const parameters = [];
const questions = [];
params.forEach((param) => {
if (param.in && param.in === 'path' || param.in === 'query') {
if (param.name) {
parameters.push(param.name);
}
if (param.in && param.in === 'body') {
const { '$ref': ref } = param.schema || {};
if (ref) {
parameters.push(ref.split('/').slice(-1)[0]);
}
}
questions.push('?');
});
return {
Expand All @@ -31,7 +25,7 @@ function getProperties(params) {
/**
* Create SQL query for the method
* @param data {object} - object with definitions & methods
* @returns {*}
* @returns {object} - same as data, but with updated methods
*/
function querier(data) {
try {
Expand All @@ -50,14 +44,9 @@ function querier(data) {
}
});

if (!special) {
const { parameters, questions } = getProperties(method.parameters);
mutable.methods[m].query = {
content: `const results = await dal.query("SELECT FN_${method.methodName}(${questions})", [${parameters}], { redis: true });`,
};
} else {

}
const { parameters, questions } = getProperties(method.parameters, special);
mutable.methods[m].query = `const results = await dal.query("${special ? 'CALL SP_' : 'SELECT FN_'}${method.methodName}(${questions})", `
+ `[${parameters}], { redis: ${!special} });`;
});

return mutable;
Expand Down
2 changes: 1 addition & 1 deletion templates/multi-method.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

{{#query}}
/*
{{&content}}
{{&query}}
*/
{{/query}}
{{^query}}
Expand Down