Skip to content

Commit

Permalink
fix: 🐛 processor functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinCK committed Jan 2, 2019
1 parent 2ce285a commit fa8f6de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/Resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,17 @@ export class Resolver {
throw new Error(`Processor "${processorPath}" not found`);
}

const processor: IProcessor<any> = require(processorPath);
const processor = require(processorPath).default;
const processorInstance = new processor();

if (typeof processor.preProcess === 'function') {
data = processor.preProcess(fixture.name, data);
if (typeof processorInstance.preProcess === 'function') {
data = processorInstance.preProcess(fixture.name, data);
}

Object.assign(entity, data);

if (typeof processor.postProcess === 'function') {
processor.postProcess(fixture.name, entity);
if (typeof processorInstance.postProcess === 'function') {
processorInstance.postProcess(fixture.name, entity);
}
} else {
Object.assign(entity, data);
Expand Down
4 changes: 2 additions & 2 deletions test/assets/processor/UserProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {IProcessor} from '../../../src/interface';
import {User} from '../entity/User';

export default class UserProcessor implements IProcessor<User> {
preProcess(name: string, object: {[key: string]: any}): object {
return {...object, name: `${object.firstName} ${object.lastName}}`};
postProcess(name: string, object: {[key: string]: any}): void {
object.name = `${object.firstName} ${object.lastName}`;
}
}

0 comments on commit fa8f6de

Please sign in to comment.