Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

koa-mongo-rest

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-mongo-rest - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

.travis.yml

9

example/example.js

@@ -0,4 +1,11 @@

var api, app, koa, logger, mongoUrl, router, schema;
koa = require('koa');
router = require('koa-router');
logger = require('koa-logger');
api = require('../lib/index');
schema = require('./schema');

@@ -10,2 +17,4 @@

app.use(logger());
app.use(router(app));

@@ -12,0 +21,0 @@

73

lib/actions.js

@@ -0,4 +1,8 @@

var parse;
parse = require('co-body');
module.exports = function(model) {
return {
get: function*() {
findAll: function*() {
var error, result;

@@ -13,3 +17,3 @@ try {

},
getById: function*() {
findById: function*() {
var error, result;

@@ -34,7 +38,13 @@ try {

},
putToId: function*() {
var error;
replaceById: function*() {
var body, error, newDocument, result;
try {
console.log("Putin");
return this.body = "Putin";
yield model.findByIdAndRemove(this.params.id).exec();
body = yield parse(this, {
limit: '1kb'
});
newDocument = body;
newDocument._id = this.params.id;
result = yield model.create(newDocument).exec();
return this.body = result;
} catch (_error) {

@@ -45,8 +55,32 @@ error = _error;

},
replaceByIdWithQuery: function*() {
var error, newDocument, result;
try {
yield model.findByIdAndRemove(this.params.id).exec();
newDocument = this.request.query;
newDocument._id = this.params.id;
result = yield model.create(newDocument).exec();
return this.body = result;
} catch (_error) {
error = _error;
return this.body = error;
}
},
updateById: function*() {
var body, error, result;
try {
body = yield parse(this, {
limit: '1kb'
});
result = yield model.findByIdAndUpdate(this.params.id, body).exec();
return this.body = result;
} catch (_error) {
error = _error;
return this.body = error;
}
},
updateByIdWithQuery: function*() {
var error, result;
try {
result = yield model.findByIdAndUpdate(this.params.id, {
$set: this.request.query
}).exec();
result = yield model.findByIdAndUpdate(this.params.id, this.request.query).exec();
return this.body = result;

@@ -58,7 +92,10 @@ } catch (_error) {

},
postToId: function*() {
var error;
create: function*() {
var body, error, result;
try {
console.log("posting");
return this.body = "posting";
body = yield parse(this, {
limit: '1kb'
});
result = yield model.create(body).exec();
return this.body = result;
} catch (_error) {

@@ -68,4 +105,14 @@ error = _error;

}
},
createWithQuery: function*() {
var error, result;
try {
result = yield model.create(this.request.query).exec();
return this.body = result;
} catch (_error) {
error = _error;
return this.body = error;
}
}
};
};

18

lib/routes.js
var routes;
routes = function(app, schema, actions) {
app.get("/" + schema.collectionName, actions.get);
app.get("/" + schema.collectionName + "/:id", actions.getById);
app.get("/" + schema.collectionName + "/find", actions.findAll);
app.get("/" + schema.collectionName + "/find/:id", actions.findById);
app.get("/" + schema.collectionName + "/create", actions.createWithQuery);
app.get("/" + schema.collectionName + "/destroy/:id", actions.deleteById);
app.get("/" + schema.collectionName + "/update/:id", actions.updateByIdWithQuery);
app.get("/" + schema.collectionName + "/replace/:id", actions.replaceByIdWithQuery);
app.get("/" + schema.collectionName, actions.findAll);
app.get("/" + schema.collectionName + "/:id", actions.findById);
app.post("/" + schema.collectionName, actions.create);
app.post("/" + schema.collectionName + "/:id", actions.updateById);
app["delete"]("/" + schema.collectionName + "/:id", actions.deleteById);
app.put("/" + schema.collectionName + "/:id", actions.putToId);
app.patch("/" + schema.collectionName + "/:id", actions.updateById);
return app.post("/" + schema.collectionName, actions.postToId);
app.put("/" + schema.collectionName + "/", actions.create);
app.put("/" + schema.collectionName + "/:id", actions.replaceById);
return app.patch("/" + schema.collectionName + "/:id", actions.updateById);
};
module.exports = routes;
{
"name": "koa-mongo-rest",
"version": "0.0.2",
"version": "0.0.3",
"description": "generate REST API with koa and mongo",

@@ -32,6 +32,7 @@ "main": "lib/index.js",

"dependencies": {
"mongoose": "~3.8.3"
"mongoose": "~3.8.3",
"co-body": "0.0.1"
},
"devDependencies": {
"mocha": "~1.16.2",
"mocha": "~1.17.0",
"grunt": "~0.4.2",

@@ -42,4 +43,6 @@ "grunt-contrib-coffee": "git://github.com/t3chnoboy/grunt-contrib-coffee.git",

"grunt-concurrent": "~0.4.2",
"koa-router": "~2.2.0"
"koa-router": "~2.3.1",
"koa": "~0.3.0",
"koa-logger": ">=1.1.1"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc