From 0f98b9747f48763c6cf2e5ac427678efd5ba0a59 Mon Sep 17 00:00:00 2001 From: Nora Date: Fri, 21 Jun 2019 09:23:56 -0400 Subject: [PATCH] fixup! apply most feedback --- .../todo-list-tutorial-repository.md | 28 +++++++++++++------ .../__tests__/fixtures/testdb.datasource.json | 0 ...todo-list-image.repository.integration.ts} | 2 +- ...ts => todo-list.repository.integration.ts} | 2 +- ...tion.ts => todo.repository.integration.ts} | 2 +- .../todo-list-image.repository.ts | 13 +++++++-- .../src/repositories/todo-list.repository.ts | 13 +++++++-- .../src/repositories/todo.repository.ts | 13 +++++++-- 8 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 examples/todo-list/src/__tests__/fixtures/testdb.datasource.json rename examples/todo-list/src/__tests__/integration/{todo-list-image.integration.ts => todo-list-image.repository.integration.ts} (97%) rename examples/todo-list/src/__tests__/integration/{todo-list.integration.ts => todo-list.repository.integration.ts} (97%) rename examples/todo-list/src/__tests__/integration/{todo.integration.ts => todo.repository.integration.ts} (97%) diff --git a/docs/site/tutorials/todo-list/todo-list-tutorial-repository.md b/docs/site/tutorials/todo-list/todo-list-tutorial-repository.md index 1cd90376160c..d4d95f3f23a5 100644 --- a/docs/site/tutorials/todo-list/todo-list-tutorial-repository.md +++ b/docs/site/tutorials/todo-list/todo-list-tutorial-repository.md @@ -109,11 +109,13 @@ async find( // Prevent juggler for applying "include" filter // Juggler is not aware of LB4 relations const include = filter && filter.include; - filter = filter && Object.assign(filter, {include: undefined}); + filter = {...filter, include: undefined}; const result = await super.find(filter, options); // poor-mans inclusion resolver, this should be handled by DefaultCrudRepo // and use `inq` operator to fetch related todos in fewer DB queries + // this is a temporary implementation, please see + // https://github.com/strongloop/loopback-next/issues/3195 if (include && include.length && include[0].relation === 'todos') { await Promise.all( result.map(async r => { @@ -133,10 +135,14 @@ async findById( // Prevent juggler for applying "include" filter // Juggler is not aware of LB4 relations const include = filter && filter.include; - filter = filter && Object.assign(filter, {include: undefined}); + filter = {...filter, include: undefined}; const result = await super.findById(id, filter, options); + // poor-mans inclusion resolver, this should be handled by DefaultCrudRepo + // and use `inq` operator to fetch related todos in fewer DB queries + // this is a temporary implementation, please see + // https://github.com/strongloop/loopback-next/issues/3195 if (include && include.length && include[0].relation === 'todos') { result.todos = await this.todos(result.id).find(); } @@ -151,12 +157,12 @@ your related `Todo`s, for example: ```json { "id": 2, - "title": "daily routine of POTUS", + "title": "My daily chores", "todos": [ { "id": 3, - "title": "terrorize senate", - "desc": "Tell them they're getting a budget cut.", + "title": "play space invaders", + "desc": "Become the very best!", "todoListId": 2 } ] @@ -175,12 +181,14 @@ async find( // Prevent juggler for applying "include" filter // Juggler is not aware of LB4 relations const include = filter && filter.include; - filter = filter && Object.assign(filter, {include: undefined}); + filter = {...filter, include: undefined}; const result = await super.find(filter, options); // poor-mans inclusion resolver, this should be handled by DefaultCrudRepo - // and use `inq` operator to fetch related todo-lists in fewer DB queries + // and use `inq` operator to fetch related todo-lists in fewer DB queries + // this is a temporary implementation, please see + // https://github.com/strongloop/loopback-next/issues/3195 if (include && include.length && include[0].relation === 'todoList') { await Promise.all( result.map(async r => { @@ -200,10 +208,14 @@ async findById( // Prevent juggler for applying "include" filter // Juggler is not aware of LB4 relations const include = filter && filter.include; - filter = filter && Object.assign(filter, {include: undefined}); + filter = {...filter, include: undefined}; const result = await super.findById(id, filter, options); + // poor-mans inclusion resolver, this should be handled by DefaultCrudRepo + // and use `inq` operator to fetch related todo-lists in fewer DB queries + // this is a temporary implementation, please see + // https://github.com/strongloop/loopback-next/issues/3195 if (include && include.length && include[0].relation === 'todoList') { result.todoList = await this.todoList(result.id); } diff --git a/examples/todo-list/src/__tests__/fixtures/testdb.datasource.json b/examples/todo-list/src/__tests__/fixtures/testdb.datasource.json new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/examples/todo-list/src/__tests__/integration/todo-list-image.integration.ts b/examples/todo-list/src/__tests__/integration/todo-list-image.repository.integration.ts similarity index 97% rename from examples/todo-list/src/__tests__/integration/todo-list-image.integration.ts rename to examples/todo-list/src/__tests__/integration/todo-list-image.repository.integration.ts index d6ea72d867ac..4e70a755268e 100644 --- a/examples/todo-list/src/__tests__/integration/todo-list-image.integration.ts +++ b/examples/todo-list/src/__tests__/integration/todo-list-image.repository.integration.ts @@ -8,7 +8,7 @@ import { givenTodoListRepositories, } from '../helpers'; -describe('TodoListApplication', () => { +describe('TodoListImageRepository', () => { let app: TodoListApplication; let todoListImageRepo: TodoListImageRepository; let todoListRepo: TodoListRepository; diff --git a/examples/todo-list/src/__tests__/integration/todo-list.integration.ts b/examples/todo-list/src/__tests__/integration/todo-list.repository.integration.ts similarity index 97% rename from examples/todo-list/src/__tests__/integration/todo-list.integration.ts rename to examples/todo-list/src/__tests__/integration/todo-list.repository.integration.ts index 66cee59fbf9b..779fdc1198a0 100644 --- a/examples/todo-list/src/__tests__/integration/todo-list.integration.ts +++ b/examples/todo-list/src/__tests__/integration/todo-list.repository.integration.ts @@ -8,7 +8,7 @@ import { givenTodoRepositories, } from '../helpers'; -describe('TodoListApplication', () => { +describe('TodoListRepository', () => { let app: TodoListApplication; let todoRepo: TodoRepository; let todoListRepo: TodoListRepository; diff --git a/examples/todo-list/src/__tests__/integration/todo.integration.ts b/examples/todo-list/src/__tests__/integration/todo.repository.integration.ts similarity index 97% rename from examples/todo-list/src/__tests__/integration/todo.integration.ts rename to examples/todo-list/src/__tests__/integration/todo.repository.integration.ts index 3f4cc40f7418..c0c7425662c8 100644 --- a/examples/todo-list/src/__tests__/integration/todo.integration.ts +++ b/examples/todo-list/src/__tests__/integration/todo.repository.integration.ts @@ -8,7 +8,7 @@ import { givenTodoRepositories, } from '../helpers'; -describe('TodoListApplication', () => { +describe('TodoRepository', () => { let app: TodoListApplication; let todoRepo: TodoRepository; let todoListRepo: TodoListRepository; diff --git a/examples/todo-list/src/repositories/todo-list-image.repository.ts b/examples/todo-list/src/repositories/todo-list-image.repository.ts index 79bc0f428999..e8549a57d805 100644 --- a/examples/todo-list/src/repositories/todo-list-image.repository.ts +++ b/examples/todo-list/src/repositories/todo-list-image.repository.ts @@ -48,11 +48,14 @@ export class TodoListImageRepository extends DefaultCrudRepository< // Prevent juggler for applying "include" filter // Juggler is not aware of LB4 relations const include = filter && filter.include; - filter = filter && Object.assign(filter, {include: undefined}); + filter = {...filter, include: undefined}; const result = await super.find(filter, options); - // this is a temporary implementation, please see https://github.com/strongloop/loopback-next/issues/3195 + // poor-mans inclusion resolver, this should be handled by DefaultCrudRepo + // and use `inq` operator to fetch related todo-lists in fewer DB queries + // this is a temporary implementation, please see + // https://github.com/strongloop/loopback-next/issues/3195 if (include && include.length && include[0].relation === 'todoList') { await Promise.all( result.map(async r => { @@ -72,10 +75,14 @@ export class TodoListImageRepository extends DefaultCrudRepository< // Prevent juggler for applying "include" filter // Juggler is not aware of LB4 relations const include = filter && filter.include; - filter = filter && Object.assign(filter, {include: undefined}); + filter = {...filter, include: undefined}; const result = await super.findById(id, filter, options); + // poor-mans inclusion resolver, this should be handled by DefaultCrudRepo + // and use `inq` operator to fetch related todo-lists in fewer DB queries + // this is a temporary implementation, please see + // https://github.com/strongloop/loopback-next/issues/3195 if (include && include.length && include[0].relation === 'todoList') { result.todoList = await this.todoList(result.id); } diff --git a/examples/todo-list/src/repositories/todo-list.repository.ts b/examples/todo-list/src/repositories/todo-list.repository.ts index 97a5058f17c5..be42faa9c1b0 100644 --- a/examples/todo-list/src/repositories/todo-list.repository.ts +++ b/examples/todo-list/src/repositories/todo-list.repository.ts @@ -66,10 +66,13 @@ export class TodoListRepository extends DefaultCrudRepository< // Prevent juggler for applying "include" filter // Juggler is not aware of LB4 relations const include = filter && filter.include; - filter = filter && Object.assign(filter, {include: undefined}); + filter = {...filter, include: undefined}; const result = await super.find(filter, options); - // this is a temporary implementation, please see https://github.com/strongloop/loopback-next/issues/3195 + // poor-mans inclusion resolver, this should be handled by DefaultCrudRepo + // and use `inq` operator to fetch related todos in fewer DB queries + // this is a temporary implementation, please see + // https://github.com/strongloop/loopback-next/issues/3195 if (include && include.length && include[0].relation === 'todos') { await Promise.all( result.map(async r => { @@ -89,10 +92,14 @@ export class TodoListRepository extends DefaultCrudRepository< // Prevent juggler for applying "include" filter // Juggler is not aware of LB4 relations const include = filter && filter.include; - filter = filter && Object.assign(filter, {include: undefined}); + filter = {...filter, include: undefined}; const result = await super.findById(id, filter, options); + // poor-mans inclusion resolver, this should be handled by DefaultCrudRepo + // and use `inq` operator to fetch related todos in fewer DB queries + // this is a temporary implementation, please see + // https://github.com/strongloop/loopback-next/issues/3195 if (include && include.length && include[0].relation === 'todos') { result.todos = await this.todos(result.id).find(); } diff --git a/examples/todo-list/src/repositories/todo.repository.ts b/examples/todo-list/src/repositories/todo.repository.ts index a7de66f05a54..7e6ef193e3c3 100644 --- a/examples/todo-list/src/repositories/todo.repository.ts +++ b/examples/todo-list/src/repositories/todo.repository.ts @@ -45,11 +45,14 @@ export class TodoRepository extends DefaultCrudRepository< // Prevent juggler for applying "include" filter // Juggler is not aware of LB4 relations const include = filter && filter.include; - filter = filter && Object.assign(filter, {include: undefined}); + filter = {...filter, include: undefined}; const result = await super.find(filter, options); - // this is a temporary implementation, please see https://github.com/strongloop/loopback-next/issues/3195 + // poor-mans inclusion resolver, this should be handled by DefaultCrudRepo + // and use `inq` operator to fetch related todo-lists in fewer DB queries + // this is a temporary implementation, please see + // https://github.com/strongloop/loopback-next/issues/3195 if (include && include.length && include[0].relation === 'todoList') { await Promise.all( result.map(async r => { @@ -69,10 +72,14 @@ export class TodoRepository extends DefaultCrudRepository< // Prevent juggler for applying "include" filter // Juggler is not aware of LB4 relations const include = filter && filter.include; - filter = filter && Object.assign(filter, {include: undefined}); + filter = {...filter, include: undefined}; const result = await super.findById(id, filter, options); + // poor-mans inclusion resolver, this should be handled by DefaultCrudRepo + // and use `inq` operator to fetch related todo-lists in fewer DB queries + // this is a temporary implementation, please see + // https://github.com/strongloop/loopback-next/issues/3195 if (include && include.length && include[0].relation === 'todoList') { result.todoList = await this.todoList(result.id); }