···
485
-
export function getAllTranscriptions(): Array<{
488
-
user_email: string;
489
-
user_name: string | null;
490
-
original_filename: string;
492
-
created_at: number;
493
-
error_message: string | null;
500
-
user_email: string;
501
-
user_name: string | null;
502
-
original_filename: string;
504
-
created_at: number;
505
-
error_message: string | null;
512
-
u.email as user_email,
513
-
u.name as user_name,
514
-
t.original_filename,
518
-
FROM transcriptions t
519
-
LEFT JOIN users u ON t.user_id = u.id
520
-
ORDER BY t.created_at DESC`,
485
+
export function getAllTranscriptions(
492
+
user_email: string;
493
+
user_name: string | null;
494
+
original_filename: string;
496
+
created_at: number;
497
+
error_message: string | null;
502
+
nextCursor: string | null;
505
+
type TranscriptionRow = {
508
+
user_email: string;
509
+
user_name: string | null;
510
+
original_filename: string;
512
+
created_at: number;
513
+
error_message: string | null;
516
+
let transcriptions: TranscriptionRow[];
519
+
const { decodeCursor } = require("./cursor");
520
+
const parts = decodeCursor(cursor);
522
+
if (parts.length !== 2) {
523
+
throw new Error("Invalid cursor format");
526
+
const cursorTime = Number.parseInt(parts[0] || "", 10);
527
+
const id = parts[1] || "";
529
+
if (Number.isNaN(cursorTime) || !id) {
530
+
throw new Error("Invalid cursor format");
533
+
transcriptions = db
534
+
.query<TranscriptionRow, [number, number, string, number]>(
538
+
u.email as user_email,
539
+
u.name as user_name,
540
+
t.original_filename,
544
+
FROM transcriptions t
545
+
LEFT JOIN users u ON t.user_id = u.id
546
+
WHERE t.created_at < ? OR (t.created_at = ? AND t.id < ?)
547
+
ORDER BY t.created_at DESC, t.id DESC
550
+
.all(cursorTime, cursorTime, id, limit + 1);
552
+
transcriptions = db
553
+
.query<TranscriptionRow, [number]>(
557
+
u.email as user_email,
558
+
u.name as user_name,
559
+
t.original_filename,
563
+
FROM transcriptions t
564
+
LEFT JOIN users u ON t.user_id = u.id
565
+
ORDER BY t.created_at DESC, t.id DESC
571
+
const hasMore = transcriptions.length > limit;
573
+
transcriptions.pop();
576
+
let nextCursor: string | null = null;
577
+
if (hasMore && transcriptions.length > 0) {
578
+
const { encodeCursor } = require("./cursor");
579
+
const last = transcriptions[transcriptions.length - 1];
581
+
nextCursor = encodeCursor([last.created_at.toString(), last.id]);
586
+
data: transcriptions,
export function deleteTranscription(transcriptionId: string): void {
···
subscription_id: string | null;
608
-
export function getAllUsersWithStats(): UserWithStats[] {
610
-
.query<UserWithStats, []>(
619
-
COUNT(DISTINCT t.id) as transcription_count,
620
-
s.status as subscription_status,
621
-
s.id as subscription_id
623
-
LEFT JOIN transcriptions t ON u.id = t.user_id
624
-
LEFT JOIN subscriptions s ON u.id = s.user_id AND s.status IN ('active', 'trialing', 'past_due')
626
-
ORDER BY u.created_at DESC`,
678
+
export function getAllUsersWithStats(
682
+
data: UserWithStats[];
686
+
nextCursor: string | null;
689
+
let users: UserWithStats[];
692
+
const { decodeCursor } = require("./cursor");
693
+
const parts = decodeCursor(cursor);
695
+
if (parts.length !== 2) {
696
+
throw new Error("Invalid cursor format");
699
+
const cursorTime = Number.parseInt(parts[0] || "", 10);
700
+
const cursorId = Number.parseInt(parts[1] || "", 10);
702
+
if (Number.isNaN(cursorTime) || Number.isNaN(cursorId)) {
703
+
throw new Error("Invalid cursor format");
707
+
.query<UserWithStats, [number, number, number, number]>(
716
+
COUNT(DISTINCT t.id) as transcription_count,
717
+
s.status as subscription_status,
718
+
s.id as subscription_id
720
+
LEFT JOIN transcriptions t ON u.id = t.user_id
721
+
LEFT JOIN subscriptions s ON u.id = s.user_id AND s.status IN ('active', 'trialing', 'past_due')
722
+
WHERE u.created_at < ? OR (u.created_at = ? AND u.id < ?)
724
+
ORDER BY u.created_at DESC, u.id DESC
727
+
.all(cursorTime, cursorTime, cursorId, limit + 1);
730
+
.query<UserWithStats, [number]>(
739
+
COUNT(DISTINCT t.id) as transcription_count,
740
+
s.status as subscription_status,
741
+
s.id as subscription_id
743
+
LEFT JOIN transcriptions t ON u.id = t.user_id
744
+
LEFT JOIN subscriptions s ON u.id = s.user_id AND s.status IN ('active', 'trialing', 'past_due')
746
+
ORDER BY u.created_at DESC, u.id DESC
752
+
const hasMore = users.length > limit;
757
+
let nextCursor: string | null = null;
758
+
if (hasMore && users.length > 0) {
759
+
const { encodeCursor } = require("./cursor");
760
+
const last = users[users.length - 1];
762
+
nextCursor = encodeCursor([last.created_at.toString(), last.id.toString()]);