From aa72cca439bce190bd8055748c34544d9b6adc39 Mon Sep 17 00:00:00 2001 From: Chneemann Date: Sat, 30 Mar 2024 10:05:41 +0100 Subject: [PATCH] clean code --- .../components/board/task/task.component.ts | 1 - src/app/services/task.service.ts | 36 ++++--------------- src/app/services/user.service.ts | 17 +++------ 3 files changed, 11 insertions(+), 43 deletions(-) diff --git a/src/app/components/board/task/task.component.ts b/src/app/components/board/task/task.component.ts index 206735f..14759d5 100644 --- a/src/app/components/board/task/task.component.ts +++ b/src/app/components/board/task/task.component.ts @@ -22,7 +22,6 @@ export class TaskComponent { constructor( public dragDropService: DragDropService, - private taskService: TaskService, private userService: UserService ) {} diff --git a/src/app/services/task.service.ts b/src/app/services/task.service.ts index 79e7c71..4cf12a6 100644 --- a/src/app/services/task.service.ts +++ b/src/app/services/task.service.ts @@ -26,26 +26,14 @@ export class TaskService implements OnDestroy { return onSnapshot(collection(this.firestore, 'tasks'), (list) => { this.allTasks = []; list.forEach((element) => { - this.allTasks.push(this.setUserObject(element.data(), element.id)); + const taskData = element.data() as Task; + const taskWithId = { ...taskData }; + taskWithId.id = element.id; + this.allTasks.push(taskWithId); }); }); } - setUserObject(obj: any, id: string): Task { - return { - id: id, - title: obj.title, - description: obj.description, - category: obj.category, - status: obj.status, - priority: obj.priority, - subtasksTitle: obj.subtasksTitle, - subtasksDone: obj.subtasksDone, - assigned: obj.assigned, - timestamp: obj.timestamp, - }; - } - getAllTasks(): Task[] { return this.allTasks; } @@ -55,23 +43,13 @@ export class TaskService implements OnDestroy { } async updateTask(taskId: any, index: number) { - await updateDoc( - doc(collection(this.firestore, 'tasks'), taskId), - this.getCleanJson(this.allTasks[index]) - ).catch((err) => { + await updateDoc(doc(collection(this.firestore, 'tasks'), taskId), { + status: this.allTasks[index].status, + }).catch((err) => { console.error(err); }); } - getCleanJson(task: any): {} { - return { - category: task.category, - description: task.description, - title: task.title, - status: task.status, - }; - } - ngOnDestroy() { this.unsubTask(); } diff --git a/src/app/services/user.service.ts b/src/app/services/user.service.ts index 19bca3c..0dcb217 100644 --- a/src/app/services/user.service.ts +++ b/src/app/services/user.service.ts @@ -21,23 +21,14 @@ export class UserService implements OnDestroy { return onSnapshot(collection(this.firestore, 'users'), (list) => { this.allUsers = []; list.forEach((element) => { - this.allUsers.push(this.setUserObject(element.data(), element.id)); + const taskData = element.data() as User; + const taskWithId = { ...taskData }; + taskWithId.id = element.id; + this.allUsers.push(taskWithId); }); }); } - setUserObject(obj: any, id: string): User { - return { - id: id, - firstName: obj.firstName, - lastName: obj.lastName, - email: obj.email, - phone: obj.phone, - initials: obj.initials, - color: obj.color, - }; - } - getUsers(): User[] { return this.allUsers; }