import { HttpClient } from '@angular/common/http' ; import { Injectable } from '@angular/core' ; import { firstValueFrom } from 'rxjs' ; import { IProductTypeTranslatable , IProductTypeTranslated } from '@gauzy/contracts' ; import { API_PREFIX } from '../constants/app.constants' ; @ Injectable ( ) export class ProductTypeService { PRODUCT_TYPES_URL = `${ API_PREFIX }/product-types` ; constructor ( private http ) { } getById ( id = '' ) { return firstValueFrom ( this . http . get < IProductTypeTranslatable > ( `${ this . PRODUCT_TYPES_URL }/${ id }` ) ) ; } count ( findInput ) { const data = JSON . stringify ( findInput ) ; return firstValueFrom ( this . http . get < number > ( `${ this . PRODUCT_TYPES_URL }/count` , { params : { data } } ) ) ; } getAll ( options , params ) { const data = JSON . stringify ( options ) ; return firstValueFrom ( this . http . get < { items : IProductTypeTranslatable [ ] ; } > ( this . PRODUCT_TYPES_URL , { params : { data , ... params } } ) ) ; } getAllTranslated ( langCode , relations ? , findInput ? ) { const data = JSON . stringify ( { relations , findInput , langCode } ) ; return firstValueFrom ( this . http . get < { items : IProductTypeTranslated [ ] ; } > ( `${ this . PRODUCT_TYPES_URL }` , { params : { data } } ) ) ; } create ( productTypeRequest ) { return firstValueFrom ( this . http . post < IProductTypeTranslatable > ( `${ this . PRODUCT_TYPES_URL }` , productTypeRequest ) ) ; } update ( productTypeRequest ) { return firstValueFrom ( this . http . put < IProductTypeTranslatable > ( `${ this . PRODUCT_TYPES_URL }/${ productTypeRequest . id }` , productTypeRequest ) ) ; } delete ( id ) { return firstValueFrom ( this . http . delete < IProductTypeTranslatable > ( `${ this . PRODUCT_TYPES_URL }/${ id }` ) ) ; } }