Added task functionality
This commit is contained in:
@@ -7,24 +7,26 @@ export const TASKSTATUS = ['ready', 'complete', 'waiting', 'archived'];
|
||||
export interface Task extends Partial<Models.Document> {
|
||||
title: string;
|
||||
description: string;
|
||||
required_skills: string[];
|
||||
tags: string[];
|
||||
required_skills: SkillTag[];
|
||||
tags: TaskTag[];
|
||||
due_date: string;
|
||||
duration: number;
|
||||
volunteers: string[];
|
||||
volunteers_required: number;
|
||||
status: string;
|
||||
depends_on: string[];
|
||||
depends_on: Task[];
|
||||
boat: string;
|
||||
} // TODO: convert some of these strings into objects.
|
||||
|
||||
export interface TaskTag extends Models.Document {
|
||||
name: string;
|
||||
description: string;
|
||||
colour: string;
|
||||
}
|
||||
export interface SkillTag extends Models.Document {
|
||||
name: string;
|
||||
description: string;
|
||||
tagColour: string;
|
||||
}
|
||||
|
||||
export const useTaskStore = defineStore('tasks', {
|
||||
@@ -41,7 +43,24 @@ export const useTaskStore = defineStore('tasks', {
|
||||
AppwriteIds.databaseId,
|
||||
AppwriteIds.collectionIdTask
|
||||
);
|
||||
this.tasks = response.documents as Task[];
|
||||
this.tasks = response.documents.map((document) => {
|
||||
// TODO: Should this be a GraphQL query, instead?
|
||||
// Map over `required_skills` and replace each skill ID with the corresponding skill object from `this.skillTags`
|
||||
const updatedRequiredSkills = document.required_skills.map(
|
||||
(skillId: string) =>
|
||||
this.skillTags.find((skillTag) => skillTag.$id === skillId) || {}
|
||||
);
|
||||
const updatedTaskTags = document.tags.map((tagid: string) =>
|
||||
this.taskTags.find((taskTag) => taskTag.$id === tagid)
|
||||
);
|
||||
|
||||
// Update the `required_skills` property of the document with the new array of skill objects
|
||||
return {
|
||||
...document,
|
||||
required_skills: updatedRequiredSkills,
|
||||
tags: updatedTaskTags,
|
||||
};
|
||||
}) as Task[];
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch tasks', error);
|
||||
}
|
||||
@@ -71,12 +90,16 @@ export const useTaskStore = defineStore('tasks', {
|
||||
}
|
||||
},
|
||||
async addTask(task: Task) {
|
||||
const newTask = <Models.Document>{ ...task };
|
||||
newTask.required_skills = task.required_skills.map((s) => s['$id']);
|
||||
newTask.tags = task.tags.map((s) => s['$id']);
|
||||
newTask.depends_on = task.depends_on.map((d) => d['$id']);
|
||||
try {
|
||||
const response = await databases.createDocument(
|
||||
AppwriteIds.databaseId,
|
||||
AppwriteIds.collectionIdTask,
|
||||
ID.unique(),
|
||||
task
|
||||
newTask
|
||||
);
|
||||
this.tasks.push(response as Task);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user