Skip to content

Commit

Permalink
argument index fix
Browse files Browse the repository at this point in the history
  • Loading branch information
iyobo committed May 1, 2021
1 parent ed60500 commit 942cdc1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"koa-router": "*",
"koa-session": "*",
"lodash": "^4.17.15",
"reflect-metadata": "^0.1.13"
"reflect-metadata": "*"
},
"devDependencies": {
"@types/boom": "^7.3.0",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'reflect-metadata'
import {generateRoutes} from './util/generateRoutes';
import {importClassesFromDirectories} from './util/importClasses';
import Boom from '@hapi/boom';
Expand Down
20 changes: 10 additions & 10 deletions src/util/generateRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,27 @@ async function _determineArgument(
type,
options: AmalaOptions
) {
let result;
let values;

if (argumentInjectorTranslations[injectSource]) {

result = await argumentInjectorTranslations[injectSource](ctx, injectOptions);
values = await argumentInjectorTranslations[injectSource](ctx, injectOptions);

} else {
// not a special arg injector? No special translation exists so just use CTX.
result = ctx[injectSource];
if (result && injectOptions) {
result = result[injectOptions];
values = ctx[injectSource];
if (values && injectOptions) {
values = values[injectOptions];
}

//TODO: implement custom function capability here for arg injectors
}

// validate if this is a class. If it is a class, validate it
if (result && isClass(type)) {
result = await plainToClass(type, result);
if (values && isClass(type)) {
values = await plainToClass(type, values);

const errors = await validate(result, options.validatorOptions); // TODO: wrap around this to trap runtime errors
const errors = await validate(values, options.validatorOptions); // TODO: wrap around this to trap runtime errors

if (errors.length > 0) {
throw boom.badData(
Expand All @@ -102,10 +102,10 @@ async function _determineArgument(
);
}
} else if (type === Number) {
result = Number(result);
values = Number(values);
}

return result;
return values;
}

async function _generateEndPoints(
Expand Down

0 comments on commit 942cdc1

Please sign in to comment.