Skip to content

blueskydigital/polymorphic-crud-resource

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

polymorphic-crud-resource

build status

Express resource that is able to handle polymorphic One2Many assotiations with sequelize.

For example we have a model person, that we want to perform CRUD on. And we want to internationalize its attribute description to retrieve this:

...
"description": [
  {"lang": "cz", "value": "CZTrolol"}
  {"lang": "en", "value": "ENTrolol"}
]

So we have to have model translats with joining attributes. Then we create CRUD like this:

app = express()
personsCRUD = CRUD sequelize.models.person, [
  name: 'description'
  model: sequelize.models.translats
  fk: 'entity_id'
  defaults: entity_type: 0  # polymorphic ID
]
# mount it to express app
personsCRUD.initApp(app)

app middlewares

You can specify for each operation an array of middlewares when doing initApp:

authMWare = expressJwt(secret: process.env.SERVER_SECRET)

personsCRUD.initApp app,
  'create': [authMWare]
  'update': [authMWare]
  'delete': [authMWare]

About

resource that is able to handle polymorphic One2Many assotiations

Resources

Stars

Watchers

Forks

Packages

No packages published