#3-calendar #11

Merged
jkeffects merged 7 commits from #3-calendar into main 2024-11-07 10:10:01 +00:00
4 changed files with 113 additions and 0 deletions
Showing only changes of commit e7b8257336 - Show all commits

View file

@ -29,6 +29,9 @@ import { memberQualifications } from "./entity/memberQualifications";
import { membership } from "./entity/membership"; import { membership } from "./entity/membership";
import { Memberdata1726301836849 } from "./migrations/1726301836849-memberdata"; import { Memberdata1726301836849 } from "./migrations/1726301836849-memberdata";
import { CommunicationFields1727439800630 } from "./migrations/1727439800630-communicationFields"; import { CommunicationFields1727439800630 } from "./migrations/1727439800630-communicationFields";
import { calendar } from "./entity/calendar";
import { calendarType } from "./entity/calendarType";
import { Calendar1729947763295 } from "./migrations/1729947763295-calendar";
const dataSource = new DataSource({ const dataSource = new DataSource({
type: DB_TYPE as any, type: DB_TYPE as any,
@ -58,6 +61,8 @@ const dataSource = new DataSource({
memberExecutivePositions, memberExecutivePositions,
memberQualifications, memberQualifications,
membership, membership,
calendar,
calendarType,
], ],
migrations: [ migrations: [
Initial1724317398939, Initial1724317398939,
@ -68,6 +73,7 @@ const dataSource = new DataSource({
MemberBaseData1725435669492, MemberBaseData1725435669492,
Memberdata1726301836849, Memberdata1726301836849,
CommunicationFields1727439800630, CommunicationFields1727439800630,
Calendar1729947763295,
], ],
migrationsRun: true, migrationsRun: true,
migrationsTransactionMode: "each", migrationsTransactionMode: "each",

30
src/entity/calendar.ts Normal file
View file

@ -0,0 +1,30 @@
import { Column, Entity, ManyToOne, PrimaryColumn, PrimaryGeneratedColumn } from "typeorm";
import { calendarType } from "./calendarType";
@Entity()
export class calendar {
@PrimaryGeneratedColumn("increment")
id: number;
@Column({ type: "date", nullable: false })
date: Date;
@Column({ type: "timestamp", nullable: true })
starttime: Date;
@Column({ type: "datetime", nullable: true })
endtime: Date;
@Column({ type: "varchar", length: 255, nullable: false })
title: string;
@Column({ type: "text", nullable: true })
content: string;
@ManyToOne(() => calendarType, (t) => t.calendar, {
nullable: false,
onDelete: "RESTRICT",
onUpdate: "RESTRICT",
})
type: calendarType;
}

View file

@ -0,0 +1,21 @@
import { Column, Entity, OneToMany, PrimaryColumn, PrimaryGeneratedColumn } from "typeorm";
import { calendar } from "./calendar";
@Entity()
export class calendarType {
@PrimaryColumn({ generated: "increment", type: "int" })
id: number;
@Column({ type: "varchar", length: 255 })
type: string;
@Column({ type: "boolean" }) // none specified cal dav request
nscdr: boolean;
@OneToMany(() => calendar, (c) => c.type, {
nullable: false,
onDelete: "RESTRICT",
onUpdate: "RESTRICT",
})
calendar: calendar[];
}

View file

@ -0,0 +1,56 @@
import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm";
import { DB_TYPE } from "../env.defaults";
export class Calendar1729947763295 implements MigrationInterface {
name = "Calendar1729947763295";
public async up(queryRunner: QueryRunner): Promise<void> {
const variableType_int = DB_TYPE == "mysql" ? "int" : "integer";
await queryRunner.createTable(
new Table({
name: "calendar_type",
columns: [
{ name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" },
{ name: "type", type: "varchar", length: "255", isNullable: false },
{ name: "nscdr", type: "tinyint", isNullable: false },
],
})
);
await queryRunner.createTable(
new Table({
name: "calendar",
columns: [
{ name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" },
{ name: "date", type: "date", isNullable: false },
{ name: "starttime", type: "timestamp", isNullable: true },
{ name: "endtime", type: "datetime", isNullable: true },
{ name: "title", type: "varchar", length: "255", isNullable: false },
{ name: "content", type: "text", isNullable: true },
{ name: "typeId", type: variableType_int, isNullable: false },
],
})
);
await queryRunner.createForeignKey(
"calendar",
new TableForeignKey({
columnNames: ["typeId"],
referencedColumnNames: ["id"],
referencedTableName: "calendar_type",
onDelete: "RESTRICT",
onUpdate: "RESTRICT",
})
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
const table = await queryRunner.getTable("calendar");
const foreignKey = table.foreignKeys.find((fk) => fk.columnNames.indexOf("typeId") !== -1);
await queryRunner.dropForeignKey("calendar", foreignKey);
await queryRunner.dropTable("calendar");
await queryRunner.dropTable("calendar_type");
}
}