feat: api v1 routes for calendar lists and notes
This commit is contained in:
@@ -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 })
|
||||
|
||||
Reference in New Issue
Block a user