Skip to content

Commit

Permalink
trying to fix public lobby
Browse files Browse the repository at this point in the history
  • Loading branch information
littlegubs committed Aug 25, 2024
1 parent 83b33ad commit bddd9df
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/lobbies/entities/lobby-user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Column,
CreateDateColumn,
Entity,
JoinColumn,
ManyToOne,
OneToOne,
PrimaryGeneratedColumn,
Expand Down Expand Up @@ -84,6 +85,7 @@ export class LobbyUser {

@OneToOne(() => User, (user) => user.currentLobby, { onDelete: 'CASCADE' })
@Expose({ groups: ['wsLobby'] })
@JoinColumn()
user: User

@ManyToOne(() => Lobby, (lobby) => lobby.lobbyUsers, {
Expand Down
26 changes: 26 additions & 0 deletions src/migration/1724582123266-userLobby.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class UserLobby1724582123266 implements MigrationInterface {
name = 'UserLobby1724582123266'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`user\` DROP FOREIGN KEY \`FK_62aaa60b7d806a445ecd50870e2\``);
await queryRunner.query(`DROP INDEX \`REL_62aaa60b7d806a445ecd50870e\` ON \`user\``);
await queryRunner.query(`ALTER TABLE \`user\` DROP COLUMN \`currentLobbyId\``);
await queryRunner.query(`ALTER TABLE \`lobby_user\` ADD \`userId\` int NULL`);
await queryRunner.query(`ALTER TABLE \`lobby_user\` ADD UNIQUE INDEX \`IDX_8299cbcd62fd1a04f84617885b\` (\`userId\`)`);
await queryRunner.query(`CREATE UNIQUE INDEX \`REL_8299cbcd62fd1a04f84617885b\` ON \`lobby_user\` (\`userId\`)`);
await queryRunner.query(`ALTER TABLE \`lobby_user\` ADD CONSTRAINT \`FK_8299cbcd62fd1a04f84617885b7\` FOREIGN KEY (\`userId\`) REFERENCES \`user\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`lobby_user\` DROP FOREIGN KEY \`FK_8299cbcd62fd1a04f84617885b7\``);
await queryRunner.query(`DROP INDEX \`REL_8299cbcd62fd1a04f84617885b\` ON \`lobby_user\``);
await queryRunner.query(`ALTER TABLE \`lobby_user\` DROP INDEX \`IDX_8299cbcd62fd1a04f84617885b\``);
await queryRunner.query(`ALTER TABLE \`lobby_user\` DROP COLUMN \`userId\``);
await queryRunner.query(`ALTER TABLE \`user\` ADD \`currentLobbyId\` int NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX \`REL_62aaa60b7d806a445ecd50870e\` ON \`user\` (\`currentLobbyId\`)`);
await queryRunner.query(`ALTER TABLE \`user\` ADD CONSTRAINT \`FK_62aaa60b7d806a445ecd50870e2\` FOREIGN KEY (\`currentLobbyId\`) REFERENCES \`lobby_user\`(\`id\`) ON DELETE SET NULL ON UPDATE NO ACTION`);
}

}
3 changes: 1 addition & 2 deletions src/users/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export class User {
games: Game[]

@OneToOne(() => LobbyUser, (lobbyUser) => lobbyUser.user, { onDelete: 'SET NULL' })
@JoinColumn()
currentLobby?: LobbyUser

@Column()
Expand All @@ -79,7 +78,7 @@ export class User {
@UpdateDateColumn()
updatedAt: Date

@BeforeInsert() async hashPassword() {
@BeforeInsert() async hashPassword(): Promise<void> {
this.password = await bcrypt.hash(this.password, 8)
}

Expand Down

0 comments on commit bddd9df

Please sign in to comment.