From 563003a26f06a7da94de7dbd6a4de67fe0f1bce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 6 Feb 2018 13:42:37 +0100 Subject: [PATCH] fix(example-getting-started): remove juggler warning Explicitly cast path parameter "id" from string to number because the REST transport does not implement parameter coercion yet. See https://github.com/strongloop/loopback-next/issues/750 This change removes the following warnings from `npm test` output: WARNING: id property cannot be changed from 3 to 3 for model:Todo in 'before save' operation hook WARNING: id property cannot be changed from 3 to 3 for model:Todo in 'loaded' operation hook --- .../src/controllers/todo.controller.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/example-getting-started/src/controllers/todo.controller.ts b/packages/example-getting-started/src/controllers/todo.controller.ts index aad4865d16cf..2e58030c68fa 100644 --- a/packages/example-getting-started/src/controllers/todo.controller.ts +++ b/packages/example-getting-started/src/controllers/todo.controller.ts @@ -43,6 +43,12 @@ export class TodoController { @param.body('todo', TodoSchema) todo: Todo, ): Promise { + // REST adapter does not coerce parameter values coming from string sources + // like path & query. As a workaround, we have to cast the value to a number + // ourselves. + // See https://github.com/strongloop/loopback-next/issues/750 + id = +id; + return await this.todoRepo.replaceById(id, todo); } @@ -52,6 +58,12 @@ export class TodoController { @param.body('todo', TodoSchema) todo: Todo, ): Promise { + // REST adapter does not coerce parameter values coming from string sources + // like path & query. As a workaround, we have to cast the value to a number + // ourselves. + // See https://github.com/strongloop/loopback-next/issues/750 + id = +id; + return await this.todoRepo.updateById(id, todo); }