Skip to content

Commit

Permalink
chore: added interface for entity variable
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinCK committed Dec 25, 2020
1 parent 33a62b4 commit 2abdc21
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs';
import * as path from 'path';
import { isObject, isArray } from 'lodash';
import { Connection } from 'typeorm';
import { IDataParser, IFixture } from './interface';
import { IDataParser, IEntity, IFixture } from './interface';
import { plainToClassFromExist } from 'class-transformer';

export class Builder {
Expand All @@ -16,7 +16,7 @@ export class Builder {
*/
async build(fixture: IFixture) {
const repository = this.connection.getRepository(fixture.entity);
let entity = repository.create();
let entity: IEntity = repository.create() as IEntity;
let data = this.parser.parse(fixture.data, fixture, this.entities);
let call: object;

Expand Down Expand Up @@ -79,10 +79,11 @@ export class Builder {
await callExecutors();
}

fixture.resolvedFields?.forEach((f) => {
// @ts-ignore
entity[f] = Promise.resolve(data[f]);
});
if (fixture.resolvedFields && Array.isArray(fixture.resolvedFields)) {
fixture.resolvedFields.forEach((propertyName) => {
entity[propertyName] = Promise.resolve(data[propertyName]);
});
}

this.entities[fixture.name] = entity;

Expand Down
3 changes: 3 additions & 0 deletions src/interface/IEntity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface IEntity {
[key: string]: any;
}
1 change: 1 addition & 0 deletions src/interface/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './IDataParser';
export * from './IEntity';
export * from './IFixture';
export * from './IFixturesConfig';
export * from './ILoader';
Expand Down

0 comments on commit 2abdc21

Please sign in to comment.