export async function handler()

in src/backend/loyalty/src/ingest/index.ts [108:136]


export async function handler(event: SNSEvent, context: Context): Promise<Result> {

  if (!table) {
    throw new Error(`Table name not defined`);
  }

  try {
    const record = JSON.parse(event.Records[0].Sns.Message);
    const customerId = record['customerId'];
    const points = record['price'];

    if (isNaN(points)) {
      throw new Error("Points cannot be undefined or falsy")
    }

    await addPoints(customerId, points, client, table)
  } catch (error) {
    if (error instanceof SyntaxError) {
      console.log(event);
      throw new Error("Invalid input");
    }

    throw error
  }

  return {
    message: "ok!",
  }
}