mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
server-ts: Convert etapi/mappers
This commit is contained in:
parent
26859e83e4
commit
4bb46aeb9c
@ -1,6 +1,6 @@
|
||||
const becca = require('../becca/becca');
|
||||
const eu = require('./etapi_utils');
|
||||
const mappers = require('./mappers.js');
|
||||
const mappers = require('./mappers');
|
||||
const v = require('./validators.js');
|
||||
const utils = require('../services/utils');
|
||||
|
||||
@ -14,7 +14,7 @@ function register(router) {
|
||||
'content': [v.isString],
|
||||
};
|
||||
|
||||
eu.route(router, 'post' ,'/etapi/attachments', (req, res, next) => {
|
||||
eu.route(router, 'post', '/etapi/attachments', (req, res, next) => {
|
||||
const params = {};
|
||||
|
||||
eu.validateAndPatch(params, req.body, ALLOWED_PROPERTIES_FOR_CREATE_ATTACHMENT);
|
||||
@ -43,7 +43,7 @@ function register(router) {
|
||||
'position': [v.notNull, v.isInteger],
|
||||
};
|
||||
|
||||
eu.route(router, 'patch' ,'/etapi/attachments/:attachmentId', (req, res, next) => {
|
||||
eu.route(router, 'patch', '/etapi/attachments/:attachmentId', (req, res, next) => {
|
||||
const attachment = eu.getAndCheckAttachment(req.params.attachmentId);
|
||||
|
||||
if (attachment.isProtected) {
|
||||
@ -85,7 +85,7 @@ function register(router) {
|
||||
return res.sendStatus(204);
|
||||
});
|
||||
|
||||
eu.route(router, 'delete' ,'/etapi/attachments/:attachmentId', (req, res, next) => {
|
||||
eu.route(router, 'delete', '/etapi/attachments/:attachmentId', (req, res, next) => {
|
||||
const attachment = becca.getAttachment(req.params.attachmentId);
|
||||
|
||||
if (!attachment) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
const becca = require('../becca/becca');
|
||||
const eu = require('./etapi_utils');
|
||||
const mappers = require('./mappers.js');
|
||||
const mappers = require('./mappers');
|
||||
const attributeService = require('../services/attributes');
|
||||
const v = require('./validators.js');
|
||||
|
||||
@ -21,7 +21,7 @@ function register(router) {
|
||||
'position': [v.notNull, v.isInteger]
|
||||
};
|
||||
|
||||
eu.route(router, 'post' ,'/etapi/attributes', (req, res, next) => {
|
||||
eu.route(router, 'post', '/etapi/attributes', (req, res, next) => {
|
||||
if (req.body.type === 'relation') {
|
||||
eu.getAndCheckNote(req.body.value);
|
||||
}
|
||||
@ -49,7 +49,7 @@ function register(router) {
|
||||
'position': [v.notNull, v.isInteger]
|
||||
};
|
||||
|
||||
eu.route(router, 'patch' ,'/etapi/attributes/:attributeId', (req, res, next) => {
|
||||
eu.route(router, 'patch', '/etapi/attributes/:attributeId', (req, res, next) => {
|
||||
const attribute = eu.getAndCheckAttribute(req.params.attributeId);
|
||||
|
||||
if (attribute.type === 'label') {
|
||||
@ -65,7 +65,7 @@ function register(router) {
|
||||
res.json(mappers.mapAttributeToPojo(attribute));
|
||||
});
|
||||
|
||||
eu.route(router, 'delete' ,'/etapi/attributes/:attributeId', (req, res, next) => {
|
||||
eu.route(router, 'delete', '/etapi/attributes/:attributeId', (req, res, next) => {
|
||||
const attribute = becca.getAttribute(req.params.attributeId);
|
||||
|
||||
if (!attribute) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
const becca = require('../becca/becca');
|
||||
const eu = require('./etapi_utils');
|
||||
const mappers = require('./mappers.js');
|
||||
const mappers = require('./mappers');
|
||||
const BBranch = require('../becca/entities/bbranch');
|
||||
const entityChangesService = require('../services/entity_changes');
|
||||
const v = require('./validators.js');
|
||||
@ -20,7 +20,7 @@ function register(router) {
|
||||
'isExpanded': [v.notNull, v.isBoolean]
|
||||
};
|
||||
|
||||
eu.route(router, 'post' ,'/etapi/branches', (req, res, next) => {
|
||||
eu.route(router, 'post', '/etapi/branches', (req, res, next) => {
|
||||
const params = {};
|
||||
|
||||
eu.validateAndPatch(params, req.body, ALLOWED_PROPERTIES_FOR_CREATE_BRANCH);
|
||||
@ -51,7 +51,7 @@ function register(router) {
|
||||
'isExpanded': [v.notNull, v.isBoolean]
|
||||
};
|
||||
|
||||
eu.route(router, 'patch' ,'/etapi/branches/:branchId', (req, res, next) => {
|
||||
eu.route(router, 'patch', '/etapi/branches/:branchId', (req, res, next) => {
|
||||
const branch = eu.getAndCheckBranch(req.params.branchId);
|
||||
|
||||
eu.validateAndPatch(branch, req.body, ALLOWED_PROPERTIES_FOR_PATCH);
|
||||
@ -60,7 +60,7 @@ function register(router) {
|
||||
res.json(mappers.mapBranchToPojo(branch));
|
||||
});
|
||||
|
||||
eu.route(router, 'delete' ,'/etapi/branches/:branchId', (req, res, next) => {
|
||||
eu.route(router, 'delete', '/etapi/branches/:branchId', (req, res, next) => {
|
||||
const branch = becca.getBranch(req.params.branchId);
|
||||
|
||||
if (!branch) {
|
||||
@ -72,7 +72,7 @@ function register(router) {
|
||||
res.sendStatus(204);
|
||||
});
|
||||
|
||||
eu.route(router, 'post' ,'/etapi/refresh-note-ordering/:parentNoteId', (req, res, next) => {
|
||||
eu.route(router, 'post', '/etapi/refresh-note-ordering/:parentNoteId', (req, res, next) => {
|
||||
eu.getAndCheckNote(req.params.parentNoteId);
|
||||
|
||||
entityChangesService.putNoteReorderingEntityChange(req.params.parentNoteId, "etapi");
|
||||
|
@ -1,5 +1,9 @@
|
||||
/** @param {BNote} note */
|
||||
function mapNoteToPojo(note) {
|
||||
import BAttachment = require("../becca/entities/battachment");
|
||||
import BAttribute = require("../becca/entities/battribute");
|
||||
import BBranch = require("../becca/entities/bbranch");
|
||||
import BNote = require("../becca/entities/bnote");
|
||||
|
||||
function mapNoteToPojo(note: BNote) {
|
||||
return {
|
||||
noteId: note.noteId,
|
||||
isProtected: note.isProtected,
|
||||
@ -19,8 +23,7 @@ function mapNoteToPojo(note) {
|
||||
};
|
||||
}
|
||||
|
||||
/** @param {BBranch} branch */
|
||||
function mapBranchToPojo(branch) {
|
||||
function mapBranchToPojo(branch: BBranch) {
|
||||
return {
|
||||
branchId: branch.branchId,
|
||||
noteId: branch.noteId,
|
||||
@ -32,8 +35,7 @@ function mapBranchToPojo(branch) {
|
||||
};
|
||||
}
|
||||
|
||||
/** @param {BAttribute} attr */
|
||||
function mapAttributeToPojo(attr) {
|
||||
function mapAttributeToPojo(attr: BAttribute) {
|
||||
return {
|
||||
attributeId: attr.attributeId,
|
||||
noteId: attr.noteId,
|
||||
@ -46,8 +48,7 @@ function mapAttributeToPojo(attr) {
|
||||
};
|
||||
}
|
||||
|
||||
/** @param {BAttachment} attachment */
|
||||
function mapAttachmentToPojo(attachment) {
|
||||
function mapAttachmentToPojo(attachment: BAttachment) {
|
||||
return {
|
||||
attachmentId: attachment.attachmentId,
|
||||
ownerId: attachment.ownerId,
|
||||
@ -63,7 +64,7 @@ function mapAttachmentToPojo(attachment) {
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export = {
|
||||
mapNoteToPojo,
|
||||
mapBranchToPojo,
|
||||
mapAttributeToPojo,
|
@ -1,7 +1,7 @@
|
||||
const becca = require('../becca/becca');
|
||||
const utils = require('../services/utils');
|
||||
const eu = require('./etapi_utils');
|
||||
const mappers = require('./mappers.js');
|
||||
const mappers = require('./mappers');
|
||||
const noteService = require('../services/notes');
|
||||
const TaskContext = require('../services/task_context');
|
||||
const v = require('./validators.js');
|
||||
@ -12,7 +12,7 @@ const zipImportService = require('../services/import/zip');
|
||||
|
||||
function register(router) {
|
||||
eu.route(router, 'get', '/etapi/notes', (req, res, next) => {
|
||||
const {search} = req.query;
|
||||
const { search } = req.query;
|
||||
|
||||
if (!search?.trim()) {
|
||||
throw new eu.EtapiError(400, 'SEARCH_QUERY_PARAM_MANDATORY', "'search' query parameter is mandatory.");
|
||||
@ -55,7 +55,7 @@ function register(router) {
|
||||
'utcDateCreated': [v.notNull, v.isString, v.isUtcDateTime]
|
||||
};
|
||||
|
||||
eu.route(router, 'post' ,'/etapi/create-note', (req, res, next) => {
|
||||
eu.route(router, 'post', '/etapi/create-note', (req, res, next) => {
|
||||
const params = {};
|
||||
|
||||
eu.validateAndPatch(params, req.body, ALLOWED_PROPERTIES_FOR_CREATE_NOTE);
|
||||
@ -81,7 +81,7 @@ function register(router) {
|
||||
'utcDateCreated': [v.notNull, v.isString, v.isUtcDateTime]
|
||||
};
|
||||
|
||||
eu.route(router, 'patch' ,'/etapi/notes/:noteId', (req, res, next) => {
|
||||
eu.route(router, 'patch', '/etapi/notes/:noteId', (req, res, next) => {
|
||||
const note = eu.getAndCheckNote(req.params.noteId);
|
||||
|
||||
if (note.isProtected) {
|
||||
@ -94,8 +94,8 @@ function register(router) {
|
||||
res.json(mappers.mapNoteToPojo(note));
|
||||
});
|
||||
|
||||
eu.route(router, 'delete' ,'/etapi/notes/:noteId', (req, res, next) => {
|
||||
const {noteId} = req.params;
|
||||
eu.route(router, 'delete', '/etapi/notes/:noteId', (req, res, next) => {
|
||||
const { noteId } = req.params;
|
||||
|
||||
const note = becca.getNote(noteId);
|
||||
|
||||
@ -139,7 +139,7 @@ function register(router) {
|
||||
return res.sendStatus(204);
|
||||
});
|
||||
|
||||
eu.route(router, 'get' ,'/etapi/notes/:noteId/export', (req, res, next) => {
|
||||
eu.route(router, 'get', '/etapi/notes/:noteId/export', (req, res, next) => {
|
||||
const note = eu.getAndCheckNote(req.params.noteId);
|
||||
const format = req.query.format || "html";
|
||||
|
||||
@ -156,7 +156,7 @@ function register(router) {
|
||||
zipExportService.exportToZip(taskContext, branch, format, res);
|
||||
});
|
||||
|
||||
eu.route(router, 'post' ,'/etapi/notes/:noteId/import', (req, res, next) => {
|
||||
eu.route(router, 'post', '/etapi/notes/:noteId/import', (req, res, next) => {
|
||||
const note = eu.getAndCheckNote(req.params.noteId);
|
||||
const taskContext = new TaskContext('no-progress-reporting');
|
||||
|
||||
@ -168,7 +168,7 @@ function register(router) {
|
||||
}); // we need better error handling here, async errors won't be properly processed.
|
||||
});
|
||||
|
||||
eu.route(router, 'post' ,'/etapi/notes/:noteId/revision', (req, res, next) => {
|
||||
eu.route(router, 'post', '/etapi/notes/:noteId/revision', (req, res, next) => {
|
||||
const note = eu.getAndCheckNote(req.params.noteId);
|
||||
|
||||
note.saveRevision();
|
||||
@ -178,7 +178,7 @@ function register(router) {
|
||||
|
||||
eu.route(router, 'get', '/etapi/notes/:noteId/attachments', (req, res, next) => {
|
||||
const note = eu.getAndCheckNote(req.params.noteId);
|
||||
const attachments = note.getAttachments({includeContentLength: true})
|
||||
const attachments = note.getAttachments({ includeContentLength: true })
|
||||
|
||||
res.json(
|
||||
attachments.map(attachment => mappers.mapAttachmentToPojo(attachment))
|
||||
|
@ -1,7 +1,7 @@
|
||||
const specialNotesService = require('../services/special_notes');
|
||||
const dateNotesService = require('../services/date_notes');
|
||||
const eu = require('./etapi_utils');
|
||||
const mappers = require('./mappers.js');
|
||||
const mappers = require('./mappers');
|
||||
|
||||
const getDateInvalidError = date => new eu.EtapiError(400, "DATE_INVALID", `Date "${date}" is not valid.`);
|
||||
const getMonthInvalidError = month => new eu.EtapiError(400, "MONTH_INVALID", `Month "${month}" is not valid.`);
|
||||
|
Loading…
x
Reference in New Issue
Block a user