From d9eec90d3c7a703e0fb094d5cb2433c1cc8cde41 Mon Sep 17 00:00:00 2001 From: Sainan Date: Sun, 16 Mar 2025 13:58:44 +0100 Subject: [PATCH] chore: use updateOne for simple inventory field setters --- .../api/addFriendImageController.ts | 23 +++++++++++++------ .../api/setEquippedInstrumentController.ts | 15 ++++++++---- .../api/setSupportedSyndicateController.ts | 15 ++++++++---- src/types/requestTypes.ts | 4 ---- 4 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/controllers/api/addFriendImageController.ts b/src/controllers/api/addFriendImageController.ts index 3772f7ef..5f224ad8 100644 --- a/src/controllers/api/addFriendImageController.ts +++ b/src/controllers/api/addFriendImageController.ts @@ -1,16 +1,25 @@ import { RequestHandler } from "express"; import { getJSONfromString } from "@/src/helpers/stringHelpers"; -import { IUpdateGlyphRequest } from "@/src/types/requestTypes"; import { getAccountIdForRequest } from "@/src/services/loginService"; -import { getInventory } from "@/src/services/inventoryService"; +import { Inventory } from "@/src/models/inventoryModels/inventoryModel"; -const addFriendImageController: RequestHandler = async (req, res) => { +export const addFriendImageController: RequestHandler = async (req, res) => { const accountId = await getAccountIdForRequest(req); const json = getJSONfromString(String(req.body)); - const inventory = await getInventory(accountId); - inventory.ActiveAvatarImageType = json.AvatarImageType; - await inventory.save(); + + await Inventory.updateOne( + { + accountOwnerId: accountId + }, + { + ActiveAvatarImageType: json.AvatarImageType + } + ); + res.json({}); }; -export { addFriendImageController }; +interface IUpdateGlyphRequest { + AvatarImageType: string; + AvatarImage: string; +} diff --git a/src/controllers/api/setEquippedInstrumentController.ts b/src/controllers/api/setEquippedInstrumentController.ts index 5b4b9800..bb80a815 100644 --- a/src/controllers/api/setEquippedInstrumentController.ts +++ b/src/controllers/api/setEquippedInstrumentController.ts @@ -1,14 +1,21 @@ import { RequestHandler } from "express"; import { getAccountIdForRequest } from "@/src/services/loginService"; -import { getInventory } from "@/src/services/inventoryService"; import { getJSONfromString } from "@/src/helpers/stringHelpers"; +import { Inventory } from "@/src/models/inventoryModels/inventoryModel"; export const setEquippedInstrumentController: RequestHandler = async (req, res) => { const accountId = await getAccountIdForRequest(req); - const inventory = await getInventory(accountId); const body = getJSONfromString(String(req.body)); - inventory.EquippedInstrument = body.Instrument; - await inventory.save(); + + await Inventory.updateOne( + { + accountOwnerId: accountId + }, + { + EquippedInstrument: body.Instrument + } + ); + res.end(); }; diff --git a/src/controllers/api/setSupportedSyndicateController.ts b/src/controllers/api/setSupportedSyndicateController.ts index e22b659f..40ce4af3 100644 --- a/src/controllers/api/setSupportedSyndicateController.ts +++ b/src/controllers/api/setSupportedSyndicateController.ts @@ -1,11 +1,18 @@ import { RequestHandler } from "express"; import { getAccountIdForRequest } from "@/src/services/loginService"; -import { getInventory } from "@/src/services/inventoryService"; +import { Inventory } from "@/src/models/inventoryModels/inventoryModel"; export const setSupportedSyndicateController: RequestHandler = async (req, res) => { const accountId = await getAccountIdForRequest(req); - const inventory = await getInventory(accountId); - inventory.SupportedSyndicate = req.query.syndicate as string; - await inventory.save(); + + await Inventory.updateOne( + { + accountOwnerId: accountId + }, + { + SupportedSyndicate: req.query.syndicate as string + } + ); + res.end(); }; diff --git a/src/types/requestTypes.ts b/src/types/requestTypes.ts index 8d1026bf..4364b77b 100644 --- a/src/types/requestTypes.ts +++ b/src/types/requestTypes.ts @@ -132,10 +132,6 @@ export interface IRewardInfo { export type IMissionStatus = "GS_SUCCESS" | "GS_FAILURE" | "GS_DUMPED" | "GS_QUIT" | "GS_INTERRUPTED"; -export interface IUpdateGlyphRequest { - AvatarImageType: string; - AvatarImage: string; -} export interface IUpgradesRequest { ItemCategory: TEquipmentKey; ItemId: IOid;