#2-protocol #10

Merged
jkeffects merged 14 commits from #2-protocol into main 2024-10-29 14:45:37 +00:00
7 changed files with 73 additions and 1 deletions
Showing only changes of commit edc35f2f87 - Show all commits

View file

@ -20,3 +20,16 @@ export async function getAllProtocols(req: Request, res: Response): Promise<any>
count: count, 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<any> {
let id = parseInt(req.params.id);
let protocol = await ProtocolService.getById(id);
res.json(ProtocolFactory.mapToSingle(protocol));
}

View file

@ -31,6 +31,7 @@ import { Memberdata1726301836849 } from "./migrations/1726301836849-memberdata";
import { CommunicationFields1727439800630 } from "./migrations/1727439800630-communicationFields"; import { CommunicationFields1727439800630 } from "./migrations/1727439800630-communicationFields";
import { protocol } from "./entity/protocol"; import { protocol } from "./entity/protocol";
import { ProtocolInit1727953803404 } from "./migrations/1727953803404-protocol-init"; import { ProtocolInit1727953803404 } from "./migrations/1727953803404-protocol-init";
import { ProtocolBase1728037129072 } from "./migrations/1728037129072-protocolBase";
const dataSource = new DataSource({ const dataSource = new DataSource({
type: DB_TYPE as any, type: DB_TYPE as any,
@ -72,6 +73,7 @@ const dataSource = new DataSource({
Memberdata1726301836849, Memberdata1726301836849,
CommunicationFields1727439800630, CommunicationFields1727439800630,
ProtocolInit1727953803404, ProtocolInit1727953803404,
ProtocolBase1728037129072,
], ],
migrationsRun: true, migrationsRun: true,
migrationsTransactionMode: "each", migrationsTransactionMode: "each",

View file

@ -10,4 +10,13 @@ export class protocol {
@Column({ type: "date" }) @Column({ type: "date" })
date: Date; date: Date;
@Column({ type: "timestamp" })
starttime: Date;
@Column({ type: "timestamp" })
endtime: Date;
@Column({ type: "text" })
summary: string;
} }

View file

@ -12,6 +12,9 @@ export default abstract class ProtocolFactory {
id: record.id, id: record.id,
title: record.title, title: record.title,
date: record.date, date: record.date,
starttime: record.starttime,
endtime: record.endtime,
summary: record.summary,
}; };
} }

View file

@ -0,0 +1,38 @@
import { MigrationInterface, QueryRunner, TableColumn } from "typeorm";
export class ProtocolBase1728037129072 implements MigrationInterface {
name = "ProtocolBase1728037129072";
public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
await queryRunner.dropColumn("protocol", "summary");
await queryRunner.dropColumn("protocol", "endtime");
await queryRunner.dropColumn("protocol", "starttime");
}
}

View file

@ -1,5 +1,5 @@
import express, { Request, Response } from "express"; 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 }); var router = express.Router({ mergeParams: true });
@ -7,4 +7,8 @@ router.get("/", async (req: Request, res: Response) => {
await getAllProtocols(req, res); await getAllProtocols(req, res);
}); });
router.get("/:id", async (req: Request, res: Response) => {
await getProtocolById(req, res);
});
export default router; export default router;

View file

@ -2,4 +2,7 @@ export interface ProtocolViewModel {
id: number; id: number;
title: string; title: string;
date: Date; date: Date;
starttime: Date;
endtime: Date;
summary: string;
} }