1.1.5
This commit is contained in:
parent
fbad320e83
commit
dff4f228c0
4 changed files with 32 additions and 12 deletions
|
@ -1,6 +1,6 @@
|
||||||
# angel_mongo
|
# angel_mongo
|
||||||
|
|
||||||
[![version 1.1.4](https://img.shields.io/badge/pub-1.1.4-brightgreen.svg)](https://pub.dartlang.org/packages/angel_mongo)
|
[![version 1.1.5](https://img.shields.io/badge/pub-1.1.5-brightgreen.svg)](https://pub.dartlang.org/packages/angel_mongo)
|
||||||
[![build status](https://travis-ci.org/angel-dart/mongo.svg?branch=master)](https://travis-ci.org/angel-dart/mongo)
|
[![build status](https://travis-ci.org/angel-dart/mongo.svg?branch=master)](https://travis-ci.org/angel-dart/mongo)
|
||||||
|
|
||||||
MongoDB-enabled services for the Angel framework.
|
MongoDB-enabled services for the Angel framework.
|
||||||
|
|
|
@ -126,7 +126,17 @@ class MongoService extends Service {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future modify(id, data, [Map params]) async {
|
Future modify(id, data, [Map params]) async {
|
||||||
var target = await read(id, params);
|
var target;
|
||||||
|
|
||||||
|
try {
|
||||||
|
target = await read(id, params);
|
||||||
|
} on AngelHttpException catch (e) {
|
||||||
|
if (e.statusCode == HttpStatus.NOT_FOUND)
|
||||||
|
return await create(data, params);
|
||||||
|
else
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
|
||||||
Map result = mergeMap([
|
Map result = mergeMap([
|
||||||
target is Map ? target : god.serializeObject(target),
|
target is Map ? target : god.serializeObject(target),
|
||||||
_removeSensitive(data)
|
_removeSensitive(data)
|
||||||
|
@ -146,7 +156,17 @@ class MongoService extends Service {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future update(id, data, [Map params]) async {
|
Future update(id, data, [Map params]) async {
|
||||||
var target = await read(id, params);
|
var target;
|
||||||
|
|
||||||
|
try {
|
||||||
|
target = await read(id, params);
|
||||||
|
} on AngelHttpException catch (e) {
|
||||||
|
if (e.statusCode == HttpStatus.NOT_FOUND)
|
||||||
|
return await create(data, params);
|
||||||
|
else
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
|
||||||
Map result = _removeSensitive(data);
|
Map result = _removeSensitive(data);
|
||||||
result['_id'] = _makeId(id);
|
result['_id'] = _makeId(id);
|
||||||
result['createdAt'] =
|
result['createdAt'] =
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: angel_mongo
|
name: angel_mongo
|
||||||
version: 1.1.4
|
version: 1.1.5
|
||||||
description: MongoDB-enabled services for the Angel framework.
|
description: MongoDB-enabled services for the Angel framework.
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/angel_mongo
|
homepage: https://github.com/angel-dart/angel_mongo
|
||||||
|
|
|
@ -73,10 +73,10 @@ main() {
|
||||||
test('insert items', () async {
|
test('insert items', () async {
|
||||||
var response = await client.post("$url/api",
|
var response = await client.post("$url/api",
|
||||||
body: god.serialize(testGreeting), headers: headers);
|
body: god.serialize(testGreeting), headers: headers);
|
||||||
expect(response.statusCode, equals(HttpStatus.OK));
|
expect(response.statusCode, isIn([200, 201]));
|
||||||
|
|
||||||
response = await client.get("$url/api");
|
response = await client.get("$url/api");
|
||||||
expect(response.statusCode, 200);
|
expect(response.statusCode, isIn([200, 201]));
|
||||||
List<Map> users = god.deserialize(response.body);
|
List<Map> users = god.deserialize(response.body);
|
||||||
expect(users.length, equals(1));
|
expect(users.length, equals(1));
|
||||||
});
|
});
|
||||||
|
@ -84,11 +84,11 @@ main() {
|
||||||
test('read item', () async {
|
test('read item', () async {
|
||||||
var response = await client.post("$url/api",
|
var response = await client.post("$url/api",
|
||||||
body: god.serialize(testGreeting), headers: headers);
|
body: god.serialize(testGreeting), headers: headers);
|
||||||
expect(response.statusCode, equals(HttpStatus.OK));
|
expect(response.statusCode, isIn([200, 201]));
|
||||||
Map created = god.deserialize(response.body);
|
Map created = god.deserialize(response.body);
|
||||||
|
|
||||||
response = await client.get("$url/api/${created['id']}");
|
response = await client.get("$url/api/${created['id']}");
|
||||||
expect(response.statusCode, equals(HttpStatus.OK));
|
expect(response.statusCode, isIn([200, 201]));
|
||||||
Map read = god.deserialize(response.body);
|
Map read = god.deserialize(response.body);
|
||||||
expect(read['id'], equals(created['id']));
|
expect(read['id'], equals(created['id']));
|
||||||
expect(read['to'], equals('world'));
|
expect(read['to'], equals('world'));
|
||||||
|
@ -98,13 +98,13 @@ main() {
|
||||||
test('modify item', () async {
|
test('modify item', () async {
|
||||||
var response = await client.post("$url/api",
|
var response = await client.post("$url/api",
|
||||||
body: god.serialize(testGreeting), headers: headers);
|
body: god.serialize(testGreeting), headers: headers);
|
||||||
expect(response.statusCode, equals(HttpStatus.OK));
|
expect(response.statusCode, isIn([200, 201]));
|
||||||
Map created = god.deserialize(response.body);
|
Map created = god.deserialize(response.body);
|
||||||
|
|
||||||
response = await client.patch("$url/api/${created['id']}",
|
response = await client.patch("$url/api/${created['id']}",
|
||||||
body: god.serialize({"to": "Mom"}), headers: headers);
|
body: god.serialize({"to": "Mom"}), headers: headers);
|
||||||
Map modified = god.deserialize(response.body);
|
Map modified = god.deserialize(response.body);
|
||||||
expect(response.statusCode, equals(HttpStatus.OK));
|
expect(response.statusCode, isIn([200, 201]));
|
||||||
expect(modified['id'], equals(created['id']));
|
expect(modified['id'], equals(created['id']));
|
||||||
expect(modified['to'], equals('Mom'));
|
expect(modified['to'], equals('Mom'));
|
||||||
expect(modified['updatedAt'], isNot(null));
|
expect(modified['updatedAt'], isNot(null));
|
||||||
|
@ -113,13 +113,13 @@ main() {
|
||||||
test('update item', () async {
|
test('update item', () async {
|
||||||
var response = await client.post("$url/api",
|
var response = await client.post("$url/api",
|
||||||
body: god.serialize(testGreeting), headers: headers);
|
body: god.serialize(testGreeting), headers: headers);
|
||||||
expect(response.statusCode, equals(HttpStatus.OK));
|
expect(response.statusCode, isIn([200, 201]));
|
||||||
Map created = god.deserialize(response.body);
|
Map created = god.deserialize(response.body);
|
||||||
|
|
||||||
response = await client.post("$url/api/${created['id']}",
|
response = await client.post("$url/api/${created['id']}",
|
||||||
body: god.serialize({"to": "Updated"}), headers: headers);
|
body: god.serialize({"to": "Updated"}), headers: headers);
|
||||||
Map modified = god.deserialize(response.body);
|
Map modified = god.deserialize(response.body);
|
||||||
expect(response.statusCode, equals(HttpStatus.OK));
|
expect(response.statusCode, isIn([200, 201]));
|
||||||
expect(modified['id'], equals(created['id']));
|
expect(modified['id'], equals(created['id']));
|
||||||
expect(modified['to'], equals('Updated'));
|
expect(modified['to'], equals('Updated'));
|
||||||
expect(modified['updatedAt'], isNot(null));
|
expect(modified['updatedAt'], isNot(null));
|
||||||
|
|
Loading…
Reference in a new issue