lrf %!s(int64=2) %!d(string=hai) anos
pai
achega
4aa4985f47
Modificáronse 1 ficheiros con 18 adicións e 1 borrados
  1. 18 1
      app/service/shop/goodsSet.js

+ 18 - 1
app/service/shop/goodsSet.js

@@ -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;