mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
server-ts: Convert etapi/validators
This commit is contained in:
parent
4bb46aeb9c
commit
3bd7231ba9
@ -1,7 +1,7 @@
|
||||
const becca = require('../becca/becca');
|
||||
const eu = require('./etapi_utils');
|
||||
const mappers = require('./mappers');
|
||||
const v = require('./validators.js');
|
||||
const v = require('./validators');
|
||||
const utils = require('../services/utils');
|
||||
|
||||
function register(router) {
|
||||
|
@ -2,7 +2,7 @@ const becca = require('../becca/becca');
|
||||
const eu = require('./etapi_utils');
|
||||
const mappers = require('./mappers');
|
||||
const attributeService = require('../services/attributes');
|
||||
const v = require('./validators.js');
|
||||
const v = require('./validators');
|
||||
|
||||
function register(router) {
|
||||
eu.route(router, 'get', '/etapi/attributes/:attributeId', (req, res, next) => {
|
||||
|
@ -3,7 +3,7 @@ const eu = require('./etapi_utils');
|
||||
const mappers = require('./mappers');
|
||||
const BBranch = require('../becca/entities/bbranch');
|
||||
const entityChangesService = require('../services/entity_changes');
|
||||
const v = require('./validators.js');
|
||||
const v = require('./validators');
|
||||
|
||||
function register(router) {
|
||||
eu.route(router, 'get', '/etapi/branches/:branchId', (req, res, next) => {
|
||||
|
@ -4,7 +4,7 @@ const eu = require('./etapi_utils');
|
||||
const mappers = require('./mappers');
|
||||
const noteService = require('../services/notes');
|
||||
const TaskContext = require('../services/task_context');
|
||||
const v = require('./validators.js');
|
||||
const v = require('./validators');
|
||||
const searchService = require('../services/search/services/search');
|
||||
const SearchContext = require('../services/search/search_context');
|
||||
const zipExportService = require('../services/export/zip');
|
||||
|
@ -1,19 +1,19 @@
|
||||
const noteTypeService = require('../services/note_types');
|
||||
const dateUtils = require('../services/date_utils');
|
||||
import noteTypeService = require('../services/note_types');
|
||||
import dateUtils = require('../services/date_utils');
|
||||
|
||||
function mandatory(obj) {
|
||||
if (obj === undefined ) {
|
||||
function mandatory(obj: any | undefined) {
|
||||
if (obj === undefined) {
|
||||
return `mandatory, but not set`;
|
||||
}
|
||||
}
|
||||
|
||||
function notNull(obj) {
|
||||
function notNull(obj: any | null) {
|
||||
if (obj === null) {
|
||||
return `cannot be null`;
|
||||
}
|
||||
}
|
||||
|
||||
function isString(obj) {
|
||||
function isString(obj: object | undefined | null) {
|
||||
if (obj === undefined || obj === null) {
|
||||
return;
|
||||
}
|
||||
@ -23,23 +23,23 @@ function isString(obj) {
|
||||
}
|
||||
}
|
||||
|
||||
function isLocalDateTime(obj) {
|
||||
if (obj === undefined || obj === null) {
|
||||
function isLocalDateTime(obj: object | undefined | null) {
|
||||
if (obj === undefined || obj === null || typeof obj !== "string") {
|
||||
return;
|
||||
}
|
||||
|
||||
return dateUtils.validateLocalDateTime(obj);
|
||||
}
|
||||
|
||||
function isUtcDateTime(obj) {
|
||||
if (obj === undefined || obj === null) {
|
||||
function isUtcDateTime(obj: object | undefined | null) {
|
||||
if (obj === undefined || obj === null || typeof obj !== "string") {
|
||||
return;
|
||||
}
|
||||
|
||||
return dateUtils.validateUtcDateTime(obj);
|
||||
}
|
||||
|
||||
function isBoolean(obj) {
|
||||
function isBoolean(obj: object | undefined | null) {
|
||||
if (obj === undefined || obj === null) {
|
||||
return;
|
||||
}
|
||||
@ -49,7 +49,7 @@ function isBoolean(obj) {
|
||||
}
|
||||
}
|
||||
|
||||
function isInteger(obj) {
|
||||
function isInteger(obj: object | undefined | null) {
|
||||
if (obj === undefined || obj === null) {
|
||||
return;
|
||||
}
|
||||
@ -59,7 +59,7 @@ function isInteger(obj) {
|
||||
}
|
||||
}
|
||||
|
||||
function isNoteId(obj) {
|
||||
function isNoteId(obj: object | undefined | null) {
|
||||
if (obj === undefined || obj === null) {
|
||||
return;
|
||||
}
|
||||
@ -75,29 +75,29 @@ function isNoteId(obj) {
|
||||
}
|
||||
}
|
||||
|
||||
function isNoteType(obj) {
|
||||
function isNoteType(obj: object | undefined | null) {
|
||||
if (obj === undefined || obj === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const noteTypes = noteTypeService.getNoteTypeNames();
|
||||
|
||||
if (!noteTypes.includes(obj)) {
|
||||
if (typeof obj !== "string" || !noteTypes.includes(obj)) {
|
||||
return `'${obj}' is not a valid note type, allowed types are: ${noteTypes.join(", ")}`;
|
||||
}
|
||||
}
|
||||
|
||||
function isAttributeType(obj) {
|
||||
function isAttributeType(obj: object | undefined | null) {
|
||||
if (obj === undefined || obj === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!['label', 'relation'].includes(obj)) {
|
||||
if (typeof obj !== "string" || !['label', 'relation'].includes(obj)) {
|
||||
return `'${obj}' is not a valid attribute type, allowed types are: label, relation`;
|
||||
}
|
||||
}
|
||||
|
||||
function isValidEntityId(obj) {
|
||||
function isValidEntityId(obj: object | undefined | null) {
|
||||
if (obj === undefined || obj === null) {
|
||||
return;
|
||||
}
|
||||
@ -107,7 +107,7 @@ function isValidEntityId(obj) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export = {
|
||||
mandatory,
|
||||
notNull,
|
||||
isString,
|
Loading…
x
Reference in New Issue
Block a user