SpaceNinjaServer/src/controllers/api/startCollectibleEntryController.ts
Sainan da2b50d537 feat: collectible series (#1025)
Closes #712

a bit unsure about the inbox messages, but otherwise it should be working

Reviewed-on: OpenWF/SpaceNinjaServer#1025
2025-02-28 18:09:37 -08:00

28 lines
1.1 KiB
TypeScript

import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { getInventory } from "@/src/services/inventoryService";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { IIncentiveState } from "@/src/types/inventoryTypes/inventoryTypes";
import { RequestHandler } from "express";
export const startCollectibleEntryController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
const request = getJSONfromString<IStartCollectibleEntryRequest>(String(req.body));
inventory.CollectibleSeries ??= [];
inventory.CollectibleSeries.push({
CollectibleType: request.target,
Count: 0,
Tracking: "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
ReqScans: request.reqScans,
IncentiveStates: request.other
});
await inventory.save();
res.status(200).end();
};
interface IStartCollectibleEntryRequest {
target: string;
reqScans: number;
other: IIncentiveState[];
}