import { Inject , Injectable } from '@angular/core' ; import { Http } from "@angular/http" ; import { environment } from "../../../environments/environment" ; import { UtilsService } from "../utils.service" ; import { ContextService } from "../context.service" ; import { UsersService } from "../users/users.service" ; @ Injectable ( ) export class RequestsService { constructor ( private http , private usersService , private context , private utils ) { } getRequest ( requestId ) { let request = environment . get_proposal ( requestId ) ; return this . http . get ( request . url , this . context . httpOptions ( ) ) . toPromise ( ) . then ( ( response ) => { return request . responseFn ( response ) ; } ) ; } approveRequest ( requestId , reason = '' ) { console . log ( 'Approved Request ' + requestId ) ; let request = environment . patch_proposal ( requestId , 'APPROVED' , reason , '' ) ; return this . http [ request . method ] ( request . url , request . body , this . context . httpOptions ( ) ) . toPromise ( ) . then ( ( response ) => { console . log ( 'Approved Request ' , response . status ) ; return response . status ; } ) . catch ( this . utils . catchError ) ; } denyRequest ( requestId , reason = '' ) { console . log ( 'Denied Request ' + requestId ) ; let request = environment . patch_proposal ( requestId , 'REJECTED' , reason , '' ) ; return this . http [ request . method ] ( request . url , request . body , this . context . httpOptions ( ) ) . toPromise ( ) . then ( ( response ) => { console . log ( 'Denied Request ' + response . status ) ; return response . status ; } ) . catch ( this . utils . catchError ) ; } emailRequestOwner ( userId , requestId ) { return this . utils . setTimeoutPromise ( 1000 ) . then ( ( ) => { return true ; } ) . catch ( this . utils . catchError ) ; } resendRequest ( userId , requestId ) { return this . utils . setTimeoutPromise ( 1000 ) . then ( ( ) => { return true ; } ) . catch ( this . utils . catchError ) ; } }