import { Injectable } from '@angular/core' ; import { IProductVariant , IVariantCreateInput , IPagination } from '@gauzy/contracts' ; import { HttpClient } from '@angular/common/http' ; import { firstValueFrom } from 'rxjs' ; import { API_PREFIX } from '../constants/app.constants' ; @ Injectable ( ) export class ProductVariantService { PRODUCT_VARIANTS_URL = `${ API_PREFIX }/product-variants` ; constructor ( private http ) { } getVariantsByProductId ( productId ) { return firstValueFrom ( this . http . get < IPagination < IProductVariant > > ( `${ this . PRODUCT_VARIANTS_URL }/product/${ productId }` ) ) ; } getProductVariant ( id ) { return firstValueFrom ( this . http . get < IProductVariant > ( `${ this . PRODUCT_VARIANTS_URL }/${ id }` ) ) ; } createProductVariants ( variantCreateInput ) { return firstValueFrom ( this . http . post < IProductVariant [ ] > ( `${ this . PRODUCT_VARIANTS_URL }/variants` , variantCreateInput ) ) ; } updateProductVariant ( productVariant ) { return firstValueFrom ( this . http . put < IProductVariant > ( `${ this . PRODUCT_VARIANTS_URL }/${ productVariant . id }` , productVariant ) ) ; } delete ( id ) { return firstValueFrom ( this . http . delete ( `${ this . PRODUCT_VARIANTS_URL }/${ id }` ) ) ; } deleteFeaturedImage ( id ) { return firstValueFrom ( this . http . delete ( `${ this . PRODUCT_VARIANTS_URL }/featured-image/${ id }` ) ) ; } }