server-ts: Convert etapi/validators

This commit is contained in:
Elian Doran 2024-04-07 14:59:40 +03:00
parent 4bb46aeb9c
commit 3bd7231ba9
No known key found for this signature in database
5 changed files with 23 additions and 23 deletions

View File

@ -1,7 +1,7 @@
const becca = require('../becca/becca'); const becca = require('../becca/becca');
const eu = require('./etapi_utils'); const eu = require('./etapi_utils');
const mappers = require('./mappers'); const mappers = require('./mappers');
const v = require('./validators.js'); const v = require('./validators');
const utils = require('../services/utils'); const utils = require('../services/utils');
function register(router) { function register(router) {

View File

@ -2,7 +2,7 @@ const becca = require('../becca/becca');
const eu = require('./etapi_utils'); const eu = require('./etapi_utils');
const mappers = require('./mappers'); const mappers = require('./mappers');
const attributeService = require('../services/attributes'); const attributeService = require('../services/attributes');
const v = require('./validators.js'); const v = require('./validators');
function register(router) { function register(router) {
eu.route(router, 'get', '/etapi/attributes/:attributeId', (req, res, next) => { eu.route(router, 'get', '/etapi/attributes/:attributeId', (req, res, next) => {

View File

@ -3,7 +3,7 @@ const eu = require('./etapi_utils');
const mappers = require('./mappers'); const mappers = require('./mappers');
const BBranch = require('../becca/entities/bbranch'); const BBranch = require('../becca/entities/bbranch');
const entityChangesService = require('../services/entity_changes'); const entityChangesService = require('../services/entity_changes');
const v = require('./validators.js'); const v = require('./validators');
function register(router) { function register(router) {
eu.route(router, 'get', '/etapi/branches/:branchId', (req, res, next) => { eu.route(router, 'get', '/etapi/branches/:branchId', (req, res, next) => {

View File

@ -4,7 +4,7 @@ const eu = require('./etapi_utils');
const mappers = require('./mappers'); const mappers = require('./mappers');
const noteService = require('../services/notes'); const noteService = require('../services/notes');
const TaskContext = require('../services/task_context'); const TaskContext = require('../services/task_context');
const v = require('./validators.js'); const v = require('./validators');
const searchService = require('../services/search/services/search'); const searchService = require('../services/search/services/search');
const SearchContext = require('../services/search/search_context'); const SearchContext = require('../services/search/search_context');
const zipExportService = require('../services/export/zip'); const zipExportService = require('../services/export/zip');

View File

@ -1,19 +1,19 @@
const noteTypeService = require('../services/note_types'); import noteTypeService = require('../services/note_types');
const dateUtils = require('../services/date_utils'); import dateUtils = require('../services/date_utils');
function mandatory(obj) { function mandatory(obj: any | undefined) {
if (obj === undefined ) { if (obj === undefined) {
return `mandatory, but not set`; return `mandatory, but not set`;
} }
} }
function notNull(obj) { function notNull(obj: any | null) {
if (obj === null) { if (obj === null) {
return `cannot be null`; return `cannot be null`;
} }
} }
function isString(obj) { function isString(obj: object | undefined | null) {
if (obj === undefined || obj === null) { if (obj === undefined || obj === null) {
return; return;
} }
@ -23,23 +23,23 @@ function isString(obj) {
} }
} }
function isLocalDateTime(obj) { function isLocalDateTime(obj: object | undefined | null) {
if (obj === undefined || obj === null) { if (obj === undefined || obj === null || typeof obj !== "string") {
return; return;
} }
return dateUtils.validateLocalDateTime(obj); return dateUtils.validateLocalDateTime(obj);
} }
function isUtcDateTime(obj) { function isUtcDateTime(obj: object | undefined | null) {
if (obj === undefined || obj === null) { if (obj === undefined || obj === null || typeof obj !== "string") {
return; return;
} }
return dateUtils.validateUtcDateTime(obj); return dateUtils.validateUtcDateTime(obj);
} }
function isBoolean(obj) { function isBoolean(obj: object | undefined | null) {
if (obj === undefined || obj === null) { if (obj === undefined || obj === null) {
return; return;
} }
@ -49,7 +49,7 @@ function isBoolean(obj) {
} }
} }
function isInteger(obj) { function isInteger(obj: object | undefined | null) {
if (obj === undefined || obj === null) { if (obj === undefined || obj === null) {
return; return;
} }
@ -59,7 +59,7 @@ function isInteger(obj) {
} }
} }
function isNoteId(obj) { function isNoteId(obj: object | undefined | null) {
if (obj === undefined || obj === null) { if (obj === undefined || obj === null) {
return; return;
} }
@ -75,29 +75,29 @@ function isNoteId(obj) {
} }
} }
function isNoteType(obj) { function isNoteType(obj: object | undefined | null) {
if (obj === undefined || obj === null) { if (obj === undefined || obj === null) {
return; return;
} }
const noteTypes = noteTypeService.getNoteTypeNames(); 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(", ")}`; 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) { if (obj === undefined || obj === null) {
return; 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`; 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) { if (obj === undefined || obj === null) {
return; return;
} }
@ -107,7 +107,7 @@ function isValidEntityId(obj) {
} }
} }
module.exports = { export = {
mandatory, mandatory,
notNull, notNull,
isString, isString,