<commit_before>import { dbs } from '$components/models/dbsetup';
import { jsonRequired, missingRequiredParam } from '$utils/commonErrors';
import { getAllUsers, countAllUsers, createUser } from '$utils/db/users';

export async function get({ query }) {
    const db = query.private ? dbs.private : dbs.public;
    // URLSearchParams objects don't destructure well, so convert to a POJO
    const queryParams = Object.fromEntries(query);
    return getAllUsers(db, queryParams);
}

export async function head({ query }) {
    const db = query.private ? dbs.private : dbs.public;
    const queryParams = Object.fromEntries(query);
    const count = await countAllUsers(db, queryParams);
    const status = count > 0 ? 200 : 404;
    return { status, body: {} };
}

export async function post({ path, body, query }) {
    if (typeof body !== 'object') {
        return jsonRequired('POST', path);
    }
    if (!body || !body.username) {
        return missingRequiredParam('username', `body of POST request to ${path}`);
    }
    // TODO: Password needs special handling
    const username = body.username;
    const db = query.private ? dbs.private : dbs.public;
    const result = await createUser(db, username, body);<commit_msg>Fix an incorrect function call<commit_after>import { dbs } from '$components/models/dbsetup';
import { jsonRequired, missingRequiredParam } from '$utils/commonErrors';
import { getAllUsers, countAllUsersQuery, createUser } from '$utils/db/users';

export async function get({ query }) {
    const db = query.private ? dbs.private : dbs.public;
    // URLSearchParams objects don't destructure well, so convert to a POJO
    const queryParams = Object.fromEntries(query);
    return getAllUsers(db, queryParams);
}

export async function head({ query }) {
    const db = query.private ? dbs.private : dbs.public;
    const queryParams = Object.fromEntries(query);
    const count = await countAllUsersQuery(db, queryParams);
    const status = count > 0 ? 200 : 404;
    return { status, body: {} };
}

export async function post({ path, body, query }) {
    if (typeof body !== 'object') {
        return jsonRequired('POST', path);
    }
    if (!body || !body.username) {
        return missingRequiredParam('username', `body of POST request to ${path}`);
    }
    // TODO: Password needs special handling
    const username = body.username;
    const db = query.private ? dbs.private : dbs.public;
    const result = await createUser(db, username, body);
{'fraction_non_alphanumeric': 0.1213338690237043, 'fraction_numerical': 0.00562474889513861, 'mean_word_length': 3.689265536723164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5370134', 'n_tokens_mistral': 711, 'n_tokens_neox': 692, 'n_words': 227}