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,69 @@
import { DataTypes, Model, Optional } from "sequelize";
import { AuracleDatabaseDriver } from "../../AuracleDatabaseDriver";
interface UserAttributes {
id: number
mail: string
password: string
name: string
avatar: string
gender: string
verified: boolean
}
interface UserCreationAttributes extends Optional<UserAttributes, 'id'> { }
class User extends Model<UserAttributes, UserCreationAttributes> implements UserAttributes {
public id!: number
public readonly mail!: string
public readonly password!: string
public name!: string
public avatar: string
public gender: string
public verified: boolean
public readonly createdAt!: Date;
public readonly updatedAt!: Date;
}
export default () => {
User.init(
{
id: {
type: DataTypes.INTEGER.UNSIGNED,
autoIncrement: true,
primaryKey: true
},
mail: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
password: {
type: DataTypes.STRING,
allowNull: false,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
avatar: {
type: DataTypes.STRING,
},
gender: {
type: DataTypes.STRING,
},
verified: {
type: DataTypes.BOOLEAN,
},
},
{
tableName: 'user',
sequelize: AuracleDatabaseDriver,
}
)
}