Skip to content

Instantly share code, notes, and snippets.

@Ranjanivraman
Last active July 19, 2021 13:14
Show Gist options
  • Select an option

  • Save Ranjanivraman/d43f42dfcce37f98d29d6f624cbe319e to your computer and use it in GitHub Desktop.

Select an option

Save Ranjanivraman/d43f42dfcce37f98d29d6f624cbe319e to your computer and use it in GitHub Desktop.

Revisions

  1. Ranjanivraman revised this gist Jul 19, 2021. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions getReturnItemDynamodb.ts
    Original file line number Diff line number Diff line change
    @@ -5,20 +5,20 @@ export async function getReturnItem(orderId: string, sku: string): Promise<Retur
    const db: DocumentClient = new DocumentClient({
    region: process.env.AWS_REGION as string,
    });
    const rdtEtlKey: DocumentClient.Key = {
    const myKey: DocumentClient.Key = {
    orderId,
    sku,
    };

    const params: DocumentClient.GetItemInput = {
    TableName: process.env.tablename as string,
    Key: rdtEtlKey,
    Key: myKey,
    };

    const response: DocumentClient.ItemResponse = await db.get(params).promise();
    if (response.Item) {
    return <ReturnItem>response.Item;
    }

    throw new Error(`Couldn't find order ${orderId} and sku ${sku} in RDTETL table`);
    throw new Error(`Couldn't find order ${orderId} and sku ${sku} in MyTablename table`);
    }
  2. Ranjanivraman created this gist Jul 19, 2021.
    24 changes: 24 additions & 0 deletions getReturnItemDynamodb.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    import { DocumentClient } from "aws-sdk/clients/dynamodb";
    import { ReturnItem } from "../Type/ReturnItem";

    export async function getReturnItem(orderId: string, sku: string): Promise<ReturnItem> {
    const db: DocumentClient = new DocumentClient({
    region: process.env.AWS_REGION as string,
    });
    const rdtEtlKey: DocumentClient.Key = {
    orderId,
    sku,
    };

    const params: DocumentClient.GetItemInput = {
    TableName: process.env.tablename as string,
    Key: rdtEtlKey,
    };

    const response: DocumentClient.ItemResponse = await db.get(params).promise();
    if (response.Item) {
    return <ReturnItem>response.Item;
    }

    throw new Error(`Couldn't find order ${orderId} and sku ${sku} in RDTETL table`);
    }