clean code
This commit is contained in:
parent
2b82514a16
commit
aa72cca439
3 changed files with 11 additions and 43 deletions
|
|
@ -22,7 +22,6 @@ export class TaskComponent {
|
|||
|
||||
constructor(
|
||||
public dragDropService: DragDropService,
|
||||
private taskService: TaskService,
|
||||
private userService: UserService
|
||||
) {}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue