Skip to content

Commit

Permalink
fix(repository): remove hidden properties from entities
Browse files Browse the repository at this point in the history
See #1914
  • Loading branch information
raymondfeng committed Oct 30, 2018
1 parent 14d9419 commit 356d579
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/repository/package.json
Expand Up @@ -30,7 +30,7 @@
"@types/debug": "0.0.30",
"debug": "^4.0.1",
"lodash": "^4.17.10",
"loopback-datasource-juggler": "^4.0.0"
"loopback-datasource-juggler": "^4.1.2"
},
"files": [
"README.md",
Expand Down
Expand Up @@ -326,7 +326,7 @@ export class DefaultCrudRepository<T extends Entity, ID>
}

protected toEntity(model: juggler.PersistedModel): T {
return new this.entityClass(model.toObject()) as T;
return new this.entityClass(model.toJSON()) as T;
}

protected toEntities(models: juggler.PersistedModel[]): T[] {
Expand Down
Expand Up @@ -49,12 +49,17 @@ describe('DefaultCrudRepository', () => {
properties: {
title: 'string',
content: 'string',
secret: 'string',
id: {name: 'id', type: 'number', id: true},
},
settings: {
hiddenProperties: ['secret'],
},
});

title?: string;
content?: string;
secret?: string;
id: number;

constructor(data: Partial<Note>) {
Expand Down Expand Up @@ -137,6 +142,18 @@ describe('DefaultCrudRepository', () => {
expect(result.toJSON()).to.eql(note.toJSON());
});

it('hides hidden properties', async () => {
const repo = new DefaultCrudRepository(Note, ds);
const note = await repo.create({
title: 't3',
content: 'c3',
secret: 'secret',
});
expect(note.secret).to.be.undefined();
const result = await repo.findById(note.id);
expect(result.secret).to.be.undefined();
});

it('implements Repository.createAll()', async () => {
const repo = new DefaultCrudRepository(Note, ds);
const notes = await repo.createAll([
Expand Down

0 comments on commit 356d579

Please sign in to comment.