@ruiapp/rapid-core 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/CHANGELOG.md +7 -7
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.js +359 -134
  4. package/dist/plugins/license/LicensePlugin.d.ts +23 -0
  5. package/dist/plugins/license/LicensePluginTypes.d.ts +78 -0
  6. package/dist/plugins/license/LicenseService.d.ts +22 -0
  7. package/dist/plugins/license/actionHandlers/getLicense.d.ts +6 -0
  8. package/dist/plugins/license/actionHandlers/index.d.ts +3 -0
  9. package/dist/plugins/license/helpers/certHelper.d.ts +2 -0
  10. package/dist/plugins/license/helpers/cryptoHelper.d.ts +8 -0
  11. package/dist/plugins/license/models/index.d.ts +2 -0
  12. package/dist/plugins/license/routes/getLicense.d.ts +12 -0
  13. package/dist/plugins/license/routes/index.d.ts +12 -0
  14. package/dist/utilities/typeUtility.d.ts +1 -0
  15. package/package.json +1 -1
  16. package/src/bootstrapApplicationConfig.ts +631 -631
  17. package/src/core/response.ts +76 -76
  18. package/src/core/routeContext.ts +47 -47
  19. package/src/core/server.ts +142 -142
  20. package/src/dataAccess/columnTypeMapper.ts +22 -22
  21. package/src/dataAccess/dataAccessTypes.ts +163 -163
  22. package/src/dataAccess/dataAccessor.ts +135 -135
  23. package/src/dataAccess/entityManager.ts +1718 -1718
  24. package/src/dataAccess/entityMapper.ts +100 -100
  25. package/src/dataAccess/propertyMapper.ts +28 -28
  26. package/src/deno-std/http/cookie.ts +372 -372
  27. package/src/helpers/entityHelpers.ts +76 -76
  28. package/src/helpers/filterHelper.ts +148 -148
  29. package/src/helpers/metaHelper.ts +89 -89
  30. package/src/helpers/runCollectionEntityActionHandler.ts +27 -27
  31. package/src/index.ts +57 -54
  32. package/src/plugins/auth/AuthPlugin.ts +85 -85
  33. package/src/plugins/auth/actionHandlers/changePassword.ts +54 -54
  34. package/src/plugins/auth/actionHandlers/createSession.ts +75 -63
  35. package/src/plugins/auth/actionHandlers/resetPassword.ts +38 -38
  36. package/src/plugins/cronJob/CronJobPlugin.ts +112 -112
  37. package/src/plugins/dataManage/DataManagePlugin.ts +163 -163
  38. package/src/plugins/dataManage/actionHandlers/addEntityRelations.ts +20 -20
  39. package/src/plugins/dataManage/actionHandlers/countCollectionEntities.ts +16 -16
  40. package/src/plugins/dataManage/actionHandlers/createCollectionEntitiesBatch.ts +42 -42
  41. package/src/plugins/dataManage/actionHandlers/createCollectionEntity.ts +24 -24
  42. package/src/plugins/dataManage/actionHandlers/deleteCollectionEntities.ts +38 -38
  43. package/src/plugins/dataManage/actionHandlers/deleteCollectionEntityById.ts +22 -22
  44. package/src/plugins/dataManage/actionHandlers/findCollectionEntities.ts +26 -26
  45. package/src/plugins/dataManage/actionHandlers/findCollectionEntityById.ts +21 -21
  46. package/src/plugins/dataManage/actionHandlers/removeEntityRelations.ts +20 -20
  47. package/src/plugins/dataManage/actionHandlers/updateCollectionEntityById.ts +41 -41
  48. package/src/plugins/entityAccessControl/EntityAccessControlPlugin.ts +146 -146
  49. package/src/plugins/fileManage/FileManagePlugin.ts +52 -52
  50. package/src/plugins/fileManage/actionHandlers/downloadDocument.ts +65 -65
  51. package/src/plugins/fileManage/actionHandlers/downloadFile.ts +44 -44
  52. package/src/plugins/license/LicensePlugin.ts +79 -0
  53. package/src/plugins/license/LicensePluginTypes.ts +95 -0
  54. package/src/plugins/license/LicenseService.ts +112 -0
  55. package/src/plugins/license/actionHandlers/getLicense.ts +18 -0
  56. package/src/plugins/license/actionHandlers/index.ts +4 -0
  57. package/src/plugins/license/helpers/certHelper.ts +21 -0
  58. package/src/plugins/license/helpers/cryptoHelper.ts +47 -0
  59. package/src/plugins/license/models/index.ts +1 -0
  60. package/src/plugins/license/routes/getLicense.ts +15 -0
  61. package/src/plugins/license/routes/index.ts +3 -0
  62. package/src/plugins/mail/MailPlugin.ts +74 -74
  63. package/src/plugins/mail/MailPluginTypes.ts +27 -27
  64. package/src/plugins/mail/MailService.ts +38 -38
  65. package/src/plugins/mail/actionHandlers/index.ts +3 -3
  66. package/src/plugins/mail/models/index.ts +1 -1
  67. package/src/plugins/mail/routes/index.ts +1 -1
  68. package/src/plugins/metaManage/MetaManagePlugin.ts +504 -504
  69. package/src/plugins/notification/NotificationPlugin.ts +68 -68
  70. package/src/plugins/notification/NotificationPluginTypes.ts +13 -13
  71. package/src/plugins/notification/NotificationService.ts +25 -25
  72. package/src/plugins/notification/actionHandlers/index.ts +3 -3
  73. package/src/plugins/notification/models/Notification.ts +60 -57
  74. package/src/plugins/notification/models/index.ts +3 -3
  75. package/src/plugins/notification/routes/index.ts +1 -1
  76. package/src/plugins/routeManage/RouteManagePlugin.ts +62 -62
  77. package/src/plugins/sequence/SequencePlugin.ts +136 -136
  78. package/src/plugins/sequence/SequencePluginTypes.ts +69 -69
  79. package/src/plugins/sequence/SequenceService.ts +81 -81
  80. package/src/plugins/sequence/actionHandlers/generateSn.ts +32 -32
  81. package/src/plugins/sequence/segments/autoIncrement.ts +78 -78
  82. package/src/plugins/sequence/segments/dayOfMonth.ts +17 -17
  83. package/src/plugins/sequence/segments/literal.ts +14 -14
  84. package/src/plugins/sequence/segments/month.ts +17 -17
  85. package/src/plugins/sequence/segments/parameter.ts +18 -18
  86. package/src/plugins/sequence/segments/year.ts +17 -17
  87. package/src/plugins/setting/SettingPlugin.ts +68 -68
  88. package/src/plugins/setting/SettingPluginTypes.ts +37 -37
  89. package/src/plugins/setting/models/SystemSettingItem.ts +48 -42
  90. package/src/plugins/setting/models/UserSettingItem.ts +55 -49
  91. package/src/plugins/stateMachine/StateMachinePlugin.ts +186 -186
  92. package/src/plugins/stateMachine/StateMachinePluginTypes.ts +48 -48
  93. package/src/plugins/stateMachine/actionHandlers/sendStateMachineEvent.ts +51 -51
  94. package/src/plugins/webhooks/WebhooksPlugin.ts +148 -148
  95. package/src/plugins/webhooks/pluginConfig.ts +75 -75
  96. package/src/queryBuilder/queryBuilder.ts +665 -665
  97. package/src/server.ts +463 -463
  98. package/src/types.ts +701 -701
  99. package/src/utilities/errorUtility.ts +15 -15
  100. package/src/utilities/pathUtility.ts +14 -14
  101. package/src/utilities/typeUtility.ts +15 -11
