From edc35f2f878e4d348086a411b85337684296d78e Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Fri, 4 Oct 2024 12:47:13 +0200 Subject: [PATCH] protocol base data --- src/controller/admin/protocolController.ts | 13 +++++++ src/data-source.ts | 2 ++ src/entity/protocol.ts | 9 +++++ src/factory/admin/protocol.ts | 3 ++ src/migrations/1728037129072-protocolBase.ts | 38 ++++++++++++++++++++ src/routes/admin/protocol.ts | 6 +++- src/viewmodel/admin/protocol.models.ts | 3 ++ 7 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/migrations/1728037129072-protocolBase.ts diff --git a/src/controller/admin/protocolController.ts b/src/controller/admin/protocolController.ts index 6df7366..b94ac1f 100644 --- a/src/controller/admin/protocolController.ts +++ b/src/controller/admin/protocolController.ts @@ -20,3 +20,16 @@ export async function getAllProtocols(req: Request, res: Response): Promise count: count, }); } + +/** + * @description get protocol by id + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getProtocolById(req: Request, res: Response): Promise { + let id = parseInt(req.params.id); + let protocol = await ProtocolService.getById(id); + + res.json(ProtocolFactory.mapToSingle(protocol)); +} diff --git a/src/data-source.ts b/src/data-source.ts index 4b01f48..e1de44b 100644 --- a/src/data-source.ts +++ b/src/data-source.ts @@ -31,6 +31,7 @@ import { Memberdata1726301836849 } from "./migrations/1726301836849-memberdata"; import { CommunicationFields1727439800630 } from "./migrations/1727439800630-communicationFields"; import { protocol } from "./entity/protocol"; import { ProtocolInit1727953803404 } from "./migrations/1727953803404-protocol-init"; +import { ProtocolBase1728037129072 } from "./migrations/1728037129072-protocolBase"; const dataSource = new DataSource({ type: DB_TYPE as any, @@ -72,6 +73,7 @@ const dataSource = new DataSource({ Memberdata1726301836849, CommunicationFields1727439800630, ProtocolInit1727953803404, + ProtocolBase1728037129072, ], migrationsRun: true, migrationsTransactionMode: "each", diff --git a/src/entity/protocol.ts b/src/entity/protocol.ts index 9285e0f..ff25531 100644 --- a/src/entity/protocol.ts +++ b/src/entity/protocol.ts @@ -10,4 +10,13 @@ export class protocol { @Column({ type: "date" }) date: Date; + + @Column({ type: "timestamp" }) + starttime: Date; + + @Column({ type: "timestamp" }) + endtime: Date; + + @Column({ type: "text" }) + summary: string; } diff --git a/src/factory/admin/protocol.ts b/src/factory/admin/protocol.ts index ef5a873..9b86894 100644 --- a/src/factory/admin/protocol.ts +++ b/src/factory/admin/protocol.ts @@ -12,6 +12,9 @@ export default abstract class ProtocolFactory { id: record.id, title: record.title, date: record.date, + starttime: record.starttime, + endtime: record.endtime, + summary: record.summary, }; } diff --git a/src/migrations/1728037129072-protocolBase.ts b/src/migrations/1728037129072-protocolBase.ts new file mode 100644 index 0000000..e1f9a71 --- /dev/null +++ b/src/migrations/1728037129072-protocolBase.ts @@ -0,0 +1,38 @@ +import { MigrationInterface, QueryRunner, TableColumn } from "typeorm"; + +export class ProtocolBase1728037129072 implements MigrationInterface { + name = "ProtocolBase1728037129072"; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.addColumn( + "protocol", + new TableColumn({ + name: "starttime", + type: "timestamp", + isNullable: false, + }) + ); + await queryRunner.addColumn( + "protocol", + new TableColumn({ + name: "endtime", + type: "timestamp", + isNullable: false, + }) + ); + await queryRunner.addColumn( + "protocol", + new TableColumn({ + name: "summary", + type: "text", + isNullable: false, + }) + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.dropColumn("protocol", "summary"); + await queryRunner.dropColumn("protocol", "endtime"); + await queryRunner.dropColumn("protocol", "starttime"); + } +} diff --git a/src/routes/admin/protocol.ts b/src/routes/admin/protocol.ts index e737ea5..e353582 100644 --- a/src/routes/admin/protocol.ts +++ b/src/routes/admin/protocol.ts @@ -1,5 +1,5 @@ import express, { Request, Response } from "express"; -import { getAllProtocols } from "../../controller/admin/protocolController"; +import { getAllProtocols, getProtocolById } from "../../controller/admin/protocolController"; var router = express.Router({ mergeParams: true }); @@ -7,4 +7,8 @@ router.get("/", async (req: Request, res: Response) => { await getAllProtocols(req, res); }); +router.get("/:id", async (req: Request, res: Response) => { + await getProtocolById(req, res); +}); + export default router; diff --git a/src/viewmodel/admin/protocol.models.ts b/src/viewmodel/admin/protocol.models.ts index 051b832..c02e60c 100644 --- a/src/viewmodel/admin/protocol.models.ts +++ b/src/viewmodel/admin/protocol.models.ts @@ -2,4 +2,7 @@ export interface ProtocolViewModel { id: number; title: string; date: Date; + starttime: Date; + endtime: Date; + summary: string; }