Automated model registration

This commit is contained in:
Alexis
2021-07-20 22:03:20 +02:00
parent c03a5d62ec
commit 4be8a25370
17 changed files with 101 additions and 52 deletions

View File

@@ -0,0 +1,54 @@
import { DataTypes, Model, Optional } from "sequelize";
import { AuracleDatabaseDriver } from "../../AuracleDatabaseDriver";
interface IngredientAttributes {
id: number
name: string
description: string
published: boolean
}
interface IngredientCreationAttributes extends Optional<IngredientAttributes, 'id'> { }
class Ingredient extends Model<IngredientAttributes, IngredientCreationAttributes> implements IngredientAttributes {
public id!: number
public name!: string
public description!: string
public published: boolean
public readonly createdAt!: Date;
public readonly updatedAt!: Date;
}
export default () => {
Ingredient.init(
{
id: {
type: DataTypes.INTEGER.UNSIGNED,
autoIncrement: true,
primaryKey: true
},
name: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
description: {
type: DataTypes.STRING,
allowNull: false,
},
published: {
type: DataTypes.BOOLEAN,
defaultValue: false
}
},
{
tableName: 'ingredient',
sequelize: AuracleDatabaseDriver,
}
)
}