Created base entities, extended normal entities with these

This commit is contained in:
2025-01-06 18:03:12 +01:00
parent be9ee97385
commit 24586855cb
42 changed files with 2006 additions and 1858 deletions

View File

@ -1,98 +1,6 @@
import { randomUUID } from 'node:crypto'
import { Entity } from '@mikro-orm/core'
import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
import bcrypt from 'bcryptjs'
import { Character } from './character'
import { PasswordResetToken } from './passwordResetToken'
import { BaseEntity } from '#application/base/baseEntity'
import { UUID } from '#application/types'
import { BaseUser } from '#entities/base/user'
@Entity()
export class User extends BaseEntity {
@PrimaryKey()
id = randomUUID()
@Property({ unique: true })
username!: string
@Property({ unique: true })
email!: string
@Property()
password!: string
@Property()
online = false
@OneToMany(() => Character, (character) => character.user)
characters = new Collection<Character>(this)
@OneToMany(() => PasswordResetToken, (token) => token.user)
passwordResetTokens = new Collection<PasswordResetToken>(this)
setId(id: UUID) {
this.id = id
return this
}
getId() {
return this.id
}
setUsername(username: string) {
this.username = username
return this
}
getUsername() {
return this.username
}
setEmail(email: string) {
this.email = email
return this
}
getEmail() {
return this.email
}
setPassword(password: string) {
this.password = bcrypt.hashSync(password, 10)
return this
}
getPassword() {
return this.password
}
setOnline(online: boolean) {
this.online = online
return this
}
getOnline() {
return this.online
}
setCharacters(characters: Collection<Character>) {
this.characters = characters
return this
}
getCharacters() {
return this.characters
}
setPasswordResetTokens(passwordResetTokens: Collection<PasswordResetToken>) {
this.passwordResetTokens = passwordResetTokens
return this
}
getPasswordResetTokens() {
return this.passwordResetTokens
return this
}
}
export class User extends BaseUser {}