Skip to content

Commit 641e99f

Browse files
committed
fix: add multi-operation checks to adapter methods
- Add allowsMulti() checks to _create, _patch, and _remove methods - Throw MethodNotAllowed error when multi operations attempted without multi option - Import errors from @feathersjs/errors - Fixes 3 adapter test failures - 180 tests now passing (up from 177)
1 parent 2dba2a5 commit 641e99f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/adapter.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// import { _ } from "@feathersjs/commons";
22
import { AdapterBase, filterQuery } from '@feathersjs/adapter-commons'
3+
import { errors } from '@feathersjs/errors'
34
import { Client } from '@elastic/elasticsearch'
45
import {
56
ElasticsearchServiceOptions,
@@ -212,6 +213,12 @@ export class ElasticAdapter extends AdapterBase implements ElasticAdapterInterfa
212213
}) as Promise<Record<string, unknown>>
213214
}
214215

216+
if (!this.allowsMulti('create', params)) {
217+
return Promise.reject(
218+
new errors.MethodNotAllowed('Can not create multiple entries')
219+
)
220+
}
221+
215222
return methods.createBulk(this, data, params).catch((error: Error) => {
216223
throw errorHandler(error)
217224
}) as Promise<Record<string, unknown>[]>
@@ -251,6 +258,12 @@ export class ElasticAdapter extends AdapterBase implements ElasticAdapterInterfa
251258
}) as Promise<Record<string, unknown>>
252259
}
253260

261+
if (!this.allowsMulti('patch', params)) {
262+
return Promise.reject(
263+
new errors.MethodNotAllowed('Can not patch multiple entries')
264+
)
265+
}
266+
254267
return methods.patchBulk(this, data, params).catch((error: Error) => {
255268
throw errorHandler(error)
256269
}) as Promise<Record<string, unknown>[]>
@@ -270,6 +283,12 @@ export class ElasticAdapter extends AdapterBase implements ElasticAdapterInterfa
270283
})
271284
}
272285

286+
if (!this.allowsMulti('remove', params)) {
287+
return Promise.reject(
288+
new errors.MethodNotAllowed('Can not remove multiple entries')
289+
)
290+
}
291+
273292
return methods.removeBulk(this, params).catch((error: Error) => {
274293
throw errorHandler(error)
275294
})

0 commit comments

Comments
 (0)