Skip to content

Commit 41e456c

Browse files
committed
fix(repository): resolve types for juggler
Fixes #1813
1 parent f6c3048 commit 41e456c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/repository/src/repositories/legacy-juggler-bridge.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
HasManyRepositoryFactory,
3030
} from './relation.factory';
3131
import {EntityCrudRepository} from './repository';
32+
import {resolveType} from '../type-resolver';
3233

3334
export namespace juggler {
3435
export import DataSource = legacy.DataSource;
@@ -122,9 +123,10 @@ export class DefaultCrudRepository<T extends Entity, ID>
122123
// the juggler understands
123124
Object.entries(definition.properties).forEach(([key, value]) => {
124125
if (value.type === 'array' || value.type === Array) {
125-
value = Object.assign({}, value, {type: [value.itemType]});
126+
value = Object.assign({}, value, {type: [resolveType(value.itemType)]});
126127
delete value.itemType;
127128
}
129+
value.type = resolveType(value.type);
128130
properties[key] = Object.assign({}, value);
129131
});
130132

packages/repository/test/unit/repositories/legacy-juggler-bridge.unit.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,21 @@ describe('DefaultCrudRepository', () => {
7878
type: 'number',
7979
id: true,
8080
},
81+
created: {
82+
type: () => Date,
83+
},
8184
toBuy: {
8285
type: 'array',
8386
itemType: 'string',
8487
},
8588
toVisit: {
8689
type: Array,
87-
itemType: String,
90+
itemType: () => String,
8891
},
8992
},
9093
});
9194

95+
created: Date;
9296
toBuy: String[];
9397
toVisit: String[];
9498
}
@@ -101,6 +105,7 @@ describe('DefaultCrudRepository', () => {
101105
const listDefinition = new DefaultCrudRepository(ShoppingList, ds)
102106
.modelClass.definition;
103107
const jugglerPropertyDefinition = {
108+
created: {type: Date},
104109
toBuy: {
105110
type: [String],
106111
},

0 commit comments

Comments
 (0)