1
1
/*
2
2
* @moleculer /database
3
- * Copyright (c) 2022 MoleculerJS (https://github.com/moleculerjs/database)
3
+ * Copyright (c) 2024 MoleculerJS (https://github.com/moleculerjs/database)
4
4
* MIT Licensed
5
5
*/
6
6
7
7
"use strict" ;
8
8
9
+ const { isisActionEnabled } = require ( "./schema" ) ;
10
+
9
11
const PARAMS_FIELDS = [
10
12
{ type : "string" , optional : true } ,
11
13
{ type : "array" , optional : true , items : "string" }
@@ -52,13 +54,6 @@ module.exports = function (mixinOpts) {
52
54
return null ;
53
55
} ;
54
56
55
- const actionEnabled = name => {
56
- if ( typeof mixinOpts . createActions == "object" ) {
57
- return mixinOpts . createActions [ name ] !== false ;
58
- }
59
- return mixinOpts . createActions !== false ;
60
- } ;
61
-
62
57
/**
63
58
* Find entities by query.
64
59
*
@@ -77,7 +72,7 @@ module.exports = function (mixinOpts) {
77
72
*
78
73
* @returns {Array<Object> } List of found entities.
79
74
*/
80
- if ( actionEnabled ( "find" ) ) {
75
+ if ( isActionEnabled ( mixinOpts , "find" ) ) {
81
76
res . find = {
82
77
visibility : mixinOpts . actionVisibility ,
83
78
rest : mixinOpts . rest ? "GET /all" : null ,
@@ -131,7 +126,7 @@ module.exports = function (mixinOpts) {
131
126
*
132
127
* @returns {Number } Count of found entities.
133
128
*/
134
- if ( actionEnabled ( "count" ) ) {
129
+ if ( isActionEnabled ( mixinOpts , "count" ) ) {
135
130
res . count = {
136
131
visibility : mixinOpts . actionVisibility ,
137
132
rest : mixinOpts . rest ? "GET /count" : null ,
@@ -166,7 +161,7 @@ module.exports = function (mixinOpts) {
166
161
*
167
162
* @returns {Object } List of found entities and total count.
168
163
*/
169
- if ( actionEnabled ( "list" ) ) {
164
+ if ( isActionEnabled ( mixinOpts , "list" ) ) {
170
165
res . list = {
171
166
visibility : mixinOpts . actionVisibility ,
172
167
rest : mixinOpts . rest ? "GET /" : null ,
@@ -237,7 +232,7 @@ module.exports = function (mixinOpts) {
237
232
*
238
233
* @throws {EntityNotFoundError } - 404 Entity not found
239
234
*/
240
- if ( actionEnabled ( "get" ) ) {
235
+ if ( isActionEnabled ( mixinOpts , "get" ) ) {
241
236
res . get = {
242
237
visibility : mixinOpts . actionVisibility ,
243
238
rest : mixinOpts . rest ? "GET /:id" : null ,
@@ -270,7 +265,7 @@ module.exports = function (mixinOpts) {
270
265
*
271
266
* @throws {EntityNotFoundError } - 404 Entity not found
272
267
*/
273
- if ( actionEnabled ( "resolve" ) ) {
268
+ if ( isActionEnabled ( mixinOpts , "resolve" ) ) {
274
269
res . resolve = {
275
270
visibility : mixinOpts . actionVisibility ,
276
271
cache : generateCacheOptions ( [
@@ -307,7 +302,7 @@ module.exports = function (mixinOpts) {
307
302
*
308
303
* @returns {Object } Saved entity.
309
304
*/
310
- if ( actionEnabled ( "create" ) ) {
305
+ if ( isActionEnabled ( mixinOpts , "create" ) ) {
311
306
res . create = {
312
307
visibility : mixinOpts . actionVisibility ,
313
308
rest : mixinOpts . rest ? "POST /" : null ,
@@ -325,7 +320,7 @@ module.exports = function (mixinOpts) {
325
320
*
326
321
* @returns {Array<Object> } Saved entities.
327
322
*/
328
- if ( actionEnabled ( "createMany" ) ) {
323
+ if ( isActionEnabled ( mixinOpts , "createMany" ) ) {
329
324
res . createMany = {
330
325
visibility : mixinOpts . actionVisibility ,
331
326
rest : null ,
@@ -345,7 +340,7 @@ module.exports = function (mixinOpts) {
345
340
*
346
341
* @throws {EntityNotFoundError } - 404 Entity not found
347
342
*/
348
- if ( actionEnabled ( "update" ) ) {
343
+ if ( isActionEnabled ( mixinOpts , "update" ) ) {
349
344
res . update = {
350
345
visibility : mixinOpts . actionVisibility ,
351
346
rest : mixinOpts . rest ? "PATCH /:id" : null ,
@@ -365,7 +360,7 @@ module.exports = function (mixinOpts) {
365
360
*
366
361
* @throws {EntityNotFoundError } - 404 Entity not found
367
362
*/
368
- if ( actionEnabled ( "replace" ) ) {
363
+ if ( isActionEnabled ( mixinOpts , "replace" ) ) {
369
364
res . replace = {
370
365
visibility : mixinOpts . actionVisibility ,
371
366
rest : mixinOpts . rest ? "PUT /:id" : null ,
@@ -386,7 +381,7 @@ module.exports = function (mixinOpts) {
386
381
*
387
382
* @throws {EntityNotFoundError } - 404 Entity not found
388
383
*/
389
- if ( actionEnabled ( "remove" ) ) {
384
+ if ( isActionEnabled ( mixinOpts , "remove" ) ) {
390
385
res . remove = {
391
386
visibility : mixinOpts . actionVisibility ,
392
387
rest : mixinOpts . rest ? "DELETE /:id" : null ,
0 commit comments