import { Injectable } from '@angular/core' ; import { AngularFireDatabase } from '@angular/fire/database' ; import { from , Subject } from 'rxjs' ; @ Injectable ( { providedIn : 'root' } ) export class AdminService { constructor ( private db ) { } selectedUser = new Subject ( ) ; selectedUser$ = this . selectedUser . asObservable ( ) ; getUsersList ( ) { const usersRef = this . db . list ( 'users' ) ; return usersRef . snapshotChanges ( ) ; } getUserProjects ( uid ) { const projectsRef = this . db . list ( 'projects/' + uid ) ; return projectsRef . snapshotChanges ( ) ; } getUserCustomers ( uid ) { const customersRef = this . db . list ( 'customers/' + uid ) ; return customersRef . snapshotChanges ( ) ; } checkAdminRole ( uid ) { return this . db . object ( 'admins/' + uid ) . valueChanges ( ) ; } deleteUserProject ( uid , projectId ) { return from ( this . db . object ( `projects/${ uid }/` + projectId ) . remove ( ) ) ; } deleteUserCustomer ( uid , customerId ) { return from ( this . db . object ( `customers/${ uid }/` + customerId ) . remove ( ) ) ; } addAdminPrivileges ( uid ) { const adminsRef = this . db . object ( 'admins/' + uid ) ; this . db . object ( 'users/' + uid ) . update ( { isAdmin : true } ) ; return from ( adminsRef . set ( true ) ) ; } removeAdminPrivileges ( uid ) { this . db . object ( 'users/' + uid ) . update ( { isAdmin : false } ) ; return from ( this . db . object ( 'admins/' + uid ) . remove ( ) ) ; } }