-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String parameters cause ParameterParseJsonError in routing-controllers when using EntityFromParam. #11
Comments
Having this issue as well :/. Is there no way to force no parsing? |
Well, the same issue is described here #22, would be great to fix it. |
@c0n5pir4cy Ok, I'll check it tomorrow, thank you |
If anybody interesting I made up with this solution import { createParamDecorator } from "routing-controllers";
import { Action } from "routing-controllers/Action";
import { EntityParamOptions } from "typeorm-routing-controllers-extensions";
import { entityTransform } from "typeorm-routing-controllers-extensions/util/Utils";
export function EntityFromParams(paramName: string = "id", options?: EntityParamOptions): (object: object, method: string, index: number) => void {
return createParamDecorator({
required: Boolean(options && options.required),
value(action: Action): Promise<any> {
const value = action.request.params[paramName];
return entityTransform(value, (this as any).targetType, false, options);
},
});
} |
I faced this problem ( |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using a parameter with a string as a value when using EntityFromParameter causes a ParameterParseJsonError to be thrown in routing-controllers.
I've dug down and found out this is because routing-controllers sees the parameters type as the type of entity you're trying to pull back and sets isTargetObject to true in ActionParameterHandler. Causing it to be parsed as a JSON object.
I've made a fix that resolves the issue by setting explicitType to "string" in the decorator, which forces the value to be parsed as a string. This seems to work for both string and number types as the parameter.
The text was updated successfully, but these errors were encountered: