chore: optimise creditsController #815
@ -6,7 +6,7 @@ import { getInventory } from "@/src/services/inventoryService";
 | 
				
			|||||||
export const creditsController: RequestHandler = async (req, res) => {
 | 
					export const creditsController: RequestHandler = async (req, res) => {
 | 
				
			||||||
    const accountId = await getAccountIdForRequest(req);
 | 
					    const accountId = await getAccountIdForRequest(req);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const inventory = await getInventory(accountId);
 | 
					    const inventory = await getInventory(accountId, "RegularCredits TradesRemaining PremiumCreditsFree PremiumCredits");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const response = {
 | 
					    const response = {
 | 
				
			||||||
        RegularCredits: inventory.RegularCredits,
 | 
					        RegularCredits: inventory.RegularCredits,
 | 
				
			||||||
 | 
				
			|||||||
@ -96,8 +96,11 @@ export const combineInventoryChanges = (InventoryChanges: IInventoryChanges, del
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const getInventory = async (accountOwnerId: string): Promise<TInventoryDatabaseDocument> => {
 | 
					export const getInventory = async (
 | 
				
			||||||
    const inventory = await Inventory.findOne({ accountOwnerId: accountOwnerId });
 | 
					    accountOwnerId: string,
 | 
				
			||||||
 | 
					    projection: string | undefined = undefined
 | 
				
			||||||
 | 
					): Promise<TInventoryDatabaseDocument> => {
 | 
				
			||||||
 | 
					    const inventory = await Inventory.findOne({ accountOwnerId: accountOwnerId }, projection);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!inventory) {
 | 
					    if (!inventory) {
 | 
				
			||||||
        throw new Error(`Didn't find an inventory for ${accountOwnerId}`);
 | 
					        throw new Error(`Didn't find an inventory for ${accountOwnerId}`);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user