typeorm#FindOperator TypeScript Examples

The following examples show how to use typeorm#FindOperator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: paginate.ts    From nestjs-paginate with MIT License 6 votes vote down vote up
OperatorSymbolToFunction = new Map<FilterOperator, (...args: any[]) => FindOperator<string>>([
    [FilterOperator.EQ, Equal],
    [FilterOperator.GT, MoreThan],
    [FilterOperator.GTE, MoreThanOrEqual],
    [FilterOperator.IN, In],
    [FilterOperator.NULL, IsNull],
    [FilterOperator.LT, LessThan],
    [FilterOperator.LTE, LessThanOrEqual],
    [FilterOperator.BTW, Between],
    [FilterOperator.NOT, Not],
])
Example #2
Source File: paginate.ts    From nestjs-paginate with MIT License 5 votes vote down vote up
function parseFilter<T>(query: PaginateQuery, config: PaginateConfig<T>) {
    const filter: { [columnName: string]: FindOperator<string> } = {}
    for (const column of Object.keys(query.filter)) {
        if (!(column in config.filterableColumns)) {
            continue
        }
        const allowedOperators = config.filterableColumns[column]
        const input = query.filter[column]
        const statements = !Array.isArray(input) ? [input] : input
        for (const raw of statements) {
            const tokens = getFilterTokens(raw)
            if (tokens.length === 0) {
                continue
            }
            const [op2, op1, value] = tokens

            if (!isOperator(op1) || !allowedOperators.includes(op1)) {
                continue
            }
            if (isOperator(op2) && !allowedOperators.includes(op2)) {
                continue
            }
            if (isOperator(op1)) {
                switch (op1) {
                    case FilterOperator.BTW:
                        filter[column] = OperatorSymbolToFunction.get(op1)(...value.split(','))
                        break
                    case FilterOperator.IN:
                        filter[column] = OperatorSymbolToFunction.get(op1)(value.split(','))
                        break
                    default:
                        filter[column] = OperatorSymbolToFunction.get(op1)(value)
                        break
                }
            }
            if (isOperator(op2)) {
                filter[column] = OperatorSymbolToFunction.get(op2)(filter[column])
            }
        }
    }
    return filter
}