async function find(id) {
  try {
    // Check if a user with the specified id exists in the database
    const findUserById = {
      text:
        'SELECT id, name, email, role, created_at, updated_at FROM users WHERE id = $1 AND is_active = TRUE AND deleted_at IS NULL',
      values: [id]
    };
    const users = await db.query(findUserById);

    // User does not exist, throw custom error
    if (users.rowCount === 0) throw new ResourceNotFoundError();

    // User found, return the user
    return users.rows[0];
  } catch (error) {
    // Bubble up the error to the global error handler
    throw error;
  }
}
/**
 * Finds a user by id.
 * @function
 * @async
 * @param {number} id - The user id
 * @throws {ResourceNotFoundError|Error}
 * @returns {Promise} Promise contains the user object
 */
Finds a user by id.
Finds a user by id .
async function find(id) {
  try {
    const findUserById = {
      text:
        'SELECT id, name, email, role, created_at, updated_at FROM users WHERE id = $1 AND is_active = TRUE AND deleted_at IS NULL',
      values: [id]
    };
    const users = await db.query(findUserById);
    if (users.rowCount === 0) throw new ResourceNotFoundError();
    return users.rows[0];
  } catch (error) {
    throw error;
  }
}
async function find ( id ) { try { const findUserById = { text : 'SELECT id, name, email, role, created_at, updated_at FROM users WHERE id = $1 AND is_active = TRUE AND deleted_at IS NULL' , values : [ id ] } ; const users = await db . query ( findUserById ) ; if ( users . rowCount === 0 ) throw new ResourceNotFoundError ( ) ; return users . rows [ 0 ] ; } catch ( error ) { throw error ; } }
Finds a user by id.
Finds a user by id .
// Check if a user with the specified id exists in the database // User does not exist, throw custom error // User found, return the user // Bubble up the error to the global error handler