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 { environment } from '../../../environments/environment' ; import { Term } from '../models/term' ; @ Injectable ( { providedIn : 'root' , } ) export class ProjectTermsService { private endpoint = environment . apiEndpoint ; constructor ( private http ) { } find ( projectId ) { return this . http . get < Payload < Term [ ] > > ( `${ this . endpoint }/projects/${ projectId }/terms` ) . pipe ( map ( res => res . data ) ) ; } create ( projectId , value ) { return this . http . post < Payload < Term > > ( `${ this . endpoint }/projects/${ projectId }/terms` , { value } ) . pipe ( map ( res => res . data ) ) ; } update ( projectId , termId , value ) { return this . http . patch < Payload < Term > > ( `${ this . endpoint }/projects/${ projectId }/terms/${ termId }` , { value } ) . pipe ( map ( res => res . data ) ) ; } delete ( projectId , termId ) { return this . http . delete < void > ( `${ this . endpoint }/projects/${ projectId }/terms/${ termId }` ) ; } }