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 { Locale } from '../models/locale' ; import { ProjectLocale } from '../models/project-locale' ; import { Translation } from '../models/translation' ; @ Injectable ( { providedIn : 'root' , } ) export class ProjectTranslationsService { private endpoint = environment . apiEndpoint ; constructor ( private http ) { } loadKnownLocales ( ) { return this . http . get < Payload < Locale [ ] > > ( `${ this . endpoint }/locales` ) . pipe ( map ( res => res . data ) ) ; } findProjectLocales ( projectId ) { return this . http . get < Payload < ProjectLocale [ ] > > ( `${ this . endpoint }/projects/${ projectId }/translations` ) . pipe ( map ( res => res . data ) ) ; } addProjectLocale ( projectId , localeCode ) { return this . http . post < Payload < ProjectLocale > > ( `${ this . endpoint }/projects/${ projectId }/translations` , { code : localeCode } ) . pipe ( map ( res => res . data ) ) ; } deleteProjectLocale ( projectId , localeCode ) { return this . http . delete < void > ( `${ this . endpoint }/projects/${ projectId }/translations/${ localeCode }` ) ; } findProjectTranslation ( projectId , localeCode ) { return this . http . get < Payload < Translation [ ] > > ( `${ this . endpoint }/projects/${ projectId }/translations/${ localeCode }` ) . pipe ( map ( res => res . data ) ) ; } updateTranslation ( projectId , localeCode , termId , value ) { return this . http . patch < Payload < Translation > > ( `${ this . endpoint }/projects/${ projectId }/translations/${ localeCode }` , { termId , value , } ) . pipe ( map ( res => res . data ) ) ; } }