| Total Complexity | 3 |
| Complexity/F | 3 |
| Lines of Code | 48 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { DateTime } from 'luxon' |
||
| 2 | import Hash from '@ioc:Adonis/Core/Hash' |
||
| 3 | import { column, beforeSave, BaseModel, scope } from '@ioc:Adonis/Lucid/Orm' |
||
| 4 | |||
| 5 | export default class User extends BaseModel { |
||
| 6 | @column({ isPrimary: true }) |
||
| 7 | public id: number |
||
| 8 | |||
| 9 | @column() |
||
| 10 | public name: string |
||
| 11 | |||
| 12 | @column() |
||
| 13 | public email: string |
||
| 14 | |||
| 15 | @column() |
||
| 16 | public emailVerifiedAt: DateTime | null | string |
||
| 17 | |||
| 18 | @column({ serializeAs: null }) //hidden |
||
| 19 | public password: string |
||
| 20 | |||
| 21 | @column({ serialize: (value: number) => { |
||
| 22 | return value === 1 ? true : false |
||
| 23 | } |
||
| 24 | }) |
||
| 25 | public isMerchant: number | boolean |
||
| 26 | |||
| 27 | @column() |
||
| 28 | public rememberMeToken: string | null |
||
| 29 | |||
| 30 | @column.dateTime({ autoCreate: true }) |
||
| 31 | public createdAt: DateTime |
||
| 32 | |||
| 33 | @column.dateTime({ autoCreate: true, autoUpdate: true }) |
||
| 34 | public updatedAt: DateTime |
||
| 35 | |||
| 36 | @beforeSave() |
||
| 37 | public static async hashPassword (user: User) { |
||
| 38 | if (user.$dirty.password) { |
||
| 39 | user.password = await Hash.make(user.password) |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | public static merchant = scope((query) => { |
||
| 44 | query.where('is_merchant', false) |
||
| 45 | }) |
||
| 46 | |||
| 47 | } |
||
| 48 |