function lookupUserPoolData()

in source/user-manager/server.js [600:652]


function lookupUserPoolData(credentials, userId, tenantId, isSystemContext, callback) {

    // construct the helper object
    var dynamoHelper = new DynamoDBHelper(userSchema, credentials, configuration);

    // if we're looking this up in a system context, query the GSI with user name only
    if (isSystemContext) {

        // init params structure with request params
        var searchParams = {
            TableName: userSchema.TableName,
            IndexName: userSchema.GlobalSecondaryIndexes[0].IndexName,
            KeyConditionExpression: "user_id = :id",
            ExpressionAttributeValues: {
                ":id": userId
            }
        };

        // get the item from the database
        dynamoHelper.query(searchParams, credentials, function (err, users) {
            if (err) {
                winston.error('Error getting user: ' + err.message);
                callback(err);
            } else {
                if (users.length == 0) {
                    var err = new Error('No user found: ' + userId);
                    callback(err);
                } else {
                    callback(null, users[0]);
                }
            }
        });
    } else {
        // if this is a tenant context, then we must get with tenant id scope
        winston.debug("Fetching user " + userId + " with tenant context " + tenantId);
        var searchParams = {
            user_id: userId,
            tenant_id: tenantId
        }

        // get the item from the database
        dynamoHelper.getItem(searchParams, credentials, function (err, user) {
            if (err) {
                winston.error('Error getting user: ' + err.message);
                callback(err);
            } else {
                winston.debug("Returning user: ");
                winston.debug(JSON.stringify(user));
                callback(null, user);
            }
        });
    }
}