fix(structures): add missing toJSON method on Subscription structure (#11431)

fix(structures): add missing `toJSON` method on Subscription

When writing tests for #11407, it became apparent that I had forgotten to add the `toJSON` method for this structure when I was initially wrote the structure. I have now added this method and it passes when running the tests that I have written for this (which will be merged in a following PR).

Signed-off-by: Asad Humayun <asad.humayun@asadh.io>
This commit is contained in:
Asad Humayun
2026-03-01 21:10:26 +00:00
committed by GitHub
parent 307b64f139
commit fce498982a

View File

@@ -1,6 +1,7 @@
import { DiscordSnowflake } from '@sapphire/snowflake';
import type { APISubscription, SubscriptionStatus } from 'discord-api-types/v10';
import { Structure } from '../Structure.js';
import { dateToDiscordISOTimestamp } from '../utils/optimization.js';
import {
kData,
kCurrentPeriodStartTimestamp,
@@ -174,4 +175,29 @@ export class Subscription<
const createdTimestamp = this.createdTimestamp;
return createdTimestamp ? new Date(createdTimestamp) : null;
}
/**
* {@inheritDoc Structure.toJSON}
*/
public override toJSON() {
const clone = super.toJSON();
const currentPeriodStartTimestamp = this[kCurrentPeriodStartTimestamp];
const currentPeriodEndTimestamp = this[kCurrentPeriodEndTimestamp];
const canceledTimestamp = this[kCanceledTimestamp];
if (currentPeriodEndTimestamp) {
clone.current_period_end = dateToDiscordISOTimestamp(new Date(currentPeriodEndTimestamp));
}
if (currentPeriodStartTimestamp) {
clone.current_period_start = dateToDiscordISOTimestamp(new Date(currentPeriodStartTimestamp));
}
if (canceledTimestamp) {
clone.canceled_at = dateToDiscordISOTimestamp(new Date(canceledTimestamp));
}
return clone;
}
}