import db, { TicketWithRelations, ticketWithRelations } from "@stealth-developers/db"; export interface PaginationOptions { limit?: number; offset?: number; } export async function getTicketsByGuildId( guildId: number, userId: number | undefined, options: PaginationOptions = {}, ): Promise { const { limit, offset } = options; const ticketsList = await db.query.tickets.findMany({ where: { guildId: guildId, ...(userId !== undefined ? { subject: userId } : {}), }, orderBy: (table, { desc }) => [desc(table.localId)], limit: limit, offset: offset, with: ticketWithRelations, }); return ticketsList; } export async function getLinkedActors(userId: number) { const actors = await db.query.actors.findMany({ where: { userId: userId, }, with: { guild: true, }, }); return actors; }