koa-mongo-rest
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -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' | ||
}); | ||
``` | ||
@@ -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; | ||
} | ||
} | ||
}; | ||
}; |
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54184
28
154