Skip to content

Commit

Permalink
Update engine/Action.ts and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed Apr 3, 2020
1 parent d599fec commit 1e0a785
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 210 deletions.
208 changes: 0 additions & 208 deletions src/engine/action/Action.js

This file was deleted.

20 changes: 18 additions & 2 deletions src/engine/action/Action.ts
Expand Up @@ -23,6 +23,7 @@ export type ActionSetup = {
resolve?: Function;
type?: string;
permissions?: Function | Permission | Permission[];
preProcessor?: Function;
postProcessor?: Function;
};

Expand All @@ -43,6 +44,7 @@ export class Action {
private _permissions: Function | Permission | Permission[];
private _defaultPermissions: Permission | Permission[];
descriptionPermissions: string | boolean;
preProcessor: Function;
postProcessor: Function;

constructor(setup: ActionSetup = {} as ActionSetup) {
Expand All @@ -54,6 +56,7 @@ export class Action {
resolve,
type,
permissions,
preProcessor,
postProcessor,
} = setup;

Expand Down Expand Up @@ -83,11 +86,20 @@ export class Action {
)}'`,
);

if (preProcessor) {
passOrThrow(
isFunction(preProcessor),
() =>
`preProcessor of of action '${name}' needs to be a valid function`,
);

this.preProcessor = preProcessor;
}

if (postProcessor) {
passOrThrow(
isFunction(postProcessor),
() =>
`postProcessor of mutation '${name}' needs to be a valid function`,
() => `postProcessor of action '${name}' needs to be a valid function`,
);

this.postProcessor = postProcessor;
Expand Down Expand Up @@ -192,6 +204,8 @@ export class Action {

_processPermissions(): null | Permission | Permission[] {
if (this._permissions) {
// if (isArray(this._permissions)) { check type for each permission }

if (isFunction(this._permissions)) {
const permissionsFn = this._permissions as Function;
const permissions: Permission | Permission[] = permissionsFn();
Expand All @@ -213,6 +227,8 @@ export class Action {

_generatePermissionDescriptions(): void {
if (this.permissions) {
// if (isArray(this._permissions)) { check type for each permission }

let permissions: Permission | Permission[];
if (isFunction(this._permissions)) {
const permissionsFn = this._permissions as Function;
Expand Down

0 comments on commit 1e0a785

Please sign in to comment.