Skip to content

[CLI] Generate Controller with CRUD methods #727

@kjdelisle

Description

@kjdelisle

Story

As a loopback4 user, I would like to run a CLI command to generate a default set of CRUD API methods based on a model and its associated datasource(s) so that I can avoid hand-writing each of these functions manually.

Acceptance Criteria

  • Prompt for controller name
  • Validate controller name
  • Prompt for whether or not they want to use the RestCrudController base template
  • If RestCrudController:
    • Generate new class that extends this type (should be a very small template!)
    async create(obj: T) : Promise<T>
    count(where: Where) : Promise<number>
    find(filter: Filter) : Promise<T[]>
    updateAll(where: Where, obj: T) : Promise<number>
    deleteAll(where: Where): Promise<number>

    findById(id: ID) :  Promise<T>
    updateById(id: ID, obj: T) :  Promise<boolean>
    deleteById(id: ID) :  Promise<boolean>
  • else
    • Fall back to generating an empty controller
  • Document this feature on loopback.io
  • Release the CLI package
  • Write a blog post about how awesome this new feature is and how to use it.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions