first commit
This commit is contained in:
12
src/app/_api/todo/todo.service.spec.ts
Normal file
12
src/app/_api/todo/todo.service.spec.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { TodoService } from './todo.service';
|
||||
|
||||
describe('TodoService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: TodoService = TestBed.get(TodoService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
53
src/app/_api/todo/todo.service.ts
Normal file
53
src/app/_api/todo/todo.service.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { AngularFirestore } from '@angular/fire/compat/firestore';
|
||||
import firebase from 'firebase/compat/app';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TodoService {
|
||||
|
||||
formData;
|
||||
loggedInUser = JSON.parse(localStorage.getItem('currentUser'));
|
||||
ref = firebase.firestore().collection('todo');
|
||||
|
||||
constructor(private firestore: AngularFirestore) {
|
||||
}
|
||||
|
||||
getTODOS(userId) {
|
||||
return this.firestore.collection('todo', ref => ref.orderBy('createdDate', 'desc')
|
||||
.where('uid', '==', userId)).snapshotChanges();
|
||||
}
|
||||
|
||||
getAssignedTODOS(userId) {
|
||||
return this.firestore.collection('todo', ref => ref.orderBy('createdDate', 'desc')
|
||||
.where('assignedTo.uid', '==', userId)).snapshotChanges();
|
||||
}
|
||||
|
||||
createTodo(todo): Observable<any> {
|
||||
return new Observable((observer) => {
|
||||
this.ref.add(todo).then((doc) => {
|
||||
observer.next({
|
||||
data: doc
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
sendMessage(todoId, data) {
|
||||
return this.firestore.collection('todo').doc(todoId).update({
|
||||
todoComments: data
|
||||
});
|
||||
}
|
||||
updateTODO(id: string, data): Observable<any> {
|
||||
return new Observable((observer) => {
|
||||
this.ref.doc(id).set(data).then(() => {
|
||||
observer.next();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
deleteTodo(id: string): Promise<void> {
|
||||
return this.ref.doc(id).delete();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user