From 2b1f6257313686d29fc66a1177a672fb8eb0fbc2 Mon Sep 17 00:00:00 2001 From: Paul Joey Clark Date: Mon, 22 Oct 2018 12:05:16 +0800 Subject: [PATCH 1/2] fix(rest): allow @patch update obj to be Partial --- .../templates/src/controllers/controller-rest-template.ts.ejs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/generators/controller/templates/src/controllers/controller-rest-template.ts.ejs b/packages/cli/generators/controller/templates/src/controllers/controller-rest-template.ts.ejs index 54e64004e8fc..c7000b1ffc28 100644 --- a/packages/cli/generators/controller/templates/src/controllers/controller-rest-template.ts.ejs +++ b/packages/cli/generators/controller/templates/src/controllers/controller-rest-template.ts.ejs @@ -77,7 +77,7 @@ export class <%= className %>Controller { }, }) async updateAll( - @requestBody() <%= modelVariableName %>: <%= modelName %>, + @requestBody() <%= modelVariableName %>: Partial<<%= modelName %>>, @param.query.object('where', getWhereSchemaFor(<%= modelName %>)) where?: Where, ): Promise { return await this.<%= repositoryNameCamel %>.updateAll(<%= modelVariableName %>, where); @@ -104,7 +104,7 @@ export class <%= className %>Controller { }) async updateById( @param.path.<%= idType %>('id') id: <%= idType %>, - @requestBody() <%= modelVariableName %>: <%= modelName %>, + @requestBody() <%= modelVariableName %>: Partial<<%= modelName %>>, ): Promise { await this.<%= repositoryNameCamel %>.updateById(id, <%= modelVariableName %>); } From c569e0cd02fbf2286742b25bd59f2cf490806ce9 Mon Sep 17 00:00:00 2001 From: Paul Joey Clark Date: Mon, 22 Oct 2018 12:33:12 +0800 Subject: [PATCH 2/2] fix(rest): update other places where @patch appears --- docs/site/Controller-generator.md | 4 ++-- docs/site/todo-list-tutorial-controller.md | 2 +- examples/todo-list/src/controllers/todo-list.controller.ts | 2 +- examples/todo-list/src/controllers/todo.controller.ts | 2 +- examples/todo/src/controllers/todo.controller.ts | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/site/Controller-generator.md b/docs/site/Controller-generator.md index 505f16ce09d1..671d493d67e1 100644 --- a/docs/site/Controller-generator.md +++ b/docs/site/Controller-generator.md @@ -168,7 +168,7 @@ export class TodoController { }, }) async updateAll( - @requestBody() data: Todo, + @requestBody() data: Partial, @param.query.object('where', getWhereSchemaFor(Todo)) where?: Where, ): Promise { return await this.todoRepository.updateAll(data, where); @@ -195,7 +195,7 @@ export class TodoController { }) async updateById( @param.path.number('id') id: number, - @requestBody() data: Todo, + @requestBody() data: Partial, ): Promise { await this.todoRepository.updateById(id, data); } diff --git a/docs/site/todo-list-tutorial-controller.md b/docs/site/todo-list-tutorial-controller.md index d3c18830982c..4ba2a85de62d 100644 --- a/docs/site/todo-list-tutorial-controller.md +++ b/docs/site/todo-list-tutorial-controller.md @@ -197,7 +197,7 @@ export class TodoListController { }) async updateById( @param.path.number('id') id: number, - @requestBody() obj: TodoList, + @requestBody() obj: Partial, ): Promise { await this.todoListRepository.updateById(id, obj); } diff --git a/examples/todo-list/src/controllers/todo-list.controller.ts b/examples/todo-list/src/controllers/todo-list.controller.ts index fa0bc5c0886f..2b57dee4c8ea 100644 --- a/examples/todo-list/src/controllers/todo-list.controller.ts +++ b/examples/todo-list/src/controllers/todo-list.controller.ts @@ -105,7 +105,7 @@ export class TodoListController { }) async updateById( @param.path.number('id') id: number, - @requestBody() obj: TodoList, + @requestBody() obj: Partial, ): Promise { await this.todoListRepository.updateById(id, obj); } diff --git a/examples/todo-list/src/controllers/todo.controller.ts b/examples/todo-list/src/controllers/todo.controller.ts index 5d6a8a5ab33e..96c56c604ec4 100644 --- a/examples/todo-list/src/controllers/todo.controller.ts +++ b/examples/todo-list/src/controllers/todo.controller.ts @@ -88,7 +88,7 @@ export class TodoController { }) async updateTodo( @param.path.number('id') id: number, - @requestBody() todo: Todo, + @requestBody() todo: Partial, ): Promise { await this.todoRepo.updateById(id, todo); } diff --git a/examples/todo/src/controllers/todo.controller.ts b/examples/todo/src/controllers/todo.controller.ts index 3cc8f8677ffa..84e2979f5709 100644 --- a/examples/todo/src/controllers/todo.controller.ts +++ b/examples/todo/src/controllers/todo.controller.ts @@ -101,7 +101,7 @@ export class TodoController { }) async updateTodo( @param.path.number('id') id: number, - @requestBody() todo: Todo, + @requestBody() todo: Partial, ): Promise { await this.todoRepo.updateById(id, todo); }