Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 351
add tables for chapter/instance roles#335
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
| export class UserRoles1581584876652 implements MigrationInterface { | ||
| name = 'UserRoles1581584876652'; | ||
| public async up(queryRunner: QueryRunner): Promise<any> { | ||
| await queryRunner.query( | ||
| `CREATE TABLE "user_chapter_roles" ("user_id" integer NOT NULL, "chapter_id" integer NOT NULL, "role_name" character varying NOT NULL, CONSTRAINT "PK_d4726976f7c0d644f1a01cebe6d" PRIMARY KEY ("user_id", "chapter_id", "role_name"))`, | ||
| undefined, | ||
| ); | ||
| await queryRunner.query( | ||
| `CREATE TABLE "user_instance_roles" ("user_id" integer NOT NULL, "role_name" character varying NOT NULL, CONSTRAINT "PK_a6668338a373b7a8d914a193f3f" PRIMARY KEY ("user_id", "role_name"))`, | ||
| undefined, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "user_chapter_roles" ADD CONSTRAINT "FK_dff88cec5f2df9a6e9d9a7af03e" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, | ||
| undefined, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "user_chapter_roles" ADD CONSTRAINT "FK_c4b23ce3d811d599cea97d064fc" FOREIGN KEY ("chapter_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, | ||
| undefined, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "user_instance_roles" ADD CONSTRAINT "FK_f6aa9d1d5bffdd18382d18729d0" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, | ||
| undefined, | ||
| ); | ||
| } | ||
| public async down(queryRunner: QueryRunner): Promise<any> { | ||
| await queryRunner.query( | ||
| `ALTER TABLE "user_instance_roles" DROP CONSTRAINT "FK_f6aa9d1d5bffdd18382d18729d0"`, | ||
| undefined, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "user_chapter_roles" DROP CONSTRAINT "FK_c4b23ce3d811d599cea97d064fc"`, | ||
| undefined, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "user_chapter_roles" DROP CONSTRAINT "FK_dff88cec5f2df9a6e9d9a7af03e"`, | ||
| undefined, | ||
| ); | ||
| await queryRunner.query(`DROP TABLE "user_instance_roles"`, undefined); | ||
| await queryRunner.query(`DROP TABLE "user_chapter_roles"`, undefined); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { Entity, JoinColumn, ManyToOne, PrimaryColumn } from 'typeorm'; | ||
| import { User } from './User'; | ||
| import { Chapter } from './Chapter'; | ||
| export type ChapterRoles = 'organizer' | 'member'; | ||
| @Entity({ name: 'user_chapter_roles' }) | ||
| export class UserChapterRole { | ||
| @PrimaryColumn() | ||
| user_id!: number; | ||
| @PrimaryColumn() | ||
| chapter_id!: number; | ||
| @PrimaryColumn() | ||
| role_name!: ChapterRoles; | ||
| @ManyToOne(_type => User) | ||
| @JoinColumn({ name: 'user_id' }) | ||
| user!: User; | ||
| @ManyToOne(_type => User) | ||
| @JoinColumn({ name: 'chapter_id' }) | ||
| chapter!: Chapter; | ||
| constructor(params: { | ||
| userId: number; | ||
| roleName: ChapterRoles; | ||
| chapterId: number; | ||
| }) { | ||
| if (params) { | ||
| this.user_id = params.userId; | ||
| this.role_name = params.roleName; | ||
| this.chapter_id = params.chapterId; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { Entity, JoinColumn, ManyToOne, PrimaryColumn } from 'typeorm'; | ||
| import { User } from './User'; | ||
| export type InstanceRoles = 'admin' | 'owner'; | ||
| @Entity({ name: 'user_instance_roles' }) | ||
| export class UserInstanceRole { | ||
| @PrimaryColumn() | ||
| user_id!: number; | ||
| @PrimaryColumn() | ||
| role_name!: InstanceRoles; | ||
| @ManyToOne(_type => User) | ||
| @JoinColumn({ name: 'user_id' }) | ||
| user!: User; | ||
| constructor(params: { userId: number; roleName: InstanceRoles }) { | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be required if you have ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The | ||
| if (params) { | ||
| this.user_id = params.userId; | ||
| this.role_name = params.roleName; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the other one, make
params?: