Kest

Search

Search the documentation

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 auth

generate has the alias g. Each schematic also has a short alias.

SchematicAliasWrites
modulemoa @Module
controllercoa @Controller with a first route
servicesan @Injectable
resourceresmodule, controller, service, model and Create/Update DTOs, wired together
guardgua Guard
interceptoritcan Interceptor
pipepia Pipe
filterfan ExceptionFilter
middlewaremia Middleware
decoratorda parameter decorator: annotation plus resolver
aspectasa method decorator: annotation plus wrapper
gatewaygaa WebSocket gateway, declared like a controller (adds the websocket dependency)
resolverrsa GraphQL resolver, declared like a controller (adds the graphql dependency)
processorpra queue processor (adds the queue dependency)
entity, repository, dtoe, r, dtORM entity, repository, validated DTO
libraryliba 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 AppModule

kest g resource orders writes a module, controller, service, model and Create/Update DTOs, wired together: a CRUD API you can run immediately.

Read more