-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #343 from TaloDev/pinned-groups
Pinned groups
- Loading branch information
Showing
16 changed files
with
447 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Entity, ManyToOne, PrimaryKey, Property, Unique } from '@mikro-orm/mysql' | ||
import User from './user' | ||
import PlayerGroup from './player-group' | ||
|
||
@Entity() | ||
@Unique({ properties: ['user', 'group'] }) | ||
export default class UserPinnedGroup { | ||
@PrimaryKey() | ||
id: number | ||
|
||
@ManyToOne(() => User, { eager: true }) | ||
user: User | ||
|
||
@ManyToOne(() => PlayerGroup, { eager: true }) | ||
group: PlayerGroup | ||
|
||
@Property() | ||
createdAt: Date = new Date() | ||
|
||
constructor(user: User, group: PlayerGroup) { | ||
this.user = user | ||
this.group = group | ||
} | ||
} |
This file contains 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
This file contains 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
19 changes: 19 additions & 0 deletions
19
src/migrations/20241001194252CreateUserPinnedGroupsTable.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Migration } from '@mikro-orm/migrations' | ||
|
||
export class CreateUserPinnedGroupsTable extends Migration { | ||
|
||
override async up(): Promise<void> { | ||
this.addSql('create table `user_pinned_group` (`id` int unsigned not null auto_increment primary key, `user_id` int unsigned not null, `group_id` varchar(255) not null, `created_at` datetime not null) default character set utf8mb4 engine = InnoDB;') | ||
this.addSql('alter table `user_pinned_group` add index `user_pinned_group_user_id_index`(`user_id`);') | ||
this.addSql('alter table `user_pinned_group` add index `user_pinned_group_group_id_index`(`group_id`);') | ||
this.addSql('alter table `user_pinned_group` add unique `user_pinned_group_user_id_group_id_unique`(`user_id`, `group_id`);') | ||
|
||
this.addSql('alter table `user_pinned_group` add constraint `user_pinned_group_user_id_foreign` foreign key (`user_id`) references `user` (`id`) on update cascade;') | ||
this.addSql('alter table `user_pinned_group` add constraint `user_pinned_group_group_id_foreign` foreign key (`group_id`) references `player_group` (`id`) on update cascade;') | ||
} | ||
|
||
override async down(): Promise<void> { | ||
this.addSql('drop table if exists `user_pinned_group`;') | ||
} | ||
|
||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Factory } from 'hefty' | ||
import UserPinnedGroup from '../../src/entities/user-pinned-group' | ||
import UserFactory from './UserFactory' | ||
import PlayerGroupFactory from './PlayerGroupFactory' | ||
import GameFactory from './GameFactory' | ||
import OrganisationFactory from './OrganisationFactory' | ||
|
||
export default class UserPinnedGroupFactory extends Factory<UserPinnedGroup> { | ||
constructor() { | ||
super(UserPinnedGroup) | ||
} | ||
|
||
protected definition(): void { | ||
this.state(async () => { | ||
const organisation = await new OrganisationFactory().one() | ||
const game = await new GameFactory(organisation).one() | ||
|
||
return { | ||
user: await new UserFactory().state(() => ({ organisation })).one(), | ||
group: await new PlayerGroupFactory().state(() => ({ game })).one() | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.