Server/project/src/callbacks/TraderCallbacks.ts
Alex d13e86ba46 Rebranding to SPT (!345)
Rebranded src code and scripts to SPT

Co-authored-by: clodan <clodan@clodan.com>
Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/345
Co-authored-by: Alex <clodan@noreply.dev.sp-tarkov.com>
Co-committed-by: Alex <clodan@noreply.dev.sp-tarkov.com>
2024-05-21 17:59:04 +00:00

58 lines
2.0 KiB
TypeScript

import { inject, injectable } from "tsyringe";
import { TraderController } from "@spt/controllers/TraderController";
import { OnLoad } from "@spt/di/OnLoad";
import { OnUpdate } from "@spt/di/OnUpdate";
import { IEmptyRequestData } from "@spt/models/eft/common/IEmptyRequestData";
import { ITraderAssort, ITraderBase } from "@spt/models/eft/common/tables/ITrader";
import { IGetBodyResponseData } from "@spt/models/eft/httpResponse/IGetBodyResponseData";
import { HttpResponseUtil } from "@spt/utils/HttpResponseUtil";
@injectable()
export class TraderCallbacks implements OnLoad, OnUpdate
{
constructor(
@inject("HttpResponseUtil") protected httpResponse: HttpResponseUtil, // TODO: delay required
@inject("TraderController") protected traderController: TraderController,
)
{}
public async onLoad(): Promise<void>
{
this.traderController.load();
}
public async onUpdate(): Promise<boolean>
{
return this.traderController.update();
}
public getRoute(): string
{
return "spt-traders";
}
/** Handle client/trading/api/traderSettings */
public getTraderSettings(
url: string,
info: IEmptyRequestData,
sessionID: string,
): IGetBodyResponseData<ITraderBase[]>
{
return this.httpResponse.getBody(this.traderController.getAllTraders(sessionID));
}
/** Handle client/trading/api/getTrader */
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));
}
/** Handle client/trading/api/getTraderAssort */
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));
}
}