feat: implement purchasing of bundles
This commit is contained in:
		
							parent
							
								
									f216d5222f
								
							
						
					
					
						commit
						6af161817b
					
				
							
								
								
									
										8
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										8
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@ -13,7 +13,7 @@
 | 
				
			|||||||
        "express": "^5.0.0-beta.3",
 | 
					        "express": "^5.0.0-beta.3",
 | 
				
			||||||
        "mongoose": "^8.1.1",
 | 
					        "mongoose": "^8.1.1",
 | 
				
			||||||
        "warframe-items": "^1.1262.74",
 | 
					        "warframe-items": "^1.1262.74",
 | 
				
			||||||
        "warframe-public-export-plus": "^0.2.2",
 | 
					        "warframe-public-export-plus": "^0.2.3",
 | 
				
			||||||
        "warframe-riven-info": "^0.1.0",
 | 
					        "warframe-riven-info": "^0.1.0",
 | 
				
			||||||
        "winston": "^3.11.0",
 | 
					        "winston": "^3.11.0",
 | 
				
			||||||
        "winston-daily-rotate-file": "^4.7.1"
 | 
					        "winston-daily-rotate-file": "^4.7.1"
 | 
				
			||||||
@ -3909,9 +3909,9 @@
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "node_modules/warframe-public-export-plus": {
 | 
					    "node_modules/warframe-public-export-plus": {
 | 
				
			||||||
      "version": "0.2.2",
 | 
					      "version": "0.2.3",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.2.2.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.2.3.tgz",
 | 
				
			||||||
      "integrity": "sha512-PAsiyiRDqXcsUwZTweihwrSksd+GT3USrbHwS/TrJUC3TqLS0Ng24OfefFKPWOmPfMxDbdkg2zV39uq72iZ/Yg=="
 | 
					      "integrity": "sha512-Bl4gb3f1LIdGXLEOJg2XTIFYqrialdTIvVhDqDzVJIRfii0PKsy9jsr9vqM14tWz7oVpQMeCUyvisDkkXijTSg=="
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "node_modules/warframe-riven-info": {
 | 
					    "node_modules/warframe-riven-info": {
 | 
				
			||||||
      "version": "0.1.0",
 | 
					      "version": "0.1.0",
 | 
				
			||||||
 | 
				
			|||||||
@ -17,7 +17,7 @@
 | 
				
			|||||||
    "express": "^5.0.0-beta.3",
 | 
					    "express": "^5.0.0-beta.3",
 | 
				
			||||||
    "mongoose": "^8.1.1",
 | 
					    "mongoose": "^8.1.1",
 | 
				
			||||||
    "warframe-items": "^1.1262.74",
 | 
					    "warframe-items": "^1.1262.74",
 | 
				
			||||||
    "warframe-public-export-plus": "^0.2.2",
 | 
					    "warframe-public-export-plus": "^0.2.3",
 | 
				
			||||||
    "warframe-riven-info": "^0.1.0",
 | 
					    "warframe-riven-info": "^0.1.0",
 | 
				
			||||||
    "winston": "^3.11.0",
 | 
					    "winston": "^3.11.0",
 | 
				
			||||||
    "winston-daily-rotate-file": "^4.7.1"
 | 
					    "winston-daily-rotate-file": "^4.7.1"
 | 
				
			||||||
 | 
				
			|||||||
@ -3,6 +3,7 @@ import { getSubstringFromKeyword } from "@/src/helpers/stringHelpers";
 | 
				
			|||||||
import { addItem, addBooster, updateCurrency, updateSlots } from "@/src/services/inventoryService";
 | 
					import { addItem, addBooster, updateCurrency, updateSlots } from "@/src/services/inventoryService";
 | 
				
			||||||
import { IPurchaseRequest, SlotPurchase } from "@/src/types/purchaseTypes";
 | 
					import { IPurchaseRequest, SlotPurchase } from "@/src/types/purchaseTypes";
 | 
				
			||||||
import { logger } from "@/src/utils/logger";
 | 
					import { logger } from "@/src/utils/logger";
 | 
				
			||||||
 | 
					import { ExportBundles } from "warframe-public-export-plus";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const getStoreItemCategory = (storeItem: string) => {
 | 
					export const getStoreItemCategory = (storeItem: string) => {
 | 
				
			||||||
    const storeItemString = getSubstringFromKeyword(storeItem, "StoreItems/");
 | 
					    const storeItemString = getSubstringFromKeyword(storeItem, "StoreItems/");
 | 
				
			||||||
@ -21,26 +22,12 @@ export const getStoreItemTypesCategory = (typesItem: string) => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountId: string) => {
 | 
					export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountId: string) => {
 | 
				
			||||||
    logger.debug("purchase request", purchaseRequest);
 | 
					    logger.debug("purchase request", purchaseRequest);
 | 
				
			||||||
    const storeCategory = getStoreItemCategory(purchaseRequest.PurchaseParams.StoreItem);
 | 
					 | 
				
			||||||
    const internalName = purchaseRequest.PurchaseParams.StoreItem.replace("/StoreItems", "");
 | 
					 | 
				
			||||||
    logger.debug(`store category ${storeCategory}`);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let purchaseResponse;
 | 
					    const purchaseResponse = await handleStoreItemAcquisition(
 | 
				
			||||||
    switch (storeCategory) {
 | 
					        purchaseRequest.PurchaseParams.StoreItem,
 | 
				
			||||||
        default:
 | 
					 | 
				
			||||||
            purchaseResponse = await addItem(accountId, internalName);
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        case "Types":
 | 
					 | 
				
			||||||
            purchaseResponse = await handleTypesPurchase(
 | 
					 | 
				
			||||||
                internalName,
 | 
					 | 
				
			||||||
        accountId,
 | 
					        accountId,
 | 
				
			||||||
        purchaseRequest.PurchaseParams.Quantity
 | 
					        purchaseRequest.PurchaseParams.Quantity
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        case "Boosters":
 | 
					 | 
				
			||||||
            purchaseResponse = await handleBoostersPurchase(internalName, accountId);
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!purchaseResponse) throw new Error("purchase response was undefined");
 | 
					    if (!purchaseResponse) throw new Error("purchase response was undefined");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -58,6 +45,43 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI
 | 
				
			|||||||
    return purchaseResponse;
 | 
					    return purchaseResponse;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const handleStoreItemAcquisition = async (
 | 
				
			||||||
 | 
					    storeItemName: string,
 | 
				
			||||||
 | 
					    accountId: string,
 | 
				
			||||||
 | 
					    quantity: number
 | 
				
			||||||
 | 
					): Promise<{ InventoryChanges: object }> => {
 | 
				
			||||||
 | 
					    let purchaseResponse = {
 | 
				
			||||||
 | 
					        InventoryChanges: {}
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    logger.debug(`handling acquision of ${storeItemName}`);
 | 
				
			||||||
 | 
					    if (storeItemName in ExportBundles) {
 | 
				
			||||||
 | 
					        const bundle = ExportBundles[storeItemName];
 | 
				
			||||||
 | 
					        logger.debug("acquiring bundle", bundle);
 | 
				
			||||||
 | 
					        for (const component of bundle.components) {
 | 
				
			||||||
 | 
					            purchaseResponse = {
 | 
				
			||||||
 | 
					                ...purchaseResponse,
 | 
				
			||||||
 | 
					                ...(await handleStoreItemAcquisition(component.typeName, accountId, component.purchaseQuantity))
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        const storeCategory = getStoreItemCategory(storeItemName);
 | 
				
			||||||
 | 
					        const internalName = storeItemName.replace("/StoreItems", "");
 | 
				
			||||||
 | 
					        logger.debug(`store category ${storeCategory}`);
 | 
				
			||||||
 | 
					        switch (storeCategory) {
 | 
				
			||||||
 | 
					            default:
 | 
				
			||||||
 | 
					                purchaseResponse = await addItem(accountId, internalName);
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            case "Types":
 | 
				
			||||||
 | 
					                purchaseResponse = await handleTypesPurchase(internalName, accountId, quantity);
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            case "Boosters":
 | 
				
			||||||
 | 
					                purchaseResponse = await handleBoostersPurchase(internalName, accountId);
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return purchaseResponse;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const slotPurchaseNameToSlotName: SlotPurchase = {
 | 
					export const slotPurchaseNameToSlotName: SlotPurchase = {
 | 
				
			||||||
    SuitSlotItem: { name: "SuitBin", slotsPerPurchase: 1 },
 | 
					    SuitSlotItem: { name: "SuitBin", slotsPerPurchase: 1 },
 | 
				
			||||||
    TwoSentinelSlotItem: { name: "SentinelBin", slotsPerPurchase: 2 },
 | 
					    TwoSentinelSlotItem: { name: "SentinelBin", slotsPerPurchase: 2 },
 | 
				
			||||||
@ -122,7 +146,9 @@ const boosterCollection = [
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const handleBoostersPurchase = async (boosterStoreName: string, accountId: string) => {
 | 
					const handleBoostersPurchase = async (boosterStoreName: string, accountId: string) => {
 | 
				
			||||||
    const match = boosterStoreName.match(/(\d+)Day/);
 | 
					    const match = boosterStoreName.match(/(\d+)Day/);
 | 
				
			||||||
    if (!match) return;
 | 
					    if (!match) {
 | 
				
			||||||
 | 
					        return { InventoryChanges: {} };
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const extractedDigit = Number(match[1]);
 | 
					    const extractedDigit = Number(match[1]);
 | 
				
			||||||
    const ItemType = boosterCollection.find(i =>
 | 
					    const ItemType = boosterCollection.find(i =>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user