Converted models to TypeORM models

This commit is contained in:
Alexis
2021-07-31 12:38:04 +02:00
parent 477dc14e63
commit dce8bf95d6
12 changed files with 113 additions and 450 deletions

View File

@@ -1,77 +1,22 @@
import { DataTypes, Model, Optional } from "sequelize";
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm"
import { AuracleDatabaseDriver } from "../../AuracleDatabaseDriver";
interface UserAttributes {
id: number
uuid: string
mail: string
password: string
name: string
avatar: string
gender: string
verified: boolean
}
interface UserCreationAttributes extends Optional<UserAttributes, 'id'> { }
export class User extends Model<UserAttributes, UserCreationAttributes> implements UserAttributes {
public readonly id!: number
@Entity()
export class User {
@PrimaryGeneratedColumn('uuid')
public readonly uuid!: string
@Column()
public readonly mail!: string
@Column()
public readonly password!: string
@Column()
public name!: string
@Column()
public avatar: string
@Column()
public gender: string
@Column()
public verified: boolean
public readonly createdAt!: Date;
public readonly updatedAt!: Date;
}
export default () => {
User.init(
{
id: {
type: DataTypes.INTEGER.UNSIGNED,
autoIncrement: true,
primaryKey: true
},
uuid: {
type: DataTypes.UUID,
allowNull: false,
unique: true,
defaultValue: DataTypes.UUIDV4
},
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: 'au_users',
sequelize: AuracleDatabaseDriver,
}
)
}