Skip to content

Commit

Permalink
move out the example in a separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
rmt-kirill committed Nov 23, 2023
1 parent ae8b00c commit 6b48a7a
Showing 1 changed file with 50 additions and 35 deletions.
85 changes: 50 additions & 35 deletions packages/examples/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,56 @@
import { Catalog, Product } from '@rmt-sdk-ts/rmt-product-service';
import {
Catalog,
ImportProduct,
ImportSessionStatusEnum,
Product,
} from '@rmt-sdk-ts/rmt-product-service';
import * as dotenv from 'dotenv';

import { createCatalog } from './product-service/catalogs';
import {
createImportSession,
getImportSessionStatus,
importEntities,
} from './product-service/imports';
import { createProduct, getProducts } from './product-service/products';

dotenv.config();

const fn = async () => {
const myNewProducts: Product[] = [
{
sku: 'PIZZAMARGHERITA',
name: 'Frozen Pizza Margherita',
brand: 'My Frozen Pizza Brand',
categories: [
{
category_key: 'pizza-1',
category_name: 'Pizza',
},
{
category_key: 'frozen-1',
category_name: 'Frozen',
},
],
},
{
sku: 'PIZZAPEPPERONI',
name: 'Frozen Pizza Pepperoni',
brand: 'My Frozen Pizza Brand',
categories: [
{
category_key: 'pizza-1',
category_name: 'Pizza',
},
{
category_key: 'frozen-1',
category_name: 'Frozen',
},
],
},
];

// This example shows how to crete products one by one and search using simple filter.
const basicExample = async () => {
const myCatalogKey = 'my-catalog';
const myNewCatalog: Catalog = {
catalog_key: myCatalogKey,
Expand All @@ -22,39 +66,6 @@ const fn = async () => {
}
}

const myNewProducts: Product[] = [
{
sku: 'PIZZAMARGHERITA',
name: 'Frozen Pizza Margherita',
brand: 'My Frozen Pizza Brand',
categories: [
{
category_key: 'pizza-1',
category_name: 'Pizza',
},
{
category_key: 'frozen-1',
category_name: 'Frozen',
},
],
},
{
sku: 'PIZZAPEPPERONI',
name: 'Frozen Pizza Pepperoni',
brand: 'My Frozen Pizza Brand',
categories: [
{
category_key: 'pizza-1',
category_name: 'Pizza',
},
{
category_key: 'frozen-1',
category_name: 'Frozen',
},
],
},
];

try {
await createProduct(myCatalogKey, myNewProducts[0]);
} catch (e: any) {
Expand Down Expand Up @@ -86,4 +97,8 @@ const fn = async () => {
console.log('Found ' + pepperonis.data.length + ' pepperoni pizza(s)');
};

const fn = async () => {
await basicExample();
};

fn().then(() => console.log('Done'));

0 comments on commit 6b48a7a

Please sign in to comment.