Merge branch 'main' into feature-rate-limiting

This commit is contained in:
rijkvanzanten
2020-09-08 12:31:57 -04:00
248 changed files with 3387 additions and 34724 deletions

View File

@@ -11,7 +11,7 @@ export default async function applyQuery(collection: string, dbQuery: QueryBuild
dbQuery.orderBy(query.sort);
}
if (query.limit && !query.offset) {
if (typeof query.limit === 'number' && !query.offset) {
dbQuery.limit(query.limit);
}
@@ -109,14 +109,14 @@ export function applyFilter(dbQuery: QueryBuilder, filter: Filter) {
}
if (operator === '_empty') {
dbQuery.andWhere(query => {
dbQuery.andWhere((query) => {
query.whereNull(key);
query.orWhere(key, '=', '');
});
}
if (operator === '_nempty') {
dbQuery.andWhere(query => {
dbQuery.andWhere((query) => {
query.whereNotNull(key);
query.orWhere(key, '!=', '');
});

View File

@@ -0,0 +1,9 @@
import { transform, isPlainObject } from 'lodash';
export function deepMap(obj: Record<string, any>, iterator: Function, context?: Function) {
return transform(obj, function (result: any, val, key) {
result[key] = isPlainObject(val)
? deepMap(val, iterator, context)
: iterator.call(context, val, key, obj);
});
}

View File

@@ -56,7 +56,7 @@ const localTypeMap: Record<string, { type: typeof types[number]; useTimezone?: b
// Postgres
json: { type: 'json' },
uuid: { type: 'string' },
uuid: { type: 'uuid' },
int2: { type: 'integer' },
serial4: { type: 'integer' },
int4: { type: 'integer' },

View File

@@ -0,0 +1,12 @@
import { Filter, Accountability } from '../types';
import { deepMap } from './deep-map';
export function parseFilter(filter: Filter, accountability: Accountability | null) {
return deepMap(filter, (val: any) => {
if (val === '$NOW') return new Date();
if (val === '$CURRENT_USER') return accountability?.user || null;
if (val === '$CURRENT_ROLE') return accountability?.role || null;
return val;
});
}