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; + } }