added user service & interface
This commit is contained in:
parent
d06e3f48bc
commit
b95a0fb328
3 changed files with 42 additions and 2 deletions
|
|
@ -29,8 +29,8 @@ export class TaskComponent {
|
||||||
// Subtasks
|
// Subtasks
|
||||||
|
|
||||||
completedSubtasks() {
|
completedSubtasks() {
|
||||||
const subtasks = this.task.subtasksDone;
|
return this.task.subtasksDone.filter((subtask: boolean) => subtask === true)
|
||||||
return subtasks.filter((subtask: boolean) => subtask === true).length;
|
.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
completedSubtasksPercent(): number {
|
completedSubtasksPercent(): number {
|
||||||
|
|
|
||||||
4
src/app/interfaces/user.interface.ts
Normal file
4
src/app/interfaces/user.interface.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
export interface User {
|
||||||
|
id?: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
36
src/app/services/user.service.ts
Normal file
36
src/app/services/user.service.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
import { Injectable, inject } from '@angular/core';
|
||||||
|
import { Firestore, collection, onSnapshot } from '@angular/fire/firestore';
|
||||||
|
import { User } from '../interfaces/user.interface';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
})
|
||||||
|
export class UserService {
|
||||||
|
firestore: Firestore = inject(Firestore);
|
||||||
|
|
||||||
|
allUsers: User[] = [];
|
||||||
|
|
||||||
|
unsubUser;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.unsubUser = this.subUserList();
|
||||||
|
}
|
||||||
|
|
||||||
|
subUserList() {
|
||||||
|
return onSnapshot(this.getUserRef(), (list) => {
|
||||||
|
this.allUsers = [];
|
||||||
|
list.forEach((element) => {
|
||||||
|
const taskData = { ...(element.data() as User), id: element.id };
|
||||||
|
this.allUsers.push(taskData);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getUserRef() {
|
||||||
|
return collection(this.firestore, 'users');
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
this.unsubUser;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue