Matteo
September 25, 2024, 2:07pm
1
Hi.
We’re migrating from forest-express-sequelize
to @forestadmin/agent
.
We have a sequelize model with an integer field with a max value defined in the model itself.
In the model we have max: 80
which acts as a <=
and the new agent (while parsing the validations) puts a 'is less than'
in the .forestadmin-schema.json
file.
But now in the new agent forest admin panel, the value 80 is not accepted any more.
Here is the error shown in forest with the new agent:
NB: with the old agent the very same model used to work, correctly validating (including) the endpoint numbers: 80 <= 80
.
Field definition in the sequelize model:
ageTo: {
type: DataTypes.INTEGER,
allowNull: true,
comment: 'Max boundary (inclusive) for age restrictions',
field: 'age_to',
validate: {
min: 0,
max: 80,
},
},
In sequelize, the min/max values are included : Validations & Constraints | Sequelize
May you please have a check about this?
Thank you.
Matteo
1 Like
Hello @Matteo
Thanks for your report.
Unfortunately, we don’t support LessThanEqual
and GreaterThanEqual
validators yet… I will have a look at adding them today.
In the meanwhile, I have made this tiny monkey patch.
ForestAdmin:main
← ForestAdmin:fix/sequelize-model-validation-min-max
opened 02:36PM - 25 Sep 24 UTC
## Definition of Done
### General
- [ ] Write an explicit title for the Pu… ll Request, following [Conventional Commits specification](https://www.conventionalcommits.org)
- [ ] Test manually the implemented changes
- [ ] Validate the code quality (indentation, syntax, style, simplicity, readability)
### Security
- [ ] Consider the security impact of the changes made
I will let you know once we have more news about that.
Kind regards,
Morgan
1 Like
Hello @Matteo ,
I’m happy to annonce that we rework the agent and the sequelize datasource in order to correctly support min
/max
sequelize validators .
To be capable of this we did add a new required feature (two new well known operators: GreaterThanOrEqual & LessThanOrEqual along side the same validators). It’s a nice improvement too to meet industry standards.
ForestAdmin:main
← ForestAdmin:fix/validation-lte-gte
opened 12:45PM - 26 Sep 24 UTC
## Definition of Done
### General
- [ ] Write an explicit title for the Pu… ll Request, following [Conventional Commits specification](https://www.conventionalcommits.org)
- [ ] Test manually the implemented changes
- [ ] Validate the code quality (indentation, syntax, style, simplicity, readability)
### Security
- [ ] Consider the security impact of the changes made
Example done with Sequelize
Sequelize model
sequelize.define('place', {
name: DataTypes.STRING,
address: DataTypes.STRING,
latitude: {
type: DataTypes.INTEGER,
validate: {
min: -90,
max: 90,
},
},
longitude: {
type: DataTypes.INTEGER,
validate: {
min: -180,
max: 180,
},
},
});
You can upgrade to the latest @forestadmin/datasource-sequelize
version and also bump to the latest @forestadmin/agent
version.
Let’s us know if it works for you.
Kind regards,
Morgan
2 Likes
Matteo
September 27, 2024, 2:23pm
4
Thank you very much @morganperre ,
as this is not the first time you pull the chestnuts out of the fire
Your help and your responsiveness is greatly appreciated.
Thank you!
Matteo
1 Like
You’re welcome.
I hope that you will finalize the migration successfully. For sure, you help us improve the new agent with new features and more accurate behaviors.
Kind regards,
Morgan
1 Like