SoftwareBrothers / adminjs-sequelizejs

Sequelizejs adapter for AdminBro
MIT License
27 stars 34 forks source link

Can't handle Sequelize UniqueConstraintError #17

Closed blurey8 closed 4 years ago

blurey8 commented 4 years ago

My model:

const Superuser = sequelize.define('superuser', {
    email: {
      type: DataTypes.STRING,
      allowNull: false,
      unique: true
    },
   ...
}

When I create new instance with existing email on admin bro dashboard, the debug console throw SequelizeUniqueConstraintError: Validation error and the loading on save button didn't stop. I want to prevent this error just like Sequelize ValidationError. Since UniqueConstraintError is subclass of ValidationError, I suggest change on resource.js on admin-bro-sequelizejs.

before:

if (error.name === SEQUELIZE_VALIDATION_ERROR) {
    throw this.createValidationError(error)
}

suggested:

const SequelizeValidationError = require('sequelize').ValidationError
...
if (error instanceof SequelizeValidationError) {
    throw this.createValidationError(error)
}

And all works just like ValidationError.

Can we get update on admin-bro-sequelizejs or is there something I can do to fix this? (either make PR or change something in my code to handle this).

github-actions[bot] commented 4 years ago

:tada: This issue has been resolved in version 1.0.0-beta.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] commented 4 years ago

:tada: This issue has been resolved in version 1.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: