Recipes
CRUD generator
Generate a whole resource with one command.
kest g resource orders # module, controller, service, model and DTOs: a CRUD API
kest g controller admin/users # in the folder admin/users
kest g guard authgenerate has the alias g. Each schematic also has a short alias.
| Schematic | Alias | Writes |
|---|---|---|
module | mo | a @Module |
controller | co | a @Controller with a first route |
service | s | an @Injectable |
resource | res | module, controller, service, model and Create/Update DTOs, wired together |
guard | gu | a Guard |
interceptor | itc | an Interceptor |
pipe | pi | a Pipe |
filter | f | an ExceptionFilter |
middleware | mi | a Middleware |
decorator | d | a parameter decorator: annotation plus resolver |
aspect | as | a method decorator: annotation plus wrapper |
gateway | ga | a WebSocket gateway, declared like a controller (adds the websocket dependency) |
resolver | rs | a GraphQL resolver, declared like a controller (adds the graphql dependency) |
processor | pr | a queue processor (adds the queue dependency) |
entity, repository, dto | e, r, dt | ORM entity, repository, validated DTO |
library | lib | a Gradle subproject under libs/, included and added to your build |
Wiring into modules
Like nest g, the new class is added to the nearest @Module: the one in the same folder, else the closest one above, else AppModule. A controller goes into controllers, a service, guard or processor into providers, a module or resource into imports, and the import line is added. --no-update-module skips that. A file that already exists is never overwritten.
@Module(
imports = [JacksonJsonModule::class, ValidationModule::class, OrdersModule::class],
controllers = [HealthController::class],
providers = [AuthGuard::class],
)
class AppModulekest g resource orders writes a module, controller, service, model and Create/Update DTOs, wired together: a CRUD API you can run immediately.