import { Injectable } from '@angular/core'; import { HttpClient, HttpResponse } from '@angular/common/http'; import { Observable } from 'rxjs'; import { isPresent } from 'app/core/util/operators'; import { ApplicationConfigService } from 'app/core/config/application-config.service'; import { createRequestOption } from 'app/core/request/request-util'; import { IEPreguntaCerradaOpcion, getEPreguntaCerradaOpcionIdentifier } from '../e-pregunta-cerrada-opcion.model'; export type EntityResponseType = HttpResponse; export type EntityArrayResponseType = HttpResponse; @Injectable({ providedIn: 'root' }) export class EPreguntaCerradaOpcionService { protected resourceUrl = this.applicationConfigService.getEndpointFor('api/e-pregunta-cerrada-opcions'); constructor(protected http: HttpClient, protected applicationConfigService: ApplicationConfigService) {} updateCount(id: number) { debugger; return this.http.post(`${this.resourceUrl}/count/${id}`, id, { observe: 'response' }); } create(ePreguntaCerradaOpcion: IEPreguntaCerradaOpcion, preguntaId?: number): Observable { return this.http.post(`${this.resourceUrl}/${preguntaId}`, ePreguntaCerradaOpcion, { observe: 'response' }); } update(ePreguntaCerradaOpcion: IEPreguntaCerradaOpcion): Observable { return this.http.put( `${this.resourceUrl}/${getEPreguntaCerradaOpcionIdentifier(ePreguntaCerradaOpcion) as number}`, ePreguntaCerradaOpcion, { observe: 'response' } ); } partialUpdate(ePreguntaCerradaOpcion: IEPreguntaCerradaOpcion): Observable { return this.http.patch( `${this.resourceUrl}/${getEPreguntaCerradaOpcionIdentifier(ePreguntaCerradaOpcion) as number}`, ePreguntaCerradaOpcion, { observe: 'response' } ); } find(id: number): Observable { return this.http.get(`${this.resourceUrl}/${id}`, { observe: 'response' }); } query(req?: any): Observable { const options = createRequestOption(req); return this.http.get(this.resourceUrl, { params: options, observe: 'response' }); } delete(id: number): Observable> { return this.http.delete(`${this.resourceUrl}/${id}`, { observe: 'response' }); } deleteMany(ids: number[]): Observable { return this.http.post(`${this.resourceUrl}/deleteMany`, ids, { observe: 'response' }); } addEPreguntaCerradaOpcionToCollectionIfMissing( ePreguntaCerradaOpcionCollection: IEPreguntaCerradaOpcion[], ...ePreguntaCerradaOpcionsToCheck: (IEPreguntaCerradaOpcion | null | undefined)[] ): IEPreguntaCerradaOpcion[] { const ePreguntaCerradaOpcions: IEPreguntaCerradaOpcion[] = ePreguntaCerradaOpcionsToCheck.filter(isPresent); if (ePreguntaCerradaOpcions.length > 0) { const ePreguntaCerradaOpcionCollectionIdentifiers = ePreguntaCerradaOpcionCollection.map( ePreguntaCerradaOpcionItem => getEPreguntaCerradaOpcionIdentifier(ePreguntaCerradaOpcionItem)! ); const ePreguntaCerradaOpcionsToAdd = ePreguntaCerradaOpcions.filter(ePreguntaCerradaOpcionItem => { const ePreguntaCerradaOpcionIdentifier = getEPreguntaCerradaOpcionIdentifier(ePreguntaCerradaOpcionItem); if ( ePreguntaCerradaOpcionIdentifier == null || ePreguntaCerradaOpcionCollectionIdentifiers.includes(ePreguntaCerradaOpcionIdentifier) ) { return false; } ePreguntaCerradaOpcionCollectionIdentifiers.push(ePreguntaCerradaOpcionIdentifier); return true; }); return [...ePreguntaCerradaOpcionsToAdd, ...ePreguntaCerradaOpcionCollection]; } return ePreguntaCerradaOpcionCollection; } }