|
@@ -3,13 +3,30 @@ const { CrudService } = require('naf-framework-mongoose-free/lib/service');
|
|
|
const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
const _ = require('lodash');
|
|
|
const assert = require('assert');
|
|
|
+const { ObjectId } = require('mongoose').Types;
|
|
|
|
|
|
-//
|
|
|
+//
|
|
|
class GoodsSetService extends CrudService {
|
|
|
constructor(ctx) {
|
|
|
super(ctx, 'goodsset');
|
|
|
this.model = this.ctx.model.Shop.GoodsSet;
|
|
|
}
|
|
|
+ async update(filter, update, { projection } = {}) {
|
|
|
+ assert(filter);
|
|
|
+ assert(update);
|
|
|
+ const beforeUpdateResult = await this.beforeUpdate(filter, update);
|
|
|
+ filter = beforeUpdateResult.filter;
|
|
|
+ update = beforeUpdateResult.update;
|
|
|
+ const { _id, id } = filter;
|
|
|
+ if (_id || id) filter = { _id: ObjectId(_id || id) };
|
|
|
+ // TODO:检查数据是否存在
|
|
|
+ const entity = await this.model.findOne(filter).exec();
|
|
|
+ if (!entity) throw new BusinessError(ErrorCode.DATA_NOT_EXIST);
|
|
|
+ await this.model.updateOne(filter, update);
|
|
|
+ let reSearchData = await this.model.findOne(filter, projection).exec();
|
|
|
+ reSearchData = await this.afterUpdate(filter, update, reSearchData);
|
|
|
+ return reSearchData;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = GoodsSetService;
|