Added parseData to related items.

This commit is contained in:
Yossi Kolesnicov 2018-10-23 13:19:56 +03:00
Родитель 0f39f5a2b1
Коммит 899a5e48bf
6 изменённых файлов: 33 добавлений и 4 удалений

Просмотреть файл

@ -1,3 +1,3 @@
import 'reflect-metadata';
global['Reflect'] = Reflect;
(<any>global)['Reflect'] = Reflect;

Просмотреть файл

@ -204,6 +204,7 @@ export class ReadonlyRepository<TEntity extends ModelBase, TRawData = any> imple
this.emitEntityHttpErrorEvent(err);
throw err
}),
map(data => this.entityBackendConfig.parseData ? this.entityBackendConfig.parseData(data) : data),
mergeMap(data => this.createItem(data, dataOptions, query))
);

Просмотреть файл

@ -1,6 +1,6 @@
{
"name": "@microsoft/paris",
"version": "1.3.4",
"version": "1.3.5",
"description": "Library for the implementation of Domain Driven Design with TypeScript + RxJS",
"repository": {
"type": "git",

Просмотреть файл

@ -6,12 +6,15 @@ import {TodoList} from "../mock/todo-list.entity";
import {Observable} from "rxjs";
import {DataSet} from "../../lib/data_access/dataset";
import {RelationshipRepository} from "../../lib/api/repository/relationship-repository";
import {Tag} from "../mock/tag.value-object";
import {TodoTagRelationship} from "../mock/todo-tag.relationships";
describe('RelationshipRepository', () => {
let paris: Paris<MockConfigData>,
todoListItemsRepo:RelationshipRepository<TodoList, Todo>,
getTodoListItems$:Observable<DataSet<Todo>>,
sourceTodoList:TodoList;
sourceTodoList:TodoList,
todoTagRepository:RelationshipRepository<Todo, Tag>;
setMockData({
items: [
@ -33,6 +36,7 @@ describe('RelationshipRepository', () => {
sourceTodoList = new TodoList({ id: 1 });
todoListItemsRepo = paris.getRelationshipRepository(TodoListItemsRelationship);
getTodoListItems$ = paris.queryForItem(TodoListItemsRelationship, sourceTodoList);
todoTagRepository = paris.getRelationshipRepository(TodoTagRelationship);
});
it('should return a DataSet of Todo for the TodoList', done => {
@ -48,4 +52,11 @@ describe('RelationshipRepository', () => {
expect(todoListItemsRepo.getEndpointUrl({ where: { todoListId: 1 }})).toBe('/lists/1/items');
});
});
it('should parse data for a related item', done => {
todoTagRepository.getRelatedItem(new Todo({ id: 5 })).subscribe((tag) => {
expect(tag.color).toEqual('Purple');
done();
});
});
});

Просмотреть файл

@ -11,6 +11,6 @@ import {EntityRelationshipRepositoryType} from "../../lib/api/entity/entity-rela
dataEntity: Todo,
endpoint: (config: ParisConfig<MockConfigData>, query: DataQuery) => `lists/${(<any>query.where).todoListId}/items`,
foreignKey: 'listId',
allowedTypes: [RelationshipType.OneToMany],
allowedTypes: [RelationshipType.OneToMany]
})
export class TodoListItemsRelationship implements EntityRelationshipRepositoryType<TodoList, Todo> {}

Просмотреть файл

@ -0,0 +1,17 @@
import {Todo} from "./todo.entity";
import {EntityRelationship} from "../../lib/config/decorators/entity-relationship.decorator";
import {ParisConfig} from "../../lib/config/paris-config";
import {DataQuery} from "../../lib/data_access/data-query";
import {RelationshipType} from "../../lib/config/relationship-type.enum";
import {EntityRelationshipRepositoryType} from "../../lib/api/entity/entity-relationship-repository-type";
import {Tag} from "./tag.value-object";
@EntityRelationship({
sourceEntity: Todo,
dataEntity: Tag,
endpoint: (config: ParisConfig<MockConfigData>, query: DataQuery) => `todo/tag/${(<any>query.where).todo}`,
foreignKey: 'todo',
allowedTypes: [RelationshipType.OneToOne],
parseData: data => ({ ...data, colorName: 'Purple' })
})
export class TodoTagRelationship implements EntityRelationshipRepositoryType<Todo, Tag> {}