SpaceNinjaServer/src/controllers/custom/setEvolutionProgressController.ts
Sainan 0d388b4b0f
All checks were successful
Build Docker image / docker-arm64 (push) Successful in 1m7s
Build / build (push) Successful in 1m53s
Build Docker image / docker-amd64 (push) Successful in 55s
feat: support websocket connections from game client (#2735)
For bootstrapper v0.11.11, out now.

Reviewed-on: #2735
Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com>
Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
2025-09-10 00:00:09 -07:00

36 lines
1.1 KiB
TypeScript

import { getInventory } from "../../services/inventoryService.ts";
import { getAccountIdForRequest } from "../../services/loginService.ts";
import type { RequestHandler } from "express";
import { broadcastInventoryUpdate } from "../../services/wsService.ts";
export const setEvolutionProgressController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
const payload = req.body as ISetEvolutionProgressRequest;
inventory.EvolutionProgress ??= [];
payload.forEach(element => {
const entry = inventory.EvolutionProgress!.find(entry => entry.ItemType === element.ItemType);
if (entry) {
entry.Progress = 0;
entry.Rank = element.Rank;
} else {
inventory.EvolutionProgress!.push({
Progress: 0,
Rank: element.Rank,
ItemType: element.ItemType
});
}
});
await inventory.save();
res.end();
broadcastInventoryUpdate(req);
};
type ISetEvolutionProgressRequest = {
ItemType: string;
Rank: number;
}[];