From 142e48bb06be2b6328545187406e167dd0da1d12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EC=A0=95=EC=9A=A9?= <89844585+sjy982@users.noreply.github.com> Date: Thu, 16 Nov 2023 20:44:18 +0900 Subject: [PATCH] =?UTF-8?q?[GWL-50]=20typeORM=20entity=20=EC=84=B8?= =?UTF-8?q?=ED=8C=85=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20(#56)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: typeORM entity 세팅 --- BackEnd/src/posts/entities/posts.entity.ts | 43 +++++++++++++++++ .../src/profiles/entities/profiles.entity.ts | 47 +++++++++++++++++++ .../src/records/entities/records.entity.ts | 47 +++++++++++++++++++ BackEnd/src/users/entities/users.entity.ts | 26 ++++++++++ 4 files changed, 163 insertions(+) create mode 100644 BackEnd/src/posts/entities/posts.entity.ts create mode 100644 BackEnd/src/profiles/entities/profiles.entity.ts create mode 100644 BackEnd/src/records/entities/records.entity.ts create mode 100644 BackEnd/src/users/entities/users.entity.ts diff --git a/BackEnd/src/posts/entities/posts.entity.ts b/BackEnd/src/posts/entities/posts.entity.ts new file mode 100644 index 00000000..bb99dc0b --- /dev/null +++ b/BackEnd/src/posts/entities/posts.entity.ts @@ -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; +} diff --git a/BackEnd/src/profiles/entities/profiles.entity.ts b/BackEnd/src/profiles/entities/profiles.entity.ts new file mode 100644 index 00000000..b5bb60e7 --- /dev/null +++ b/BackEnd/src/profiles/entities/profiles.entity.ts @@ -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[]; +} diff --git a/BackEnd/src/records/entities/records.entity.ts b/BackEnd/src/records/entities/records.entity.ts new file mode 100644 index 00000000..bf373e7f --- /dev/null +++ b/BackEnd/src/records/entities/records.entity.ts @@ -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; +} diff --git a/BackEnd/src/users/entities/users.entity.ts b/BackEnd/src/users/entities/users.entity.ts new file mode 100644 index 00000000..1cc00a63 --- /dev/null +++ b/BackEnd/src/users/entities/users.entity.ts @@ -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; +}