Skip to content

Commit

Permalink
schema(WIP): add many-to-many to track user signups
Browse files Browse the repository at this point in the history
part of a feature to keep track of users signing up for a specific
launch time and:

1. getting notified via email when the lobby is open + how many signups
   are there / signed in users (still tbd)
2. visual indicator of number of total signups in that time slot

refs virtualcommons/planning#63

Co-authored-by: Scott Foster <[email protected]>
Co-authored-by: Sabrina Nelson <[email protected]>
  • Loading branch information
3 people committed Dec 12, 2023
1 parent 10c2f64 commit ccf18ae
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
7 changes: 6 additions & 1 deletion server/src/entity/TournamentRoundDate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Column, Entity, ManyToOne, CreateDateColumn, PrimaryGeneratedColumn } from "typeorm";
import { Column, Entity, JoinTable, ManyToMany, ManyToOne, CreateDateColumn, PrimaryGeneratedColumn } from "typeorm";
import { TournamentRound } from "./TournamentRound";
import { TournamentRoundInvite } from "./TournamentRoundInvite";

@Entity()
export class TournamentRoundDate {
Expand All @@ -12,6 +13,10 @@ export class TournamentRoundDate {
@ManyToOne(type => TournamentRound, tournamentRound => tournamentRound.scheduledDates)
tournamentRound!: TournamentRound;

@ManyToMany(type => TournamentRoundInvite)
@JoinTable()
signups!: TournamentRoundInvite[];

@CreateDateColumn()
dateCreated!: Date;

Expand Down
5 changes: 5 additions & 0 deletions server/src/entity/TournamentRoundInvite.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import {
Column,
Entity,
ManyToMany,
ManyToOne,
CreateDateColumn,
PrimaryGeneratedColumn,
Unique,
} from "typeorm";
import { TournamentRound } from "./TournamentRound";
import { User } from "./User";
import { TournamentRoundDate } from "./TournamentRoundDate";

@Entity()
@Unique(["user", "tournamentRound"])
Expand All @@ -21,6 +23,9 @@ export class TournamentRoundInvite {
@ManyToOne(type => TournamentRound, tournamentRound => tournamentRound.invitations)
tournamentRound!: TournamentRound;

@ManyToMany(type => TournamentRoundDate, tournamentRoundDate => tournamentRoundDate.signups)
signupDates!: TournamentRoundDate[];

@Column()
userId!: number;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {MigrationInterface, QueryRunner} from "typeorm";

export class AddTournamentRoundSignupDates1702416761748 implements MigrationInterface {
name = 'AddTournamentRoundSignupDates1702416761748'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "tournament_round_date_signups_tournament_round_invite" ("tournamentRoundDateId" integer NOT NULL, "tournamentRoundInviteId" integer NOT NULL, CONSTRAINT "PK_ea476e541957d189cb43e5566fb" PRIMARY KEY ("tournamentRoundDateId", "tournamentRoundInviteId"))`);
await queryRunner.query(`CREATE INDEX "IDX_179d52130a0f8722d72cfff0c5" ON "tournament_round_date_signups_tournament_round_invite" ("tournamentRoundDateId") `);
await queryRunner.query(`CREATE INDEX "IDX_d78ddb4862cff6e11870e81ced" ON "tournament_round_date_signups_tournament_round_invite" ("tournamentRoundInviteId") `);
await queryRunner.query(`ALTER TABLE "tournament_round_date_signups_tournament_round_invite" ADD CONSTRAINT "FK_179d52130a0f8722d72cfff0c5d" FOREIGN KEY ("tournamentRoundDateId") REFERENCES "tournament_round_date"("id") ON DELETE CASCADE ON UPDATE CASCADE`);
await queryRunner.query(`ALTER TABLE "tournament_round_date_signups_tournament_round_invite" ADD CONSTRAINT "FK_d78ddb4862cff6e11870e81ced8" FOREIGN KEY ("tournamentRoundInviteId") REFERENCES "tournament_round_invite"("id") ON DELETE CASCADE ON UPDATE CASCADE`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "tournament_round_date_signups_tournament_round_invite" DROP CONSTRAINT "FK_d78ddb4862cff6e11870e81ced8"`);
await queryRunner.query(`ALTER TABLE "tournament_round_date_signups_tournament_round_invite" DROP CONSTRAINT "FK_179d52130a0f8722d72cfff0c5d"`);
await queryRunner.query(`DROP INDEX "public"."IDX_d78ddb4862cff6e11870e81ced"`);
await queryRunner.query(`DROP INDEX "public"."IDX_179d52130a0f8722d72cfff0c5"`);
await queryRunner.query(`DROP TABLE "tournament_round_date_signups_tournament_round_invite"`);
}

}

0 comments on commit ccf18ae

Please sign in to comment.