From 12adf848cb72e2728a76bd160ce17eb13eac9e90 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 14 Jun 2022 13:00:50 -0400 Subject: [PATCH] Adding rest of nested types. --- src/interfaces/api/comment.ts | 7 ++- src/interfaces/api/community.ts | 6 +++ src/interfaces/api/person.ts | 15 +++++- src/interfaces/api/post.ts | 12 ++++- src/interfaces/api/site.ts | 22 +++++++++ src/interfaces/views.ts | 83 +++++++++++++++++++++++++++++++++ 6 files changed, 142 insertions(+), 3 deletions(-) diff --git a/src/interfaces/api/comment.ts b/src/interfaces/api/comment.ts index 5d29cf8..c92a188 100644 --- a/src/interfaces/api/comment.ts +++ b/src/interfaces/api/comment.ts @@ -1,5 +1,6 @@ import { Option, Some } from "@sniptt/monads"; -import { Expose, Transform } from "class-transformer"; +import { Expose, Transform, Type } from "class-transformer"; +import "reflect-metadata"; import { toUndefined } from "../../utils"; import { ListingType, SortType } from "../others"; import { CommentReportView, CommentView } from "../views"; @@ -96,6 +97,7 @@ export class SaveComment { } export class CommentResponse { + @Type(() => CommentView) comment_view: CommentView; recipient_ids: number[]; /** @@ -163,6 +165,7 @@ export class GetComments { } export class GetCommentsResponse { + @Type(() => CommentView) comments: CommentView[]; } @@ -177,6 +180,7 @@ export class CreateCommentReport { } export class CommentReportResponse { + @Type(() => CommentReportView) comment_report_view: CommentReportView; } @@ -225,5 +229,6 @@ export class ListCommentReports { } export class ListCommentReportsResponse { + @Type(() => CommentReportView) comment_reports: CommentReportView[]; } diff --git a/src/interfaces/api/community.ts b/src/interfaces/api/community.ts index e0c0fa8..1255f68 100644 --- a/src/interfaces/api/community.ts +++ b/src/interfaces/api/community.ts @@ -41,6 +41,7 @@ export class GetCommunityResponse { @Expose() @Type(() => Site) site: Option; + @Type(() => CommunityModeratorView) moderators: CommunityModeratorView[]; online: number; } @@ -76,6 +77,7 @@ export class CreateCommunity { } export class CommunityResponse { + @Type(() => CommunityView) community_view: CommunityView; } @@ -107,6 +109,7 @@ export class ListCommunities { } export class ListCommunitiesResponse { + @Type(() => CommunityView) communities: CommunityView[]; } @@ -141,6 +144,7 @@ export class BanFromCommunity { } export class BanFromCommunityResponse { + @Type(() => PersonViewSafe) person_view: PersonViewSafe; banned: boolean; } @@ -157,6 +161,7 @@ export class AddModToCommunity { } export class AddModToCommunityResponse { + @Type(() => CommunityModeratorView) moderators: CommunityModeratorView[]; } @@ -261,6 +266,7 @@ export class BlockCommunity { } export class BlockCommunityResponse { + @Type(() => CommunityView) community_view: CommunityView; blocked: boolean; } diff --git a/src/interfaces/api/person.ts b/src/interfaces/api/person.ts index a0892e5..fc8c9d9 100644 --- a/src/interfaces/api/person.ts +++ b/src/interfaces/api/person.ts @@ -72,10 +72,10 @@ export class GetCaptchaResponse { /** * Will be undefined if captchas are disabled. */ - @Type(() => CaptchaResponse) @Transform(({ value }) => Some(value), { toClassOnly: true }) @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) @Expose() + @Type(() => CaptchaResponse) ok: Option; } @@ -264,17 +264,23 @@ export class GetPersonDetails { } export class GetPersonDetailsResponse { + @Type(() => PersonViewSafe) person_view: PersonViewSafe; + @Type(() => CommentView) comments: CommentView[]; + @Type(() => PostView) posts: PostView[]; + @Type(() => CommunityModeratorView) moderates: CommunityModeratorView[]; } export class GetRepliesResponse { + @Type(() => CommentView) replies: CommentView[]; } export class GetPersonMentionsResponse { + @Type(() => PersonMentionView) mentions: PersonMentionView[]; } @@ -297,6 +303,7 @@ export class AddAdmin { } export class AddAdminResponse { + @Type(() => PersonViewSafe) admins: PersonViewSafe[]; } @@ -330,6 +337,7 @@ export class BanPerson { } export class BanPersonResponse { + @Type(() => PersonViewSafe) person_view: PersonViewSafe; banned: boolean; } @@ -393,6 +401,7 @@ export class MarkPersonMentionAsRead { } export class PersonMentionResponse { + @Type(() => PersonMentionView) person_mention_view: PersonMentionView; } @@ -491,10 +500,12 @@ export class GetPrivateMessages { } export class PrivateMessagesResponse { + @Type(() => PrivateMessageView) private_messages: PrivateMessageView[]; } export class PrivateMessageResponse { + @Type(() => PrivateMessageView) private_message_view: PrivateMessageView; } @@ -557,6 +568,7 @@ export class BlockPerson { } export class BlockPersonResponse { + @Type(() => PersonViewSafe) person_view: PersonViewSafe; blocked: boolean; } @@ -570,5 +582,6 @@ export class GetBannedPersons { } export class BannedPersonsResponse { + @Type(() => PersonViewSafe) banned: PersonViewSafe[]; } diff --git a/src/interfaces/api/post.ts b/src/interfaces/api/post.ts index 87d8cbf..b401556 100644 --- a/src/interfaces/api/post.ts +++ b/src/interfaces/api/post.ts @@ -1,5 +1,6 @@ import { Option, Some } from "@sniptt/monads"; -import { Expose, Transform } from "class-transformer"; +import { Expose, Transform, Type } from "class-transformer"; +import "reflect-metadata"; import { toUndefined } from "../../utils"; import { ListingType, SiteMetadata, SortType } from "../others"; import { @@ -37,6 +38,7 @@ export class CreatePost { } export class PostResponse { + @Type(() => PostView) post_view: PostView; } @@ -53,9 +55,13 @@ export class GetPost { } export class GetPostResponse { + @Type(() => PostView) post_view: PostView; + @Type(() => CommunityView) community_view: CommunityView; + @Type(() => CommentView) comments: CommentView[]; + @Type(() => CommunityModeratorView) moderators: CommunityModeratorView[]; online: number; } @@ -103,6 +109,7 @@ export class GetPosts { } export class GetPostsResponse { + @Type(() => PostView) posts: PostView[]; } @@ -232,6 +239,7 @@ export class CreatePostReport { } export class PostReportResponse { + @Type(() => PostReportView) post_report_view: PostReportView; } @@ -279,6 +287,7 @@ export class ListPostReports { } export class ListPostReportsResponse { + @Type(() => PostReportView) post_reports: PostReportView[]; } @@ -291,5 +300,6 @@ export class GetSiteMetadata { } export class GetSiteMetadataResponse { + @Type(() => SiteMetadata) metadata: SiteMetadata; } diff --git a/src/interfaces/api/site.ts b/src/interfaces/api/site.ts index cf1ebf0..7e1a861 100644 --- a/src/interfaces/api/site.ts +++ b/src/interfaces/api/site.ts @@ -82,9 +82,13 @@ export class SearchResponse { * The [[SearchType]]. */ type_: string; + @Type(() => CommentView) comments: CommentView[]; + @Type(() => PostView) posts: PostView[]; + @Type(() => CommunityView) communities: CommunityView[]; + @Type(() => PersonViewSafe) users: PersonViewSafe[]; } @@ -116,15 +120,25 @@ export class GetModlog { } export class GetModlogResponse { + @Type(() => ModRemovePostView) removed_posts: ModRemovePostView[]; + @Type(() => ModLockPostView) locked_posts: ModLockPostView[]; + @Type(() => ModStickyPostView) stickied_posts: ModStickyPostView[]; + @Type(() => ModRemoveCommentView) removed_comments: ModRemoveCommentView[]; + @Type(() => ModRemoveCommunityView) removed_communities: ModRemoveCommunityView[]; + @Type(() => ModBanFromCommunityView) banned_from_community: ModBanFromCommunityView[]; + @Type(() => ModBanView) banned: ModBanView[]; + @Type(() => ModAddCommunityView) added_to_community: ModAddCommunityView[]; + @Type(() => ModTransferCommunityView) transferred_to_community: ModTransferCommunityView[]; + @Type(() => ModAddView) added: ModAddView[]; } @@ -277,6 +291,7 @@ export class GetSite { } export class SiteResponse { + @Type(() => SiteView) site_view: SiteView; } @@ -289,6 +304,7 @@ export class GetSiteResponse { @Expose() @Type(() => SiteView) site_view: Option; + @Type(() => PersonViewSafe) admins: PersonViewSafe[]; online: number; version: string; @@ -311,10 +327,15 @@ export class GetSiteResponse { * Your user info, such as blocks, follows, etc. */ export class MyUserInfo { + @Type(() => LocalUserSettingsView) local_user_view: LocalUserSettingsView; + @Type(() => CommunityFollowerView) follows: CommunityFollowerView[]; + @Type(() => CommunityModeratorView) moderates: CommunityModeratorView[]; + @Type(() => CommunityBlockView) community_blocks: CommunityBlockView[]; + @Type(() => PersonBlockView) person_blocks: PersonBlockView[]; } @@ -440,6 +461,7 @@ export class ApproveRegistrationApplication { } export class RegistrationApplicationResponse { + @Type(() => RegistrationApplicationView) registration_application: RegistrationApplicationView; } diff --git a/src/interfaces/views.ts b/src/interfaces/views.ts index 2d071cd..17e4352 100644 --- a/src/interfaces/views.ts +++ b/src/interfaces/views.ts @@ -34,16 +34,23 @@ import { } from "./source"; export class PersonViewSafe { + @Type(() => PersonSafe) person: PersonSafe; counts: PersonAggregates; } export class PersonMentionView { + @Type(() => PersonMention) person_mention: PersonMention; + @Type(() => Comment) comment: Comment; + @Type(() => PersonSafe) creator: PersonSafe; + @Type(() => Post) post: Post; + @Type(() => CommunitySafe) community: CommunitySafe; + @Type(() => PersonSafe) recipient: PersonSafe; counts: CommentAggregates; creator_banned_from_community: boolean; @@ -57,7 +64,9 @@ export class PersonMentionView { } export class LocalUserSettingsView { + @Type(() => LocalUserSettings) local_user: LocalUserSettings; + @Type(() => PersonSafe) person: PersonSafe; counts: PersonAggregates; } @@ -69,14 +78,20 @@ export class SiteView { } export class PrivateMessageView { + @Type(() => PrivateMessage) private_message: PrivateMessage; + @Type(() => PersonSafe) creator: PersonSafe; + @Type(() => PersonSafe) recipient: PersonSafe; } export class PostView { + @Type(() => Post) post: Post; + @Type(() => PersonSafe) creator: PersonSafe; + @Type(() => CommunitySafe) community: CommunitySafe; creator_banned_from_community: boolean; counts: PostAggregates; @@ -91,10 +106,15 @@ export class PostView { } export class PostReportView { + @Type(() => PostReport) post_report: PostReport; + @Type(() => Post) post: Post; + @Type(() => CommunitySafe) community: CommunitySafe; + @Type(() => PersonSafe) creator: PersonSafe; + @Type(() => PersonSafe) post_creator: PersonSafe; creator_banned_from_community: boolean; @Transform(({ value }) => Some(value), { toClassOnly: true }) @@ -110,14 +130,18 @@ export class PostReportView { } export class CommentView { + @Type(() => Comment) comment: Comment; + @Type(() => PersonSafe) creator: PersonSafe; @Transform(({ value }) => Some(value), { toClassOnly: true }) @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) @Expose() @Type(() => PersonSafe) recipient: Option; + @Type(() => Post) post: Post; + @Type(() => CommunitySafe) community: CommunitySafe; counts: CommentAggregates; creator_banned_from_community: boolean; @@ -131,11 +155,17 @@ export class CommentView { } export class CommentReportView { + @Type(() => CommentReport) comment_report: CommentReport; + @Type(() => Comment) comment: Comment; + @Type(() => Post) post: Post; + @Type(() => CommunitySafe) community: CommunitySafe; + @Type(() => PersonSafe) creator: PersonSafe; + @Type(() => PersonSafe) comment_creator: PersonSafe; counts: CommentAggregates; creator_banned_from_community: boolean; @@ -151,100 +181,150 @@ export class CommentReportView { } export class ModAddCommunityView { + @Type(() => ModAddCommunity) mod_add_community: ModAddCommunity; + @Type(() => PersonSafe) moderator: PersonSafe; + @Type(() => CommunitySafe) community: CommunitySafe; + @Type(() => PersonSafe) modded_person: PersonSafe; } export class ModTransferCommunityView { + @Type(() => ModTransferCommunity) mod_transfer_community: ModTransferCommunity; + @Type(() => PersonSafe) moderator: PersonSafe; + @Type(() => CommunitySafe) community: CommunitySafe; + @Type(() => PersonSafe) modded_person: PersonSafe; } export class ModAddView { + @Type(() => ModAdd) mod_add: ModAdd; + @Type(() => PersonSafe) moderator: PersonSafe; + @Type(() => PersonSafe) modded_person: PersonSafe; } export class ModBanFromCommunityView { + @Type(() => ModBanFromCommunity) mod_ban_from_community: ModBanFromCommunity; + @Type(() => PersonSafe) moderator: PersonSafe; + @Type(() => CommunitySafe) community: CommunitySafe; + @Type(() => PersonSafe) banned_person: PersonSafe; } export class ModBanView { + @Type(() => ModBan) mod_ban: ModBan; + @Type(() => PersonSafe) moderator: PersonSafe; + @Type(() => PersonSafe) banned_person: PersonSafe; } export class ModLockPostView { + @Type(() => ModLockPost) mod_lock_post: ModLockPost; + @Type(() => PersonSafe) moderator: PersonSafe; + @Type(() => Post) post: Post; + @Type(() => CommunitySafe) community: CommunitySafe; } export class ModRemoveCommentView { + @Type(() => ModRemoveComment) mod_remove_comment: ModRemoveComment; + @Type(() => PersonSafe) moderator: PersonSafe; + @Type(() => Comment) comment: Comment; + @Type(() => PersonSafe) commenter: PersonSafe; + @Type(() => Post) post: Post; + @Type(() => CommunitySafe) community: CommunitySafe; } export class ModRemoveCommunityView { + @Type(() => ModRemoveCommunity) mod_remove_community: ModRemoveCommunity; + @Type(() => PersonSafe) moderator: PersonSafe; + @Type(() => CommunitySafe) community: CommunitySafe; } export class ModRemovePostView { + @Type(() => ModRemovePost) mod_remove_post: ModRemovePost; + @Type(() => PersonSafe) moderator: PersonSafe; + @Type(() => Post) post: Post; + @Type(() => CommunitySafe) community: CommunitySafe; } export class ModStickyPostView { + @Type(() => ModStickyPost) mod_sticky_post: ModStickyPost; + @Type(() => PersonSafe) moderator: PersonSafe; + @Type(() => Post) post: Post; + @Type(() => CommunitySafe) community: CommunitySafe; } export class CommunityFollowerView { + @Type(() => CommunitySafe) community: CommunitySafe; + @Type(() => PersonSafe) follower: PersonSafe; } export class CommunityBlockView { + @Type(() => PersonSafe) person: PersonSafe; + @Type(() => CommunitySafe) community: CommunitySafe; } export class CommunityModeratorView { + @Type(() => CommunitySafe) community: CommunitySafe; + @Type(() => PersonSafe) moderator: PersonSafe; } export class CommunityPersonBanView { + @Type(() => CommunitySafe) community: CommunitySafe; + @Type(() => PersonSafe) person: PersonSafe; } export class PersonBlockView { + @Type(() => PersonSafe) person: PersonSafe; + @Type(() => PersonSafe) target: PersonSafe; } export class CommunityView { + @Type(() => CommunitySafe) community: CommunitySafe; subscribed: boolean; blocked: boolean; @@ -252,8 +332,11 @@ export class CommunityView { } export class RegistrationApplicationView { + @Type(() => RegistrationApplication) registration_application: RegistrationApplication; + @Type(() => LocalUserSettings) creator_local_user: LocalUserSettings; + @Type(() => PersonSafe) creator: PersonSafe; @Transform(({ value }) => Some(value), { toClassOnly: true }) @Transform(({ value }) => toUndefined(value), { toPlainOnly: true })