calendar fixes

This commit is contained in:
Julian Krauser 2024-10-28 16:02:56 +01:00
parent 136da08b70
commit 8c597fd68d
8 changed files with 70 additions and 27 deletions

View file

@ -1,22 +1,24 @@
export interface CreateCalendarCommand {
date: Date;
starttime: Date;
endtime: Date;
title: string;
content: string;
location: string;
allDay: boolean;
typeId: number;
}
export interface UpdateCalendarCommand {
id: number;
date: Date;
id: string;
starttime: Date;
endtime: Date;
title: string;
content: string;
location: string;
allDay: boolean;
typeId: number;
}
export interface DeleteCalendarCommand {
id: number;
id: string;
}

View file

@ -16,11 +16,12 @@ export default abstract class CalendarCommandHandler {
.insert()
.into(calendar)
.values({
date: createCalendar.date,
starttime: createCalendar.starttime,
endtime: createCalendar.endtime,
title: createCalendar.title,
content: createCalendar.content,
location: createCalendar.location,
allDay: createCalendar.allDay,
type: await dataSource
.getRepository(calendarType)
.createQueryBuilder("type")
@ -46,11 +47,12 @@ export default abstract class CalendarCommandHandler {
.createQueryBuilder()
.update(calendar)
.set({
date: updateCalendar.date,
starttime: updateCalendar.starttime,
endtime: updateCalendar.endtime,
title: updateCalendar.title,
content: updateCalendar.content,
location: updateCalendar.location,
allDay: updateCalendar.allDay,
type: await dataSource
.getRepository(calendarType)
.createQueryBuilder("type")

View file

@ -69,19 +69,21 @@ export async function getCalendarTypeById(req: Request, res: Response): Promise<
* @returns {Promise<*>}
*/
export async function createCalendarItem(req: Request, res: Response): Promise<any> {
const date = req.body.date;
const starttime = req.body.starttime;
const endtime = req.body.endtime;
const title = req.body.title;
const content = req.body.content;
const location = req.body.location;
const allDay = req.body.allDay;
const typeId = req.body.typeId;
let createItem: CreateCalendarCommand = {
date,
starttime,
endtime,
title,
content,
location,
allDay,
typeId,
};
let id = await CalendarCommandHandler.create(createItem);
@ -117,21 +119,23 @@ export async function createCalendarType(req: Request, res: Response): Promise<a
* @returns {Promise<*>}
*/
export async function updateCalendarItem(req: Request, res: Response): Promise<any> {
const id = parseInt(req.params.id);
const date = req.body.date;
const id = req.params.id;
const starttime = req.body.starttime;
const endtime = req.body.endtime;
const title = req.body.title;
const content = req.body.content;
const location = req.body.location;
const allDay = req.body.allDay;
const typeId = req.body.typeId;
let updateItem: UpdateCalendarCommand = {
id,
date,
starttime,
endtime,
title,
content,
location,
allDay,
typeId,
};
await CalendarCommandHandler.update(updateItem);
@ -169,7 +173,7 @@ export async function updateCalendarType(req: Request, res: Response): Promise<a
* @returns {Promise<*>}
*/
export async function deleteCalendarItem(req: Request, res: Response): Promise<any> {
const id = parseInt(req.params.id);
const id = req.params.id;
let deleteItem: DeleteCalendarCommand = {
id,

View file

@ -1,18 +1,23 @@
import { Column, Entity, ManyToOne, PrimaryColumn, PrimaryGeneratedColumn } from "typeorm";
import {
Column,
Entity,
ManyToOne,
PrimaryColumn,
PrimaryGeneratedColumn,
CreateDateColumn,
UpdateDateColumn,
} from "typeorm";
import { calendarType } from "./calendarType";
@Entity()
export class calendar {
@PrimaryGeneratedColumn("increment")
id: number;
@PrimaryGeneratedColumn("uuid")
id: string;
@Column({ type: "date", nullable: false })
date: Date;
@Column({ type: "timestamp", nullable: true })
@Column({ type: "datetime", nullable: false })
starttime: Date;
@Column({ type: "datetime", nullable: true })
@Column({ type: "datetime", nullable: false })
endtime: Date;
@Column({ type: "varchar", length: 255, nullable: false })
@ -21,6 +26,18 @@ export class calendar {
@Column({ type: "text", nullable: true })
content: string;
@Column({ type: "text", nullable: true })
location: string;
@Column({ type: "boolean", default: false })
allDay: boolean;
@CreateDateColumn()
createdAt: Date;
@UpdateDateColumn()
updatedAt: Date;
@ManyToOne(() => calendarType, (t) => t.calendar, {
nullable: false,
onDelete: "RESTRICT",

View file

@ -11,11 +11,14 @@ export default abstract class CalendarFactory {
public static mapToSingle(record: calendar): CalendarViewModel {
return {
id: record.id,
date: record.date,
starttime: record.starttime,
endtime: record.endtime,
title: record.title,
content: record.content,
location: record.location,
allDay: record.allDay,
createdAt: record.createdAt,
updatedAt: record.updatedAt,
type: CalendarTypeFactory.mapToSingle(record.type),
};
}

View file

@ -23,12 +23,22 @@ export class Calendar1729947763295 implements MigrationInterface {
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: "id", type: "varchar", length: "36", isPrimary: true, isGenerated: true, generationStrategy: "uuid" },
{ name: "starttime", type: "datetime", isNullable: false },
{ name: "endtime", type: "datetime", isNullable: false },
{ name: "title", type: "varchar", length: "255", isNullable: false },
{ name: "content", type: "text", isNullable: true },
{ name: "allDay", type: "tinyint", isNullable: false, default: 0 },
{ name: "location", type: "text", isNullable: true },
{ name: "createdAt", type: "datetime", precision: 6, isNullable: false, default: "CURRENT_TIMESTAMP(6)" },
{
name: "updatedAt",
type: "datetime",
precision: 6,
isNullable: false,
default: "CURRENT_TIMESTAMP(6)",
onUpdate: "CURRENT_TIMESTAMP(6)",
},
{ name: "typeId", type: variableType_int, isNullable: false },
],
})

View file

@ -11,6 +11,7 @@ export default abstract class CalendarService {
return await dataSource
.getRepository(calendar)
.createQueryBuilder("calendar")
.leftJoinAndSelect("calendar.type", "type")
.getMany()
.then((res) => {
return res;
@ -28,6 +29,7 @@ export default abstract class CalendarService {
return await dataSource
.getRepository(calendar)
.createQueryBuilder("calendar")
.leftJoinAndSelect("calendar.type", "type")
.where("calendar.id = :id", { id: id })
.getOneOrFail()
.then((res) => {

View file

@ -1,11 +1,14 @@
import { CalendarTypeViewModel } from "./calendarType.models";
export interface CalendarViewModel {
id: number;
date: Date;
id: string;
starttime: Date;
endtime: Date;
title: string;
content: string;
location: string;
allDay: boolean;
createdAt: Date;
updatedAt: Date;
type: CalendarTypeViewModel;
}