Notes/src/public/app/services/date_notes.ts

75 lines
1.9 KiB
TypeScript
Raw Normal View History

import dayjs from "dayjs";
import { FNoteRow } from "../entities/fnote.js";
2021-04-16 23:01:56 +02:00
import froca from "./froca.js";
import server from "./server.js";
2020-12-05 23:00:28 +01:00
import ws from "./ws.js";
2020-11-27 22:21:13 +01:00
async function getInboxNote() {
const note = await server.get<FNoteRow>(`special-notes/inbox/${dayjs().format("YYYY-MM-DD")}`, "date-note");
2020-11-27 22:21:13 +01:00
2021-04-16 22:57:37 +02:00
return await froca.getNote(note.noteId);
2020-11-27 22:21:13 +01:00
}
async function getTodayNote() {
2022-01-10 17:09:20 +01:00
return await getDayNote(dayjs().format("YYYY-MM-DD"));
}
async function getDayNote(date: string) {
const note = await server.get<FNoteRow>(`special-notes/days/${date}`, "date-note");
await ws.waitForMaxKnownEntityChangeId();
2021-04-16 22:57:37 +02:00
return await froca.getNote(note.noteId);
}
async function getWeekNote(date: string) {
const note = await server.get<FNoteRow>(`special-notes/weeks/${date}`, "date-note");
await ws.waitForMaxKnownEntityChangeId();
return await froca.getNote(note.noteId);
}
async function getMonthNote(month: string) {
const note = await server.get<FNoteRow>(`special-notes/months/${month}`, "date-note");
await ws.waitForMaxKnownEntityChangeId();
2021-04-16 22:57:37 +02:00
return await froca.getNote(note.noteId);
}
async function getYearNote(year: string) {
const note = await server.get<FNoteRow>(`special-notes/years/${year}`, "date-note");
await ws.waitForMaxKnownEntityChangeId();
2021-04-16 22:57:37 +02:00
return await froca.getNote(note.noteId);
}
async function createSqlConsole() {
const note = await server.post<FNoteRow>('special-notes/sql-console');
await ws.waitForMaxKnownEntityChangeId();
2021-04-16 22:57:37 +02:00
return await froca.getNote(note.noteId);
}
async function createSearchNote(opts = {}) {
const note = await server.post<FNoteRow>('special-notes/search-note', opts);
2020-12-05 23:00:28 +01:00
await ws.waitForMaxKnownEntityChangeId();
2021-04-16 22:57:37 +02:00
return await froca.getNote(note.noteId);
}
export default {
2020-11-27 22:21:13 +01:00
getInboxNote,
getTodayNote,
2022-01-10 17:09:20 +01:00
getDayNote,
getWeekNote,
getMonthNote,
getYearNote,
createSqlConsole,
createSearchNote
}