Files
CT/src/Model/Files/taskModel.ts
T

141 lines
2.9 KiB
TypeScript
Raw Normal View History

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,
2024-07-22 12:22:52 +02:00
ValidObject,
2024-07-22 11:49:05 +02:00
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 12:39:26 +02:00
// paths
getBasePath = (): string[] => {
return this.fileModel.getModelDirectoryPath("taskModel");
};
getLocationDirPath = (): string[] => {
return [...this.getBasePath(), subDirectories.locations];
};
getTaskLocationPath = (fileId: string): string[] => {
return [...this.getLocationDirPath(), fileId];
};
getBoardDirPath = (): string[] => {
return [...this.getBasePath(), subDirectories.boards];
};
getBoardPath = (boardName: string): string[] => {
return [...this.getBoardDirPath(), boardName];
};
getTaskPath = (boardName: string, fileId: string): string[] => {
return [...this.getBoardPath(boardName), fileId];
};
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 12:39:26 +02:00
// locations
updateTaskLocation = (
file: File,
taskFileContent: TaskFileContent
): void => {};
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
2024-07-22 12:39:26 +02:00
export const subDirectories = {
locations: "locations",
boards: "boards",
};
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
2024-07-22 12:22:52 +02:00
export interface TaskLocation extends ValidObject {
board: string;
category?: string;
status?: string;
}
// reference
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: "",
};
2024-07-22 12:22:52 +02:00
export const TaskLocationReference: TaskLocation = {
dataVersion: DATA_VERSION,
board: "",
};