add handlers in TaskModel

This commit is contained in:
marlon-erler
2024-07-22 11:49:05 +02:00
parent 6d126a2fa8
commit 29c3e4ad43
4 changed files with 160 additions and 39 deletions
+54 -6
View File
@@ -1,26 +1,73 @@
// thile file is responsible for managing task files within chats.
import FileModel, { FileContent } from "./fileModel";
import {
DATA_VERSION,
checkMatchesObjectStructure,
} from "../Utility/typeSafety";
import FileModel, { File, FileContent } from "./fileModel";
import ChatModel from "../Chat/chatModel";
import { DATA_VERSION } from "../Utility/typeSafety";
export default class TaskModel {
chatModel: ChatModel;
fileModel: FileModel;
// handler
handleTaskFileContent = (
file: File,
fileContent: FileContent<string>
): void => {
if (
checkMatchesObjectStructure(fileContent, TaskFileContentReference) ==
false
)
return;
// TODO handle
};
// methods
createTask = (board: string, name: string): void => {
const file: File = FileModel.createFile();
const taskFileContent: TaskFileContent = TaskModel.createTaskFileContent(
board,
name
);
this.saveTask(file, taskFileContent);
};
saveTask = (file: File, newTaskFileContent: TaskFileContent): void => {
file.contentVersions.add(newTaskFileContent);
this.fileModel.addOrUpdateFile(file);
};
// init
constructor(chatModel: ChatModel, fileModel: FileModel) {
this.chatModel = chatModel;
this.fileModel = fileModel;
}
// utility
static createTaskFileContent = (
name: string,
board: string
): TaskFileContent => {
const fileContent: FileContent<"task"> =
FileModel.createFileContent("task");
return {
...fileContent,
name,
board,
};
};
}
// types
export interface TaskFileContent extends FileContent {
type: "task";
export interface TaskFileContent extends FileContent<"task"> {
name: string;
board: string;
category?: string;
status?: string;
@@ -37,6 +84,7 @@ export const TaskFileContentReference: TaskFileContent = {
id: "",
creationDate: "",
type: "task",
name: "",
board: "",
};