2024-07-22 02:05:27 +02:00
|
|
|
// thile file is responsible for managing task files within chats.
|
|
|
|
|
|
2024-07-22 11:49:05 +02:00
|
|
|
import {
|
|
|
|
|
DATA_VERSION,
|
|
|
|
|
checkMatchesObjectStructure,
|
|
|
|
|
} from "../Utility/typeSafety";
|
|
|
|
|
import FileModel, { File, FileContent } from "./fileModel";
|
2024-07-22 02:05:27 +02:00
|
|
|
|
2024-07-22 02:16:58 +02:00
|
|
|
import ChatModel from "../Chat/chatModel";
|
|
|
|
|
|
|
|
|
|
export default class TaskModel {
|
|
|
|
|
chatModel: ChatModel;
|
|
|
|
|
fileModel: FileModel;
|
|
|
|
|
|
2024-07-22 11:49:05 +02:00
|
|
|
// 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);
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-22 02:16:58 +02:00
|
|
|
// init
|
|
|
|
|
constructor(chatModel: ChatModel, fileModel: FileModel) {
|
|
|
|
|
this.chatModel = chatModel;
|
|
|
|
|
this.fileModel = fileModel;
|
|
|
|
|
}
|
2024-07-22 11:49:05 +02:00
|
|
|
|
|
|
|
|
// utility
|
|
|
|
|
static createTaskFileContent = (
|
|
|
|
|
name: string,
|
|
|
|
|
board: string
|
|
|
|
|
): TaskFileContent => {
|
|
|
|
|
const fileContent: FileContent<"task"> =
|
|
|
|
|
FileModel.createFileContent("task");
|
|
|
|
|
return {
|
|
|
|
|
...fileContent,
|
|
|
|
|
|
|
|
|
|
name,
|
|
|
|
|
board,
|
|
|
|
|
};
|
|
|
|
|
};
|
2024-07-22 02:16:58 +02:00
|
|
|
}
|
2024-07-22 02:05:27 +02:00
|
|
|
|
|
|
|
|
// types
|
2024-07-22 11:49:05 +02:00
|
|
|
export interface TaskFileContent extends FileContent<"task"> {
|
|
|
|
|
name: string;
|
2024-07-22 02:16:58 +02:00
|
|
|
board: string;
|
2024-07-22 11:49:05 +02:00
|
|
|
|
2024-07-22 02:16:58 +02:00
|
|
|
category?: string;
|
|
|
|
|
status?: string;
|
|
|
|
|
|
|
|
|
|
description?: string;
|
|
|
|
|
|
|
|
|
|
priority?: number;
|
|
|
|
|
date?: string;
|
|
|
|
|
time?: string;
|
|
|
|
|
}
|
2024-07-22 11:20:43 +02:00
|
|
|
|
|
|
|
|
export const TaskFileContentReference: TaskFileContent = {
|
|
|
|
|
dataVersion: DATA_VERSION,
|
|
|
|
|
|
|
|
|
|
id: "",
|
|
|
|
|
creationDate: "",
|
|
|
|
|
type: "task",
|
2024-07-22 11:49:05 +02:00
|
|
|
|
|
|
|
|
name: "",
|
2024-07-22 11:20:43 +02:00
|
|
|
board: "",
|
|
|
|
|
};
|