Skip to content

Commit

Permalink
fix(example-todo-list): use latest cli code
Browse files Browse the repository at this point in the history
  • Loading branch information
nabdelgadir committed Jan 23, 2020
1 parent 11ab4bd commit 0e45a08
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 86 deletions.
5 changes: 5 additions & 0 deletions examples/todo-list/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
npm-debug.log
/dist
# Cache used by TypeScript's incremental build
*.tsbuildinfo
28 changes: 28 additions & 0 deletions examples/todo-list/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Check out https://hub.docker.com/_/node to select a new base image
FROM node:10-slim

# Set to a non-root built-in user `node`
USER node

# Create app directory (with user `node`)
RUN mkdir -p /home/node/app

WORKDIR /home/node/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY --chown=node package*.json ./

RUN npm install

# Bundle app source code
COPY --chown=node . .

RUN npm run build

# Bind to all network interfaces so that it can be mapped to the host OS
ENV HOST=0.0.0.0 PORT=3000

EXPOSE ${PORT}
CMD [ "node", "." ]
18 changes: 10 additions & 8 deletions examples/todo-list/src/controllers/todo.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import {Todo, TodoList} from '../models';
import {TodoRepository} from '../repositories';

export class TodoController {
constructor(@repository(TodoRepository) protected todoRepo: TodoRepository) {}
constructor(
@repository(TodoRepository) protected todoRepository: TodoRepository,
) {}

@post('/todos', {
responses: {
Expand All @@ -39,7 +41,7 @@ export class TodoController {
})
todo: Omit<Todo, 'id'>,
): Promise<Todo> {
return this.todoRepo.create(todo);
return this.todoRepository.create(todo);
}

@get('/todos/{id}', {
Expand All @@ -59,7 +61,7 @@ export class TodoController {
@param.query.object('filter', getFilterSchemaFor(Todo))
filter?: Filter<Todo>,
): Promise<Todo> {
return this.todoRepo.findById(id, filter);
return this.todoRepository.findById(id, filter);
}

@get('/todos', {
Expand All @@ -81,7 +83,7 @@ export class TodoController {
@param.query.object('filter', getFilterSchemaFor(Todo))
filter?: Filter<Todo>,
): Promise<Todo[]> {
return this.todoRepo.find(filter);
return this.todoRepository.find(filter);
}

@put('/todos/{id}', {
Expand All @@ -95,7 +97,7 @@ export class TodoController {
@param.path.number('id') id: number,
@requestBody() todo: Todo,
): Promise<void> {
await this.todoRepo.replaceById(id, todo);
await this.todoRepository.replaceById(id, todo);
}

@patch('/todos/{id}', {
Expand All @@ -116,7 +118,7 @@ export class TodoController {
})
todo: Partial<Todo>,
): Promise<void> {
await this.todoRepo.updateById(id, todo);
await this.todoRepository.updateById(id, todo);
}

@del('/todos/{id}', {
Expand All @@ -127,7 +129,7 @@ export class TodoController {
},
})
async deleteTodo(@param.path.number('id') id: number): Promise<void> {
await this.todoRepo.deleteById(id);
await this.todoRepository.deleteById(id);
}

@get('/todos/{id}/todo-list', {
Expand All @@ -139,6 +141,6 @@ export class TodoController {
},
})
async findOwningList(@param.path.number('id') id: number): Promise<TodoList> {
return this.todoRepo.todoList(id);
return this.todoRepository.todoList(id);
}
}
28 changes: 0 additions & 28 deletions examples/todo-list/src/datasources/geocoder.datasource.config.json

This file was deleted.

26 changes: 0 additions & 26 deletions examples/todo-list/src/datasources/geocoder.datasource.ts

This file was deleted.

1 change: 1 addition & 0 deletions examples/todo-list/src/models/todo-list-image.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class TodoListImage extends Entity {
@property({
type: 'number',
id: true,
generated: false,
})
id: number;

Expand Down
5 changes: 3 additions & 2 deletions examples/todo-list/src/models/todo-list.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class TodoList extends Entity {
@property({
type: 'number',
id: true,
generated: false,
})
id: number;

Expand All @@ -30,10 +31,10 @@ export class TodoList extends Entity {
color?: string;

@hasMany(() => Todo)
todos?: Todo[];
todos: Todo[];

@hasOne(() => TodoListImage)
image?: TodoListImage;
image: TodoListImage;

constructor(data?: Partial<TodoList>) {
super(data);
Expand Down
1 change: 1 addition & 0 deletions examples/todo-list/src/models/todo.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class Todo extends Entity {
@property({
type: 'number',
id: true,
generated: false,
})
id: number;

Expand Down
21 changes: 0 additions & 21 deletions examples/todo-list/src/services/geocoder.service.ts

This file was deleted.

1 change: 0 additions & 1 deletion examples/todo-list/src/services/index.ts

This file was deleted.

0 comments on commit 0e45a08

Please sign in to comment.