File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import BaseServiceModel from '@/api/BaseServiceModel' ;
22import { ApiResponse , ProductDemandResponse , ProductResponse } from '@/types' ;
3- import { parseRequestToJSON } from '@/utils/ServiceUtils' ;
3+ import { jsonToCsv , parseRequestToJSON } from '@/utils/ServiceUtils' ;
44
55class ProductService extends BaseServiceModel {
66 async getDemand ( id : string ) : Promise < ApiResponse < ProductDemandResponse > > {
@@ -22,6 +22,24 @@ class ProductService extends BaseServiceModel {
2222 throw new Error ( 'Problem fetching product data' ) ;
2323 }
2424 }
25+
26+ async importProducts ( data : Record < string , string > [ ] ) : Promise < ApiResponse < ProductResponse [ ] > > {
27+ try {
28+ const csvContent = jsonToCsv ( data ) ;
29+
30+ const apiResponse = await this . request . post (
31+ './api/products/import' ,
32+ {
33+ data : csvContent ,
34+ headers : { 'Content-Type' : 'text/csv' }
35+ }
36+ ) ;
37+
38+ return await parseRequestToJSON ( apiResponse ) ;
39+ } catch ( error ) {
40+ throw new Error ( 'Problem importing products' ) ;
41+ }
42+ }
2543}
2644
2745export default ProductService ;
You can’t perform that action at this time.
0 commit comments