Server/project/src/services/RagfairRequiredItemsService.ts
CZPZ 8c37bc7837 Lint: ts files (!82)
Co-authored-by: alimoncul <alimoncul@gmail.com>
Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/82
Co-authored-by: CZPZ <czpz@noreply.dev.sp-tarkov.com>
Co-committed-by: CZPZ <czpz@noreply.dev.sp-tarkov.com>
2023-03-22 14:31:05 +00:00

54 lines
1.5 KiB
TypeScript

import { inject, injectable } from "tsyringe";
import { PaymentHelper } from "../helpers/PaymentHelper";
import { RagfairOfferService } from "../services/RagfairOfferService";
import { ILogger } from "../models/spt/utils/ILogger";
@injectable()
export class RagfairRequiredItemsService
{
protected requiredItemsCache = {};
constructor(
@inject("WinstonLogger") protected logger: ILogger,
@inject("PaymentHelper") protected paymentHelper: PaymentHelper,
@inject("RagfairOfferService") protected ragfairOfferService: RagfairOfferService
)
{ }
public getRequiredItemsById(searchId: string): any
{
return this.requiredItemsCache[searchId] || [];
}
public buildRequiredItemTable(): void
{
const requiredItems = {};
const getRequiredItems = (id: string) =>
{
if (!(id in requiredItems))
{
requiredItems[id] = new Set();
}
return requiredItems[id];
};
for (const offer of this.ragfairOfferService.getOffers())
{
for (const requirement of offer.requirements)
{
if (this.paymentHelper.isMoneyTpl(requirement._tpl))
{
// This would just be too noisy.
continue;
}
getRequiredItems(requirement._tpl).add(offer);
}
}
this.requiredItemsCache = requiredItems;
}
}