Skip to content

Commit

Permalink
add ahem dynamic import
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleguido committed Oct 2, 2024
1 parent 9cbb278 commit 592d7da
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/services/sequelize.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,22 @@ class SequelizeService {
this.name = String(name)
this.modelName = String(modelName || name)
this.sequelize = sequelize.client(app.get('sequelize'))
import(`../models/${this.modelName}.model`)
.then(m => {
debug('MODEL', m)
if (m.Model) {
this.Model = m.Model
this.sequelizeKlass = this.Model.sequelize(this.sequelize)
} else {
this.Model = m.default
this.sequelizeKlass = this.Model.sequelize(this.sequelize)
}

this.Model = require(`../models/${this.modelName}.model`)
this.sequelizeKlass = this.Model.sequelize(this.sequelize)
debug(`Configuring service: ${this.name} (model:${this.modelName}) success!`)
})
.catch(err => {
throw new Error(`Sequelize Model not found in import: ${this.modelName}`, err)
})

this.cacheReads = cacheReads
this.cacheManager = app.get('cacheManager')
Expand Down

0 comments on commit 592d7da

Please sign in to comment.