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