Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NestJs: Is there a way to generate a resource, already wired to a TypeOrm entity?

I'm playing around with NestJs, for the purpose of automating REST API creation as much as possible. So far, I do not see any quick way to create a fully functional resource.

For example, if I use the Nest CLI like this:

nest g resource

And call my resource "posts", I get a module, a controller, a service, dto's and an empty entity

In order to make it functional, I would need to manually go through every method of the PostsService, remove the placeholder, and wire it to the corresponding entity method. For example, this needs to be altered:

findAll() {
    return `This action returns all posts`;
  }

to:

findAll(){
 return this.postsRepository.find()
}

Not to mention, that I need to add various decorators and imports. In my opinion, this undermines the whole idea of CRUD generator. A lot of files are created for me, but they need to be altered.

Is there any way in Nest to create a fully functioning resource(of course i would still need to manually set the fields of the entity), with all parts wired to each other correctly?

like image 919
i.brod Avatar asked Oct 15 '25 04:10

i.brod


1 Answers

I also tried to find something similar. And this is the best what I found https://github.com/ashinzekene/generator-nestjs-app I think if such a thing existed, then it should have been mentioned in this repository. https://github.com/nestjs/awesome-nestjs But it's not. Maybe I'm wrong 😑

like image 182
overkektus Avatar answered Oct 16 '25 16:10

overkektus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!