diff --git a/src/database/schemas/inventory/stockevent.schema.js b/src/database/schemas/inventory/stockevent.schema.js index 36cc569..4d886fb 100644 --- a/src/database/schemas/inventory/stockevent.schema.js +++ b/src/database/schemas/inventory/stockevent.schema.js @@ -6,7 +6,6 @@ import { aggregateRollups, aggregateRollupsHistory, } from '../../database.js'; -import { refId } from '../../objectid.js'; const { Schema } = mongoose; const parentStockModelNames = { @@ -61,10 +60,10 @@ const buildParentState = (parentType, parentStock, currentAmount, startingAmount }; const getStockEventTotal = async (parentId, parentType) => { - const id = refId(parentId); - if (typeof id !== 'string' || !/^[a-fA-F\d]{24}$/.test(id)) return null; + if (!parentId) return null; - const objectId = new mongoose.Types.ObjectId(id); + const objectId = + parentId instanceof mongoose.Types.ObjectId ? parentId : new mongoose.Types.ObjectId(parentId); const [result] = await mongoose .model('stockEvent') diff --git a/src/socket/__tests__/socketmanager.test.js b/src/socket/__tests__/socketmanager.test.js index e805ca1..146f024 100644 --- a/src/socket/__tests__/socketmanager.test.js +++ b/src/socket/__tests__/socketmanager.test.js @@ -4,6 +4,7 @@ jest.unstable_mockModule('socket.io', () => ({ Server: jest.fn(() => ({ on: jest.fn(), emit: jest.fn(), + use: jest.fn(), })), }));