2023-11-02 06:47:28 +01:00
|
|
|
import "reflect-metadata";
|
|
|
|
import { container } from "tsyringe";
|
2023-11-10 23:21:20 +01:00
|
|
|
|
2023-11-02 06:47:28 +01:00
|
|
|
import { ItemHelper } from "@spt-aki/helpers/ItemHelper";
|
2023-11-10 23:21:20 +01:00
|
|
|
import { Insurance } from "@spt-aki/models/eft/profile/IAkiProfile";
|
|
|
|
import { profileInsuranceFixture } from "@tests/__fixture__/profileInsurance.fixture";
|
|
|
|
import { format } from "date-fns";
|
2023-11-02 06:47:28 +01:00
|
|
|
|
2023-11-10 23:21:20 +01:00
|
|
|
type DateInput = number | number[] | {[index: number]: number;};
|
2023-11-02 06:47:28 +01:00
|
|
|
|
|
|
|
export class ProfileInsuranceFactory
|
|
|
|
{
|
|
|
|
private profileInsuranceFixture: Insurance[];
|
|
|
|
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
public init(): this
|
|
|
|
{
|
|
|
|
this.profileInsuranceFixture = JSON.parse(JSON.stringify(profileInsuranceFixture)); // Deep clone.
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adjusts the scheduledTime and messageContent.systemData.date and messageContent.systemData.time, otherwise the
|
|
|
|
* dates in the original fixture will likely be expired.
|
|
|
|
*/
|
|
|
|
public adjustPackageDates(dateInput?: DateInput): this
|
|
|
|
{
|
|
|
|
this.profileInsuranceFixture = this.profileInsuranceFixture.map((insurance, index) =>
|
|
|
|
{
|
2023-11-03 22:39:33 +01:00
|
|
|
// Default to 1 hour ago.
|
|
|
|
const defaultDate = Math.floor((Date.now() / 1000) - (1 * 60 * 60));
|
2023-11-02 06:47:28 +01:00
|
|
|
|
|
|
|
let date: number;
|
|
|
|
if (Array.isArray(dateInput) || typeof dateInput === "object")
|
|
|
|
{
|
|
|
|
date = dateInput[index] || defaultDate;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
date = dateInput || defaultDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
insurance.scheduledTime = date;
|
|
|
|
insurance.messageContent.systemData.date = format(date, "MM.dd.yyyy");
|
|
|
|
insurance.messageContent.systemData.time = format(date, "HH:mm");
|
|
|
|
return insurance;
|
|
|
|
});
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes all attachment items that are currently attached to their parent, leaving the "normal" base items.
|
|
|
|
*/
|
|
|
|
public removeAttachmentItems(): this
|
|
|
|
{
|
|
|
|
const itemHelper = container.resolve<ItemHelper>("ItemHelper");
|
|
|
|
|
|
|
|
this.profileInsuranceFixture = this.profileInsuranceFixture.map((insurance) =>
|
|
|
|
{
|
2023-11-10 23:21:20 +01:00
|
|
|
insurance.items = insurance.items.filter((item) => !itemHelper.isAttachmentAttached(item));
|
2023-11-02 06:47:28 +01:00
|
|
|
return insurance;
|
|
|
|
});
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes all normal base items leaving only attachment items that are currently attached to their parent.
|
|
|
|
* This *will* cause orphaned attachments.
|
|
|
|
*/
|
|
|
|
public removeRegularItems(): this
|
|
|
|
{
|
|
|
|
const itemHelper = container.resolve<ItemHelper>("ItemHelper");
|
|
|
|
|
|
|
|
this.profileInsuranceFixture = this.profileInsuranceFixture.map((insurance) =>
|
|
|
|
{
|
2023-11-10 23:21:20 +01:00
|
|
|
insurance.items = insurance.items.filter((item) => itemHelper.isAttachmentAttached(item));
|
2023-11-02 06:47:28 +01:00
|
|
|
return insurance;
|
|
|
|
});
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get(): Insurance[]
|
|
|
|
{
|
|
|
|
return this.profileInsuranceFixture;
|
|
|
|
}
|
|
|
|
}
|