Created
March 18, 2021 11:30
-
-
Save alanfoandrade/7a471c10533b53c869e762e3cf250685 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { | |
Entity, | |
Column, | |
PrimaryGeneratedColumn, | |
CreateDateColumn, | |
UpdateDateColumn, | |
OneToMany, | |
} from 'typeorm'; | |
import StoppingPoint from './StoppingPoint'; | |
@Entity('activities') | |
class Activity { | |
@PrimaryGeneratedColumn('uuid') | |
id: string; | |
@Column('varchar') | |
video_url: string; | |
@Column('varchar') | |
title: string; | |
@Column('varchar') | |
description: string; | |
@OneToMany(() => StoppingPoint, (stoppingPoint) => stoppingPoint.activity, { | |
cascade: true, | |
nullable: true, | |
}) | |
stopping_points?: StoppingPoint[]; | |
@CreateDateColumn({ type: 'timestamp with time zone' }) | |
created_at: Date; | |
@UpdateDateColumn({ type: 'timestamp with time zone' }) | |
updated_at: Date; | |
} | |
export default Activity; |
This file contains hidden or 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
import { Exclude } from 'class-transformer'; | |
import { | |
Entity, | |
Column, | |
PrimaryGeneratedColumn, | |
OneToMany, | |
ManyToOne, | |
JoinColumn, | |
} from 'typeorm'; | |
import Activity from './Activity'; | |
import StoppingPointOption from './StoppingPointOption'; | |
@Entity('activity_stopping_points') | |
class StoppingPoint { | |
@PrimaryGeneratedColumn('uuid') | |
id: string; | |
@Column('integer') | |
seconds: number; | |
@Column({ type: 'uuid', nullable: true }) | |
@Exclude() | |
activity_id?: string; | |
@ManyToOne(() => Activity, (activity) => activity.stopping_points, { | |
onDelete: 'CASCADE', | |
onUpdate: 'CASCADE', | |
}) | |
@JoinColumn({ name: 'activity_id' }) | |
activity: Activity; | |
@OneToMany( | |
() => StoppingPointOption, | |
(stoppingPointOption) => stoppingPointOption.stopping_point, | |
{ cascade: true, nullable: true }, | |
) | |
options?: StoppingPointOption[]; | |
} | |
export default StoppingPoint; |
This file contains hidden or 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
import { Exclude } from 'class-transformer'; | |
import { | |
Entity, | |
Column, | |
PrimaryGeneratedColumn, | |
ManyToOne, | |
JoinColumn, | |
} from 'typeorm'; | |
import StoppingPoint from './StoppingPoint'; | |
@Entity('stopping_point_options') | |
class StoppingPointOption { | |
@PrimaryGeneratedColumn('uuid') | |
id: string; | |
@Column('varchar') | |
text: string; | |
@Column('varchar') | |
text_color: string; | |
@Column('boolean') | |
response: boolean; | |
@Column('varchar') | |
color: string; | |
@Column({ | |
type: 'enum', | |
enum: ['circle', 'triangle', 'square'], | |
}) | |
shape: string; | |
@Column({ type: 'uuid', nullable: true }) | |
@Exclude() | |
stopping_point_id?: string; | |
@ManyToOne(() => StoppingPoint, (stoppingPoint) => stoppingPoint.options, { | |
onDelete: 'CASCADE', | |
onUpdate: 'CASCADE', | |
}) | |
@JoinColumn({ name: 'stopping_point_id' }) | |
stopping_point: StoppingPoint; | |
} | |
export default StoppingPointOption; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment