Server/project/src/helpers/PaymentHelper.ts

50 lines
1.4 KiB
TypeScript
Raw Normal View History

import { inject, injectable } from "tsyringe";
2023-03-03 16:23:46 +01:00
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
import { Money } from "@spt-aki/models/enums/Money";
import { IInventoryConfig } from "@spt-aki/models/spt/config/IInventoryConfig";
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
2023-03-03 16:23:46 +01:00
@injectable()
export class PaymentHelper
{
protected inventoryConfig: IInventoryConfig;
2023-11-16 02:35:05 +01:00
constructor(@inject("ConfigServer") protected configServer: ConfigServer)
{
this.inventoryConfig = this.configServer.getConfig(ConfigTypes.INVENTORY);
}
2023-03-03 16:23:46 +01:00
/**
* Is the passed in tpl money (also checks custom currencies in inventoryConfig.customMoneyTpls)
2023-03-03 16:23:46 +01:00
* @param {string} tpl
* @returns void
*/
public isMoneyTpl(tpl: string): boolean
{
2023-11-16 02:35:05 +01:00
return [Money.DOLLARS, Money.EUROS, Money.ROUBLES, ...this.inventoryConfig.customMoneyTpls].some((element) =>
element === tpl
);
2023-03-03 16:23:46 +01:00
}
/**
2023-11-16 02:35:05 +01:00
* Gets currency TPL from TAG
* @param {string} currency
* @returns string
*/
2023-03-03 16:23:46 +01:00
public getCurrency(currency: string): string
{
switch (currency)
{
case "EUR":
return Money.EUROS;
case "USD":
return Money.DOLLARS;
case "RUB":
return Money.ROUBLES;
default:
return "";
}
}
2023-11-16 02:35:05 +01:00
}