Skip to content

Commit

Permalink
feat: handle field names containing underscores on update record acti…
Browse files Browse the repository at this point in the history
…ons (#735)
  • Loading branch information
Thenkei authored Jun 19, 2023
1 parent 56d4278 commit d5d7661
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin } from '@forestadmin/datasource-customizer';
import { ActionContext, Plugin } from '@forestadmin/datasource-customizer';
import {
ModelCustomization,
UpdateRecordActionConfiguration,
Expand All @@ -25,13 +25,17 @@ export default class UpdateRecordActionsPlugin {

collection.addAction(action.name, {
scope: action.configuration.scope,
execute: async context => {
execute: async (context: ActionContext) => {
const {
configuration: {
configuration: { fields },
configuration: { fields: fieldsToUpdate },
},
} = action;

const fields = fieldsToUpdate.reduce((acc, fieldToUpdate) => {
return { ...acc, [fieldToUpdate.fieldName]: fieldToUpdate.value };
}, {});

await context.collection.update(context.filter, fields);
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Services > ModelCustomizations > Actions > UpdateRecordActionsPlugin',
configuration: {
type: 'update-record',
scope,
configuration: { fields: { field: 'value' } },
configuration: { fields: [{ fieldName: 'field', value: 'value' }] },
},
};

Expand Down Expand Up @@ -56,7 +56,7 @@ describe('Services > ModelCustomizations > Actions > UpdateRecordActionsPlugin',
configuration: {
type: 'update-record',
scope: 'Global',
configuration: { fields: { field: 'value' } },
configuration: { fields: [{ fieldName: 'field', value: 'value' }] },
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type WebhookActionConfiguration = ActionConfiguration<WebhookActionConfig
};

export type UpdateRecordActionConfigurationSpecific = {
fields: Record<string, unknown>;
fields: Array<{ fieldName: string; value: unknown }>;
};

export type UpdateRecordActionConfiguration =
Expand Down

0 comments on commit d5d7661

Please sign in to comment.