From 1fdaf5696a088a966bc4cd704916240ad340f5ef Mon Sep 17 00:00:00 2001 From: Sainan Date: Wed, 26 Feb 2025 03:32:45 +0100 Subject: [PATCH] feat: startCollectibleEntry --- .../api/startCollectibleEntryController.ts | 27 +++++++++++++++++++ src/models/inventoryModels/inventoryModel.ts | 26 ++++++++++++++++-- src/routes/api.ts | 2 ++ src/types/inventoryTypes/inventoryTypes.ts | 4 +-- 4 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 src/controllers/api/startCollectibleEntryController.ts diff --git a/src/controllers/api/startCollectibleEntryController.ts b/src/controllers/api/startCollectibleEntryController.ts new file mode 100644 index 00000000..ffc440c1 --- /dev/null +++ b/src/controllers/api/startCollectibleEntryController.ts @@ -0,0 +1,27 @@ +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(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[]; +} diff --git a/src/models/inventoryModels/inventoryModel.ts b/src/models/inventoryModels/inventoryModel.ts index 8d3f871b..31ada0e8 100644 --- a/src/models/inventoryModels/inventoryModel.ts +++ b/src/models/inventoryModels/inventoryModel.ts @@ -71,7 +71,9 @@ import { ILibraryDailyTaskInfo, IDroneDatabase, IDroneClient, - IAlignment + IAlignment, + ICollectibleEntry, + IIncentiveState } from "../../types/inventoryTypes/inventoryTypes"; import { IOid } from "../../types/commonTypes"; import { @@ -943,6 +945,26 @@ const calenderProgressSchema = new Schema( { _id: false } ); +const incentiveStateSchema = new Schema( + { + threshold: Number, + complete: Boolean, + sent: Boolean + }, + { _id: false } +); + +const collectibleEntrySchema = new Schema( + { + CollectibleType: String, + Count: Number, + Tracking: String, + ReqScans: Number, + IncentiveStates: [incentiveStateSchema] + }, + { _id: false } +); + const pendingCouponSchema = new Schema( { Expiry: { type: Date, default: new Date(0) }, @@ -1286,7 +1308,7 @@ const inventorySchema = new Schema( RecentVendorPurchases: [Schema.Types.Mixed], Robotics: [Schema.Types.Mixed], UsedDailyDeals: [Schema.Types.Mixed], - CollectibleSeries: [Schema.Types.Mixed], + CollectibleSeries: { type: [collectibleEntrySchema], default: undefined }, HasResetAccount: { type: Boolean, default: false }, //Discount Coupon diff --git a/src/routes/api.ts b/src/routes/api.ts index 0bc16ccf..dafa2a36 100644 --- a/src/routes/api.ts +++ b/src/routes/api.ts @@ -76,6 +76,7 @@ import { setShipFavouriteLoadoutController } from "@/src/controllers/api/setShip import { setSupportedSyndicateController } from "@/src/controllers/api/setSupportedSyndicateController"; import { setWeaponSkillTreeController } from "@/src/controllers/api/setWeaponSkillTreeController"; import { shipDecorationsController } from "@/src/controllers/api/shipDecorationsController"; +import { startCollectibleEntryController } from "@/src/controllers/api/startCollectibleEntryController"; import { startDojoRecipeController } from "@/src/controllers/api/startDojoRecipeController"; import { startLibraryDailyTaskController } from "@/src/controllers/api/startLibraryDailyTaskController"; import { startLibraryPersonalTargetController } from "@/src/controllers/api/startLibraryPersonalTargetController"; @@ -181,6 +182,7 @@ apiRouter.post("/setShipCustomizations.php", setShipCustomizationsController); apiRouter.post("/setShipFavouriteLoadout.php", setShipFavouriteLoadoutController); apiRouter.post("/setWeaponSkillTree.php", setWeaponSkillTreeController); apiRouter.post("/shipDecorations.php", shipDecorationsController); +apiRouter.post("/startCollectibleEntry.php", startCollectibleEntryController); apiRouter.post("/startDojoRecipe.php", startDojoRecipeController); apiRouter.post("/startRecipe.php", startRecipeController); apiRouter.post("/stepSequencers.php", stepSequencersController); diff --git a/src/types/inventoryTypes/inventoryTypes.ts b/src/types/inventoryTypes/inventoryTypes.ts index 3472f692..e044a1b7 100644 --- a/src/types/inventoryTypes/inventoryTypes.ts +++ b/src/types/inventoryTypes/inventoryTypes.ts @@ -315,7 +315,7 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu UsedDailyDeals: any[]; LibraryPersonalTarget: string; LibraryPersonalProgress: ILibraryPersonalProgress[]; - CollectibleSeries: ICollectibleSery[]; + CollectibleSeries?: ICollectibleEntry[]; LibraryAvailableDailyTaskInfo?: ILibraryDailyTaskInfo; LibraryActiveDailyTaskInfo?: ILibraryDailyTaskInfo; HasResetAccount: boolean; @@ -364,7 +364,7 @@ export interface IChallengeProgress { Completed?: string[]; } -export interface ICollectibleSery { +export interface ICollectibleEntry { CollectibleType: string; Count: number; Tracking: string;