Skip to content

Commit

Permalink
fix(example-todo-list): allow partial updates via PATCH
Browse files Browse the repository at this point in the history
  • Loading branch information
bajtos committed Jun 24, 2019
1 parent f2b1219 commit c5cea9a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
10 changes: 9 additions & 1 deletion examples/todo-list/src/controllers/todo-list-todo.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import {
del,
get,
getModelSchemaRef,
getWhereSchemaFor,
param,
patch,
Expand Down Expand Up @@ -71,7 +72,14 @@ export class TodoListTodoController {
})
async patch(
@param.path.number('id') id: number,
@requestBody() todo: Partial<Todo>,
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(Todo, {partial: true}),
},
},
})
todo: Partial<Todo>,
@param.query.object('where', getWhereSchemaFor(Todo)) where?: Where<Todo>,
): Promise<Count> {
return await this.todoListRepo.todos(id).patch(todo, where);
Expand Down
18 changes: 16 additions & 2 deletions examples/todo-list/src/controllers/todo-list.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ export class TodoListController {
},
})
async updateAll(
@requestBody() obj: Partial<TodoList>,
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(TodoList, {partial: true}),
},
},
})
obj: Partial<TodoList>,
@param.query.object('where', getWhereSchemaFor(TodoList))
where?: Where<TodoList>,
): Promise<Count> {
Expand Down Expand Up @@ -124,7 +131,14 @@ export class TodoListController {
})
async updateById(
@param.path.number('id') id: number,
@requestBody() obj: TodoList,
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(TodoList, {partial: true}),
},
},
})
obj: Partial<TodoList>,
): Promise<void> {
await this.todoListRepository.updateById(id, obj);
}
Expand Down
9 changes: 8 additions & 1 deletion examples/todo-list/src/controllers/todo.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ export class TodoController {
})
async updateTodo(
@param.path.number('id') id: number,
@requestBody() todo: Todo,
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(TodoList, {partial: true}),
},
},
})
todo: Partial<TodoList>,
): Promise<void> {
await this.todoRepo.updateById(id, todo);
}
Expand Down

0 comments on commit c5cea9a

Please sign in to comment.