import { Injectable } from '@angular/core' ; import { HttpClient } from '@angular/common/http' ; import { firstValueFrom } from 'rxjs' ; import { IWarehouse , IWarehouseProductCreateInput , IWarehouseProduct , IWarehouseProductVariant } from '@gauzy/contracts' ; import { API_PREFIX } from '../constants/app.constants' ; @ Injectable ( ) export class WarehouseService { WAREHOUSES_URL = `${ API_PREFIX }/warehouses` ; constructor ( private http ) { } count ( findInput ) { const data = JSON . stringify ( findInput ) ; return firstValueFrom ( this . http . get < number > ( `${ this . WAREHOUSES_URL }/count` , { params : { data } } ) ) ; } getAll ( options ? , params ? ) { const data = JSON . stringify ( { relations : options . relations , findInput : options . findInput } ) ; return firstValueFrom ( this . http . get < { items : IWarehouse [ ] ; } > ( `${ this . WAREHOUSES_URL }` , { params : { data , ... params } } ) ) ; } create ( warehouseRequest ) { return firstValueFrom ( this . http . post < IWarehouse > ( `${ this . WAREHOUSES_URL }` , warehouseRequest ) ) ; } update ( id , warehouseRequest ) { return firstValueFrom ( this . http . put < IWarehouse > ( `${ this . WAREHOUSES_URL }/${ id }` , warehouseRequest ) ) ; } getById ( id , relations ? , findInput ? ) { const data = JSON . stringify ( { relations , findInput } ) ; return firstValueFrom ( this . http . get < IWarehouse > ( `${ this . WAREHOUSES_URL }/${ id }` , { params : { data } } ) ) ; } deleteFeaturedImage ( id ) { return firstValueFrom ( this . http . delete < { raw : any ; affected : number ; } > ( `${ this . WAREHOUSES_URL }/${ id }` ) ) ; } addWarehouseProducts ( warehouseProductCreateInput , warehouseId ) { return firstValueFrom ( this . http . post < IWarehouseProduct [ ] > ( `${ this . WAREHOUSES_URL }/inventory/${ warehouseId }` , warehouseProductCreateInput ) ) ; } getWarehouseProducts ( warehouseId ) { return firstValueFrom ( this . http . get < IWarehouseProduct [ ] > ( `${ this . WAREHOUSES_URL }/inventory/${ warehouseId }` ) ) ; } updateWarehouseProductCount ( warehouseProductId , count ) { return firstValueFrom ( this . http . post < IWarehouseProduct > ( `${ this . WAREHOUSES_URL }/inventory-quantity/${ warehouseProductId }` , { count : count } ) ) ; } updateWarehouseProductVariantCount ( warehouseProductVariantId , count ) { return firstValueFrom ( this . http . post < IWarehouseProductVariant > ( `${ this . WAREHOUSES_URL }/inventory-quantity/variants/${ warehouseProductVariantId }` , { count : count } ) ) ; } }