@@ -10,7 +10,7 @@ import { pickRandom, repeat } from '../util/random.js'
10
10
import { getFactoryStorage } from '../factory/storage.js'
11
11
import { generateResourceInstances } from '../resource/generateInstances.js'
12
12
import { createResourceInstanceReference } from '../resource/resourceReference.js'
13
- import { isPlainObject } from '../util/object.js'
13
+ import { get , isPlainObject } from '../util/object.js'
14
14
import { type HookBeforeSendResponseContext , hooks } from '../hooks.js'
15
15
import type { UntypedQueryManagerProxy } from '../resource/queryManagerProxy.js'
16
16
@@ -162,7 +162,7 @@ export async function setupRestApi(mq: MoquerieInstance, expressApp: Application
162
162
163
163
if ( ! mq . data . silent ) {
164
164
// eslint-disable-next-line no-console
165
- console . log ( `[Auto REST] ${ req . method } ${ req . path } ` , req . body )
165
+ console . log ( `[Auto REST] ${ req . method } ${ req . path } ` , 'query:' , query , 'body:' , req . body )
166
166
}
167
167
168
168
if ( ! resourceType ) {
@@ -210,7 +210,19 @@ export async function setupRestApi(mq: MoquerieInstance, expressApp: Application
210
210
}
211
211
else {
212
212
if ( req . method === 'GET' ) {
213
- data = await ( ctx . db as UntypedQueryManagerProxy ) [ resourceType . name ] . findMany ( )
213
+ const predicate = ( data : any ) => {
214
+ for ( const key in query ) {
215
+ if ( key . startsWith ( '__' ) ) {
216
+ continue
217
+ }
218
+ // eslint-disable-next-line eqeqeq
219
+ if ( get ( data , key ) != query [ key ] ) {
220
+ return false
221
+ }
222
+ }
223
+ return true
224
+ }
225
+ data = await ( ctx . db as UntypedQueryManagerProxy ) [ resourceType . name ] . findMany ( predicate )
214
226
}
215
227
if ( req . method === 'POST' ) {
216
228
data = await ( ctx . db as UntypedQueryManagerProxy ) [ resourceType . name ] . create ( req . body )
0 commit comments