You've already forked Nitro_Render_V3
mirror of
https://github.com/duckietm/Nitro_Render_V3.git
synced 2026-06-19 23:16:20 +00:00
Move to Renderer V2
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { IProductData } from '@nitrots/api';
|
||||
import { GetConfiguration } from '@nitrots/configuration';
|
||||
import { ProductData } from './ProductData';
|
||||
|
||||
export class ProductDataLoader
|
||||
{
|
||||
private _products: Map<string, IProductData>;
|
||||
|
||||
constructor(products: Map<string, IProductData>)
|
||||
{
|
||||
this._products = products;
|
||||
}
|
||||
|
||||
public async init(): Promise<void>
|
||||
{
|
||||
const url = GetConfiguration().getValue<string>('productdata.url');
|
||||
|
||||
if(!url || !url.length) throw new Error('invalid product data url');
|
||||
|
||||
const response = await fetch(url);
|
||||
|
||||
if(response.status !== 200) throw new Error('Invalid product data file');
|
||||
|
||||
const responseData = await response.json();
|
||||
|
||||
this.parseProducts(responseData.productdata);
|
||||
}
|
||||
|
||||
private parseProducts(data: { [index: string]: any }): void
|
||||
{
|
||||
if(!data) return;
|
||||
|
||||
for(const product of data.product) (product && this._products.set(product.code, new ProductData(product.code, product.name, product.description)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user