feat: track vendor purchases
All checks were successful
Build / build (18) (push) Successful in 1m3s
Build / build (22) (push) Successful in 41s
Build / build (20) (push) Successful in 1m6s
Build / build (20) (pull_request) Successful in 42s
Build / build (18) (pull_request) Successful in 1m4s
Build / build (22) (pull_request) Successful in 1m3s

This commit is contained in:
Sainan 2025-03-11 15:57:17 +01:00
parent 38dfe14776
commit eef87947ce
3 changed files with 95 additions and 3 deletions

View File

@ -76,7 +76,10 @@ import {
IIncentiveState, IIncentiveState,
ISongChallenge, ISongChallenge,
ILibraryPersonalProgress, ILibraryPersonalProgress,
ICrewShipWeaponDatabase ICrewShipWeaponDatabase,
IRecentVendorPurchaseDatabase,
IVendorPurchaseHistoryEntryDatabase,
IVendorPurchaseHistoryEntryClient
} from "../../types/inventoryTypes/inventoryTypes"; } from "../../types/inventoryTypes/inventoryTypes";
import { IOid } from "../../types/commonTypes"; import { IOid } from "../../types/commonTypes";
import { import {
@ -974,6 +977,31 @@ const incentiveStateSchema = new Schema<IIncentiveState>(
{ _id: false } { _id: false }
); );
const vendorPurchaseHistoryEntrySchema = new Schema<IVendorPurchaseHistoryEntryDatabase>(
{
Expiry: Date,
NumPurchased: Number,
ItemId: String
},
{ _id: false }
);
vendorPurchaseHistoryEntrySchema.set("toJSON", {
transform(_doc, obj) {
const db = obj as IVendorPurchaseHistoryEntryDatabase;
const client = obj as IVendorPurchaseHistoryEntryClient;
client.Expiry = toMongoDate(db.Expiry);
}
});
const recentVendorPurchaseSchema = new Schema<IRecentVendorPurchaseDatabase>(
{
VendorType: String,
PurchaseHistory: [vendorPurchaseHistoryEntrySchema]
},
{ _id: false }
);
const collectibleEntrySchema = new Schema<ICollectibleEntry>( const collectibleEntrySchema = new Schema<ICollectibleEntry>(
{ {
CollectibleType: String, CollectibleType: String,
@ -1361,7 +1389,7 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
RandomUpgradesIdentified: Number, RandomUpgradesIdentified: Number,
BountyScore: Number, BountyScore: Number,
ChallengeInstanceStates: [Schema.Types.Mixed], ChallengeInstanceStates: [Schema.Types.Mixed],
RecentVendorPurchases: [Schema.Types.Mixed], RecentVendorPurchases: { type: [recentVendorPurchaseSchema], default: undefined },
Robotics: [Schema.Types.Mixed], Robotics: [Schema.Types.Mixed],
UsedDailyDeals: [Schema.Types.Mixed], UsedDailyDeals: [Schema.Types.Mixed],
CollectibleSeries: { type: [collectibleEntrySchema], default: undefined }, CollectibleSeries: { type: [collectibleEntrySchema], default: undefined },

View File

@ -28,6 +28,7 @@ import {
import { config } from "./configService"; import { config } from "./configService";
import { TInventoryDatabaseDocument } from "../models/inventoryModels/inventoryModel"; import { TInventoryDatabaseDocument } from "../models/inventoryModels/inventoryModel";
import { fromStoreItem, toStoreItem } from "./itemDataService"; import { fromStoreItem, toStoreItem } from "./itemDataService";
import { toMongoDate } from "../helpers/inventoryHelpers";
export const getStoreItemCategory = (storeItem: string): string => { export const getStoreItemCategory = (storeItem: string): string => {
const storeItemString = getSubstringFromKeyword(storeItem, "StoreItems/"); const storeItemString = getSubstringFromKeyword(storeItem, "StoreItems/");
@ -69,6 +70,45 @@ export const handlePurchase = async (
); );
} }
purchaseRequest.PurchaseParams.Quantity *= offer.QuantityMultiplier; purchaseRequest.PurchaseParams.Quantity *= offer.QuantityMultiplier;
inventory.RecentVendorPurchases ??= [];
let vendorPurchases = inventory.RecentVendorPurchases.find(
x => x.VendorType == manifest.VendorInfo.TypeName
);
if (!vendorPurchases) {
vendorPurchases =
inventory.RecentVendorPurchases[
inventory.RecentVendorPurchases.push({
VendorType: manifest.VendorInfo.TypeName,
PurchaseHistory: []
}) - 1
];
}
const expiry = new Date(offer.RotatedWeekly ? Date.now() + 7 * 24 * 3600 * 1000 : 2051240400000);
const historyEntry = vendorPurchases.PurchaseHistory.find(x => x.ItemId == ItemId);
let numPurchased = purchaseRequest.PurchaseParams.Quantity;
if (historyEntry) {
numPurchased += historyEntry.NumPurchased;
historyEntry.NumPurchased += purchaseRequest.PurchaseParams.Quantity;
} else {
vendorPurchases.PurchaseHistory.push({
ItemId: ItemId,
NumPurchased: purchaseRequest.PurchaseParams.Quantity,
Expiry: expiry
});
}
inventoryChanges.RecentVendorPurchases = [
{
VendorType: manifest.VendorInfo.TypeName,
PurchaseHistory: [
{
ItemId: ItemId,
NumPurchased: numPurchased,
Expiry: toMongoDate(expiry)
}
]
}
];
} else if (!ExportVendors[purchaseRequest.PurchaseParams.SourceId!]) { } else if (!ExportVendors[purchaseRequest.PurchaseParams.SourceId!]) {
throw new Error(`unknown vendor: ${purchaseRequest.PurchaseParams.SourceId!}`); throw new Error(`unknown vendor: ${purchaseRequest.PurchaseParams.SourceId!}`);
} }

View File

@ -41,6 +41,7 @@ export interface IInventoryDatabase
| "KubrowPetEggs" | "KubrowPetEggs"
| "PendingCoupon" | "PendingCoupon"
| "Drones" | "Drones"
| "RecentVendorPurchases"
| TEquipmentKey | TEquipmentKey
>, >,
InventoryDatabaseEquipment { InventoryDatabaseEquipment {
@ -67,6 +68,7 @@ export interface IInventoryDatabase
KubrowPetEggs?: IKubrowPetEggDatabase[]; KubrowPetEggs?: IKubrowPetEggDatabase[];
PendingCoupon?: IPendingCouponDatabase; PendingCoupon?: IPendingCouponDatabase;
Drones: IDroneDatabase[]; Drones: IDroneDatabase[];
RecentVendorPurchases?: IRecentVendorPurchaseDatabase[];
} }
export interface IQuestKeyDatabase { export interface IQuestKeyDatabase {
@ -277,7 +279,7 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu
BountyScore: number; BountyScore: number;
ChallengeInstanceStates: IChallengeInstanceState[]; ChallengeInstanceStates: IChallengeInstanceState[];
LoginMilestoneRewards: string[]; LoginMilestoneRewards: string[];
RecentVendorPurchases: Array<number | string>; RecentVendorPurchases?: IRecentVendorPurchaseClient[];
NodeIntrosCompleted: string[]; NodeIntrosCompleted: string[];
GuildId?: IOid; GuildId?: IOid;
CompletedJobChains: ICompletedJobChain[]; CompletedJobChains: ICompletedJobChain[];
@ -361,6 +363,28 @@ export interface IParam {
v: string; v: string;
} }
export interface IRecentVendorPurchaseClient {
VendorType: string;
PurchaseHistory: IVendorPurchaseHistoryEntryClient[];
}
export interface IVendorPurchaseHistoryEntryClient {
Expiry: IMongoDate;
NumPurchased: number;
ItemId: string;
}
export interface IRecentVendorPurchaseDatabase {
VendorType: string;
PurchaseHistory: IVendorPurchaseHistoryEntryDatabase[];
}
export interface IVendorPurchaseHistoryEntryDatabase {
Expiry: Date;
NumPurchased: number;
ItemId: string;
}
export interface IChallengeProgress { export interface IChallengeProgress {
Progress: number; Progress: number;
Name: string; Name: string;