#3-calendar #11

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

View file

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

View file

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

View file

@ -69,19 +69,21 @@ export async function getCalendarTypeById(req: Request, res: Response): Promise<
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function createCalendarItem(req: Request, res: Response): Promise<any> { export async function createCalendarItem(req: Request, res: Response): Promise<any> {
const date = req.body.date;
const starttime = req.body.starttime; const starttime = req.body.starttime;
const endtime = req.body.endtime; const endtime = req.body.endtime;
const title = req.body.title; const title = req.body.title;
const content = req.body.content; const content = req.body.content;
const location = req.body.location;
const allDay = req.body.allDay;
const typeId = req.body.typeId; const typeId = req.body.typeId;
let createItem: CreateCalendarCommand = { let createItem: CreateCalendarCommand = {
date,
starttime, starttime,
endtime, endtime,
title, title,
content, content,
location,
allDay,
typeId, typeId,
}; };
let id = await CalendarCommandHandler.create(createItem); let id = await CalendarCommandHandler.create(createItem);
@ -117,21 +119,23 @@ export async function createCalendarType(req: Request, res: Response): Promise<a
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function updateCalendarItem(req: Request, res: Response): Promise<any> { export async function updateCalendarItem(req: Request, res: Response): Promise<any> {
const id = parseInt(req.params.id); const id = req.params.id;
const date = req.body.date;
const starttime = req.body.starttime; const starttime = req.body.starttime;
const endtime = req.body.endtime; const endtime = req.body.endtime;
const title = req.body.title; const title = req.body.title;
const content = req.body.content; const content = req.body.content;
const location = req.body.location;
const allDay = req.body.allDay;
const typeId = req.body.typeId; const typeId = req.body.typeId;
let updateItem: UpdateCalendarCommand = { let updateItem: UpdateCalendarCommand = {
id, id,
date,
starttime, starttime,
endtime, endtime,
title, title,
content, content,
location,
allDay,
typeId, typeId,
}; };
await CalendarCommandHandler.update(updateItem); await CalendarCommandHandler.update(updateItem);
@ -169,7 +173,7 @@ export async function updateCalendarType(req: Request, res: Response): Promise<a
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function deleteCalendarItem(req: Request, res: Response): Promise<any> { export async function deleteCalendarItem(req: Request, res: Response): Promise<any> {
const id = parseInt(req.params.id); const id = req.params.id;
let deleteItem: DeleteCalendarCommand = { let deleteItem: DeleteCalendarCommand = {
id, 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"; import { calendarType } from "./calendarType";
@Entity() @Entity()
export class calendar { export class calendar {
@PrimaryGeneratedColumn("increment") @PrimaryGeneratedColumn("uuid")
id: number; id: string;
@Column({ type: "date", nullable: false }) @Column({ type: "datetime", nullable: false })
date: Date;
@Column({ type: "timestamp", nullable: true })
starttime: Date; starttime: Date;
@Column({ type: "datetime", nullable: true }) @Column({ type: "datetime", nullable: false })
endtime: Date; endtime: Date;
@Column({ type: "varchar", length: 255, nullable: false }) @Column({ type: "varchar", length: 255, nullable: false })
@ -21,6 +26,18 @@ export class calendar {
@Column({ type: "text", nullable: true }) @Column({ type: "text", nullable: true })
content: string; 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, { @ManyToOne(() => calendarType, (t) => t.calendar, {
nullable: false, nullable: false,
onDelete: "RESTRICT", onDelete: "RESTRICT",

View file

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

View file

@ -23,12 +23,22 @@ export class Calendar1729947763295 implements MigrationInterface {
new Table({ new Table({
name: "calendar", name: "calendar",
columns: [ columns: [
{ name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, { name: "id", type: "varchar", length: "36", isPrimary: true, isGenerated: true, generationStrategy: "uuid" },
{ name: "date", type: "date", isNullable: false }, { name: "starttime", type: "datetime", isNullable: false },
{ name: "starttime", type: "timestamp", isNullable: true }, { name: "endtime", type: "datetime", isNullable: false },
{ name: "endtime", type: "datetime", isNullable: true },
{ name: "title", type: "varchar", length: "255", isNullable: false }, { name: "title", type: "varchar", length: "255", isNullable: false },
{ name: "content", type: "text", isNullable: true }, { 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 }, { name: "typeId", type: variableType_int, isNullable: false },
], ],
}) })

View file

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

View file

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