UNPKG

802 BPlain TextView Raw
1import { DateTime } from 'luxon'
2import Hash from '@ioc:Adonis/Core/Hash'
3import {
4 column,
5 beforeSave,
6 BaseModel,
7} from '@ioc:Adonis/Lucid/Orm'
8
9export default class {{ modelName }} extends BaseModel {
10 @column({ isPrimary: true })
11 public id: number
12
13 @column()
14 public email: string
15
16 @column({ serializeAs: null })
17 public password: string
18
19 @column()
20 public rememberMeToken?: string
21
22 @column.dateTime({ autoCreate: true })
23 public createdAt: DateTime
24
25 @column.dateTime({ autoCreate: true, autoUpdate: true })
26 public updatedAt: DateTime
27
28 @beforeSave()
29 public static async hashPassword ({{ modelReference }}: {{ modelName }}) {
30 if ({{ modelReference }}.$dirty.password) {
31 {{ modelReference }}.password = await Hash.make({{ modelReference }}.password)
32 }
33 }
34}