From 092d6b55c05e9ec653b3e51cdecd7274c974b6fb Mon Sep 17 00:00:00 2001 From: eug-vs Date: Mon, 26 Apr 2021 08:31:36 +0300 Subject: fix: only add $options to $regex queries --- src/hooks/ignoreCaseRegex.ts | 4 ++-- src/services/waybills.service.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/hooks/ignoreCaseRegex.ts b/src/hooks/ignoreCaseRegex.ts index e996000..3a1ab63 100644 --- a/src/hooks/ignoreCaseRegex.ts +++ b/src/hooks/ignoreCaseRegex.ts @@ -2,8 +2,8 @@ import { HookContext } from '@feathersjs/feathers'; import _ from 'lodash'; const ignoreCaseRegex = async (context: HookContext): Promise => { - context.params.query = _.mapValues(context.params.query, (data, key) => { - return key.startsWith('$') ? data : _.set(data, '$options', 'i'); + context.params.query = _.mapValues(context.params.query, data => { + return '$regex' in data ? _.set(data, '$options', 'i') : data; }); return context; }; diff --git a/src/services/waybills.service.ts b/src/services/waybills.service.ts index 66225ac..84dba71 100644 --- a/src/services/waybills.service.ts +++ b/src/services/waybills.service.ts @@ -59,8 +59,8 @@ const reflectStatus = async (context: HookContext): Promise => { const addFields = (item: WaybillSchema) => { - const { operation, records, date } = item; - const total = item.records.reduce((sum, record) => sum + record.price * record.quantity, 0); + const { operation, records } = item; + const total = records.reduce((sum, record) => sum + record.price * record.quantity, 0); const op = operation === 'in' ? 'приход' : 'расход'; const name = `Накладная: ${op} ${total}р`; return { ...item, name, total }; -- cgit v1.2.3