2024-06-20 13:05:07 +02:00
|
|
|
import { RequestHandler } from "express";
|
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
|
|
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
2025-03-31 09:18:33 -07:00
|
|
|
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
|
|
|
|
import { equipmentKeys, TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
|
2024-06-20 13:05:07 +02:00
|
|
|
|
|
|
|
export const setWeaponSkillTreeController: RequestHandler = async (req, res) => {
|
|
|
|
const accountId = await getAccountIdForRequest(req);
|
2025-01-24 14:27:10 +01:00
|
|
|
const payload = getJSONfromString<ISetWeaponSkillTreeRequest>(String(req.body));
|
2024-06-20 13:05:07 +02:00
|
|
|
|
2025-03-31 09:18:33 -07:00
|
|
|
if (equipmentKeys.indexOf(req.query.Category as TEquipmentKey) != -1) {
|
|
|
|
await Inventory.updateOne(
|
|
|
|
{
|
|
|
|
accountOwnerId: accountId,
|
|
|
|
[`${req.query.Category as string}._id`]: req.query.ItemId as string
|
|
|
|
},
|
|
|
|
{
|
|
|
|
[`${req.query.Category as string}.$.SkillTree`]: payload.SkillTree
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2024-06-20 13:05:07 +02:00
|
|
|
|
|
|
|
res.end();
|
|
|
|
};
|
|
|
|
|
|
|
|
interface ISetWeaponSkillTreeRequest {
|
|
|
|
SkillTree: string;
|
|
|
|
}
|