-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GWL-50] typeORM entity 세팅 및 테스트 (#56)
* chore: typeORM entity 세팅
- Loading branch information
Showing
4 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
Column, | ||
CreateDateColumn, | ||
UpdateDateColumn, | ||
ManyToOne, | ||
OneToOne, | ||
JoinColumn, | ||
} from 'typeorm'; | ||
import { RecordModel } from 'src/records/entities/records.entity'; | ||
import { ProfileModel } from 'src/profiles/entities/profiles.entity'; | ||
|
||
@Entity() | ||
export class PostModel { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
publicId: string; | ||
|
||
@Column() | ||
content: string; | ||
|
||
@Column({ nullable: true }) | ||
like: number; | ||
|
||
@CreateDateColumn() | ||
createdAt: Date; | ||
|
||
@UpdateDateColumn() | ||
updatedAt: Date; | ||
|
||
@Column() | ||
deletedAt: Date; | ||
|
||
@OneToOne(() => RecordModel) | ||
@JoinColumn() | ||
record: RecordModel; | ||
|
||
@ManyToOne(() => ProfileModel, (profile) => profile.posts) | ||
profile: ProfileModel; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { PostModel } from 'src/posts/entities/posts.entity'; | ||
import { RecordModel } from 'src/records/entities/records.entity'; | ||
import { UserModel } from 'src/users/entities/users.entity'; | ||
import { | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
Column, | ||
CreateDateColumn, | ||
UpdateDateColumn, | ||
Generated, | ||
OneToOne, | ||
OneToMany, | ||
} from 'typeorm'; | ||
|
||
@Entity() | ||
export class ProfileModel { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column({ unique: true }) | ||
nickname: string; | ||
|
||
@Column({ nullable: false }) | ||
gender: string; | ||
|
||
@Column({ nullable: false }) | ||
birthdate: Date; | ||
|
||
@CreateDateColumn() | ||
createdAt: Date; | ||
|
||
@UpdateDateColumn() | ||
updatedAt: Date; | ||
|
||
@Column({ unique: true }) | ||
@Generated('uuid') | ||
publicId: string; | ||
|
||
@OneToOne(() => UserModel, (user) => user.profile) | ||
user: UserModel; | ||
|
||
@OneToMany(() => RecordModel, (record) => record.profile) | ||
records: RecordModel[]; | ||
|
||
@OneToMany(() => PostModel, (post) => post.profile) | ||
posts: PostModel[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
Column, | ||
CreateDateColumn, | ||
ManyToOne, | ||
OneToOne, | ||
} from 'typeorm'; | ||
|
||
import { UserModel } from 'src/users/entities/users.entity'; | ||
import { PostModel } from 'src/posts/entities/posts.entity'; | ||
import { ProfileModel } from 'src/profiles/entities/profiles.entity'; | ||
@Entity() | ||
export class RecordModel { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
exercise: string; | ||
|
||
@Column() | ||
runningTime: number; | ||
|
||
@Column() | ||
distance: number; | ||
|
||
@Column({ nullable: true }) | ||
avgBpm: number; | ||
|
||
@Column({ nullable: true }) | ||
minBpm: number; | ||
|
||
@Column({ nullable: true }) | ||
maxBpm: number; | ||
|
||
@CreateDateColumn() | ||
createdAt: Date; | ||
|
||
@Column() | ||
checker: boolean; | ||
|
||
@ManyToOne(() => ProfileModel, (profile) => profile.records) //manyToOne이 항상 외래키를 갖고 있음 | ||
profile: ProfileModel; | ||
|
||
@OneToOne(() => PostModel, (post) => post.record) | ||
post: PostModel; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
Column, | ||
OneToOne, | ||
JoinColumn, | ||
} from 'typeorm'; | ||
import { ProfileModel } from 'src/profiles/entities/profiles.entity'; | ||
@Entity() | ||
export class UserModel { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
userId: string; | ||
|
||
@Column() | ||
provider: string; | ||
|
||
@OneToOne(() => ProfileModel, (profile) => profile.user, { | ||
eager: true, | ||
cascade: true, | ||
}) | ||
@JoinColumn() | ||
profile: ProfileModel; | ||
} |