- Improved handling of the `giveawayCreate` job in the bot's job processing for better consistency. - Updated `.env.example` to clarify the usage of `BOT_TOKEN` for both the bot and WebUI. - Added `bullmq` dependency to the WebUI package for enhanced job management capabilities.
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
import type { SocialFeedDashboard, SocialFeedDashboardCreate, SocialFeedDashboardUpdate } from '@nexumi/shared';
|
|
import type { SocialFeed } from '@prisma/client';
|
|
import { prisma } from '../prisma';
|
|
|
|
function toDashboard(feed: SocialFeed): SocialFeedDashboard {
|
|
return {
|
|
id: feed.id,
|
|
type: feed.type as SocialFeedDashboard['type'],
|
|
sourceId: feed.sourceId,
|
|
channelId: feed.channelId,
|
|
rolePingId: feed.rolePingId ?? '',
|
|
template: feed.template,
|
|
enabled: feed.enabled
|
|
};
|
|
}
|
|
|
|
export async function listSocialFeeds(guildId: string): Promise<SocialFeedDashboard[]> {
|
|
const feeds = await prisma.socialFeed.findMany({ where: { guildId }, orderBy: { createdAt: 'asc' } });
|
|
return feeds.map(toDashboard);
|
|
}
|
|
|
|
export async function createSocialFeed(
|
|
guildId: string,
|
|
input: SocialFeedDashboardCreate
|
|
): Promise<SocialFeedDashboard> {
|
|
await prisma.guild.upsert({ where: { id: guildId }, update: {}, create: { id: guildId } });
|
|
const feed = await prisma.socialFeed.create({
|
|
data: {
|
|
guildId,
|
|
type: input.type,
|
|
sourceId: input.sourceId,
|
|
channelId: input.channelId,
|
|
rolePingId: input.rolePingId ? input.rolePingId : null,
|
|
template: input.template ?? null,
|
|
enabled: input.enabled
|
|
}
|
|
});
|
|
return toDashboard(feed);
|
|
}
|
|
|
|
export async function updateSocialFeed(
|
|
guildId: string,
|
|
feedId: string,
|
|
patch: SocialFeedDashboardUpdate
|
|
): Promise<SocialFeedDashboard | null> {
|
|
const existing = await prisma.socialFeed.findFirst({ where: { id: feedId, guildId } });
|
|
if (!existing) {
|
|
return null;
|
|
}
|
|
|
|
const { rolePingId, ...rest } = patch;
|
|
const updated = await prisma.socialFeed.update({
|
|
where: { id: feedId },
|
|
data: {
|
|
...rest,
|
|
...(rolePingId !== undefined ? { rolePingId: rolePingId === '' ? null : rolePingId } : {})
|
|
}
|
|
});
|
|
return toDashboard(updated);
|
|
}
|
|
|
|
export async function deleteSocialFeed(guildId: string, feedId: string): Promise<boolean> {
|
|
const result = await prisma.socialFeed.deleteMany({ where: { id: feedId, guildId } });
|
|
return result.count > 0;
|
|
}
|