Controller
TODO
// example in-progress
// action must return connection
const {json, setStatus, setHeader} = Restful.Controller;
ItemControllerV3 = {
debug: true,
create(conn, {item}) {
const docId = db.items.insert({name: item.title, age: item.desc})
const doc = db.items.findOne(docId);
conn = setStatus(conn, 201);
return json(conn, {data: doc});
},
index(conn, params) {
const data = db.items.find({}, {limit: 3}).fetch();
conn = setHeader(conn, 'foo', 'bar');
return json(conn, {data: data});
},
update(conn, {id, name, age}) {
const count = db.items.update(id, {name, age});
const doc = db.items.findOne(id);
return json(conn, {data: doc});
},
show(conn, {id}) {
const data = db.items.findOne(id);
return json(conn, {data: data});
},
delete(conn, {id}) {
const data = db.items.remove(id);
json(conn, {})
}
};
Updated less than a minute ago