SpaceNinjaServer/src/controllers/api/valenceSwapController.ts
Sainan 9b16dc2c6a
All checks were successful
Build / build (20) (push) Successful in 38s
Build / build (18) (push) Successful in 1m8s
Build / build (22) (push) Successful in 1m5s
Build Docker image / docker (push) Successful in 31s
feat: valence fusion (#1251)
Reviewed-on: #1251
2025-03-20 15:27:37 -07:00

30 lines
1.2 KiB
TypeScript

import { getInventory } from "@/src/services/inventoryService";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { IOid } from "@/src/types/commonTypes";
import { IInnateDamageFingerprint, TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
import { RequestHandler } from "express";
export const valenceSwapController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const body = JSON.parse(String(req.body)) as IValenceSwapRequest;
const inventory = await getInventory(accountId, body.WeaponCategory);
const weapon = inventory[body.WeaponCategory].id(body.WeaponId.$oid)!;
const upgradeFingerprint = JSON.parse(weapon.UpgradeFingerprint!) as IInnateDamageFingerprint;
upgradeFingerprint.buffs[0].Tag = body.NewValenceUpgradeTag;
weapon.UpgradeFingerprint = JSON.stringify(upgradeFingerprint);
await inventory.save();
res.json({
InventoryChanges: {
[body.WeaponCategory]: [weapon.toJSON()]
}
});
};
interface IValenceSwapRequest {
WeaponId: IOid;
WeaponCategory: TEquipmentKey;
NewValenceUpgradeTag: string;
}