mirror of
https://github.com/arthur-pbty/portfolio2023.git
synced 2026-06-04 15:56:24 +02:00
31 lines
801 B
Plaintext
31 lines
801 B
Plaintext
import { DateTime } from 'luxon'
|
|
import Hash from '@ioc:Adonis/Core/Hash'
|
|
import { column, beforeSave, BaseModel } from '@ioc:Adonis/Lucid/Orm'
|
|
|
|
export default class {{ modelName }} extends BaseModel {
|
|
@column({ isPrimary: true })
|
|
public id: number
|
|
|
|
@column()
|
|
public email: string
|
|
|
|
@column({ serializeAs: null })
|
|
public password: string
|
|
|
|
@column()
|
|
public rememberMeToken: string | null
|
|
|
|
@column.dateTime({ autoCreate: true })
|
|
public createdAt: DateTime
|
|
|
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
|
public updatedAt: DateTime
|
|
|
|
@beforeSave()
|
|
public static async hashPassword ({{ modelReference }}: {{ modelName }}) {
|
|
if ({{ modelReference }}.$dirty.password) {
|
|
{{ modelReference }}.password = await Hash.make({{ modelReference }}.password)
|
|
}
|
|
}
|
|
}
|