diff --git a/src/controllers/api/sellController.ts b/src/controllers/api/sellController.ts index c6f4662b..cf74ca92 100644 --- a/src/controllers/api/sellController.ts +++ b/src/controllers/api/sellController.ts @@ -17,7 +17,7 @@ import { InventorySlot } from "../../types/inventoryTypes/inventoryTypes.ts"; import { ExportDojoRecipes } from "warframe-public-export-plus"; import type { IInventoryChanges } from "../../types/purchaseTypes.ts"; import type { TInventoryDatabaseDocument } from "../../models/inventoryModels/inventoryModel.ts"; -import { sendWsBroadcastEx, sendWsBroadcastTo } from "../../services/wsService.ts"; +import { broadcastInventoryUpdate } from "../../services/wsService.ts"; import { parseFusionTreasure } from "../../helpers/inventoryHelpers.ts"; export const sellController: RequestHandler = async (req, res) => { @@ -307,10 +307,7 @@ export const sellController: RequestHandler = async (req, res) => { res.json({ inventoryChanges: inventoryChanges // "inventoryChanges" for this response instead of the usual "InventoryChanges" }); - sendWsBroadcastEx({ update_inventory: true }, accountId, parseInt(String(req.query.wsid))); - if (req.query.wsid) { - sendWsBroadcastTo(accountId, { sync_inventory: true }); - } + broadcastInventoryUpdate(req); }; interface ISellRequest { diff --git a/src/services/wsService.ts b/src/services/wsService.ts index 4404eb9a..bf5dd036 100644 --- a/src/services/wsService.ts +++ b/src/services/wsService.ts @@ -7,6 +7,7 @@ import { createAccount, createNonce, getUsernameFromEmail, isCorrectPassword } f import type { IDatabaseAccountJson } from "../types/loginTypes.ts"; import type { HydratedDocument } from "mongoose"; import { logError, logger } from "../utils/logger.ts"; +import type { Request } from "express"; let wsServer: WebSocketServer | undefined; let wssServer: WebSocketServer | undefined; @@ -230,6 +231,14 @@ export const sendWsBroadcastEx = (data: IWsMsgToClient, accountId?: string, excl }); }; +export const broadcastInventoryUpdate = (req: Request): void => { + const accountId = req.query.accountId as string; + sendWsBroadcastEx({ update_inventory: true }, accountId, parseInt(String(req.query.wsid))); + if (req.query.wsid) { + sendWsBroadcastTo(accountId, { sync_inventory: true }); + } +}; + export const handleNonceInvalidation = (accountId: string): void => { forEachClient(client => { if (client.accountId == accountId) {