Initial commit

This commit is contained in:
2020-10-05 11:44:05 -05:00
commit 5917935505
29 changed files with 385 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import { Model, Type, Field, Relation } from '../../bundle/daton_orm.ts'
import User from "./User.model.ts";
export default class LoginAttempt extends Model<LoginAttempt> {
protected static table = 'daton_login_attempts'
protected static key = 'daton_login_attempt_id'
protected static readonly CREATED_AT = 'attempt_date'
protected static readonly UPDATED_AT = null
@Field(Type.int)
protected daton_login_attempt_id?: number
@Field(Type.int)
protected user_id!: number
@Field(Type.timestamp)
protected attempt_date!: Date
@Relation()
public user() {
return this.belongs_to_one(User, 'login_attempts')
}
}

27
app/models/User.model.ts Normal file
View File

@@ -0,0 +1,27 @@
import { Model, Type, Field, Relation } from '../../bundle/daton_orm.ts'
import LoginAttemptModel from './LoginAttempt.model.ts'
export default class User extends Model<User> {
protected static table = 'daton_users'
protected static key = 'user_id'
protected static readonly CREATED_AT = 'created_at'
protected static readonly UPDATED_AT = 'updated_at'
@Field(Type.int)
protected user_id?: number
@Field(Type.varchar)
protected first_name!: String
@Field(Type.varchar)
protected last_name!: String
@Field(Type.bool)
protected active!: Boolean
@Relation()
public login_attempts() {
return this.has_many(LoginAttemptModel)
}
}

View File

@@ -0,0 +1,19 @@
import { SessionModel } from '../../../bundle/daton.ts'
import { Field, Type } from '../../../bundle/daton_orm.ts'
export default class Session extends SessionModel {
protected static table = 'sessions'
protected static key = 'session_key'
protected static readonly CREATED_AT = 'start_time'
protected static readonly UPDATED_AT = null // No updated at
@Field(Type.varchar)
protected session_key!: string
@Field(Type.int)
protected user_id?: number
@Field(Type.timestamp)
protected start_time!: Date
}