or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-2/

User Profile Query System

Build a simple user profile query system that safely retrieves user information from a PostgreSQL database using parameterized queries.

Requirements

Create a module that provides functions to query user profiles from a database. The system should support:

  1. Retrieving a user by their ID
  2. Finding users by email address
  3. Searching for users by age range (minimum and maximum age)

All database queries must use proper parameterization to prevent SQL injection vulnerabilities. Assume the database has a users table with columns: id, email, age, and registration_date.

Implementation

@generates

API

/**
 * Retrieves a user profile by user ID
 *
 * @param {Object} client - Database client instance
 * @param {number} userId - The user's ID
 * @returns {Promise<Object|null>} User object or null if not found
 */
async function getUserById(client, userId) {
  // IMPLEMENTATION HERE
}

/**
 * Finds a user by email address
 *
 * @param {Object} client - Database client instance
 * @param {string} email - The user's email address
 * @returns {Promise<Object|null>} User object or null if not found
 */
async function getUserByEmail(client, email) {
  // IMPLEMENTATION HERE
}

/**
 * Finds all users within a specified age range
 *
 * @param {Object} client - Database client instance
 * @param {number} minAge - Minimum age (inclusive)
 * @param {number} maxAge - Maximum age (inclusive)
 * @returns {Promise<Array>} Array of user objects
 */
async function getUsersByAgeRange(client, minAge, maxAge) {
  // IMPLEMENTATION HERE
}

module.exports = {
  getUserById,
  getUserByEmail,
  getUsersByAgeRange
};

Test Cases

The following test cases verify the functionality:

  • Given a valid user ID, getUserById returns the correct user object @test
  • Given an invalid user ID, getUserById returns null @test
  • Given a valid email address, getUserByEmail returns the correct user @test
  • Given an age range of 25-35, getUsersByAgeRange returns all users within that range @test

Dependencies { .dependencies }

pg-native { .dependency }

Provides PostgreSQL database connectivity and query execution.