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