Skip to content

Commit

Permalink
fix(example-getting-started): remove juggler warning
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bajtos authored and kjdelisle committed Feb 7, 2018
1 parent f11b9fe commit 563003a
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export class TodoController {
@param.body('todo', TodoSchema)
todo: Todo,
): Promise<boolean> {
// 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);
}

Expand All @@ -52,6 +58,12 @@ export class TodoController {
@param.body('todo', TodoSchema)
todo: Todo,
): Promise<boolean> {
// 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);
}

Expand Down

0 comments on commit 563003a

Please sign in to comment.