1.1.0
This commit is contained in:
parent
5f5c00352c
commit
026d75cf7a
6 changed files with 49 additions and 15 deletions
10
.vscode/tasks.json
vendored
Normal file
10
.vscode/tasks.json
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
"version": "0.1.0",
|
||||
"command": "test",
|
||||
"isShellCommand": true,
|
||||
"args": ["pub", "run", "test"],
|
||||
"showOutput": "always",
|
||||
"suppressTaskName": true
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
# angel_mongo
|
||||
|
||||
![version 1.0.0-dev+6](https://img.shields.io/badge/version-1.0.0--dev+6-red.svg)
|
||||
![build status](https://travis-ci.org/angel-dart/mongo.svg?branch=master)
|
||||
[![version 1.1.0](https://img.shields.io/badge/pub-1.1.0-red.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)
|
||||
|
||||
MongoDB-enabled services for the Angel framework.
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ class MongoService extends Service {
|
|||
item = _removeSensitive(item);
|
||||
|
||||
try {
|
||||
item['createdAt'] = new DateTime.now();
|
||||
item['createdAt'] = new DateTime.now().toIso8601String();
|
||||
await collection.insert(item);
|
||||
return await _lastItem(collection, _jsonify, params);
|
||||
} catch (e, st) {
|
||||
|
@ -71,7 +71,7 @@ class MongoService extends Service {
|
|||
target is Map ? target : god.serializeObject(target),
|
||||
_removeSensitive(data)
|
||||
]);
|
||||
result['updatedAt'] = new DateTime.now();
|
||||
result['updatedAt'] = new DateTime.now().toIso8601String();
|
||||
|
||||
try {
|
||||
await collection.update(where.id(_makeId(id)), result);
|
||||
|
@ -89,8 +89,13 @@ class MongoService extends Service {
|
|||
var target = await read(id, params);
|
||||
Map result = _removeSensitive(data);
|
||||
result['_id'] = _makeId(id);
|
||||
result['createdAt'] = target is Map ? ['createdAt'] : target.createdAt;
|
||||
result['updatedAt'] = new DateTime.now();
|
||||
result['createdAt'] =
|
||||
target is Map ? target['createdAt'] : target.createdAt;
|
||||
|
||||
if (result['createdAt'] is DateTime)
|
||||
result['createdAt'] = result['createdAt'].toIso8601String();
|
||||
|
||||
result['updatedAt'] = new DateTime.now().toIso8601String();
|
||||
|
||||
try {
|
||||
await collection.update(where.id(_makeId(id)), result);
|
||||
|
@ -105,7 +110,7 @@ class MongoService extends Service {
|
|||
|
||||
@override
|
||||
Future remove(id, [Map params]) async {
|
||||
Map result = await read(id, params);
|
||||
var result = await read(id, params);
|
||||
|
||||
try {
|
||||
await collection.remove(where.id(_makeId(id)).and(_makeQuery(params)));
|
||||
|
|
|
@ -9,6 +9,7 @@ class MongoTypedService<T> extends MongoService {
|
|||
}
|
||||
|
||||
_deserialize(x) {
|
||||
// print('DESERIALIZE: $x (${x.runtimeType})');
|
||||
if (x == dynamic || x == Object || x is T)
|
||||
return x;
|
||||
else if (x is Map) {
|
||||
|
@ -16,13 +17,30 @@ class MongoTypedService<T> extends MongoService {
|
|||
var value = x[key];
|
||||
|
||||
if ((key == 'createdAt' || key == 'updatedAt') && value is String) {
|
||||
return map..[key] = '44'; // DateTime.parse(value).toIso8601String();
|
||||
} else
|
||||
return map..[key] = DateTime.parse(value).toIso8601String();
|
||||
} else if (value is DateTime) {
|
||||
return map..[key] = value.toIso8601String();
|
||||
} else {
|
||||
return map..[key] = value;
|
||||
}
|
||||
});
|
||||
|
||||
print('x: $x\ndata: $data');
|
||||
return god.deserializeDatum(data, outputType: T);
|
||||
Model result = god.deserializeDatum(data, outputType: T);
|
||||
|
||||
if (x['createdAt'] is String) {
|
||||
result.createdAt = DateTime.parse(x['createdAt']);
|
||||
} else if (x['createdAt'] is DateTime) {
|
||||
result.createdAt = x['createdAt'];
|
||||
}
|
||||
|
||||
if (x['updatedAt'] is String) {
|
||||
result.updatedAt = DateTime.parse(x['updatedAt']);
|
||||
} else if (x['updatedAt'] is DateTime) {
|
||||
result.updatedAt = x['updatedAt'];
|
||||
}
|
||||
|
||||
// print('x: $x\nresult: $result');
|
||||
return result;
|
||||
} else
|
||||
return x;
|
||||
}
|
||||
|
@ -30,8 +48,10 @@ class MongoTypedService<T> extends MongoService {
|
|||
_serialize(x) {
|
||||
if (x is Model)
|
||||
return god.serializeObject(x);
|
||||
else
|
||||
else if (x is Map)
|
||||
return x;
|
||||
else
|
||||
throw new ArgumentError('Cannot serialize ${x.runtimeType}');
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: angel_mongo
|
||||
version: 1.0.0
|
||||
version: 1.1.0
|
||||
description: MongoDB-enabled services for the Angel framework.
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/angel_mongo
|
||||
|
|
|
@ -149,8 +149,7 @@ main() {
|
|||
expect(queried[0].keys.length, equals(3));
|
||||
expect(queried[0]["id"], equals(world["id"]));
|
||||
expect(queried[0]["to"], equals(world["to"]));
|
||||
expect(queried[0]["createdAt"],
|
||||
equals(world["createdAt"].toIso8601String()));
|
||||
expect(queried[0]["createdAt"], equals(world["createdAt"]));
|
||||
|
||||
/*response = await client.get("$url/api?\$sort.createdAt=-1");
|
||||
print(response.body);
|
||||
|
|
Loading…
Reference in a new issue