From c85f23ed73caf1c4d0fef389065aa53e38c4d2bf Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Wed, 4 Sep 2024 11:36:52 +0200 Subject: [PATCH] self defined value tables --- src/data-source.ts | 27 ++- src/entity/award.ts | 16 ++ src/entity/communication.ts | 40 ++++ src/entity/communicationType.ts | 31 +++ src/entity/executivePosition.ts | 16 ++ src/entity/membershipStatus.ts | 14 ++ src/entity/qualification.ts | 19 ++ .../1725435669492-member_base_data.ts | 222 ++++++++++++++++++ 8 files changed, 382 insertions(+), 3 deletions(-) create mode 100644 src/entity/award.ts create mode 100644 src/entity/communication.ts create mode 100644 src/entity/communicationType.ts create mode 100644 src/entity/executivePosition.ts create mode 100644 src/entity/membershipStatus.ts create mode 100644 src/entity/qualification.ts create mode 100644 src/migrations/1725435669492-member_base_data.ts diff --git a/src/data-source.ts b/src/data-source.ts index 15aaf25..8f5b1f4 100644 --- a/src/data-source.ts +++ b/src/data-source.ts @@ -7,14 +7,21 @@ import { user } from "./entity/user"; import { refresh } from "./entity/refresh"; import { invite } from "./entity/invite"; import { userPermission } from "./entity/user_permission"; +import { role } from "./entity/role"; +import { rolePermission } from "./entity/role_permission"; +import { award } from "./entity/award"; +import { communication } from "./entity/communication"; +import { communicationType } from "./entity/communicationType"; +import { executivePosition } from "./entity/executivePosition"; +import { membershipStatus } from "./entity/membershipStatus"; +import { qualification } from "./entity/qualification"; import { Initial1724317398939 } from "./migrations/1724317398939-initial"; import { RefreshPrimaryChange1724573307851 } from "./migrations/1724573307851-refreshPrimaryChange"; import { Invite1724579024939 } from "./migrations/1724579024939-invite"; import { Permissions1724661484664 } from "./migrations/1724661484664-permissions"; -import { role } from "./entity/role"; -import { rolePermission } from "./entity/role_permission"; import { RolePermission1724771491085 } from "./migrations/1724771491085-role_permission"; +import { MemberBaseData1725435669492 } from "./migrations/1725435669492-member_base_data"; const dataSource = new DataSource({ type: DB_TYPE as any, @@ -26,13 +33,27 @@ const dataSource = new DataSource({ synchronize: false, logging: process.env.NODE_ENV ? true : ["schema", "error", "warn", "log", "migration"], bigNumberStrings: false, - entities: [user, refresh, invite, userPermission, role, rolePermission], + entities: [ + user, + refresh, + invite, + userPermission, + role, + rolePermission, + award, + communication, + communicationType, + executivePosition, + membershipStatus, + qualification, + ], migrations: [ Initial1724317398939, RefreshPrimaryChange1724573307851, Invite1724579024939, Permissions1724661484664, RolePermission1724771491085, + MemberBaseData1725435669492, ], migrationsRun: true, migrationsTransactionMode: "each", diff --git a/src/entity/award.ts b/src/entity/award.ts new file mode 100644 index 0000000..e5b8d38 --- /dev/null +++ b/src/entity/award.ts @@ -0,0 +1,16 @@ +import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm"; +//import { memberAwards } from "./memberAwards"; + +@Entity() +export class award { + @PrimaryColumn({ generated: "increment", type: "int" }) + id: number; + + @Column({ type: "varchar", length: 255 }) + award: string; + + // @OneToMany(() => memberAwards, (member) => member.award, { + // onDelete: "RESTRICT", + // }) + // members: memberAwards[]; +} diff --git a/src/entity/communication.ts b/src/entity/communication.ts new file mode 100644 index 0000000..78164d8 --- /dev/null +++ b/src/entity/communication.ts @@ -0,0 +1,40 @@ +import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from "typeorm"; +//import { member } from "./member"; +import { communicationType } from "./communicationType"; + +@Entity() +export class communication { + @PrimaryColumn({ generated: "increment", type: "int" }) + id: number; + + @Column({ type: "boolean", default: false }) + preffered: boolean; + + @Column({ type: "varchar", length: 255 }) + mobile: string; + + @Column({ type: "varchar", length: 255 }) + email: string; + + @Column({ type: "varchar", length: 255 }) + city: string; + + @Column({ type: "varchar", length: 255 }) + street: string; + + @Column({ type: "integer" }) + streetNumber: number; + + @Column({ type: "varchar", length: 255 }) + streetNumberAddition: string; + + @ManyToOne(() => communicationType, (communicationType) => communicationType.communications, { + nullable: false, + }) + type: communicationType; + + // @ManyToOne(() => member, (member) => member.awards, { + // onDelete: "RESTRICT", + // }) + // member: member; +} diff --git a/src/entity/communicationType.ts b/src/entity/communicationType.ts new file mode 100644 index 0000000..90da06f --- /dev/null +++ b/src/entity/communicationType.ts @@ -0,0 +1,31 @@ +import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm"; +import { communication } from "./communication"; + +@Entity() +export class communicationType { + @PrimaryColumn({ generated: "increment", type: "int" }) + id: number; + + @Column({ type: "varchar", length: 255 }) + type: string; + + @Column({ + type: "varchar", + length: 255, + default: "", + transformer: { + from(value: string): Array { + return value.split(","); + }, + to(value: Array): string { + return value.join(","); + }, + }, + }) + useColumns: Array; + + @OneToMany(() => communication, (communication) => communication.type, { + onDelete: "RESTRICT", + }) + communications: communication[]; +} diff --git a/src/entity/executivePosition.ts b/src/entity/executivePosition.ts new file mode 100644 index 0000000..1b11e7e --- /dev/null +++ b/src/entity/executivePosition.ts @@ -0,0 +1,16 @@ +import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm"; +//import { memberExecutivePositions } from "./memberExecutivePositions"; + +@Entity() +export class executivePosition { + @PrimaryColumn({ generated: "increment", type: "int" }) + id: number; + + @Column({ type: "varchar", length: 255 }) + position: string; + + // @OneToMany(() => memberExecutivePositions, (memberExecutivePositions) => memberExecutivePositions.executivePosition, { + // onDelete: "RESTRICT", + // }) + // members: memberExecutivePositions[]; +} diff --git a/src/entity/membershipStatus.ts b/src/entity/membershipStatus.ts new file mode 100644 index 0000000..640836b --- /dev/null +++ b/src/entity/membershipStatus.ts @@ -0,0 +1,14 @@ +import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm"; +//import { membership } from "./membership"; + +@Entity() +export class membershipStatus { + @PrimaryColumn({ generated: "increment", type: "int" }) + id: number; + + @Column({ type: "varchar", length: 255 }) + status: string; + + // @OneToMany(() => membership, (membership) => membership.status) + // memberships: membership[]; +} diff --git a/src/entity/qualification.ts b/src/entity/qualification.ts new file mode 100644 index 0000000..2f4652d --- /dev/null +++ b/src/entity/qualification.ts @@ -0,0 +1,19 @@ +import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm"; +//import { memberQualifications } from "./memberQualifications"; + +@Entity() +export class qualification { + @PrimaryColumn({ generated: "increment", type: "int" }) + id: number; + + @Column({ type: "varchar", length: 255 }) + qualification: string; + + @Column({ type: "varchar", length: 255, nullable: true, default: null }) + description?: string; + + // @OneToMany(() => memberQualifications, (memberQualifications) => memberQualifications.qualification, { + // onDelete: "RESTRICT", + // }) + // members: memberQualifications[]; +} diff --git a/src/migrations/1725435669492-member_base_data.ts b/src/migrations/1725435669492-member_base_data.ts new file mode 100644 index 0000000..cc85791 --- /dev/null +++ b/src/migrations/1725435669492-member_base_data.ts @@ -0,0 +1,222 @@ +import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm"; + +export class MemberBaseData1725435669492 implements MigrationInterface { + name = "MemberBaseData1725435669492"; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.createTable( + new Table({ + name: "award", + columns: [ + { + name: "id", + type: "int", + isPrimary: true, + isNullable: false, + isGenerated: true, + generationStrategy: "increment", + }, + { + name: "award", + type: "varchar", + length: "255", + isNullable: false, + }, + ], + }), + true + ); + + await queryRunner.createTable( + new Table({ + name: "communication_type", + columns: [ + { + name: "id", + type: "int", + isPrimary: true, + isNullable: false, + isGenerated: true, + generationStrategy: "increment", + }, + { + name: "type", + type: "varchar", + length: "255", + isNullable: false, + }, + { + name: "useColumns", + type: "varchar", + length: "255", + isNullable: false, + default: "''", + }, + ], + }), + true + ); + + await queryRunner.createTable( + new Table({ + name: "communication", + columns: [ + { + name: "id", + type: "int", + isPrimary: true, + isNullable: false, + isGenerated: true, + generationStrategy: "increment", + }, + { + name: "preffered", + type: "tinyint", + isNullable: false, + default: 0, + }, + { + name: "mobile", + type: "varchar", + length: "255", + isNullable: false, + }, + { + name: "email", + type: "varchar", + length: "255", + isNullable: false, + }, + { + name: "city", + type: "varchar", + length: "255", + isNullable: false, + }, + { + name: "street", + type: "varchar", + length: "255", + isNullable: false, + }, + { + name: "streetNumber", + type: "int", + isNullable: false, + }, + { + name: "streetNumberAddition", + type: "varchar", + length: "255", + isNullable: false, + }, + { + name: "typeId", + type: "int", + isNullable: false, + }, + ], + }), + true + ); + + await queryRunner.createTable( + new Table({ + name: "executive_position", + columns: [ + { + name: "id", + type: "int", + isPrimary: true, + isNullable: false, + isGenerated: true, + generationStrategy: "increment", + }, + { + name: "position", + type: "varchar", + length: "255", + isNullable: false, + }, + ], + }), + true + ); + + await queryRunner.createTable( + new Table({ + name: "membership_status", + columns: [ + { + name: "id", + type: "int", + isPrimary: true, + isNullable: false, + isGenerated: true, + generationStrategy: "increment", + }, + { + name: "status", + type: "varchar", + length: "255", + isNullable: false, + }, + ], + }), + true + ); + + await queryRunner.createTable( + new Table({ + name: "qualification", + columns: [ + { + name: "id", + type: "int", + isPrimary: true, + isNullable: false, + isGenerated: true, + generationStrategy: "increment", + }, + { + name: "qualification", + type: "varchar", + length: "255", + isNullable: false, + }, + { + name: "description", + type: "varchar", + length: "255", + isNullable: true, + default: null, + }, + ], + }), + true + ); + + await queryRunner.createForeignKey( + "communication", + new TableForeignKey({ + columnNames: ["typeId"], + referencedColumnNames: ["id"], + referencedTableName: "communication_type", + onDelete: "RESTRICT", + }) + ); + } + + public async down(queryRunner: QueryRunner): Promise { + const communication = await queryRunner.getTable("communication"); + const foreignKey = communication.foreignKeys.find((fk) => fk.columnNames.indexOf("typeId") !== -1); + await queryRunner.dropForeignKey("communication", foreignKey); + + await queryRunner.dropTable("qualification"); + await queryRunner.dropTable("membership_status"); + await queryRunner.dropTable("executive_position"); + await queryRunner.dropTable("communication"); + await queryRunner.dropTable("communication_type"); + await queryRunner.dropTable("award"); + } +}