Skip to content

Commit

Permalink
fix(vercel): stor update func return updated value
Browse files Browse the repository at this point in the history
  • Loading branch information
lizheming committed Feb 14, 2021
1 parent f6d6a93 commit 59cc1c5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
9 changes: 5 additions & 4 deletions packages/server/src/controller/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@ module.exports = class extends BaseRest {
const {path} = this.post();
const resp = await this.modelInstance.select({url: path});
if(think.isEmpty(resp)) {
const ret = await this.modelInstance.add(
{url: path, time: 1},
const time = 1;
await this.modelInstance.add(
{url: path, time},
{access: {read: true, write: true}}
);
return this.success(ret);
return this.json(time);
}

const ret = await this.modelInstance.update(function(counter) {
return {time: counter.time + 1};
}, {
objectId: ['IN', resp.map(({objectId}) => objectId)]
});
return this.success(ret);
return this.json(ret[0].time);
}
}
3 changes: 2 additions & 1 deletion packages/server/src/service/storage/cloudbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ module.exports = class extends Base {
return Promise.all(list.map(async item => {
const updateData = typeof data === 'function' ? data(item) : data;
const instance = await this.collection(this.tableName);
return instance.doc(item._id).update(updateData);
await instance.doc(item._id).update(updateData);
return {...item, ...updateData};
}));
}

Expand Down
1 change: 1 addition & 0 deletions packages/server/src/service/storage/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ module.exports = class extends Base {
}
});
await this.save(this.tableName, instance, instance.sha);
return list;
}

async delete(where) {
Expand Down
5 changes: 3 additions & 2 deletions packages/server/src/service/storage/mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,12 @@ module.exports = class extends Base {
this.where(instance, where);
const list = await instance.select();

return Promise.all(list.map(item => {
return Promise.all(list.map(async item => {
const updateData = typeof data === 'function' ? data(item) : data;
const instance = this.mongo(this.tableName);
this.where(instance, where);
return instance.update(updateData);
await instance.update(updateData);
return {...item, ...updateData};
}));
}

Expand Down
3 changes: 2 additions & 1 deletion packages/server/src/service/storage/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ module.exports = class extends Base {
const list = await this.model(this.tableName).where(this.parseWhere(where)).select();
return Promise.all(list.map(item => {

This comment has been minimized.

Copy link
@njzjz

njzjz Feb 14, 2021

Contributor

should make a change here

-    return Promise.all(list.map(item => {
+    return Promise.all(list.map(async item => {
const updateData = typeof data === 'function' ? data(item) : data;
return this.model(this.tableName).where({id: item.id}).update(updateData);
await this.model(this.tableName).where({id: item.id}).update(updateData);
return {...item, ...updateData};
}));
}

Expand Down

0 comments on commit 59cc1c5

Please sign in to comment.