chore: formatting and linting (#3261)

* chore: lint packages/payload

* chore: lint packages/db-postgres

* chore: lint packages/db-mongodb

* chore: update eslintrc exclusion rules

* chore: update eslintrc exclusion rules

* chore: lint misc files

* chore: run prettier through packages

* chore: run eslint on payload again

* chore: prettier misc files

* chore: prettier docs
This commit is contained in:
Alessio Gravili
2023-09-01 17:39:44 +02:00
committed by GitHub
parent 5f7673d735
commit ae7d6f97d2
1403 changed files with 48072 additions and 46231 deletions

View File

@@ -1,78 +1,80 @@
/* eslint-disable no-restricted-syntax */
/* eslint-disable no-await-in-loop */
import { FilterQuery } from 'mongoose';
import deepmerge from 'deepmerge';
import { Operator, Where } from 'payload/types';
import { combineMerge } from 'payload/utilities';
import { Field } from 'payload/types';
import { validOperators } from 'payload/types';
import { Payload } from 'payload';
import { buildSearchParam } from './buildSearchParams';
import { buildAndOrConditions } from './buildAndOrConditions';
import type { FilterQuery } from 'mongoose'
import type { Payload } from 'payload'
import type { Operator, Where } from 'payload/types'
import type { Field } from 'payload/types'
import deepmerge from 'deepmerge'
import { validOperators } from 'payload/types'
import { combineMerge } from 'payload/utilities'
import { buildAndOrConditions } from './buildAndOrConditions'
import { buildSearchParam } from './buildSearchParams'
export async function parseParams({
where,
collectionSlug,
globalSlug,
payload,
locale,
fields,
globalSlug,
locale,
payload,
where,
}: {
where: Where,
collectionSlug?: string,
globalSlug?: string,
payload: Payload,
locale: string,
fields: Field[],
collectionSlug?: string
fields: Field[]
globalSlug?: string
locale: string
payload: Payload
where: Where
}): Promise<Record<string, unknown>> {
let result = {} as FilterQuery<any>;
let result = {} as FilterQuery<any>
if (typeof where === 'object') {
// We need to determine if the whereKey is an AND, OR, or a schema path
for (const relationOrPath of Object.keys(where)) {
const condition = where[relationOrPath];
let conditionOperator: '$and' | '$or';
const condition = where[relationOrPath]
let conditionOperator: '$and' | '$or'
if (relationOrPath.toLowerCase() === 'and') {
conditionOperator = '$and';
conditionOperator = '$and'
} else if (relationOrPath.toLowerCase() === 'or') {
conditionOperator = '$or';
conditionOperator = '$or'
}
if (Array.isArray(condition)) {
const builtConditions = await buildAndOrConditions({
collectionSlug,
fields,
globalSlug,
payload,
locale,
payload,
where: condition,
});
if (builtConditions.length > 0) result[conditionOperator] = builtConditions;
})
if (builtConditions.length > 0) result[conditionOperator] = builtConditions
} else {
// It's a path - and there can be multiple comparisons on a single path.
// For example - title like 'test' and title not equal to 'tester'
// So we need to loop on keys again here to handle each operator independently
const pathOperators = where[relationOrPath];
const pathOperators = where[relationOrPath]
if (typeof pathOperators === 'object') {
for (const operator of Object.keys(pathOperators)) {
if (validOperators.includes(operator as Operator)) {
const searchParam = await buildSearchParam({
collectionSlug,
globalSlug,
payload,
locale,
fields,
globalSlug,
incomingPath: relationOrPath,
val: pathOperators[operator],
locale,
operator,
});
payload,
val: pathOperators[operator],
})
if (searchParam?.value && searchParam?.path) {
result = {
...result,
[searchParam.path]: searchParam.value,
};
}
} else if (typeof searchParam?.value === 'object') {
result = deepmerge(result, searchParam.value, { arrayMerge: combineMerge });
result = deepmerge(result, searchParam.value, { arrayMerge: combineMerge })
}
}
}
@@ -81,5 +83,5 @@ export async function parseParams({
}
}
return result;
return result
}