This commit is contained in:
masnn committed 2020-04-17 13:53:06 +08:00
1 parent ce3d11b999
commit b1153b641a
13 files changed
+163 -42

No files matched your search

+5 -2
View File
@@ -39,9 +39,12 @@ function getMany(query, sort, page, limit) {
return coll.find(query).sort(sort).skip((page - 1) * limit).limit(limit)
.toArray();
}
async function update(rid, $set) {
async function update(rid, $set, $push) {
const _id = new ObjectID(rid);
await coll.findOneAndUpdate({ _id }, { $set });
const upd = {};
if ($set && Object.keys($set).length) upd.$set = $set;
if ($push && Object.keys($push).length) upd.$push = $push;
await coll.findOneAndUpdate({ _id }, upd);
const rdoc = await coll.findOne({ _id });
if (!rdoc) throw new RecordNotFoundError(rid);
return rdoc;