Skip to content
Merged
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
27 changes: 14 additions & 13 deletions lib/expose.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,26 @@ function expose(definitions, methods, path, directory) {
});
}


// add validation
let validation = '';
let validators = [];
if (secure.length > 0) {
validation = '';
secure.forEach((property) => {
let origin = property.type;
if (origin === 'path') {origin = 'req.params' }else {origin = 'this.data'}
validation = `
async validate() {
try {
${origin}['${property.property}'] = await global.FieldValidator.validate('${property.value}','${property.parameter_type}',${origin}['${property.property}'], this.req, this.res)
} catch (error) {
console.log('validation error', error);
throw new Error(error.message);
}
}
`;
if (origin === 'path') { origin = 'req.params' } else { origin = 'this.data' };
validators.push(`${origin}['${property.property}'] = await global.FieldValidator.validate('${property.value}','${property.parameter_type}',${origin}['${property.property}'], this.req, this.res);`);
});

validation = `
async validate() {
try {
${validators.join('\n')}
} catch (error) {
console.log('validation error', error);
throw new Error(error.message);
}
}
`;
}

// compile the file
Expand Down