chore: use updateOne for simple inventory field setters #1211

Merged
Sainan merged 1 commits from updateOne into main 2025-03-16 08:16:28 -07:00
4 changed files with 38 additions and 19 deletions

View File

@ -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<IUpdateGlyphRequest>(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;
}

View File

@ -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<ISetEquippedInstrumentRequest>(String(req.body));
inventory.EquippedInstrument = body.Instrument;
await inventory.save();
await Inventory.updateOne(
{
accountOwnerId: accountId
},
{
EquippedInstrument: body.Instrument
}
);
res.end();
};

View File

@ -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();
};

View File

@ -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;