feat: api v1 routes for calendar lists and notes

This commit is contained in:
ginnoir
2026-07-04 19:03:08 -05:00
parent ea5d1d050c
commit d4304b005c
25 changed files with 1141 additions and 236 deletions
+14 -6
View File
@@ -18,30 +18,38 @@ export type NoteDto = {
updatedAt: string;
};
export async function listNotes(): Promise<NoteDto[]> {
const { household } = await getCurrentSession();
export async function listNotesForScope(householdId: string): Promise<NoteDto[]> {
const rows = await db
.select()
.from(notes)
.where(eq(notes.householdId, household.id))
.where(eq(notes.householdId, householdId))
.orderBy(desc(notes.pinned), desc(notes.updatedAt));
return rows.map(toNoteDto);
}
export async function getNote(id: string): Promise<NoteDto> {
const parsed = z.string().uuid().parse(id);
export async function listNotes(): Promise<NoteDto[]> {
const { household } = await getCurrentSession();
return listNotesForScope(household.id);
}
export async function getNoteForScope(householdId: string, id: string): Promise<NoteDto> {
const parsed = z.string().uuid().parse(id);
const [note] = await db
.select()
.from(notes)
.where(and(eq(notes.id, parsed), eq(notes.householdId, household.id)))
.where(and(eq(notes.id, parsed), eq(notes.householdId, householdId)))
.limit(1);
if (!note) throw new Error("Note not found");
return toNoteDto(note);
}
export async function getNote(id: string): Promise<NoteDto> {
const { household } = await getCurrentSession();
return getNoteForScope(household.id, id);
}
export async function canAccessNote(noteId: string, householdId: string) {
const [note] = await db
.select({ id: notes.id })