diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/services/waybills.service.ts | 22 | 
1 files changed, 8 insertions, 14 deletions
diff --git a/src/services/waybills.service.ts b/src/services/waybills.service.ts index 8c8c718..ce820bc 100644 --- a/src/services/waybills.service.ts +++ b/src/services/waybills.service.ts @@ -6,8 +6,6 @@ import Bluebird from 'bluebird';  import _ from 'lodash';  import Model from '../models/waybill/waybill.model';  import { WaybillSchema } from '../models/waybill/waybill.schema'; -import Contractor from '../models/contractor/contractor.model'; -import Product from '../models/product/product.model';  const waybills = service({ Model }); @@ -36,23 +34,19 @@ const reflectStatus = async (context: HookContext): Promise<HookContext> => {      const signMultiplier = (waybill.operation === 'in' ? 1 : -1) * (status === 'cancelled' ? -1 : 1);      const total = waybill.records.reduce((sum, record) => sum + record.price * record.quantity, 0); -    await Bluebird.map(waybill.records, record => Product.updateOne( -      { _id: record.productId }, -      { +    await Bluebird.map(waybill.records, record => { +      return context.app.service('products').patch(record.productId, {          $inc: {            quantity: record.quantity * signMultiplier          } -      } -    )); +      }); +    }); -    await Contractor.updateOne( -      { _id: waybill.contractorId }, -      { -        $inc: { -          debt: total * signMultiplier * (-1) -        } +    await context.app.service('contractors').patch(waybill.contractorId, { +      $inc: { +        debt: total * signMultiplier * (-1)        } -    ); +    });    }    return context;  };  |