0.1.17 • Published 5 years ago

typecrud v0.1.17

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

TypeCRUD

This library aims to be a drop-in CRUD route generator for node.js express applications, using TypeORM. TypeCRUD works if you are using the active record pattern of TypeORM, extending your models from BaseEntity.

Usage

To let TypeCRUD generate routes, simply use the provided TypeCrud class:

// generates all CRUD endpoints on /events for the Event class
app.use(new TypeCrud(Event, '/events').router)

By default, TypeCrud will generate all CRUD routes (Create/Read/Update/Delete) as follows:

  • POST /
  • GET /
  • GET /:id
  • PUT/PATCH /:id
  • DELETE /:id

You can adjust this using the (optional) parameter that takes an array of CRUDType.

// generates only a POST endpoint on /events for the Event class
app.use('/events', new TypeCrud(Event, { crudTypes: [CRUDType.Create] }).router)

There are also a couple of methods that allow you to further customize the routes:

const typeCrudRouter = new TypeCrud(Event, {
  filterBy: ['name'], // allows to append query parameters to filter, such as ?name=superevent
  includeRelations: ['guests'], // includes fully populated relations based on their property name
  isPaginatable: true, // enabled pagination
  softDeleteBy: 'deletedAt', // DELETE does not remove the entitiy, but only sets a "deletedAt" flag. GET will not return those.
  hooks: {
    pre: {
      [CRUDType.Create]: (request: Express.Request, entity: Guestlist) => {
        entity.owner = request.user.owner
      }
    }
  }
}).router
0.1.17

5 years ago

0.1.16

5 years ago

0.1.15

5 years ago

0.1.14

5 years ago

0.1.13

5 years ago

0.1.12

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago