Server/project/src/callbacks/TraderCallbacks.ts

53 lines
2.0 KiB
TypeScript
Raw Normal View History

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