Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Add TypeORM models #162

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion server/models/Chapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,24 @@ import {
Table,
UpdatedAt,
DataType,
PrimaryKey,
HasOne,
HasMany,
BelongsToMany,
} from 'sequelize-typescript';
import { IChapter, ILocation, IUser, IUserBan, IEvent } from 'types/models';
import { Location } from './Location';
import { User } from './User';
import { UserBan } from './UserBan';
import { Event } from './Event';
import { UserChapter } from './UserChapter';

@Table
export class Chapter extends Model<Chapter> {
export class Chapter extends Model<IChapter> {
@PrimaryKey
@Column
id!: number;

@Column
name!: string;

Expand All @@ -21,6 +35,21 @@ export class Chapter extends Model<Chapter> {
@Column(DataType.JSON)
details!: any;

@Column
creator_id!: number;

@HasMany(() => Event)
events!: IEvent[];

@HasOne(() => Location)
location!: ILocation;

@BelongsToMany(() => User, () => UserChapter)
users!: IUser[];

@HasMany(() => UserBan)
user_bans!: IUserBan[];

@CreatedAt
@Column
created_at!: Date;
Expand Down
78 changes: 78 additions & 0 deletions server/models/Event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import {
Column,
CreatedAt,
Model,
Table,
UpdatedAt,
PrimaryKey,
HasMany,
HasOne,
BelongsToMany,
ForeignKey,
BelongsTo,
} from 'sequelize-typescript';
import { IEvent, ITag, IVenue, IRsvp, IChapter, ISponsor } from 'types/models';
import { EventSponsor } from './EventSponsor';
import { Tag } from './Tag';
import { Venue } from './Venue';
import { Rsvp } from './Rsvp';
import { Sponsor } from './Sponsor';
import { Chapter } from './Chapter';

@Table
export class Event extends Model<IEvent> {
@PrimaryKey
@Column
id!: number;

@Column
name!: string;

@Column
description!: string;

@Column
start_at!: Date;

@Column
ends_at!: Date;

@ForeignKey(() => Chapter)
@Column
chapter_id!: number;

@BelongsTo(() => Chapter)
chapter: IChapter;

@Column
venue_id!: number;

@BelongsToMany(() => Sponsor, () => EventSponsor)
sponsors: ISponsor[];

@HasMany(() => Tag)
tags: ITag[];

@HasOne(() => Venue)
venue: IVenue;

@HasMany(() => Rsvp)
rsvps: IRsvp[];

@Column
tag_id!: number;

@Column
canceled!: boolean;

@Column
capacity!: number;

@CreatedAt
@Column
created_at: Date;

@UpdatedAt
@Column
updated_at: Date;
}
30 changes: 30 additions & 0 deletions server/models/EventSponsor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
Column,
CreatedAt,
Model,
Table,
UpdatedAt,
ForeignKey,
} from 'sequelize-typescript';
import { IEventSponsor } from 'types/models';
import { Sponsor } from './Sponsor';
import { Event } from './Event';

@Table
export class EventSponsor extends Model<IEventSponsor> {
@ForeignKey(() => Event)
@Column
event_id!: number;

@ForeignKey(() => Sponsor)
@Column
sponsor_id!: number;

@CreatedAt
@Column
created_at!: Date;

@UpdatedAt
@Column
updated_at!: Date;
}
36 changes: 36 additions & 0 deletions server/models/Location.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
Column,
CreatedAt,
Model,
Table,
UpdatedAt,
PrimaryKey,
} from 'sequelize-typescript';
import { ILocation } from 'types/models';

@Table
export class Location extends Model<ILocation> {
@PrimaryKey
@Column
id!: number;

@Column
country_code!: string;

@Column
city!: string;

@Column
region!: string;

@Column
postal_code!: string;

@CreatedAt
@Column
created_at: Date;

@UpdatedAt
@Column
updated_at: Date;
}
43 changes: 43 additions & 0 deletions server/models/Rsvp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
Column,
CreatedAt,
Model,
Table,
UpdatedAt,
ForeignKey,
BelongsTo,
} from 'sequelize-typescript';
import { IRsvp, IUser } from 'types/models';
import { Event } from './Event';
import { User } from './User';

@Table
export class Rsvp extends Model<IRsvp> {
@ForeignKey(() => User)
@Column
user_id!: number;

@BelongsTo(() => User)
user: IUser;

@ForeignKey(() => Event)
@Column
event_id: number;

@BelongsTo(() => Event)
event: Event;

@Column
date: Date;

@Column
on_waitlist: boolean;

@CreatedAt
@Column
created_at: Date;

@UpdatedAt
@Column
updated_at: Date;
}
33 changes: 33 additions & 0 deletions server/models/SocialProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {
Column,
CreatedAt,
Model,
Table,
UpdatedAt,
PrimaryKey,
BelongsToMany,
} from 'sequelize-typescript';
import { ISocialProvider } from 'types/models';
import { User } from './User';
import { SocialProviderUser } from './SocialProviderUser';

@Table
export class SocialProvider extends Model<ISocialProvider> {
@PrimaryKey
@Column
id!: number;

@Column
name!: string;

@BelongsToMany(() => User, () => SocialProviderUser)
users: User[];

@CreatedAt
@Column
created_at!: Date;

@UpdatedAt
@Column
updated_at!: Date;
}
33 changes: 33 additions & 0 deletions server/models/SocialProviderUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {
Column,
CreatedAt,
Model,
Table,
UpdatedAt,
PrimaryKey,
} from 'sequelize-typescript';
import { ISocialProviderUser } from 'types/models';

@Table
export class SocialProviderUser extends Model<ISocialProviderUser> {
@PrimaryKey
@Column
id!: number;

@Column
provider_id!: number;

@Column
provider_user_id!: string;

@Column
user_id!: number;

@CreatedAt
@Column
created_at!: Date;

@UpdatedAt
@Column
updated_at!: Date;
}
42 changes: 42 additions & 0 deletions server/models/Sponsor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
Column,
CreatedAt,
Model,
Table,
UpdatedAt,
PrimaryKey,
BelongsToMany,
} from 'sequelize-typescript';
import { ISponsor } from 'types/models';
import { EventSponsor } from './EventSponsor';
import { Event } from './Event';

@Table
export class Sponsor extends Model<ISponsor> {
@PrimaryKey
@Column
id!: number;

@Column
name!: string;

@Column
website!: string;

@Column
logoPath!: string;

@Column
type!: string;

@CreatedAt
@Column
created_at!: Date;

@UpdatedAt
@Column
updated_at!: Date;

@BelongsToMany(() => Event, () => EventSponsor)
events: Event[];
}
29 changes: 29 additions & 0 deletions server/models/Tag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {
Column,
Model,
Table,
PrimaryKey,
BelongsTo,
ForeignKey,
} from 'sequelize-typescript';
import { ITag } from 'types/models';
import { Event } from './Event';

@Table
export class Tag extends Model<ITag> {
@PrimaryKey
@Column
id!: number;

@Column
name!: string;

// Below is not included in schema.png, but necessary for
// one to many relationship with event
@ForeignKey(() => Event)
@Column
event_id: number;

@BelongsTo(() => Event)
event: Event;
}
Loading