mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 03:06:31 -05:00
Implement User entity.
This commit implements the User entity according to the database schema and adds the Identity and AuthToken entities. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
6bee3b16cf
commit
2654f1fa36
4 changed files with 117 additions and 2 deletions
22
src/users/auth-token.entity.ts
Normal file
22
src/users/auth-token.entity.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
import {
|
||||
Column,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm/index';
|
||||
import { User } from './user.entity';
|
||||
|
||||
@Entity()
|
||||
export class AuthToken {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@ManyToOne(
|
||||
_ => User,
|
||||
user => user.authToken,
|
||||
)
|
||||
user: User;
|
||||
|
||||
@Column()
|
||||
accessToken: string;
|
||||
}
|
48
src/users/identity.entity.ts
Normal file
48
src/users/identity.entity.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm/index';
|
||||
import { User } from './user.entity';
|
||||
|
||||
@Entity()
|
||||
export class Identity {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@ManyToOne(
|
||||
_ => User,
|
||||
user => user.identities,
|
||||
)
|
||||
user: User;
|
||||
|
||||
@Column()
|
||||
providerName: string;
|
||||
|
||||
@Column()
|
||||
syncSource: boolean;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: Date;
|
||||
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
providerUserId?: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
oAuthAccessToken?: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
passwordHash?: string;
|
||||
}
|
|
@ -1,8 +1,51 @@
|
|||
import { Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { Column, OneToMany } from 'typeorm/index';
|
||||
import { Note } from '../notes/note.entity';
|
||||
import { AuthToken } from './auth-token.entity';
|
||||
import { Identity } from './identity.entity';
|
||||
|
||||
@Entity()
|
||||
export class User {
|
||||
//TODO: Still missing many properties
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column()
|
||||
userName: string;
|
||||
|
||||
@Column()
|
||||
displayName: string;
|
||||
|
||||
@Column()
|
||||
createdAt: Date;
|
||||
|
||||
@Column()
|
||||
updatedAt: Date;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
photo?: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
email?: string;
|
||||
|
||||
@OneToMany(
|
||||
_ => Note,
|
||||
note => note.owner,
|
||||
)
|
||||
ownedNotes: Note[];
|
||||
|
||||
@OneToMany(
|
||||
_ => AuthToken,
|
||||
authToken => authToken.user,
|
||||
)
|
||||
authToken: AuthToken[];
|
||||
|
||||
@OneToMany(
|
||||
_ => Identity,
|
||||
identity => identity.user,
|
||||
)
|
||||
identities: Identity[];
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { AuthToken } from './auth-token.entity';
|
||||
import { Identity } from './identity.entity';
|
||||
import { User } from './user.entity';
|
||||
import { UsersService } from './users.service';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([User])],
|
||||
imports: [TypeOrmModule.forFeature([User, AuthToken, Identity])],
|
||||
providers: [UsersService],
|
||||
exports: [UsersService],
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue