From dde22ee9722d708938f1be2d533c831e8d91d651 Mon Sep 17 00:00:00 2001 From: luying Date: Wed, 18 May 2022 12:28:59 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=93=E5=85=B7=EF=BC=9A=E6=B6=88=E8=80=97?= =?UTF-8?q?=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared/db/Item.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shared/db/Item.ts b/shared/db/Item.ts index d97d35cbc..a66150e5c 100644 --- a/shared/db/Item.ts +++ b/shared/db/Item.ts @@ -1,6 +1,5 @@ import BaseModel from './BaseModel'; import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose'; -import { findIndex } from 'underscore'; import { BAG } from '../pubUtils/dicParam'; import { SearchItemParam } from '../domain/backEndField/search'; // const Transaction = require("mongoose-transactions"); @@ -70,9 +69,10 @@ export default class Item extends BaseModel { rec = await ItemModel.findOneAndUpdate({ roleId, id }, { $inc: { count: ratio * count } }, { new: true, upsert: true }).lean(lean); } if (!!rec) { - let index = findIndex(result,{id}) - if (!!result[index]) { - result[index] = { id: rec.id, count: rec.count, inc: -count } + let index = result.findIndex(cur => cur.id == rec.id); + if (index != -1) { + result[index].count = rec.count; + result[index].inc += -count; } else { result.push({ id: rec.id, count: rec.count, inc: -count }); }