mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-02 21:42:15 +08:00
feat: 🎸 add and update etapi
This commit is contained in:
parent
1313003bdb
commit
1164126885
@ -5,6 +5,8 @@ import mappers from "./mappers.js";
|
|||||||
import type { Router } from "express";
|
import type { Router } from "express";
|
||||||
|
|
||||||
const getDateInvalidError = (date: string) => new eu.EtapiError(400, "DATE_INVALID", `Date "${date}" is not valid.`);
|
const getDateInvalidError = (date: string) => new eu.EtapiError(400, "DATE_INVALID", `Date "${date}" is not valid.`);
|
||||||
|
const getWeekInvalidError = (week: string) => new eu.EtapiError(400, "WEEK_INVALID", `Week "${week}" is not valid.`);
|
||||||
|
const getWeekNotFoundError = (week: string) => new eu.EtapiError(404, "WEEK_NOT_FOUND", `Week "${week}" not found. Check if week note is enabled.`);
|
||||||
const getMonthInvalidError = (month: string) => new eu.EtapiError(400, "MONTH_INVALID", `Month "${month}" is not valid.`);
|
const getMonthInvalidError = (month: string) => new eu.EtapiError(400, "MONTH_INVALID", `Month "${month}" is not valid.`);
|
||||||
const getYearInvalidError = (year: string) => new eu.EtapiError(400, "YEAR_INVALID", `Year "${year}" is not valid.`);
|
const getYearInvalidError = (year: string) => new eu.EtapiError(400, "YEAR_INVALID", `Year "${year}" is not valid.`);
|
||||||
|
|
||||||
@ -16,6 +18,13 @@ function isValidDate(date: string) {
|
|||||||
return !!Date.parse(date);
|
return !!Date.parse(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isValidWeek(week: string) {
|
||||||
|
if (!/[0-9]{4}-W[0-9]{2}/.test(week)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function register(router: Router) {
|
function register(router: Router) {
|
||||||
eu.route(router, "get", "/etapi/inbox/:date", (req, res, next) => {
|
eu.route(router, "get", "/etapi/inbox/:date", (req, res, next) => {
|
||||||
const { date } = req.params;
|
const { date } = req.params;
|
||||||
@ -39,7 +48,7 @@ function register(router: Router) {
|
|||||||
res.json(mappers.mapNoteToPojo(note));
|
res.json(mappers.mapNoteToPojo(note));
|
||||||
});
|
});
|
||||||
|
|
||||||
eu.route(router, "get", "/etapi/calendar/weeks/:date", (req, res, next) => {
|
eu.route(router, "get", "/etapi/calendar/week-first-day/:date", (req, res, next) => {
|
||||||
const { date } = req.params;
|
const { date } = req.params;
|
||||||
|
|
||||||
if (!isValidDate(date)) {
|
if (!isValidDate(date)) {
|
||||||
@ -50,6 +59,22 @@ function register(router: Router) {
|
|||||||
res.json(mappers.mapNoteToPojo(note));
|
res.json(mappers.mapNoteToPojo(note));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
eu.route(router, "get", "/etapi/calendar/weeks/:week", (req, res, next) => {
|
||||||
|
const { week } = req.params;
|
||||||
|
|
||||||
|
if (!isValidWeek(week)) {
|
||||||
|
throw getWeekInvalidError(week);
|
||||||
|
}
|
||||||
|
|
||||||
|
const note = dateNotesService.getWeekNote(week);
|
||||||
|
|
||||||
|
if (!note) {
|
||||||
|
throw getWeekNotFoundError(week);
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json(mappers.mapNoteToPojo(note));
|
||||||
|
});
|
||||||
|
|
||||||
eu.route(router, "get", "/etapi/calendar/months/:month", (req, res, next) => {
|
eu.route(router, "get", "/etapi/calendar/months/:month", (req, res, next) => {
|
||||||
const { month } = req.params;
|
const { month } = req.params;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user