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.1.1 to 0.1.2

71

docs/docs.md

@@ -97,2 +97,14 @@ # TOC

#### POST /:model/:id
should respond with JSON for the updated record.
```js
return request.post('/user/2').send({
age: 28
}).expect(200).expect({
name: 'Joff',
age: 28,
_id: 2
}).end(done);
```
<a name="rest-api-routes-delete"></a>

@@ -102,2 +114,12 @@ ### DELETE

#### DELETE /:model/:id
should respond with JSON for the destroyed record.
```js
return request.del('/user/2').expect(200).expect({
name: 'Joff',
age: 27,
_id: 2
}).end(done);
```
<a name="rest-api-routes-put"></a>

@@ -107,4 +129,31 @@ ### PUT

#### PUT /:model
should respond with JSON for the created record.
```js
return request.put('/user').send({
name: 'John',
age: 26,
_id: 5
}).expect(201).expect({
name: 'John',
age: 26,
_id: 5
}).end(done);
```
<a name="rest-api-routes-put-put-modelid"></a>
#### PUT /:model/:id
should return JSON for the replaced record.
```js
return request.put('/user/2').send({
name: 'Joseph',
age: 37
}).expect(200).expect({
name: 'Joseph',
age: 37,
_id: 2
}).end(done);
```
<a name="rest-api-routes-patch"></a>

@@ -114,2 +163,14 @@ ### PATCH

#### PATCH /:model/:id
should respond with JSON for the updated record.
```js
return request.patch('/user/2').send({
age: 28
}).expect(200).expect({
name: 'Joff',
age: 28,
_id: 2
}).end(done);
```
<a name="model"></a>

@@ -119,1 +180,11 @@ # Model

## createModel(schema, mongoURL)
should connect to mongoDB and return a mongoose model.
```js
var model;
model = createModel(schema, mongoUrl);
return model.should.have.property({
modelName: 'person'
});
```

34

lib/actions.js

@@ -53,15 +53,2 @@ var parse;

},
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*() {

@@ -80,12 +67,2 @@ var body, error, result;

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

@@ -104,15 +81,4 @@ var body, error, result;

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

8

lib/routes.js

@@ -7,8 +7,2 @@ var generateRoutes;

}
app.get(prefix + ("/" + schema.collectionName + "/find"), actions.findAll);
app.get(prefix + ("/" + schema.collectionName + "/find/:id"), actions.findById);
app.get(prefix + ("/" + schema.collectionName + "/create"), actions.createWithQuery);
app.get(prefix + ("/" + schema.collectionName + "/destroy/:id"), actions.deleteById);
app.get(prefix + ("/" + schema.collectionName + "/update/:id"), actions.updateByIdWithQuery);
app.get(prefix + ("/" + schema.collectionName + "/replace/:id"), actions.replaceByIdWithQuery);
app.get(prefix + ("/" + schema.collectionName), actions.findAll);

@@ -18,3 +12,3 @@ app.get(prefix + ("/" + schema.collectionName + "/:id"), actions.findById);

app.post(prefix + ("/" + schema.collectionName + "/:id"), actions.updateById);
app["delete"](prefix + ("/" + schema.collectionName + "/:id"), actions.deleteById);
app.del(prefix + ("/" + schema.collectionName + "/:id"), actions.deleteById);
app.put(prefix + ("/" + schema.collectionName), actions.create);

@@ -21,0 +15,0 @@ app.put(prefix + ("/" + schema.collectionName + "/:id"), actions.replaceById);

{
"name": "koa-mongo-rest",
"version": "0.1.1",
"version": "0.1.2",
"description": "generate REST API with koa and mongo",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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