Last active
April 3, 2025 07:19
-
-
Save andrewjmead/a227b79c04af149b78f4 to your computer and use it in GitHub Desktop.
Sequelize model validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = function (sequelize, DataTypes) { | |
| return sequelize.define('todo', { | |
| description: { | |
| type: DataTypes.STRING, | |
| allowNull: false, | |
| validate: { | |
| len: [1, 250], | |
| isString: function (value) { | |
| if (typeof value !== 'string') { | |
| throw new Error('Description must be a string'); | |
| } | |
| } | |
| } | |
| }, | |
| completed: { | |
| type: DataTypes.BOOLEAN, | |
| allowNull: false, | |
| defaultValue: false, | |
| validate: { | |
| isBoolean: function (value) { | |
| if (typeof value !== 'boolean') { | |
| throw new Error('Completed must be a boolean'); | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment