import { HttpClient } from '@angular/common/http' ; import { Injectable } from '@angular/core' ; import { Observable } from 'rxjs' ; import { map } from 'rxjs/operators' ; import { Payload } from 'src/app/shared/models/http' ; import { Plan } from '../models/plan' ; import { Project } from '../models/project' ; import { environment } from './../../../environments/environment' ; @ Injectable ( { providedIn : 'root' , } ) export class ProjectsService { private endpoint = environment . apiEndpoint ; constructor ( private http ) { } find ( ) { return this . http . get < Payload < Project [ ] > > ( `${ this . endpoint }/projects` ) . pipe ( map ( res => res . data ) ) ; } findOne ( id ) { return this . http . get < Payload < Project > > ( `${ this . endpoint }/projects/${ id }` ) . pipe ( map ( res => res . data ) ) ; } findPlan ( projectId ) { return this . http . get < Payload < Plan > > ( `${ this . endpoint }/projects/${ projectId }/plan` ) . pipe ( map ( res => res . data ) ) ; } create ( data ) { return this . http . post < Payload < Project > > ( `${ this . endpoint }/projects` , data ) . pipe ( map ( res => res . data ) ) ; } update ( id , data ) { return this . http . patch < Payload < Project > > ( `${ this . endpoint }/projects/${ id }` , data ) . pipe ( map ( res => res . data ) ) ; } delete ( id ) { return this . http . delete < void > ( `${ this . endpoint }/projects/${ id }` ) ; } }