Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
initial commit
- Loading branch information
0 parents
commit 9b3759e
Showing
9 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"presets": ["es2015", "stage-0"], | ||
"plugins": ["transform-decorators-legacy"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# todo-backend-modern-js | ||
|
||
This is an implementation of [Todo-Backend](http://www.todobackend.com/). | ||
|
||
This implementation uses modern Javascript features like decorators. It combines | ||
a few libraries meant to organize and simplify your node.js stack while taking | ||
advantage of ES6/7 features. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default function() { | ||
this.runlevel('configured') | ||
.use('connie', 'file', 'config/${environment}.json'); | ||
|
||
this.runlevel('connected') | ||
.use('access-mongo', '$mongodb') | ||
|
||
this.runlevel('running') | ||
.use('express'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"mongodb": "mongodb://localhost/test" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"mongodb": "${MONGODB_URL}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "todo-backend", | ||
"version": "1.0.0", | ||
"description": "An implementation of Todo-Backend using modern Javascript features", | ||
"author": "Matt Insler <matt.insler@gmail.com>", | ||
"repository": "mattinsler/todo-backend-modern-js", | ||
"engines": { | ||
"node": "5.x.x", | ||
"npm": "3.x.x" | ||
}, | ||
"scripts": { | ||
"start": "app-context start" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"@mattinsler/garnish": "0.0.4", | ||
"app-context": "0.3.1", | ||
"app-context-access-mongo": "0.0.2", | ||
"app-context-connie": "1.1.0", | ||
"app-context-express": "1.1.0", | ||
"babel-plugin-transform-decorators-legacy": "1.3.4", | ||
"babel-preset-es2015": "6.9.0", | ||
"babel-preset-stage-0": "6.5.0", | ||
"cors": "2.7.1", | ||
"routers": "0.1.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import cors from 'cors'; | ||
import { classApiResolver } from 'routers'; | ||
|
||
export default function(app) { | ||
const resolve = classApiResolver('routes'); | ||
|
||
app.use(cors()); | ||
|
||
app.get('/todos', resolve('todos#index')); | ||
app.post('/todos', resolve('todos#create')); | ||
app.delete('/todos', resolve('todos#clear')); | ||
app.get('/todos/:id', resolve('todos#get')); | ||
app.patch('/todos/:id', resolve('todos#patch')); | ||
app.delete('/todos/:id', resolve('todos#destroy')); | ||
|
||
app.use(resolve.errorHandler); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { view } from '@mattinsler/garnish'; | ||
|
||
const { mongodb } = APP; | ||
const Todo = mongodb.createModel('todos'); | ||
|
||
const TodoView = { | ||
id: '!_id', | ||
url: ({ _id }, req) => `http://${req.get('host')}/todos/${_id}` | ||
}; | ||
|
||
class TodosRoute { | ||
@view(TodoView) | ||
index(req) { | ||
return Todo.array(); | ||
} | ||
|
||
@view(TodoView) | ||
create({ body }) { | ||
return Todo.create({ completed: false, ...body }); | ||
} | ||
|
||
clear() { | ||
return Todo.remove({ override: true }); | ||
} | ||
|
||
@view(TodoView) | ||
get({ params: { id } }) { | ||
return Todo.where({ _id: Todo.ObjectID(id) }).first(); | ||
} | ||
|
||
@view(TodoView) | ||
async patch({ body, params: { id } }) { | ||
const query = Todo.where({ _id: Todo.ObjectID(id) }); | ||
await query.update({ $set: body }); | ||
return query.first(); | ||
} | ||
|
||
destroy({ params: { id } }) { | ||
return Todo.where({ _id: Todo.ObjectID(id) }).remove(); | ||
} | ||
} | ||
|
||
export default TodosRoute; |