Skip to content

Commit

Permalink
feat: add channel socials
Browse files Browse the repository at this point in the history
  • Loading branch information
zSoulweaver committed Jul 30, 2024
1 parent 3dc8146 commit 6d2a17d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/api/channels/get-socials.response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// biome-ignore lint/style/useImportType: deepkit/type
import { Social } from '../../structures/social'

export interface ChannelSocialsResponse {
socials: Social[]
}
22 changes: 22 additions & 0 deletions src/api/channels/get-socials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { cast } from '@deepkit/type'
import type { Kient } from '../../kient'
// biome-ignore lint/style/useImportType: deepkit/type
import { CommonAPIResponse, isSuccessResponse } from '../../util/common-api-response'
// biome-ignore lint/style/useImportType: deepkit/type
import { ChannelSocialsResponse } from './get-socials.response'
// biome-ignore lint/style/useImportType: deepkit/type
import { Social } from '../../structures/social'

export async function getSocials(kient: Kient, slugOrId: string) {
const response = await kient._apiClient.fetch<CommonAPIResponse<ChannelSocialsResponse>>(
`/channels/${slugOrId}/socials`,
)

const typedResponse = cast<CommonAPIResponse<ChannelSocialsResponse>>(response)
if (!isSuccessResponse(typedResponse)) {
throw new Error(`Request failed: ${typedResponse.data}`)
}

const socials = cast<Social[]>({ ...typedResponse.data.socials, kient })
return socials
}
1 change: 1 addition & 0 deletions src/structures/social.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class Social {}

0 comments on commit 6d2a17d

Please sign in to comment.