client-ts: Port services/app/date_notes

This commit is contained in:
Elian Doran 2024-07-25 20:49:37 +03:00
parent ac7316ae93
commit cd5ea28e14
No known key found for this signature in database

View File

@ -1,67 +1,61 @@
import dayjs from "dayjs";
import { FNoteRow } from "../entities/fnote.js";
import froca from "./froca.js"; import froca from "./froca.js";
import server from "./server.js"; import server from "./server.js";
import ws from "./ws.js"; import ws from "./ws.js";
/** @returns {FNote} */
async function getInboxNote() { async function getInboxNote() {
const note = await server.get(`special-notes/inbox/${dayjs().format("YYYY-MM-DD")}`, "date-note"); const note = await server.get<FNoteRow>(`special-notes/inbox/${dayjs().format("YYYY-MM-DD")}`, "date-note");
return await froca.getNote(note.noteId); return await froca.getNote(note.noteId);
} }
/** @returns {FNote} */
async function getTodayNote() { async function getTodayNote() {
return await getDayNote(dayjs().format("YYYY-MM-DD")); return await getDayNote(dayjs().format("YYYY-MM-DD"));
} }
/** @returns {FNote} */ async function getDayNote(date: string) {
async function getDayNote(date) { const note = await server.get<FNoteRow>(`special-notes/days/${date}`, "date-note");
const note = await server.get(`special-notes/days/${date}`, "date-note");
await ws.waitForMaxKnownEntityChangeId(); await ws.waitForMaxKnownEntityChangeId();
return await froca.getNote(note.noteId); return await froca.getNote(note.noteId);
} }
/** @returns {FNote} */ async function getWeekNote(date: string) {
async function getWeekNote(date) { const note = await server.get<FNoteRow>(`special-notes/weeks/${date}`, "date-note");
const note = await server.get(`special-notes/weeks/${date}`, "date-note");
await ws.waitForMaxKnownEntityChangeId(); await ws.waitForMaxKnownEntityChangeId();
return await froca.getNote(note.noteId); return await froca.getNote(note.noteId);
} }
/** @returns {FNote} */ async function getMonthNote(month: string) {
async function getMonthNote(month) { const note = await server.get<FNoteRow>(`special-notes/months/${month}`, "date-note");
const note = await server.get(`special-notes/months/${month}`, "date-note");
await ws.waitForMaxKnownEntityChangeId(); await ws.waitForMaxKnownEntityChangeId();
return await froca.getNote(note.noteId); return await froca.getNote(note.noteId);
} }
/** @returns {FNote} */ async function getYearNote(year: string) {
async function getYearNote(year) { const note = await server.get<FNoteRow>(`special-notes/years/${year}`, "date-note");
const note = await server.get(`special-notes/years/${year}`, "date-note");
await ws.waitForMaxKnownEntityChangeId(); await ws.waitForMaxKnownEntityChangeId();
return await froca.getNote(note.noteId); return await froca.getNote(note.noteId);
} }
/** @returns {FNote} */
async function createSqlConsole() { async function createSqlConsole() {
const note = await server.post('special-notes/sql-console'); const note = await server.post<FNoteRow>('special-notes/sql-console');
await ws.waitForMaxKnownEntityChangeId(); await ws.waitForMaxKnownEntityChangeId();
return await froca.getNote(note.noteId); return await froca.getNote(note.noteId);
} }
/** @returns {FNote} */
async function createSearchNote(opts = {}) { async function createSearchNote(opts = {}) {
const note = await server.post('special-notes/search-note', opts); const note = await server.post<FNoteRow>('special-notes/search-note', opts);
await ws.waitForMaxKnownEntityChangeId(); await ws.waitForMaxKnownEntityChangeId();