@@ -1,42 +1,42 @@
1
- import { RunEntityActionHandlerOptions } from "~/types";
2
- import { mergeInput } from "~/helpers/inputHelper";
3
- import { isArray } from "lodash";
4
- import { ActionHandlerContext } from "~/core/actionHandler";
5
- import { RapidPlugin } from "~/core/server";
6
-
7
- export const code = "createCollectionEntitiesBatch";
8
-
9
- export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
10
- const { logger, server, input } = ctx;
11
-
12
- const { defaultInput, fixedInput } = options;
13
- logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, input });
14
-
15
- const { entities } = input;
16
- if (!isArray(entities)) {
17
- throw new Error("input.entities should be an array.");
18
- }
19
-
20
- const output: any[] = [];
21
- for (const entity of entities) {
22
- const mergedEntity = mergeInput(defaultInput?.entity || {}, entity, fixedInput?.entity);
23
-
24
- const userId = ctx.routerContext.state?.userId;
25
- if (userId) {
26
- mergedEntity.createdBy = userId;
27
- }
28
-
29
- const entityManager = server.getEntityManager(options.singularCode);
30
- const newEntity = await entityManager.createEntity(
31
- {
32
- entity: mergedEntity,
33
- routeContext: ctx.routerContext,
34
- },
35
- plugin,
36
- );
37
-
38
- output.push(newEntity);
39
- }
40
-
41
- ctx.output = output;
42
- }
1
+ import { RunEntityActionHandlerOptions } from "~/types";
2
+ import { mergeInput } from "~/helpers/inputHelper";
3
+ import { isArray } from "lodash";
4
+ import { ActionHandlerContext } from "~/core/actionHandler";
5
+ import { RapidPlugin } from "~/core/server";
6
+
7
+ export const code = "createCollectionEntitiesBatch";
8
+
9
+ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
10
+ const { logger, server, input } = ctx;
11
+
12
+ const { defaultInput, fixedInput } = options;
13
+ logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, input });
14
+
15
+ const { entities } = input;
16
+ if (!isArray(entities)) {
17
+ throw new Error("input.entities should be an array.");
18
+ }
19
+
20
+ const output: any[] = [];
21
+ for (const entity of entities) {
22
+ const mergedEntity = mergeInput(defaultInput?.entity || {}, entity, fixedInput?.entity);
23
+
24
+ const userId = ctx.routerContext.state?.userId;
25
+ if (userId) {
26
+ mergedEntity.createdBy = userId;
27
+ }
28
+
29
+ const entityManager = server.getEntityManager(options.singularCode);
30
+ const newEntity = await entityManager.createEntity(
31
+ {
32
+ entity: mergedEntity,
33
+ routeContext: ctx.routerContext,
34
+ },
35
+ plugin,
36
+ );
37
+
38
+ output.push(newEntity);
39
+ }
40
+
41
+ ctx.output = output;
42
+ }
@@ -1,24 +1,24 @@
1
- import { RunEntityActionHandlerOptions } from "~/types";
2
- import { mergeInput } from "~/helpers/inputHelper";
3
- import { ActionHandlerContext } from "~/core/actionHandler";
4
- import { RapidPlugin } from "~/core/server";
5
-
6
- export const code = "createCollectionEntity";
7
-
8
- export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
9
- const { logger, server, input } = ctx;
10
-
11
- const { defaultInput, fixedInput } = options;
12
- const mergedInput = mergeInput(defaultInput, input, fixedInput);
13
- logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
14
-
15
- const entityManager = server.getEntityManager(options.singularCode);
16
- const output = await entityManager.createEntity(
17
- {
18
- entity: input,
19
- routeContext: ctx.routerContext,
20
- },
21
- plugin,
22
- );
23
- ctx.output = output;
24
- }
1
+ import { RunEntityActionHandlerOptions } from "~/types";
2
+ import { mergeInput } from "~/helpers/inputHelper";
3
+ import { ActionHandlerContext } from "~/core/actionHandler";
4
+ import { RapidPlugin } from "~/core/server";
5
+
6
+ export const code = "createCollectionEntity";
7
+
8
+ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
9
+ const { logger, server, input } = ctx;
10
+
11
+ const { defaultInput, fixedInput } = options;
12
+ const mergedInput = mergeInput(defaultInput, input, fixedInput);
13
+ logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
14
+
15
+ const entityManager = server.getEntityManager(options.singularCode);
16
+ const output = await entityManager.createEntity(
17
+ {
18
+ entity: input,
19
+ routeContext: ctx.routerContext,
20
+ },
21
+ plugin,
22
+ );
23
+ ctx.output = output;
24
+ }
@@ -1,38 +1,38 @@
1
- import { FindEntityOptions, RunEntityActionHandlerOptions } from "~/types";
2
- import { ActionHandlerContext } from "~/core/actionHandler";
3
- import { RapidPlugin } from "~/core/server";
4
-
5
- export interface DeleteCollectionEntitiesInput {
6
- filters: FindEntityOptions["filters"];
7
- }
8
-
9
- export const code = "deleteCollectionEntities";
10
-
11
- export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
12
- const { logger, server, routerContext } = ctx;
13
- const input: DeleteCollectionEntitiesInput = ctx.input;
14
- logger.debug(`Running ${code} handler...`);
15
-
16
- if (!input.filters || !input.filters.length) {
17
- throw new Error("Filters are required when deleting entities.");
18
- }
19
-
20
- const entityManager = server.getEntityManager(options.singularCode);
21
- const entities = await entityManager.findEntities({
22
- routeContext: routerContext,
23
- filters: input.filters,
24
- });
25
-
26
- for (const entity of entities) {
27
- await entityManager.deleteById(
28
- {
29
- routeContext: ctx.routerContext,
30
- id: entity.id,
31
- },
32
- plugin,
33
- );
34
- }
35
-
36
- ctx.status = 200;
37
- ctx.output = {};
38
- }
1
+ import { FindEntityOptions, RunEntityActionHandlerOptions } from "~/types";
2
+ import { ActionHandlerContext } from "~/core/actionHandler";
3
+ import { RapidPlugin } from "~/core/server";
4
+
5
+ export interface DeleteCollectionEntitiesInput {
6
+ filters: FindEntityOptions["filters"];
7
+ }
8
+
9
+ export const code = "deleteCollectionEntities";
10
+
11
+ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
12
+ const { logger, server, routerContext } = ctx;
13
+ const input: DeleteCollectionEntitiesInput = ctx.input;
14
+ logger.debug(`Running ${code} handler...`);
15
+
16
+ if (!input.filters || !input.filters.length) {
17
+ throw new Error("Filters are required when deleting entities.");
18
+ }
19
+
20
+ const entityManager = server.getEntityManager(options.singularCode);
21
+ const entities = await entityManager.findEntities({
22
+ routeContext: routerContext,
23
+ filters: input.filters,
24
+ });
25
+
26
+ for (const entity of entities) {
27
+ await entityManager.deleteById(
28
+ {
29
+ routeContext: ctx.routerContext,
30
+ id: entity.id,
31
+ },
32
+ plugin,
33
+ );
34
+ }
35
+
36
+ ctx.status = 200;
37
+ ctx.output = {};
38
+ }
@@ -1,22 +1,22 @@
1
- import { RunEntityActionHandlerOptions } from "~/types";
2
- import { ActionHandlerContext } from "~/core/actionHandler";
3
- import { RapidPlugin } from "~/core/server";
4
-
5
- export const code = "deleteCollectionEntityById";
6
-
7
- export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
8
- const { logger, server, input } = ctx;
9
- logger.debug(`Running ${code} handler...`);
10
-
11
- const entityManager = server.getEntityManager(options.singularCode);
12
- await entityManager.deleteById(
13
- {
14
- id: input.id,
15
- routeContext: ctx.routerContext,
16
- },
17
- plugin,
18
- );
19
-
20
- ctx.status = 200;
21
- ctx.output = {};
22
- }
1
+ import { RunEntityActionHandlerOptions } from "~/types";
2
+ import { ActionHandlerContext } from "~/core/actionHandler";
3
+ import { RapidPlugin } from "~/core/server";
4
+
5
+ export const code = "deleteCollectionEntityById";
6
+
7
+ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
8
+ const { logger, server, input } = ctx;
9
+ logger.debug(`Running ${code} handler...`);
10
+
11
+ const entityManager = server.getEntityManager(options.singularCode);
12
+ await entityManager.deleteById(
13
+ {
14
+ id: input.id,
15
+ routeContext: ctx.routerContext,
16
+ },
17
+ plugin,
18
+ );
19
+
20
+ ctx.status = 200;
21
+ ctx.output = {};
22
+ }
@@ -1,26 +1,26 @@
1
- import { FindEntityOptions, RunEntityActionHandlerOptions } from "~/types";
2
- import runCollectionEntityActionHandler from "~/helpers/runCollectionEntityActionHandler";
3
- import { removeFiltersWithNullValue } from "~/helpers/filterHelper";
4
- import { ActionHandlerContext } from "~/core/actionHandler";
5
- import { RapidPlugin } from "~/core/server";
6
-
7
- export const code = "findCollectionEntities";
8
-
9
- export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
10
- await runCollectionEntityActionHandler(ctx, options, code, async (entityManager, input: FindEntityOptions) => {
11
- input.filters = removeFiltersWithNullValue(input.filters);
12
- input.routeContext = ctx.routerContext;
13
- const entities = await entityManager.findEntities(input);
14
- const result: {
15
- list: any;
16
- total?: any;
17
- } = { list: entities };
18
-
19
- if (input.pagination && !input.pagination.withoutTotal) {
20
- // TOOD: count entities when calling findEntities for performance.
21
- const total = await entityManager.count(input);
22
- result.total = total;
23
- }
24
- return result;
25
- });
26
- }
1
+ import { FindEntityOptions, RunEntityActionHandlerOptions } from "~/types";
2
+ import runCollectionEntityActionHandler from "~/helpers/runCollectionEntityActionHandler";
3
+ import { removeFiltersWithNullValue } from "~/helpers/filterHelper";
4
+ import { ActionHandlerContext } from "~/core/actionHandler";
5
+ import { RapidPlugin } from "~/core/server";
6
+
7
+ export const code = "findCollectionEntities";
8
+
9
+ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
10
+ await runCollectionEntityActionHandler(ctx, options, code, async (entityManager, input: FindEntityOptions) => {
11
+ input.filters = removeFiltersWithNullValue(input.filters);
12
+ input.routeContext = ctx.routerContext;
13
+ const entities = await entityManager.findEntities(input);
14
+ const result: {
15
+ list: any;
16
+ total?: any;
17
+ } = { list: entities };
18
+
19
+ if (input.pagination && !input.pagination.withoutTotal) {
20
+ // TOOD: count entities when calling findEntities for performance.
21
+ const total = await entityManager.count(input);
22
+ result.total = total;
23
+ }
24
+ return result;
25
+ });
26
+ }
@@ -1,21 +1,21 @@
1
- import { RunEntityActionHandlerOptions } from "~/types";
2
- import { ActionHandlerContext } from "~/core/actionHandler";
3
- import { RapidPlugin } from "~/core/server";
4
-
5
- export const code = "findCollectionEntityById";
6
-
7
- export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
8
- const { logger, server, input } = ctx;
9
- logger.debug(`Running ${code} handler...`, { input });
10
- const { id } = input;
11
-
12
- const entityManager = server.getEntityManager(options.singularCode);
13
- const entity = await entityManager.findById({
14
- id,
15
- routeContext: ctx.routerContext,
16
- });
17
- if (!entity) {
18
- throw new Error(`${options.namespace}.${options.singularCode} with id "${id}" was not found.`);
19
- }
20
- ctx.output = entity;
21
- }
1
+ import { RunEntityActionHandlerOptions } from "~/types";
2
+ import { ActionHandlerContext } from "~/core/actionHandler";
3
+ import { RapidPlugin } from "~/core/server";
4
+
5
+ export const code = "findCollectionEntityById";
6
+
7
+ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
8
+ const { logger, server, input } = ctx;
9
+ logger.debug(`Running ${code} handler...`, { input });
10
+ const { id } = input;
11
+
12
+ const entityManager = server.getEntityManager(options.singularCode);
13
+ const entity = await entityManager.findById({
14
+ id,
15
+ routeContext: ctx.routerContext,
16
+ });
17
+ if (!entity) {
18
+ throw new Error(`${options.namespace}.${options.singularCode} with id "${id}" was not found.`);
19
+ }
20
+ ctx.output = entity;
21
+ }
@@ -1,20 +1,20 @@
1
- import { RemoveEntityRelationsOptions, RunEntityActionHandlerOptions } from "~/types";
2
- import { mergeInput } from "~/helpers/inputHelper";
3
- import { ActionHandlerContext } from "~/core/actionHandler";
4
- import { RapidPlugin } from "~/core/server";
5
-
6
- export const code = "removeEntityRelations";
7
-
8
- export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
9
- const { logger, server, input } = ctx;
10
- const { defaultInput, fixedInput } = options;
11
-
12
- const mergedInput: RemoveEntityRelationsOptions = mergeInput(defaultInput, input, fixedInput);
13
- logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
14
- mergedInput.routeContext = ctx.routerContext;
15
-
16
- const entityManager = server.getEntityManager(options.singularCode);
17
- await entityManager.removeRelations(mergedInput, plugin);
18
-
19
- ctx.output = {};
20
- }
1
+ import { RemoveEntityRelationsOptions, RunEntityActionHandlerOptions } from "~/types";
2
+ import { mergeInput } from "~/helpers/inputHelper";
3
+ import { ActionHandlerContext } from "~/core/actionHandler";
4
+ import { RapidPlugin } from "~/core/server";
5
+
6
+ export const code = "removeEntityRelations";
7
+
8
+ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
9
+ const { logger, server, input } = ctx;
10
+ const { defaultInput, fixedInput } = options;
11
+
12
+ const mergedInput: RemoveEntityRelationsOptions = mergeInput(defaultInput, input, fixedInput);
13
+ logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
14
+ mergedInput.routeContext = ctx.routerContext;
15
+
16
+ const entityManager = server.getEntityManager(options.singularCode);
17
+ await entityManager.removeRelations(mergedInput, plugin);
18
+
19
+ ctx.output = {};
20
+ }
@@ -1,41 +1,41 @@
1
- import { RunEntityActionHandlerOptions, UpdateEntityByIdOptions } from "~/types";
2
- import { mergeInput } from "~/helpers/inputHelper";
3
- import { ActionHandlerContext } from "~/core/actionHandler";
4
- import { RapidPlugin } from "~/core/server";
5
-
6
- export const code = "updateCollectionEntityById";
7
-
8
- export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
9
- const { logger, server, input } = ctx;
10
-
11
- const { defaultInput, fixedInput } = options;
12
- const mergedInput = mergeInput(defaultInput, input, fixedInput);
13
- logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
14
-
15
- const operation = mergedInput.$operation;
16
- if (operation) {
17
- delete mergedInput.$operation;
18
- }
19
-
20
- const stateProperties = mergedInput.$stateProperties;
21
- if (stateProperties) {
22
- delete mergedInput.$stateProperties;
23
- }
24
-
25
- const relationPropertiesToUpdate = mergedInput.$relationPropertiesToUpdate;
26
- if (relationPropertiesToUpdate) {
27
- delete mergedInput.$relationPropertiesToUpdate;
28
- }
29
-
30
- const updateEntityByIdOptions: UpdateEntityByIdOptions = {
31
- id: mergedInput.id,
32
- entityToSave: mergedInput,
33
- operation,
34
- stateProperties,
35
- relationPropertiesToUpdate,
36
- routeContext: ctx.routerContext,
37
- };
38
- const entityManager = server.getEntityManager(options.singularCode);
39
- const output = await entityManager.updateEntityById(updateEntityByIdOptions, plugin);
40
- ctx.output = output;
41
- }
1
+ import { RunEntityActionHandlerOptions, UpdateEntityByIdOptions } from "~/types";
2
+ import { mergeInput } from "~/helpers/inputHelper";
3
+ import { ActionHandlerContext } from "~/core/actionHandler";
4
+ import { RapidPlugin } from "~/core/server";
5
+
6
+ export const code = "updateCollectionEntityById";
7
+
8
+ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
9
+ const { logger, server, input } = ctx;
10
+
11
+ const { defaultInput, fixedInput } = options;
12
+ const mergedInput = mergeInput(defaultInput, input, fixedInput);
13
+ logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
14
+
15
+ const operation = mergedInput.$operation;
16
+ if (operation) {
17
+ delete mergedInput.$operation;
18
+ }
19
+
20
+ const stateProperties = mergedInput.$stateProperties;
21
+ if (stateProperties) {
22
+ delete mergedInput.$stateProperties;
23
+ }
24
+
25
+ const relationPropertiesToUpdate = mergedInput.$relationPropertiesToUpdate;
26
+ if (relationPropertiesToUpdate) {
27
+ delete mergedInput.$relationPropertiesToUpdate;
28
+ }
29
+
30
+ const updateEntityByIdOptions: UpdateEntityByIdOptions = {
31
+ id: mergedInput.id,
32
+ entityToSave: mergedInput,
33
+ operation,
34
+ stateProperties,
35
+ relationPropertiesToUpdate,
36
+ routeContext: ctx.routerContext,
37
+ };
38
+ const entityManager = server.getEntityManager(options.singularCode);
39
+ const output = await entityManager.updateEntityById(updateEntityByIdOptions, plugin);
40
+ ctx.output = output;
41
+ }