Skip to content

Commit 86139f6

Browse files
bajtosKevin Delisle
authored andcommitted
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 #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
1 parent f11b9fe commit 86139f6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/example-getting-started/src/controllers/todo.controller.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ export class TodoController {
4343
@param.body('todo', TodoSchema)
4444
todo: Todo,
4545
): Promise<boolean> {
46+
// REST adapter does not coerce parameter values coming from string sources
47+
// like path & query. As a workaround, we have to cast the value to a number
48+
// ourselves.
49+
// See https://github.com/strongloop/loopback-next/issues/750
50+
id = +id;
51+
4652
return await this.todoRepo.replaceById(id, todo);
4753
}
4854

@@ -52,6 +58,12 @@ export class TodoController {
5258
@param.body('todo', TodoSchema)
5359
todo: Todo,
5460
): Promise<boolean> {
61+
// REST adapter does not coerce parameter values coming from string sources
62+
// like path & query. As a workaround, we have to cast the value to a number
63+
// ourselves.
64+
// See https://github.com/strongloop/loopback-next/issues/750
65+
id = +id;
66+
5567
return await this.todoRepo.updateById(id, todo);
5668
}
5769

0 commit comments

Comments
 (0)