async listApplications()

in source/services/api/admin/lib/admin.js [87:126]


  async listApplications() {
    let params = {
      TableName: process.env.APPLICATIONS_TABLE
    };
    let length = 0;
    let docClient = new AWS.DynamoDB.DocumentClient(this.config);
    try {
      let result = await docClient.scan(params).promise();
      length += result.Items.length;
      if (length < 1){
        return Promise.reject({
          code: 404,
          error: 'NotFoundException',
          message: 'No applications are registered with the solution.'
        });
      } else {
        let results = [];
        result.Items.forEach(function(item) {
          results.push({
            'ApplicationId': item.application_id,
            'ApplicationName': item.application_name,
            'Description': item.description,
            'UpdatedAt': item.updated_at,
            'CreatedAt': item.created_at
          });  
        });
        return Promise.resolve({
          "Applications": results,
          "Count": length
        });
      }
    } catch (err) {
      console.log(JSON.stringify(err));
      return Promise.reject({
        code: 500,
        error: 'InternalFailure',
        message: 'Error occurred while attempting to retrieve applications',
      });
    }
  }