All checks were successful
Build / build (20) (push) Successful in 37s
Build / build (18) (push) Successful in 1m4s
Build / build (22) (push) Successful in 1m1s
Build / build (18) (pull_request) Successful in 40s
Build / build (20) (pull_request) Successful in 1m2s
Build / build (22) (pull_request) Successful in 1m7s
63 lines
2.2 KiB
TypeScript
63 lines
2.2 KiB
TypeScript
import { getAccountIdForRequest } from "@/src/services/loginService";
|
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
|
import { getInventory } from "@/src/services/inventoryService";
|
|
import { IMongoDate } from "@/src/types/commonTypes";
|
|
import { RequestHandler } from "express";
|
|
import { unixTimesInMs } from "@/src/constants/timeConstants";
|
|
import { IInventoryChanges } from "@/src/types/purchaseTypes";
|
|
import { createMessage } from "@/src/services/inboxService";
|
|
|
|
interface ITrainingResultsRequest {
|
|
numLevelsGained: number;
|
|
}
|
|
|
|
interface ITrainingResultsResponse {
|
|
NewTrainingDate: IMongoDate;
|
|
NewLevel: number;
|
|
InventoryChanges: IInventoryChanges;
|
|
}
|
|
|
|
const trainingResultController: RequestHandler = async (req, res): Promise<void> => {
|
|
const accountId = await getAccountIdForRequest(req);
|
|
|
|
const trainingResults = getJSONfromString<ITrainingResultsRequest>(String(req.body));
|
|
|
|
const inventory = await getInventory(accountId);
|
|
|
|
if (trainingResults.numLevelsGained == 1) {
|
|
inventory.TrainingDate = new Date(Date.now() + unixTimesInMs.hour * 23);
|
|
inventory.PlayerLevel += 1;
|
|
|
|
await createMessage(accountId, [
|
|
{
|
|
sndr: "/Lotus/Language/Menu/Mailbox_WarframeSender",
|
|
msg: "/Lotus/Language/Inbox/MasteryRewardMsg",
|
|
arg: [
|
|
{
|
|
Key: "NEW_RANK",
|
|
Tag: inventory.PlayerLevel
|
|
}
|
|
],
|
|
att: [
|
|
`/Lotus/Types/Items/ShipDecos/MasteryTrophies/Rank${inventory.PlayerLevel.toString().padStart(2, "0")}Trophy`
|
|
],
|
|
sub: "/Lotus/Language/Inbox/MasteryRewardTitle",
|
|
icon: "/Lotus/Interface/Icons/Npcs/Lotus_d.png",
|
|
highPriority: true
|
|
}
|
|
]);
|
|
}
|
|
|
|
const changedinventory = await inventory.save();
|
|
|
|
res.json({
|
|
NewTrainingDate: {
|
|
$date: { $numberLong: changedinventory.TrainingDate.getTime().toString() }
|
|
},
|
|
NewLevel: trainingResults.numLevelsGained == 1 ? changedinventory.PlayerLevel : inventory.PlayerLevel,
|
|
InventoryChanges: {}
|
|
} satisfies ITrainingResultsResponse);
|
|
};
|
|
|
|
export { trainingResultController };
|