feat(02-01): add getOrdered method to repository

- Add getOrdered(options?) method to EntryRepository interface
- Implement filtering for completed entries (showCompleted option)
- Order by type ASC (task before thought), then createdAt DESC
- Import asc, ne operators from drizzle-orm
This commit is contained in:
Thomas Richter
2026-01-29 11:01:59 +01:00
parent 457cd407a8
commit 87bf928c12

View File

@@ -1,4 +1,4 @@
import { eq, desc } from 'drizzle-orm';
import { eq, desc, asc, ne } from 'drizzle-orm';
import { db } from './index';
import { entries, type Entry, type NewEntry } from './schema';
import { nanoid } from 'nanoid';
@@ -7,6 +7,7 @@ export interface EntryRepository {
create(entry: Omit<NewEntry, 'id' | 'createdAt' | 'updatedAt'>): Entry;
getById(id: string): Entry | undefined;
getAll(options?: { limit?: number; offset?: number }): Entry[];
getOrdered(options?: { showCompleted?: boolean }): Entry[];
update(id: string, updates: Partial<Omit<Entry, 'id' | 'createdAt'>>): Entry | undefined;
delete(id: string): boolean;
count(): number;
@@ -35,6 +36,25 @@ class SQLiteEntryRepository implements EntryRepository {
return db.select().from(entries).orderBy(desc(entries.createdAt)).limit(limit).offset(offset).all();
}
getOrdered(options: { showCompleted?: boolean } = {}): Entry[] {
const { showCompleted = false } = options;
if (!showCompleted) {
return db
.select()
.from(entries)
.where(ne(entries.status, 'done'))
.orderBy(asc(entries.type), desc(entries.createdAt))
.all();
}
return db
.select()
.from(entries)
.orderBy(asc(entries.type), desc(entries.createdAt))
.all();
}
update(id: string, updates: Partial<Omit<Entry, 'id' | 'createdAt'>>): Entry | undefined {
const existing = this.getById(id);
if (!existing) return undefined;