2023-03-03 16:23:46 +01:00
|
|
|
import { inject, injectable } from "tsyringe";
|
|
|
|
|
2023-10-19 19:21:17 +02:00
|
|
|
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,
|
2023-11-16 22:42:06 +01:00
|
|
|
@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();
|
|
|
|
}
|
|
|
|
|
2023-11-16 22:42:06 +01:00
|
|
|
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 */
|
2023-11-16 22:42:06 +01:00
|
|
|
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));
|
|
|
|
}
|
2023-11-16 22:42:06 +01:00
|
|
|
}
|