diff --git a/docs/api.md b/docs/api.md index 0039a6f0..cb8ec8e2 100644 --- a/docs/api.md +++ b/docs/api.md @@ -29,7 +29,6 @@ Expose a `Model` to remote clients. // create a testing data source var memory = loopback.memory(); var Color = memory.createModel('color', {name: String}); -Color.attachTo(memory); app.model(Color); app.use(loopback.rest()); diff --git a/example/todos/app.js b/example/todos/app.js deleted file mode 100644 index 8a2dd304..00000000 --- a/example/todos/app.js +++ /dev/null @@ -1,8 +0,0 @@ -var loopback = require('../../'); -var app = loopback(); - -app.use(loopback.configure()); -app.use(loopback.bodyParser()); -app.use(loopback.routes()); - -app.listen(3000); \ No newline at end of file diff --git a/example/todos/db/config.json b/example/todos/db/config.json deleted file mode 100644 index a0c0ca91..00000000 --- a/example/todos/db/config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "module": "data-source" -} \ No newline at end of file diff --git a/example/todos/todos/config.json b/example/todos/todos/config.json deleted file mode 100644 index dd5d6bf0..00000000 --- a/example/todos/todos/config.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "module": "model", - "main": "./todos.js", - "options": { - "properties": [ - { - "name": "title", - "type": "string" - }, - { - "name": "done", - "type": "boolean" - }, - { - "name": "order", - "type": "number" - } - ] - }, - "dependencies": { - "data-source": "db" - } -} \ No newline at end of file diff --git a/example/todos/todos/todos.js b/example/todos/todos/todos.js deleted file mode 100644 index 2bce4761..00000000 --- a/example/todos/todos/todos.js +++ /dev/null @@ -1,58 +0,0 @@ -var Todo = require('.'); - -Todo.beforeRemote('*', function (ctx) { - // only allow logged in users to access the todo model - ctx.cancelUnless(ctx.me); -}); - -Todo.beforeRemote('save', function (todo, ctx) { - if(!todo.title) { - // throw an error to cancel an operation - throw new Error('title is required'); - } - - if(todo.title.length > 144) { - // or use the ctx api - ctx.error('title must be shorter than 144 characters'); - } -}); - -Todo.beforeRemote('save', function (todo, ctx, done) { - // the ctx api has various validation helpers - ctx.errorUnless(ctx.isEmail(todos.creator), 'creator must be a valid email'); - - if(todo.isNew()) { - Todo.count({owner: todo.owner}, function (err) { - if(err) { - done(err); - } else { - ctx.errorIf(count > 100, 'each user can only have 100 todos'); - - done(); - } - }); - } else { - done(); - } -}); - -Todo.beforeRemote('all', function (query, ctx) { - // only allow remote queries when filtering by user - ctx.cancelUnless(query.creator); - - query.limit = query.limit || 16; - ctx.errorIf(query.limit > 16, 'you may only request 16 todos at a time'); -}); - -Todo.beforeRemote('save', function (todo, ctx) { - ctx.cancelUnless(ctx.isMe(todo.creator)); -}); - -// define a custom method to be exposed to SDKs -Todo.totalRemaining = function (fn) { - Todo.count({where: {done: {ne: true}}}, fn); -} -Todo.totalRemaining.remotable = true; -Todo.totalRemaining.returns = [ - {arg: 'total', type: 'Number'} -];