Skip to content

Commit fce4989

Browse files
authored
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>
1 parent 307b64f commit fce4989

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

packages/structures/src/subscriptions/Subscription.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { DiscordSnowflake } from '@sapphire/snowflake';
22
import type { APISubscription, SubscriptionStatus } from 'discord-api-types/v10';
33
import { Structure } from '../Structure.js';
4+
import { dateToDiscordISOTimestamp } from '../utils/optimization.js';
45
import {
56
kData,
67
kCurrentPeriodStartTimestamp,
@@ -174,4 +175,29 @@ export class Subscription<
174175
const createdTimestamp = this.createdTimestamp;
175176
return createdTimestamp ? new Date(createdTimestamp) : null;
176177
}
178+
179+
/**
180+
* {@inheritDoc Structure.toJSON}
181+
*/
182+
public override toJSON() {
183+
const clone = super.toJSON();
184+
185+
const currentPeriodStartTimestamp = this[kCurrentPeriodStartTimestamp];
186+
const currentPeriodEndTimestamp = this[kCurrentPeriodEndTimestamp];
187+
const canceledTimestamp = this[kCanceledTimestamp];
188+
189+
if (currentPeriodEndTimestamp) {
190+
clone.current_period_end = dateToDiscordISOTimestamp(new Date(currentPeriodEndTimestamp));
191+
}
192+
193+
if (currentPeriodStartTimestamp) {
194+
clone.current_period_start = dateToDiscordISOTimestamp(new Date(currentPeriodStartTimestamp));
195+
}
196+
197+
if (canceledTimestamp) {
198+
clone.canceled_at = dateToDiscordISOTimestamp(new Date(canceledTimestamp));
199+
}
200+
201+
return clone;
202+
}
177203
}

0 commit comments

Comments
 (0)