From fce498982a12973282e7b632e44696cf2673cf75 Mon Sep 17 00:00:00 2001 From: Asad Humayun <105254706+AsadHumayun@users.noreply.github.com> Date: Sun, 1 Mar 2026 21:10:26 +0000 Subject: [PATCH] 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 --- .../src/subscriptions/Subscription.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/structures/src/subscriptions/Subscription.ts b/packages/structures/src/subscriptions/Subscription.ts index d2d5cc259..c6c56116f 100644 --- a/packages/structures/src/subscriptions/Subscription.ts +++ b/packages/structures/src/subscriptions/Subscription.ts @@ -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; + } }