<commit_before>/// <reference path="./../typings/typings.d.ts" />

import pouch = require("pouchdb");
import {User} from "gearworks";

// Add the pouchdb-find plugin
pouch.plugin(require("pouchdb-find"));

export const DatabaseUrl: string = process.env.couchUrl;
export const users = new pouch(`${DatabaseUrl}/users`);

/**
 * Finds a user by their Shop Id.
 */
export async function findUserByShopId(shopId: number): Promise<User>
{
    // Don't search for null
    if (!shopId)
    {
        return undefined;
    }

    await users.createIndex({
        index: {
            fields: ["shopifyShopId"]
        }
    });

    const result = await users.find<User>({
        selector: {
            shopifyShopId: shopId,
        },
        limit: 1,
    });

    return result.docs.length > 0 ? result.docs[0] : undefined;
}<commit_msg>Don't search for null, undefined or NaN values<commit_after>/// <reference path="./../typings/typings.d.ts" />

import pouch = require("pouchdb");
import {User} from "gearworks";

// Add the pouchdb-find plugin
pouch.plugin(require("pouchdb-find"));

export const DatabaseUrl: string = process.env.couchUrl;
export const users = new pouch(`${DatabaseUrl}/users`);

/**
 * Finds a user by their Shop Id.
 */
export async function findUserByShopId(shopId: number): Promise<User>
{
    // Don't search for null, undefined or NaN values
    if (!shopId)
    {
        return undefined;
    }

    await users.createIndex({
        index: {
            fields: ["shopifyShopId"]
        }
    });

    const result = await users.find<User>({
        selector: {
            shopifyShopId: shopId,
        },
        limit: 1,
    });

    return result.docs.length > 0 ? result.docs[0] : undefined;
}
{'fraction_non_alphanumeric': 0.1426096997690531, 'fraction_numerical': 0.003464203233256351, 'mean_word_length': 2.6104166666666666, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '2838663', 'n_tokens_mistral': 550, 'n_tokens_neox': 531, 'n_words': 141}