Converted models to TypeORM models
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import express, { Application } from 'express'
|
import express, { Application } from 'express'
|
||||||
import { Sequelize } from 'sequelize'
|
import { Connection } from 'typeorm'
|
||||||
import { AuracleApiRouter } from './AuracleApiRouter'
|
import { AuracleApiRouter } from './AuracleApiRouter'
|
||||||
|
|
||||||
export class AuracleApi {
|
export class AuracleApi {
|
||||||
public app: Application
|
public app: Application
|
||||||
public port: number
|
public port: number
|
||||||
@@ -11,7 +10,7 @@ export class AuracleApi {
|
|||||||
constructor(
|
constructor(
|
||||||
init: {
|
init: {
|
||||||
port: any
|
port: any
|
||||||
database: Sequelize
|
database: Promise<Connection>
|
||||||
routers?: Array<AuracleApiRouter>
|
routers?: Array<AuracleApiRouter>
|
||||||
modules?: Array<any>
|
modules?: Array<any>
|
||||||
middlewares?: Array<any>
|
middlewares?: Array<any>
|
||||||
@@ -48,11 +47,15 @@ export class AuracleApi {
|
|||||||
* Links the API with a Sequelize Database Object
|
* Links the API with a Sequelize Database Object
|
||||||
* @param db_driver A Sequelize instance
|
* @param db_driver A Sequelize instance
|
||||||
*/
|
*/
|
||||||
private db_connect = async (db_driver: Sequelize) => {
|
private db_connect = async (db_driver: Promise<Connection>) => {
|
||||||
try {
|
try {
|
||||||
const connection = await db_driver.authenticate();
|
const connection = await db_driver
|
||||||
console.info('Connection has been established successfully.')
|
console.info('Connection has been established successfully.')
|
||||||
|
|
||||||
|
// Builds the data schema from registered entities
|
||||||
|
await connection.synchronize()
|
||||||
|
console.info('Database schema has been generated successfully.')
|
||||||
|
|
||||||
return connection
|
return connection
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Unable to connect to the database.')
|
console.error('Unable to connect to the database.')
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
import { Sequelize } from 'sequelize'
|
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
|
import { createConnection } from 'typeorm';
|
||||||
import { dbConfig } from './config'
|
import { dbConfig } from './config'
|
||||||
|
|
||||||
export let AuracleDatabaseDriver: Sequelize;
|
export const AuracleDatabaseDriver = createConnection(dbConfig);
|
||||||
|
|
||||||
// Creates the sequelize instance
|
|
||||||
AuracleDatabaseDriver = new Sequelize(dbConfig)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches all Typescript files from a given directory
|
* Fetches all Typescript files from a given directory
|
||||||
@@ -36,16 +33,9 @@ export const fetchAllTypescriptFiles = (dir: string, acc: string[] = []): string
|
|||||||
const modelDir = __dirname + '/models'
|
const modelDir = __dirname + '/models'
|
||||||
const models = fetchAllTypescriptFiles(modelDir)
|
const models = fetchAllTypescriptFiles(modelDir)
|
||||||
|
|
||||||
models.forEach(modelPath => {
|
|
||||||
const registerModel = require(modelPath).default as Function
|
|
||||||
registerModel()
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the environement is production, sync the DB
|
* If the environement is production, sync the DB
|
||||||
*/
|
*/
|
||||||
if (process.env.NODE_ENV != 'production') {
|
if (process.env.NODE_ENV != 'production') {
|
||||||
AuracleDatabaseDriver.sync({
|
// Todo
|
||||||
force: true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,41 @@
|
|||||||
import { Model, ModelOptions, Options } from "sequelize/types"
|
import { MysqlConnectionOptions } from "typeorm/driver/mysql/MysqlConnectionOptions"
|
||||||
|
|
||||||
|
import { Spell } from "../models/spells/Spell"
|
||||||
|
import { School } from "../models/spells/School"
|
||||||
|
import { Variable } from "../models/spells/Variable"
|
||||||
|
import { Ingredient } from "../models/spells/Ingredient"
|
||||||
|
import { MetaSchool } from "../models/spells/MetaSchool"
|
||||||
|
import { User } from "../models/users/User"
|
||||||
|
import { Permission } from "../models/users/Permission"
|
||||||
|
import { Role } from "../models/users/Role"
|
||||||
|
|
||||||
const tablePrefix = 'au_'
|
const tablePrefix = 'au_'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the options to create the sequelize instance
|
* Registers the options to create the sequelize instance
|
||||||
*/
|
*/
|
||||||
export const dbConfig: Options = {
|
export const dbConfig: MysqlConnectionOptions = {
|
||||||
/**
|
/**
|
||||||
* Access to database
|
* Access to database
|
||||||
*/
|
*/
|
||||||
|
type: 'mariadb',
|
||||||
database: process.env.DB_NAME,
|
database: process.env.DB_NAME,
|
||||||
username: process.env.DB_USER,
|
username: process.env.DB_USER,
|
||||||
password: process.env.DB_PASSWORD,
|
password: process.env.DB_PASSWORD,
|
||||||
host: process.env.DB_HOST,
|
host: process.env.DB_HOST,
|
||||||
dialect: 'mariadb',
|
|
||||||
logging: false,
|
logging: false,
|
||||||
|
|
||||||
/**
|
entityPrefix: tablePrefix,
|
||||||
* Sequelize Hooks
|
entities: [
|
||||||
* Docs : https://sequelize.org/master/manual/hooks.html
|
User,
|
||||||
*/
|
Permission,
|
||||||
hooks: {}
|
Role,
|
||||||
|
|
||||||
|
Spell,
|
||||||
|
School,
|
||||||
|
MetaSchool,
|
||||||
|
|
||||||
|
Variable,
|
||||||
|
Ingredient,
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,56 +1,15 @@
|
|||||||
import { DataTypes, Model, Optional } from "sequelize";
|
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
||||||
|
|
||||||
import { AuracleDatabaseDriver } from "../../AuracleDatabaseDriver";
|
@Entity()
|
||||||
|
export class Ingredient {
|
||||||
interface IngredientAttributes {
|
@PrimaryGeneratedColumn('uuid')
|
||||||
uuid: string
|
|
||||||
name: string
|
|
||||||
description: string
|
|
||||||
|
|
||||||
published: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
interface IngredientCreationAttributes extends Optional<IngredientAttributes, 'uuid'> { }
|
|
||||||
|
|
||||||
export class Ingredient extends Model<IngredientAttributes, IngredientCreationAttributes> implements IngredientAttributes {
|
|
||||||
public readonly uuid!: string
|
public readonly uuid!: string
|
||||||
|
|
||||||
|
@Column()
|
||||||
public name!: string
|
public name!: string
|
||||||
|
@Column()
|
||||||
public description!: string
|
public description!: string
|
||||||
|
|
||||||
|
@Column()
|
||||||
public published: boolean
|
public published: boolean
|
||||||
|
|
||||||
public readonly createdAt!: Date;
|
|
||||||
public readonly updatedAt!: Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default () => {
|
|
||||||
Ingredient.init(
|
|
||||||
{
|
|
||||||
uuid: {
|
|
||||||
type: DataTypes.UUID,
|
|
||||||
unique: true,
|
|
||||||
allowNull: false,
|
|
||||||
defaultValue: DataTypes.UUIDV4,
|
|
||||||
primaryKey: true
|
|
||||||
},
|
|
||||||
name: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: false,
|
|
||||||
unique: true,
|
|
||||||
},
|
|
||||||
description: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: false,
|
|
||||||
},
|
|
||||||
|
|
||||||
published: {
|
|
||||||
type: DataTypes.BOOLEAN,
|
|
||||||
defaultValue: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tableName: 'au_ingredients',
|
|
||||||
sequelize: AuracleDatabaseDriver,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,56 +1,15 @@
|
|||||||
import { DataTypes, Model, Optional } from "sequelize";
|
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm"
|
||||||
|
|
||||||
import { AuracleDatabaseDriver } from "../../AuracleDatabaseDriver";
|
@Entity()
|
||||||
|
export class MetaSchool {
|
||||||
interface MetaSchoolAttributes {
|
@PrimaryGeneratedColumn('uuid')
|
||||||
uuid: string
|
|
||||||
name: string
|
|
||||||
description: string
|
|
||||||
|
|
||||||
published: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
interface MetaSchoolCreationAttributes extends Optional<MetaSchoolAttributes, 'uuid'> { }
|
|
||||||
|
|
||||||
export class MetaSchool extends Model<MetaSchoolAttributes, MetaSchoolCreationAttributes> implements MetaSchoolAttributes {
|
|
||||||
public readonly uuid!: string
|
public readonly uuid!: string
|
||||||
|
|
||||||
|
@Column()
|
||||||
public name!: string
|
public name!: string
|
||||||
|
@Column()
|
||||||
public description!: string
|
public description!: string
|
||||||
|
|
||||||
|
@Column()
|
||||||
public published: boolean
|
public published: boolean
|
||||||
|
|
||||||
public readonly createdAt!: Date;
|
|
||||||
public readonly updatedAt!: Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default () => {
|
|
||||||
MetaSchool.init(
|
|
||||||
{
|
|
||||||
uuid: {
|
|
||||||
type: DataTypes.UUID,
|
|
||||||
unique: true,
|
|
||||||
allowNull: false,
|
|
||||||
defaultValue: DataTypes.UUIDV4,
|
|
||||||
primaryKey: true
|
|
||||||
},
|
|
||||||
name: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: false,
|
|
||||||
unique: true,
|
|
||||||
},
|
|
||||||
description: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: false,
|
|
||||||
},
|
|
||||||
|
|
||||||
published: {
|
|
||||||
type: DataTypes.BOOLEAN,
|
|
||||||
defaultValue: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tableName: 'au_meta_schools',
|
|
||||||
sequelize: AuracleDatabaseDriver,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,56 +1,15 @@
|
|||||||
import { DataTypes, Model, Optional } from "sequelize";
|
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
||||||
|
|
||||||
import { AuracleDatabaseDriver } from "../../AuracleDatabaseDriver";
|
@Entity()
|
||||||
|
export class School {
|
||||||
interface SchoolAttributes {
|
@PrimaryGeneratedColumn('uuid')
|
||||||
uuid: string
|
|
||||||
name: string
|
|
||||||
description: string
|
|
||||||
|
|
||||||
published: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
interface SchoolCreationAttributes extends Optional<SchoolAttributes, 'uuid'> { }
|
|
||||||
|
|
||||||
export class School extends Model<SchoolAttributes, SchoolCreationAttributes> implements SchoolAttributes {
|
|
||||||
public readonly uuid!: string
|
public readonly uuid!: string
|
||||||
|
|
||||||
|
@Column()
|
||||||
public name!: string
|
public name!: string
|
||||||
|
@Column()
|
||||||
public description!: string
|
public description!: string
|
||||||
|
|
||||||
|
@Column()
|
||||||
public published: boolean
|
public published: boolean
|
||||||
|
|
||||||
public readonly createdAt!: Date;
|
|
||||||
public readonly updatedAt!: Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default () => {
|
|
||||||
School.init(
|
|
||||||
{
|
|
||||||
uuid: {
|
|
||||||
type: DataTypes.UUID,
|
|
||||||
unique: true,
|
|
||||||
allowNull: false,
|
|
||||||
defaultValue: DataTypes.UUIDV4,
|
|
||||||
primaryKey: true
|
|
||||||
},
|
|
||||||
name: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: false,
|
|
||||||
unique: true,
|
|
||||||
},
|
|
||||||
description: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: false,
|
|
||||||
},
|
|
||||||
|
|
||||||
published: {
|
|
||||||
type: DataTypes.BOOLEAN,
|
|
||||||
defaultValue: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tableName: 'au_schools',
|
|
||||||
sequelize: AuracleDatabaseDriver,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,89 +1,27 @@
|
|||||||
import { DataTypes, Model, Optional, TableHints } from "sequelize";
|
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm"
|
||||||
|
|
||||||
import { AuracleDatabaseDriver } from "../../AuracleDatabaseDriver";
|
@Entity()
|
||||||
|
export class Spell {
|
||||||
interface SpellAttributes {
|
@PrimaryGeneratedColumn('uuid')
|
||||||
uuid: string
|
|
||||||
name: string
|
|
||||||
description: string
|
|
||||||
|
|
||||||
level?: number
|
|
||||||
charge?: number
|
|
||||||
cost?: string
|
|
||||||
isRitual?: boolean
|
|
||||||
|
|
||||||
published?: boolean
|
|
||||||
public?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SpellCreationAttributes extends Optional<SpellAttributes, 'uuid'> { }
|
|
||||||
|
|
||||||
export class Spell extends Model<SpellAttributes, SpellCreationAttributes> implements SpellAttributes {
|
|
||||||
public readonly uuid!: string
|
public readonly uuid!: string
|
||||||
public name!: string
|
|
||||||
public description!: string
|
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
public name!: string
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
public description!: string
|
||||||
|
@Column()
|
||||||
public level?: number
|
public level?: number
|
||||||
|
|
||||||
|
@Column()
|
||||||
public charge?: number
|
public charge?: number
|
||||||
|
@Column()
|
||||||
public cost?: string
|
public cost?: string
|
||||||
|
@Column()
|
||||||
public isRitual?: boolean
|
public isRitual?: boolean
|
||||||
|
|
||||||
|
@Column()
|
||||||
public published?: boolean
|
public published?: boolean
|
||||||
|
@Column()
|
||||||
public public?: boolean
|
public public?: boolean
|
||||||
|
|
||||||
public readonly createdAt!: Date;
|
|
||||||
public readonly updatedAt!: Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default async () => {
|
|
||||||
Spell.init(
|
|
||||||
{
|
|
||||||
uuid: {
|
|
||||||
type: DataTypes.UUID,
|
|
||||||
unique: true,
|
|
||||||
allowNull: false,
|
|
||||||
defaultValue: DataTypes.UUIDV4,
|
|
||||||
primaryKey: true
|
|
||||||
},
|
|
||||||
name: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: false,
|
|
||||||
unique: true,
|
|
||||||
},
|
|
||||||
description: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: false,
|
|
||||||
},
|
|
||||||
|
|
||||||
level: {
|
|
||||||
type: DataTypes.INTEGER,
|
|
||||||
defaultValue: 0
|
|
||||||
},
|
|
||||||
charge: {
|
|
||||||
type: DataTypes.INTEGER,
|
|
||||||
defaultValue: 0
|
|
||||||
},
|
|
||||||
cost: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
defaultValue: '0'
|
|
||||||
},
|
|
||||||
isRitual: {
|
|
||||||
type: DataTypes.BOOLEAN,
|
|
||||||
defaultValue: false
|
|
||||||
},
|
|
||||||
|
|
||||||
published: {
|
|
||||||
type: DataTypes.BOOLEAN,
|
|
||||||
defaultValue: false
|
|
||||||
},
|
|
||||||
public: {
|
|
||||||
type: DataTypes.BOOLEAN,
|
|
||||||
defaultValue: false
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tableName: 'au_spells',
|
|
||||||
sequelize: AuracleDatabaseDriver,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,49 +1,13 @@
|
|||||||
import { DataTypes, Model, Optional } from "sequelize";
|
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
||||||
|
|
||||||
import { AuracleDatabaseDriver } from "../../AuracleDatabaseDriver";
|
@Entity()
|
||||||
|
export class Variable {
|
||||||
interface VariableAttributes {
|
@PrimaryGeneratedColumn('uuid')
|
||||||
uuid: string
|
|
||||||
description: string
|
|
||||||
|
|
||||||
published: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
interface VariableCreationAttributes extends Optional<VariableAttributes, 'uuid'> { }
|
|
||||||
|
|
||||||
export class Variable extends Model<VariableAttributes, VariableCreationAttributes> implements VariableAttributes {
|
|
||||||
public readonly uuid!: string
|
public readonly uuid!: string
|
||||||
|
|
||||||
|
@Column()
|
||||||
public description!: string
|
public description!: string
|
||||||
|
|
||||||
|
@Column()
|
||||||
public published: boolean
|
public published: boolean
|
||||||
|
|
||||||
public readonly createdAt!: Date;
|
|
||||||
public readonly updatedAt!: Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default () => {
|
|
||||||
Variable.init(
|
|
||||||
{
|
|
||||||
uuid: {
|
|
||||||
type: DataTypes.UUID,
|
|
||||||
unique: true,
|
|
||||||
allowNull: false,
|
|
||||||
defaultValue: DataTypes.UUIDV4,
|
|
||||||
primaryKey: true
|
|
||||||
},
|
|
||||||
description: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: false,
|
|
||||||
},
|
|
||||||
|
|
||||||
published: {
|
|
||||||
type: DataTypes.BOOLEAN,
|
|
||||||
defaultValue: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tableName: 'au_variables',
|
|
||||||
sequelize: AuracleDatabaseDriver,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,41 +1,10 @@
|
|||||||
import { DataTypes, Model, Optional } from "sequelize";
|
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
||||||
|
|
||||||
import { AuracleDatabaseDriver } from "../../AuracleDatabaseDriver";
|
@Entity()
|
||||||
|
export class Permission {
|
||||||
interface PermissionAttributes {
|
@PrimaryGeneratedColumn('uuid')
|
||||||
uuid: string
|
|
||||||
slug: string
|
|
||||||
}
|
|
||||||
|
|
||||||
interface PermissionCreationAttributes extends Optional<PermissionAttributes, 'uuid'> { }
|
|
||||||
|
|
||||||
export class Permission extends Model<PermissionAttributes, PermissionCreationAttributes> implements PermissionAttributes {
|
|
||||||
public readonly uuid!: string
|
public readonly uuid!: string
|
||||||
|
|
||||||
|
@Column()
|
||||||
public slug!: string
|
public slug!: string
|
||||||
|
|
||||||
public readonly createdAt!: Date;
|
|
||||||
public readonly updatedAt!: Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default () => {
|
|
||||||
Permission.init(
|
|
||||||
{
|
|
||||||
uuid: {
|
|
||||||
type: DataTypes.UUID,
|
|
||||||
unique: true,
|
|
||||||
allowNull: false,
|
|
||||||
defaultValue: DataTypes.UUIDV4,
|
|
||||||
primaryKey: true
|
|
||||||
},
|
|
||||||
slug: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: false,
|
|
||||||
unique: true
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tableName: 'au_permissions',
|
|
||||||
sequelize: AuracleDatabaseDriver,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,54 +1,12 @@
|
|||||||
import { DataTypes, Model, Optional } from "sequelize";
|
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
||||||
|
|
||||||
import { AuracleDatabaseDriver } from "../../AuracleDatabaseDriver";
|
@Entity()
|
||||||
|
export class Role {
|
||||||
interface RoleAttributes {
|
@PrimaryGeneratedColumn('uuid')
|
||||||
id: number
|
|
||||||
uuid: string
|
|
||||||
name: string
|
|
||||||
description: string
|
|
||||||
}
|
|
||||||
|
|
||||||
interface RoleCreationAttributes extends Optional<RoleAttributes, 'id'> { }
|
|
||||||
|
|
||||||
export class Role extends Model<RoleAttributes, RoleCreationAttributes> implements RoleAttributes {
|
|
||||||
public readonly id!: number
|
|
||||||
public readonly uuid!: string
|
public readonly uuid!: string
|
||||||
|
|
||||||
|
@Column()
|
||||||
public name!: string
|
public name!: string
|
||||||
|
@Column()
|
||||||
public description!: 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
|
|
||||||
},
|
|
||||||
uuid: {
|
|
||||||
type: DataTypes.UUID,
|
|
||||||
allowNull: false,
|
|
||||||
unique: true,
|
|
||||||
defaultValue: DataTypes.UUIDV4
|
|
||||||
},
|
|
||||||
name: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: false,
|
|
||||||
unique: true
|
|
||||||
},
|
|
||||||
description: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: false,
|
|
||||||
unique: true
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tableName: 'au_roles',
|
|
||||||
sequelize: AuracleDatabaseDriver,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,77 +1,22 @@
|
|||||||
import { DataTypes, Model, Optional } from "sequelize";
|
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm"
|
||||||
|
|
||||||
import { AuracleDatabaseDriver } from "../../AuracleDatabaseDriver";
|
@Entity()
|
||||||
|
export class User {
|
||||||
interface UserAttributes {
|
@PrimaryGeneratedColumn('uuid')
|
||||||
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
|
|
||||||
public readonly uuid!: string
|
public readonly uuid!: string
|
||||||
|
|
||||||
|
@Column()
|
||||||
public readonly mail!: string
|
public readonly mail!: string
|
||||||
|
@Column()
|
||||||
public readonly password!: string
|
public readonly password!: string
|
||||||
|
|
||||||
|
@Column()
|
||||||
public name!: string
|
public name!: string
|
||||||
|
@Column()
|
||||||
public avatar: string
|
public avatar: string
|
||||||
|
@Column()
|
||||||
public gender: string
|
public gender: string
|
||||||
|
|
||||||
|
@Column()
|
||||||
public verified: boolean
|
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,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ import * as dotenv from 'dotenv'
|
|||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
// Packages
|
// Packages
|
||||||
|
|
||||||
|
// TypeORM
|
||||||
|
import "reflect-metadata";
|
||||||
|
|
||||||
import morgan from 'morgan'
|
import morgan from 'morgan'
|
||||||
import helmet from 'helmet'
|
import helmet from 'helmet'
|
||||||
import express from 'express'
|
import express from 'express'
|
||||||
@@ -21,9 +25,7 @@ const apiPort = process.env.API_PORT
|
|||||||
const app = new AuracleApi({
|
const app = new AuracleApi({
|
||||||
port: apiPort,
|
port: apiPort,
|
||||||
middlewares: [],
|
middlewares: [],
|
||||||
routers: [
|
routers: [],
|
||||||
new SpellRouter()
|
|
||||||
],
|
|
||||||
modules: [
|
modules: [
|
||||||
express.json({ limit: '10kb' }),
|
express.json({ limit: '10kb' }),
|
||||||
morgan('dev'),
|
morgan('dev'),
|
||||||
|
|||||||
Reference in New Issue
Block a user