diff --git a/src/controllers/api/updateAlignmentController.ts b/src/controllers/api/updateAlignmentController.ts new file mode 100644 index 00000000..2942ad6f --- /dev/null +++ b/src/controllers/api/updateAlignmentController.ts @@ -0,0 +1,25 @@ +import { getJSONfromString } from "@/src/helpers/stringHelpers"; +import { getInventory } from "@/src/services/inventoryService"; +import { getAccountIdForRequest } from "@/src/services/loginService"; +import { IAlignment } from "@/src/types/inventoryTypes/inventoryTypes"; +import { RequestHandler } from "express"; + +export const updateAlignmentController: RequestHandler = async (req, res) => { + const accountId = await getAccountIdForRequest(req); + const inventory = await getInventory(accountId); + const body = getJSONfromString(String(req.body)); + inventory.Alignment = { + Alignment: body.Alignment, + Wisdom: body.Wisdom + }; + await inventory.save(); + res.json(inventory.Alignment); +}; + +interface IUpdateAlignmentRequest { + Wisdom: number; + Alignment: number; + PreviousAlignment: IAlignment; + AlignmentAction: string; // e.g. "/Lotus/Language/Game/MawCinematicDualChoice" + KeyChainName: string; +} diff --git a/src/models/inventoryModels/inventoryModel.ts b/src/models/inventoryModels/inventoryModel.ts index 1d81bbca..8d3f871b 100644 --- a/src/models/inventoryModels/inventoryModel.ts +++ b/src/models/inventoryModels/inventoryModel.ts @@ -70,7 +70,8 @@ import { IPendingCouponClient, ILibraryDailyTaskInfo, IDroneDatabase, - IDroneClient + IDroneClient, + IAlignment } from "../../types/inventoryTypes/inventoryTypes"; import { IOid } from "../../types/commonTypes"; import { @@ -970,6 +971,14 @@ const libraryDailyTaskInfoSchema = new Schema( { _id: false } ); +const alignmentSchema = new Schema( + { + Alignment: Number, + Wisdom: Number + }, + { _id: false } +); + const inventorySchema = new Schema( { accountOwnerId: Schema.Types.ObjectId, @@ -1171,8 +1180,8 @@ const inventorySchema = new Schema( //https://warframe.fandom.com/wiki/Alignment //like "Alignment": { "Wisdom": 9, "Alignment": 1 }, - Alignment: Schema.Types.Mixed, - AlignmentReplay: Schema.Types.Mixed, + Alignment: alignmentSchema, + AlignmentReplay: alignmentSchema, //https://warframe.fandom.com/wiki/Sortie CompletedSorties: [String], diff --git a/src/routes/api.ts b/src/routes/api.ts index 335c59df..0bc16ccf 100644 --- a/src/routes/api.ts +++ b/src/routes/api.ts @@ -87,6 +87,7 @@ import { syndicateStandingBonusController } from "@/src/controllers/api/syndicat import { tauntHistoryController } from "@/src/controllers/api/tauntHistoryController"; import { trainingResultController } from "@/src/controllers/api/trainingResultController"; import { unlockShipFeatureController } from "@/src/controllers/api/unlockShipFeatureController"; +import { updateAlignmentController } from "@/src/controllers/api/updateAlignmentController"; import { updateChallengeProgressController } from "@/src/controllers/api/updateChallengeProgressController"; import { updateQuestController } from "@/src/controllers/api/updateQuestController"; import { updateSessionGetController, updateSessionPostController } from "@/src/controllers/api/updateSessionController"; @@ -188,6 +189,7 @@ apiRouter.post("/syndicateStandingBonus.php", syndicateStandingBonusController); apiRouter.post("/tauntHistory.php", tauntHistoryController); apiRouter.post("/trainingResult.php", trainingResultController); apiRouter.post("/unlockShipFeature.php", unlockShipFeatureController); +apiRouter.post("/updateAlignment.php", updateAlignmentController); apiRouter.post("/updateChallengeProgress.php", updateChallengeProgressController); apiRouter.post("/updateNodeIntros.php", genericUpdateController); apiRouter.post("/updateQuest.php", updateQuestController); diff --git a/src/types/inventoryTypes/inventoryTypes.ts b/src/types/inventoryTypes/inventoryTypes.ts index 6fb8d2af..3472f692 100644 --- a/src/types/inventoryTypes/inventoryTypes.ts +++ b/src/types/inventoryTypes/inventoryTypes.ts @@ -253,7 +253,7 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu CompletedSyndicates: string[]; FocusXP?: IFocusXP; Wishlist: string[]; - Alignment: IAlignment; + Alignment?: IAlignment; CompletedSorties: string[]; LastSortieReward: ILastSortieReward[]; Drones: IDroneClient[]; @@ -267,7 +267,7 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu HasContributedToDojo?: boolean; HWIDProtectEnabled?: boolean; KubrowPetPrints: IKubrowPetPrint[]; - AlignmentReplay: IAlignment; + AlignmentReplay?: IAlignment; PersonalGoalProgress: IPersonalGoalProgress[]; ThemeStyle: string; ThemeBackground: string;