mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 08:03:30 +01:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user