summaryrefslogtreecommitdiff
path: root/src/services/waybills.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/services/waybills.service.ts')
-rw-r--r--src/services/waybills.service.ts8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/services/waybills.service.ts b/src/services/waybills.service.ts
index 824be4b..8fb6ef4 100644
--- a/src/services/waybills.service.ts
+++ b/src/services/waybills.service.ts
@@ -1,7 +1,7 @@
import { Application } from '@feathersjs/express';
import { HookContext } from '@feathersjs/feathers';
import service from 'feathers-mongoose';
-import { populate, alterItems } from 'feathers-hooks-common';
+import { populate, stashBefore, alterItems } from 'feathers-hooks-common';
import Bluebird from 'bluebird';
import _ from 'lodash';
import Model from '../models/waybill/waybill.model';
@@ -29,6 +29,10 @@ const populateSchema = {
const reflectStatus = async (context: HookContext): Promise<HookContext> => {
const { status } = context.data;
+
+ // If status has not changed, do nothing
+ if (status === context.params.before.status) return context;
+
if (['cancelled', 'executed'].includes(status) && context.id) {
const waybill: WaybillSchema = await context.service.get(context.id);
@@ -74,7 +78,7 @@ export default (app: Application): void => {
],
},
before: {
- patch: reflectStatus,
+ patch: [stashBefore(), reflectStatus],
},
})
};