Server/project/src/callbacks/TraderCallbacks.ts

60 lines
2.1 KiB
TypeScript
Raw Normal View History

2023-03-03 16:23:46 +01:00
import { inject, injectable } from "tsyringe";
import { TraderController } from "@spt-aki/controllers/TraderController";
import { OnLoad } from "@spt-aki/di/OnLoad";
import { OnUpdate } from "@spt-aki/di/OnUpdate";
import { IEmptyRequestData } from "@spt-aki/models/eft/common/IEmptyRequestData";
import { ITraderAssort, ITraderBase } from "@spt-aki/models/eft/common/tables/ITrader";
import { IGetBodyResponseData } from "@spt-aki/models/eft/httpResponse/IGetBodyResponseData";
import { HttpResponseUtil } from "@spt-aki/utils/HttpResponseUtil";
2023-03-03 16:23:46 +01:00
@injectable()
export class TraderCallbacks implements OnLoad, OnUpdate
{
constructor(
@inject("HttpResponseUtil") protected httpResponse: HttpResponseUtil,
@inject("TraderController") protected traderController: TraderController,
)
// TODO: delay required
2023-03-03 16:23:46 +01:00
{
}
public async onLoad(): Promise<void>
{
this.traderController.load();
}
public async onUpdate(): Promise<boolean>
{
return this.traderController.update();
}
public getRoute(): string
2023-03-03 16:23:46 +01:00
{
return "aki-traders";
}
2023-07-15 15:49:25 +02:00
/** Handle client/trading/api/traderSettings */
public getTraderSettings(
url: string,
info: IEmptyRequestData,
sessionID: string,
): IGetBodyResponseData<ITraderBase[]>
2023-03-03 16:23:46 +01:00
{
return this.httpResponse.getBody(this.traderController.getAllTraders(sessionID));
}
2023-07-15 15:49:25 +02:00
/** Handle client/trading/api/getTrader */
2023-03-03 16:23:46 +01:00
public getTrader(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<ITraderBase>
{
const traderID = url.replace("/client/trading/api/getTrader/", "");
return this.httpResponse.getBody(this.traderController.getTrader(sessionID, traderID));
}
2023-07-15 15:49:25 +02:00
/** Handle client/trading/api/getTraderAssort */
2023-03-03 16:23:46 +01:00
public getAssort(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<ITraderAssort>
{
const traderID = url.replace("/client/trading/api/getTraderAssort/", "");
return this.httpResponse.getBody(this.traderController.getAssort(sessionID, traderID));
}
}