mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-09 23:15:36 +00:00
refactor: split backend by context instead of type 'controllers/models/...'
This commit is contained in:
54
app/user/models/user.ts
Normal file
54
app/user/models/user.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import Collection from '#collections/models/collection';
|
||||
import AppBaseModel from '#core/models/app_base_model';
|
||||
import Link from '#links/models/link';
|
||||
import type { GoogleToken } from '@adonisjs/ally/types';
|
||||
import { column, computed, hasMany } from '@adonisjs/lucid/orm';
|
||||
import type { HasMany } from '@adonisjs/lucid/types/relations';
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
export default class User extends AppBaseModel {
|
||||
@column()
|
||||
declare email: string;
|
||||
|
||||
@column()
|
||||
declare name: string;
|
||||
|
||||
@column()
|
||||
declare nickName: string; // public username
|
||||
|
||||
@column()
|
||||
declare avatarUrl: string;
|
||||
|
||||
@column()
|
||||
declare isAdmin: boolean;
|
||||
|
||||
@column({ serializeAs: null })
|
||||
declare token?: GoogleToken;
|
||||
|
||||
@column({ serializeAs: null })
|
||||
declare providerId: number;
|
||||
|
||||
@column({ serializeAs: null })
|
||||
declare providerType: 'google';
|
||||
|
||||
@hasMany(() => Collection, {
|
||||
foreignKey: 'authorId',
|
||||
})
|
||||
declare collections: HasMany<typeof Collection>;
|
||||
|
||||
@hasMany(() => Link, {
|
||||
foreignKey: 'authorId',
|
||||
})
|
||||
declare links: HasMany<typeof Link>;
|
||||
|
||||
@computed()
|
||||
get fullname() {
|
||||
return this.nickName || this.name;
|
||||
}
|
||||
|
||||
@column.dateTime({
|
||||
autoCreate: true,
|
||||
autoUpdate: true,
|
||||
})
|
||||
declare lastSeenAt: DateTime;
|
||||
}
|
||||
Reference in New Issue
Block a user