2023-03-03 16:23:46 +01:00
|
|
|
import { inject, injectable } from "tsyringe";
|
|
|
|
import { EventOutputHolder } from "../routers/EventOutputHolder";
|
|
|
|
|
|
|
|
import { IPmcData } from "../models/eft/common/IPmcData";
|
|
|
|
import { IItemEventRouterResponse } from "../models/eft/itemEvent/IItemEventRouterResponse";
|
|
|
|
import { IWishlistActionData } from "../models/eft/wishlist/IWishlistActionData";
|
|
|
|
|
|
|
|
@injectable()
|
|
|
|
export class WishlistController
|
|
|
|
{
|
|
|
|
constructor(
|
|
|
|
@inject("EventOutputHolder") protected eventOutputHolder: EventOutputHolder
|
|
|
|
)
|
|
|
|
{ }
|
|
|
|
|
2023-07-15 15:49:25 +02:00
|
|
|
/** Handle AddToWishList */
|
2023-03-03 16:23:46 +01:00
|
|
|
public addToWishList(pmcData: IPmcData, body: IWishlistActionData, sessionID: string): IItemEventRouterResponse
|
|
|
|
{
|
|
|
|
for (const item in pmcData.WishList)
|
|
|
|
{
|
|
|
|
// don't add the item
|
|
|
|
if (pmcData.WishList[item] === body.templateId)
|
|
|
|
{
|
|
|
|
return this.eventOutputHolder.getOutput(sessionID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the item to the wishlist
|
|
|
|
pmcData.WishList.push(body.templateId);
|
|
|
|
return this.eventOutputHolder.getOutput(sessionID);
|
|
|
|
}
|
|
|
|
|
2023-07-15 15:49:25 +02:00
|
|
|
/** Handle RemoveFromWishList event */
|
2023-03-03 16:23:46 +01:00
|
|
|
public removeFromWishList(pmcData: IPmcData, body: IWishlistActionData, sessionID: string): IItemEventRouterResponse
|
|
|
|
{
|
|
|
|
for (let i = 0; i < pmcData.WishList.length; i++)
|
|
|
|
{
|
|
|
|
if (pmcData.WishList[i] === body.templateId)
|
|
|
|
{
|
|
|
|
pmcData.WishList.splice(i, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.eventOutputHolder.getOutput(sessionID);
|
|
|
|
}
|
|
|
|
}
|