Server/project/src/callbacks/InsuranceCallbacks.ts
Refringe 50c7a26a58
ESLint Pass
This is the first pass of ESLint on the codebase.

ESLint formatting is less strict when it comes to line-length and line-breaks then dprint/biome, so if you see formatting that you don't like... fix it! It shouldn't require a configuration change.

- This should merge clean into master (when the time comes).
- This will not merge clean into `3.9.0-DEV`, but the conflicts aren't that bad.
2024-05-07 23:57:08 -04:00

68 lines
2.7 KiB
TypeScript

import { inject, injectable } from "tsyringe";
import { InsuranceController } from "@spt-aki/controllers/InsuranceController";
import { OnUpdate } from "@spt-aki/di/OnUpdate";
import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
import { IGetBodyResponseData } from "@spt-aki/models/eft/httpResponse/IGetBodyResponseData";
import { IGetInsuranceCostRequestData } from "@spt-aki/models/eft/insurance/IGetInsuranceCostRequestData";
import { IGetInsuranceCostResponseData } from "@spt-aki/models/eft/insurance/IGetInsuranceCostResponseData";
import { IInsureRequestData } from "@spt-aki/models/eft/insurance/IInsureRequestData";
import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse";
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
import { IInsuranceConfig } from "@spt-aki/models/spt/config/IInsuranceConfig";
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
import { InsuranceService } from "@spt-aki/services/InsuranceService";
import { HttpResponseUtil } from "@spt-aki/utils/HttpResponseUtil";
@injectable()
export class InsuranceCallbacks implements OnUpdate
{
protected insuranceConfig: IInsuranceConfig;
constructor(
@inject("InsuranceController") protected insuranceController: InsuranceController,
@inject("InsuranceService") protected insuranceService: InsuranceService,
@inject("HttpResponseUtil") protected httpResponse: HttpResponseUtil,
@inject("ConfigServer") protected configServer: ConfigServer,
)
{
this.insuranceConfig = this.configServer.getConfig(ConfigTypes.INSURANCE);
}
/**
* Handle client/insurance/items/list/cost
* @returns IGetInsuranceCostResponseData
*/
public getInsuranceCost(
url: string,
info: IGetInsuranceCostRequestData,
sessionID: string,
): IGetBodyResponseData<IGetInsuranceCostResponseData>
{
return this.httpResponse.getBody(this.insuranceController.cost(info, sessionID));
}
/**
* Handle Insure event
* @returns IItemEventRouterResponse
*/
public insure(pmcData: IPmcData, body: IInsureRequestData, sessionID: string): IItemEventRouterResponse
{
return this.insuranceController.insure(pmcData, body, sessionID);
}
public async onUpdate(secondsSinceLastRun: number): Promise<boolean>
{
// People edit the config value to be 0 and break it, force value to no lower than 1
if (secondsSinceLastRun > Math.max(this.insuranceConfig.runIntervalSeconds, 1))
{
this.insuranceController.processReturn();
return true;
}
return false;
}
public getRoute(): string
{
return "aki-insurance";
}
}