a fun bot for the hc slack
at v0.0.3 885 B view raw
1import { db } from "../../../libs/db"; 2import { takes as takesTable } from "../../../libs/schema"; 3import { eq, and, desc, not } from "drizzle-orm"; 4 5export async function getActiveTake(userId: string) { 6 return db 7 .select() 8 .from(takesTable) 9 .where( 10 and(eq(takesTable.userId, userId), eq(takesTable.status, "active")), 11 ) 12 .limit(1); 13} 14 15export async function getPausedTake(userId: string) { 16 return db 17 .select() 18 .from(takesTable) 19 .where( 20 and(eq(takesTable.userId, userId), eq(takesTable.status, "paused")), 21 ) 22 .limit(1); 23} 24 25export async function getCompletedTakes(userId: string, limit = 5) { 26 return db 27 .select() 28 .from(takesTable) 29 .where( 30 and( 31 eq(takesTable.userId, userId), 32 and( 33 not(eq(takesTable.status, "active")), 34 not(eq(takesTable.status, "paused")), 35 ), 36 ), 37 ) 38 .orderBy(desc(takesTable.completedAt)) 39 .limit(limit); 40}