async function getActiveGames()

in backend/Functions/HTTP/activegames_list/app.js [36:76]


async function getActiveGames(event) {
  if(event.rawQueryString === '') {
    return { statusCode: 200, body: 'No parameters provided' };
  }
  if(event['rawQueryString'].indexOf('host')!==-1) {
    const gameType = 'LIVE='+event['queryStringParameters']['host'];
    //perform the query on the GSI for the record and return it
    try {
      const parms = {TableName: playerInventoryTableName,
        IndexName: 'gsi-GameType',
        KeyConditionExpression: 'gameType = :gameType',
        ExpressionAttributeValues: {':gameType': gameType }
      };
      const result = await ddb.query(parms).promise();
      const games = result.Items;
      return { statusCode: 200, body: JSON.stringify(games) };
    } catch(e) {
      console.error(`error getting live game ${e}`);
      return { statusCode: 500, body: 'Could not retrieve game' };
    }
  }
  if(event['rawQueryString'].indexOf('category')!==-1) {
    const gameType = 'SINGLE='+event['queryStringParameters']['category'];
    //perform the query on the GSI for the record and return it
    try {
      const parms = {TableName: playerInventoryTableName,
        IndexName: 'gsi-GameType',
        KeyConditionExpression: 'gameType = :gameType',
        ExpressionAttributeValues: {':gameType': gameType }
      };
      const result = await ddb.query(parms).promise();
      const games = result.Items;
      return { statusCode: 200, body: JSON.stringify(games) };
    } catch(e) {
      console.error(`error getting live game ${e}`);
      return { statusCode: 500, body: 'Could not retrieve game' };
    }
  }
  //fallthrough
  return { statusCode: 200, body: 'Please include proper query parameters' };
}