diff options
Diffstat (limited to 'umosapi/app_db/uobject.py')
-rw-r--r-- | umosapi/app_db/uobject.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/umosapi/app_db/uobject.py b/umosapi/app_db/uobject.py index df07450..ebb7a9e 100644 --- a/umosapi/app_db/uobject.py +++ b/umosapi/app_db/uobject.py @@ -46,3 +46,22 @@ class UObject(object): mongo.db.uobjects.remove({"_id": ObjectId(_id)}) return {"msg": "UObject {} deleted".format(_id), "code": 200} return error + + def update(self, _id, datas): + db = MongoDB(self.app) + mongo = db.connection() + error = {} + + if not _id: + error = {"msg": "UObject _id is required", "code": 400} + elif len(list(mongo.db.uobjects.find({"_id": ObjectId(_id)}))) == 0: + error = { + "msg": "UObject {} does not exist.".format(_id), + "code": 404 + } + + datas = dict(("datas.{}".format(key), value) for (key, value) in datas.items()) + if not error: + mongo.db.uobjects.update_one({"_id": ObjectId(_id)}, {"$set": datas}) + return {"msg": "UObject updated.", "code": 200} + return error |