clean code

This commit is contained in:
Chneemann 2024-03-30 10:05:41 +01:00
parent 2b82514a16
commit aa72cca439
3 changed files with 11 additions and 43 deletions

View file

@ -22,7 +22,6 @@ export class TaskComponent {
constructor( constructor(
public dragDropService: DragDropService, public dragDropService: DragDropService,
private taskService: TaskService,
private userService: UserService private userService: UserService
) {} ) {}

View file

@ -26,26 +26,14 @@ export class TaskService implements OnDestroy {
return onSnapshot(collection(this.firestore, 'tasks'), (list) => { return onSnapshot(collection(this.firestore, 'tasks'), (list) => {
this.allTasks = []; this.allTasks = [];
list.forEach((element) => { 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[] { getAllTasks(): Task[] {
return this.allTasks; return this.allTasks;
} }
@ -55,23 +43,13 @@ export class TaskService implements OnDestroy {
} }
async updateTask(taskId: any, index: number) { async updateTask(taskId: any, index: number) {
await updateDoc( await updateDoc(doc(collection(this.firestore, 'tasks'), taskId), {
doc(collection(this.firestore, 'tasks'), taskId), status: this.allTasks[index].status,
this.getCleanJson(this.allTasks[index]) }).catch((err) => {
).catch((err) => {
console.error(err); console.error(err);
}); });
} }
getCleanJson(task: any): {} {
return {
category: task.category,
description: task.description,
title: task.title,
status: task.status,
};
}
ngOnDestroy() { ngOnDestroy() {
this.unsubTask(); this.unsubTask();
} }

View file

@ -21,23 +21,14 @@ export class UserService implements OnDestroy {
return onSnapshot(collection(this.firestore, 'users'), (list) => { return onSnapshot(collection(this.firestore, 'users'), (list) => {
this.allUsers = []; this.allUsers = [];
list.forEach((element) => { 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[] { getUsers(): User[] {
return this.allUsers; return this.allUsers;
} }