feat(postgres): implement notes CRUD and export/import #16

Merged
codinget merged 2 commits from feat/issue-15 into master 2026-07-23 23:02:17 +02:00
2 changed files with 13 additions and 9 deletions
Showing only changes of commit 1e10391e20 - Show all commits
+1 -4
View File
@@ -564,10 +564,7 @@ export class PostgresInterface
return selectPartialNotes(this.#db, sql`n."aid" = ${{ uuid: aid }}`);
}
async listNotesByUserId(uid: string): Promise<PartialNote[]> {
return selectPartialNotes(
this.#db,
sql`n."created_by" = ${{ uuid: uid }}`,
);
return selectPartialNotes(this.#db, sql`n."created_by" = ${{ uuid: uid }}`);
}
export(options: ExportOptions = {}): NodeJS.ReadableStream {
+12 -5
View File
@@ -1,7 +1,12 @@
import type { Abode } from "../types/Abode.js";
import type { ApikeyPermissions, ClientApikey } from "../types/Apikey.js";
import type { Resident, ResidentFlags } from "../types/Resident.js";
import type { Note, NoteProperties, PartialNote, PartialNoteProperties } from "../types/Note.js";
import type {
Note,
NoteProperties,
PartialNote,
PartialNoteProperties,
} from "../types/Note.js";
import type { ClientUser, PartialUser, UserFlags } from "../types/User.js";
export function pgToDate(d: Date | string): string {
@@ -140,7 +145,11 @@ export function pgToClientApikey(apikey: {
const validNoteTypes = new Set(["note"]);
function pgToNoteProperties(properties: unknown): NoteProperties {
if (typeof properties !== "object" || !properties || Array.isArray(properties))
if (
typeof properties !== "object" ||
!properties ||
Array.isArray(properties)
)
return {};
const value = properties as Record<string, unknown>;
return validNoteTypes.has(value.type as string)
@@ -148,9 +157,7 @@ function pgToNoteProperties(properties: unknown): NoteProperties {
: {};
}
function pgToPartialNoteProperties(
properties: unknown,
): PartialNoteProperties {
function pgToPartialNoteProperties(properties: unknown): PartialNoteProperties {
return { type: pgToNoteProperties(properties).type ?? "note" };
}