Skip to content
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

ParsedRequest is broken with newest changes in NestJS #443

Closed
BSStefan opened this issue Mar 14, 2020 · 3 comments · Fixed by #446
Closed

ParsedRequest is broken with newest changes in NestJS #443

BSStefan opened this issue Mar 14, 2020 · 3 comments · Fixed by #446

Comments

@BSStefan
Copy link

BSStefan commented Mar 14, 2020

NestJs version: 7.0.1
Package version: 4.4.1

There is a breaking change in the way how we create custom decorators in NestJS v7:
https://docs.nestjs.com/migration-guide#custom-route-decorators
And that will break this decorator: https://github.com/nestjsx/crud/blob/master/packages/crud/src/decorators/parsed-request.decorator.ts
Fix should be easy but it is breaking change like in nestjs migration above. :)

Also there is a problem with getManyBase and getOneBase. Request here:
https://github.com/nestjsx/crud/blob/master/packages/crud/src/crud/crud-routes.factory.ts#L208 is undefined, so i get this message from typeorm-crud.service.js: Cannot destructure property parsed of 'undefined' or 'null'.

@lywzx
Copy link

lywzx commented Mar 15, 2020

hello, because of nestjs/core modified, we need change these files:

factory: (_, req) => req[paramtype],

changed like this:

factory: (_, req) => req.switchToHttp().getRequest()[paramtype],

return req[PARSED_CRUD_REQUEST_KEY];

changed like this:

req.switchToHttp().getRequest()[PARSED_CRUD_REQUEST_KEY]

So I wrote the following code to temporarily fix the problem

create file: crud-fix.js

const fs = require('fs');
const files = ['node_modules/@nestjsx/crud/lib/decorators/parsed-request.decorator.js', 'node_modules/@nestjsx/crud/lib/crud/reflection.helper.js'];
fs.writeFileSync(files[0], fs.readFileSync(files[0]).toString().replace(/return req\[([^\]]*)]/, 'return req.switchToHttp().getRequest()[$1]'));
fs.writeFileSync(files[1], fs.readFileSync(files[1]).toString().replace('req[paramtype]', 'req.switchToHttp().getRequest()[paramtype]'));

then run:

node crud-fix.js

michaelyali added a commit that referenced this issue Mar 17, 2020
…anges

fixed custom routes params caused by NestJs v7 breaking changes

fix #443
@michaelyali
Copy link
Member

Fixed in v4.4.2

@neutron92
Copy link

@michaelyali @lywzx #830

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants