1- import { NotFound } from '@feathersjs/errors' ;
21import { OPERATORS_MAP } from './constants' ;
32import { EagerQuery , FeathersQueryData , IdField , QueryParam , QueryParamRecordFilters } from './types' ;
43
@@ -40,7 +39,7 @@ export const castFeathersQueryToPrismaFilters = (p: QueryParamRecordFilters, whi
4039
4140export const castEagerQueryToPrismaInclude = ( value : EagerQuery , whitelist : string [ ] , idField : string ) => {
4241 // we don't care about feathers compliance, we want where queries in our include
43- // thus just returnung the $eager value as include 1:1
42+ // thus just returning the $eager value as include 1:1
4443 return value ;
4544 // const include: Record<string, any> = {};
4645 // if (Array.isArray(value)) {
@@ -82,23 +81,6 @@ export const castEagerQueryToPrismaInclude = (value: EagerQuery, whitelist: stri
8281 // return include;
8382} ;
8483
85- export const mergeFiltersWithSameKey = (
86- where : Record < string , any > ,
87- key : string ,
88- filter : Record < string , any > | string | number | boolean | null ,
89- ) : Record < string , any > | string | number | boolean => {
90- const current = where [ key ] ;
91- if ( typeof filter === 'object' ) {
92- const currentIsObj = typeof current === 'object' ;
93- return {
94- ...( currentIsObj ? current : { } ) ,
95- ...filter ,
96- ...( ! currentIsObj && current ? { equals : current } : { } )
97- } ;
98- }
99- return filter ;
100- } ;
101-
10284/**
10385 * WARN: This method is not safe for Feathers queries because unwanted queries can reach the Prisma-Client.
10486 **/
@@ -125,18 +107,13 @@ export const buildWhereAndInclude = (query: QueryParam, whitelist: string[], idF
125107 if ( value === null ) {
126108 where [ k ] = null ;
127109 } else if ( k === idField ) {
128- where [ k ] = mergeFiltersWithSameKey ( where , k , buildIdField ( value , whitelist ) ) ;
110+ where [ k ] = buildIdField ( value , whitelist ) ;
129111 } else if ( k === '$or' && Array . isArray ( value ) ) {
130112 where . OR = value . map ( ( v ) => buildWhereAndInclude ( v , whitelist , idField ) . where ) ;
131113 } else if ( k === '$and' && Array . isArray ( value ) ) {
132- value . forEach ( ( v ) => {
133- const whereValue = buildWhereAndInclude ( v , whitelist , idField ) . where ;
134- Object . keys ( whereValue ) . map ( ( subKey ) => {
135- where [ subKey ] = mergeFiltersWithSameKey ( where , subKey , whereValue [ subKey ] ) ;
136- } ) ;
137- } ) ;
114+ where . AND = value . map ( ( v ) => buildWhereAndInclude ( v , whitelist , idField ) . where ) ;
138115 } else if ( k !== '$eager' && typeof value === 'object' && ! Array . isArray ( value ) ) {
139- where [ k ] = mergeFiltersWithSameKey ( where , k , castFeathersQueryToPrismaFilters ( value , whitelist ) ) ;
116+ where [ k ] = castFeathersQueryToPrismaFilters ( value , whitelist ) ;
140117 } else if ( k !== '$eager' && typeof value !== 'object' && ! Array . isArray ( value ) ) {
141118 where [ k ] = castToNumberBooleanStringOrNull ( value ) ;
142119 } else if ( k === '$eager' && whitelist . includes ( k ) ) {
0 commit comments