2023-02-23 07:16:05 -08:00
|
|
|
import flow from 'lodash.flow';
|
|
|
|
import sortBy from 'lodash.sortby';
|
|
|
|
import uniqBy from 'lodash.uniqby';
|
2021-04-03 02:07:21 -07:00
|
|
|
|
|
|
|
export type DocumentProperties = {
|
2022-08-01 13:47:55 -07:00
|
|
|
customProperty: Array<{ field: string; value: string }>;
|
2021-04-03 02:07:21 -07:00
|
|
|
};
|
|
|
|
|
2022-08-01 13:47:55 -07:00
|
|
|
type DocFields = Array<{ name: string; value: string }>;
|
2021-04-03 02:07:21 -07:00
|
|
|
|
2022-08-01 13:47:55 -07:00
|
|
|
const ensureName = (docFields: DocFields) => docFields.filter((o) => o.name);
|
2021-04-03 02:07:21 -07:00
|
|
|
const sortByName = (docFields: DocFields) => sortBy(docFields, ['name']);
|
2022-08-01 13:47:55 -07:00
|
|
|
const uniqueByName = (docFields: DocFields) => uniqBy(docFields, (o) => o.name);
|
2021-04-03 02:07:21 -07:00
|
|
|
|
|
|
|
export const processNames = flow(ensureName, sortByName, uniqueByName);
|
|
|
|
|
|
|
|
export const toSQL = (operator: string) => {
|
|
|
|
const operators: { [key: string]: string } = {
|
2022-08-01 13:47:55 -07:00
|
|
|
is: '=',
|
|
|
|
isNot: '!=',
|
|
|
|
greater: '>',
|
|
|
|
less: '<',
|
|
|
|
equalsGreater: '>=',
|
|
|
|
equalsLess: '<=',
|
2021-04-03 02:07:21 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
return operators[operator];
|
|
|
|
};
|