Skip to content

Commit

Permalink
fix(docs): todoTutorial
Browse files Browse the repository at this point in the history
Fixing the code with the correct one (createTodo w/ geocode).
Fixes #3977
  • Loading branch information
irineul authored and raymondfeng committed Oct 23, 2019
1 parent 47ebf72 commit f424c23
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions docs/site/tutorials/todo/todo-tutorial-geocoding-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,33 @@ property and convert it to GPS coordinates stored in `remindAtGeo`.
export class TodoController {
// constructor, etc.

@post('/todos')
async createTodo(@requestBody() todo: Todo) {
if (!todo.title) {
throw new HttpErrors.BadRequest('title is required');
}

@post('/todos', {
responses: {
'200': {
description: 'Todo model instance',
content: {'application/json': {schema: getModelSchemaRef(Todo)}},
},
},
})
async createTodo(
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(Todo, {title: 'NewTodo', exclude: ['id']}),
},
},
})
todo: Omit<Todo, 'id'>,
): Promise<Todo> {
if (todo.remindAtAddress) {
// TODO handle "address not found"
const geo = await this.geoService.geocode(todo.remindAtAddress);
// Encode the coordinates as "lat,lng"
// Encode the coordinates as "lat,lng" (Google Maps API format). See also
// https://stackoverflow.com/q/7309121/69868
// https://gis.stackexchange.com/q/7379
// eslint-disable-next-line require-atomic-updates
todo.remindAtGeo = `${geo[0].y},${geo[0].x}`;
}

return this.todoRepo.create(todo);
}

Expand Down

0 comments on commit f424c23

Please sign in to comment.