ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • NestJS_온라인 공연 예매 서비스 프로젝트_entity 관계 설정 수정
    TIL (Today I Learned) 2023. 12. 29. 21:36

    # ERD 설계 재구성

     

    TicketPlatform(테이블 4개로 다시 구성)

    Draw ERD with your team members. All states are shared in real time. And it's FREE. Database modeling tool.

    www.erdcloud.com

    # user.entity.ts

    import {
      Column,
      Entity,
      Index,
      PrimaryGeneratedColumn,
      CreateDateColumn,
      UpdateDateColumn,
      DeleteDateColumn,
      OneToMany,
    } from 'typeorm';
    
    import { Role } from '../types/userRole.type';
    import { Reservation } from '../../reservation/entities/reservation.entity';
    
    @Index('email', ['email'], { unique: true })
    @Entity({ name: 'users' })
    export class User {
      @PrimaryGeneratedColumn()
      id: number;
    
      @Column({ type: 'varchar', unique: true, nullable: false, name: 'email' })
      email: string;
    
      @Column({ type: 'varchar', nullable: false, name: 'password' })
      password: string;
    
      @Column({ type: 'varchar', nullable: false, name: 'name' })
      name: string;
    
      @Column({ type: 'varchar', nullable: false, name: 'nickName' })
      nickName: string;
    
      @Column({ type: 'varchar', nullable: false, name: 'gender' })
      gender: string;
    
      @Column({ type: 'tinyint', nullable: false, name: 'age' })
      age: number;
    
      @Column({ type: 'varchar', nullable: false, name: 'phone' })
      phone: string;
    
      @Column({ type: 'varchar', nullable: false, name: 'grade' })
      grade: string;
    
      @Column({ type: 'varchar', nullable: false, name: 'permission' })
      permission: string;
    
      @Column({ type: 'enum', enum: Role, default: Role.User, name: 'role' })
      role: Role;
    
      @CreateDateColumn({ name: 'createdAt', comment: '생성일시' })
      createdAt: Date;
    
      @UpdateDateColumn({ name: 'updatedAt', comment: '수정일시' })
      updatedAt: Date;
    
      @DeleteDateColumn({ name: 'deletedAt', comment: '삭제일시' })
      deletedAt?: Date | null;
    
      @OneToMany(() => Reservation, (reservation) => reservation.user)
      reservations: Reservation[];
    }

    # show.entity.ts

    import {
      Column,
      Entity,
      PrimaryGeneratedColumn,
      CreateDateColumn,
      UpdateDateColumn,
      DeleteDateColumn,
      OneToMany,
    } from 'typeorm';
    
    import { Reservation } from '../../reservation/entities/reservation.entity';
    import { Seat } from '../../seat/entities/seat.entity';
    
    @Entity({ name: 'shows' })
    export class Show {
      @PrimaryGeneratedColumn()
      id: number;
    
      @Column({ type: 'integer', nullable: false, name: 'showPoster' })
      showPoster: number;
    
      @Column({ type: 'varchar', nullable: false, name: 'showTitle' })
      showTitle: string;
    
      @Column({ type: 'varchar', nullable: false, name: 'showCast' })
      showCast: string;
    
      @Column({ type: 'varchar', nullable: false, name: 'showGenre' })
      showGenre: string;
    
      @Column({ type: 'varchar', nullable: false, name: 'showDescription' })
      showDescription: string;
    
      @Column({ type: 'varchar', nullable: false, name: 'showDateTime' })
      showDateTime: string;
    
      @Column({ type: 'varchar', nullable: false, name: 'showVenue' })
      showVenue: string;
    
      @Column({ type: 'date', nullable: false, name: 'showRunTime' })
      showRunTime: Date;
    
      @Column({ type: 'integer', nullable: false, name: 'showAgeRating' })
      showAgeRating: number;
    
      @Column({ type: 'integer', nullable: false, name: 'ticketPrice' })
      ticketPrice: number;
    
      @Column({ type: 'integer', nullable: false, name: 'seat' })
      seat: number;
    
      @CreateDateColumn({ name: 'createdAt', comment: '생성일시' })
      createdAt: Date;
    
      @UpdateDateColumn({ name: 'updatedAt', comment: '수정일시' })
      updatedAt: Date;
    
      @DeleteDateColumn({ name: 'deletedAt', comment: '삭제일시' })
      deletedAt?: Date | null;
    
      @OneToMany(() => Reservation, (reservation) => reservation.show)
      reservations: Reservation[];
    
      @OneToMany(() => Seat, (seat) => seat.show)
      seats: Seat[];
    }

    # reservation.entity.ts

    import {
      Column,
      Entity,
      PrimaryGeneratedColumn,
      CreateDateColumn,
      UpdateDateColumn,
      DeleteDateColumn,
      ManyToOne,
    } from 'typeorm';
    
    import { User } from '../../user/entities/user.entity';
    import { Show } from '../../show/entities/show.entity';
    import { Seat } from '../../seat/entities/seat.entity';
    
    @Entity({ name: 'reservations' })
    export class Reservation {
      @PrimaryGeneratedColumn()
      id: number;
    
      @Column({ type: 'integer', nullable: false, name: 'userId' })
      userId: number;
    
      @Column({ type: 'integer', nullable: false, name: 'showId' })
      showId: number;
    
      @Column({ type: 'integer', nullable: false, name: 'seatId' })
      seatId: number;
    
      @Column({ type: 'integer', nullable: false, name: 'reservationPrice' })
      reservationPrice: number;
    
      @Column({ type: 'integer', nullable: false, name: 'reservationQuantity' })
      reservationQuantity: number;
    
      @Column({
        type: 'boolean',
        nullable: false,
        default: true,
        name: 'isReservationPossible',
      })
      isReservationPossible: boolean;
    
      @CreateDateColumn({ name: 'createdAt', comment: '생성일시' })
      createdAt: Date;
    
      @UpdateDateColumn({ name: 'updatedAt', comment: '수정일시' })
      updatedAt: Date;
    
      @DeleteDateColumn({ name: 'deletedAt', comment: '삭제일시' })
      deletedAt?: Date | null;
    
      @ManyToOne(() => User, (user) => user.reservations, { onDelete: 'CASCADE' })
      user: User;
    
      @ManyToOne(() => Show, (show) => show.reservations, { onDelete: 'CASCADE' })
      show: Show;
    
      @ManyToOne(() => Seat, (seat) => seat.reservations, { onDelete: 'CASCADE' })
      seat: Seat;
    }

    # seat.entity.ts

    import {
      Column,
      Entity,
      PrimaryGeneratedColumn,
      CreateDateColumn,
      UpdateDateColumn,
      DeleteDateColumn,
      OneToMany,
      ManyToOne,
    } from 'typeorm';
    
    import { Reservation } from '../../reservation/entities/reservation.entity';
    import { Show } from '../../show/entities/show.entity';
    
    @Entity({ name: 'seats' })
    export class Seat {
      @PrimaryGeneratedColumn()
      id: number;
    
      @Column({ type: 'integer', nullable: false, name: 'showId' })
      showId: number;
    
      @Column({ type: 'varchar', nullable: false, name: 'seatNumber' })
      seatNumber: string;
    
      @Column({ type: 'varchar', nullable: false, name: 'seatClass' })
      seatClass: string;
    
      @Column({ type: 'integer', nullable: false, name: 'seatPrice' })
      seatPrice: number;
    
      @Column({
        type: 'boolean',
        nullable: false,
        default: true,
        name: 'seatAvailable',
      })
      seatAvailable: boolean;
    
      @CreateDateColumn({ name: 'createdAt', comment: '생성일시' })
      createdAt: Date;
    
      @UpdateDateColumn({ name: 'updatedAt', comment: '수정일시' })
      updatedAt: Date;
    
      @DeleteDateColumn({ name: 'deletedAt', comment: '삭제일시' })
      deletedAt?: Date | null;
    
      @OneToMany(() => Reservation, (reservation) => reservation.seat)
      reservations: Reservation[];
    
      @ManyToOne(() => Show, (show) => show.seats, { onDelete: 'CASCADE' })
      show: Show[];
    }
Designed by Tistory.