This repository has no description
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657// SPDX-License-Identifier: AGPL-3.0-or-later
import type {WebhookResponse, WebhookTokenResponse} from '@fluxer/schema/src/domains/webhook/WebhookSchemas';import type {z} from 'zod';import type {UserCacheService} from '../infrastructure/UserCacheService';import type {RequestCache} from '../middleware/RequestCacheMiddleware';import type {Webhook} from '../models/Webhook';import {getCachedUserPartialResponse} from '../user/UserCacheHelpers';
export function mapWebhookToTokenResponse(webhook: Webhook): z.infer<typeof WebhookTokenResponse> { return { id: webhook.id.toString(), guild_id: webhook.guildId?.toString() || '', channel_id: webhook.channelId?.toString() || '', name: webhook.name || '', avatar: webhook.avatarHash, token: webhook.token, };}
export async function mapWebhookToResponseWithCache({ webhook, userCacheService, requestCache,}: { webhook: Webhook; userCacheService: UserCacheService; requestCache: RequestCache;}): Promise<z.infer<typeof WebhookResponse>> { const creatorPartial = await getCachedUserPartialResponse({ userId: webhook.creatorId!, userCacheService, requestCache, }); if (!creatorPartial) { throw new Error(`Creator user ${webhook.creatorId} not found for webhook`); } return { ...mapWebhookToTokenResponse(webhook), user: creatorPartial, };}
export async function mapWebhooksToResponse({ webhooks, userCacheService, requestCache,}: { webhooks: Array<Webhook>; userCacheService: UserCacheService; requestCache: RequestCache;}): Promise<Array<z.infer<typeof WebhookResponse>>> { return await Promise.all( webhooks.map((webhook) => mapWebhookToResponseWithCache({webhook, userCacheService, requestCache})), );}