Automated model registration
This commit is contained in:
46
src/database/models/users/Role.ts
Normal file
46
src/database/models/users/Role.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { DataTypes, Model, Optional } from "sequelize";
|
||||
|
||||
import { AuracleDatabaseDriver } from "../../AuracleDatabaseDriver";
|
||||
|
||||
interface RoleAttributes {
|
||||
id: number
|
||||
name: string
|
||||
description: string
|
||||
}
|
||||
|
||||
interface RoleCreationAttributes extends Optional<RoleAttributes, 'id'> { }
|
||||
|
||||
class Role extends Model<RoleAttributes, RoleCreationAttributes> implements RoleAttributes {
|
||||
public id!: number
|
||||
public name!: string
|
||||
public description!: string
|
||||
|
||||
public readonly createdAt!: Date;
|
||||
public readonly updatedAt!: Date;
|
||||
}
|
||||
|
||||
export default () => {
|
||||
Role.init(
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
autoIncrement: true,
|
||||
primaryKey: true
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: true
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: true
|
||||
},
|
||||
},
|
||||
{
|
||||
tableName: 'role',
|
||||
sequelize: AuracleDatabaseDriver,
|
||||
}
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user