tududi/backend/modules/areas/validation.js
Chris 542be2c1e9
Fix bug 366 (#764)
* Optimize DB

* Clean up names

* fixup! Clean up names

* fixup! fixup! Clean up names
2026-01-07 18:18:07 +02:00

40 lines
912 B
JavaScript

'use strict';
const { ValidationError } = require('../../shared/errors');
const { isValidUid } = require('../../utils/slug-utils');
/**
* Validates area name.
* @param {string} name - The name to validate
* @returns {string} - The sanitized name
* @throws {ValidationError} - If validation fails
*/
function validateName(name) {
if (!name || typeof name !== 'string') {
throw new ValidationError('Area name is required.');
}
const trimmed = name.trim();
if (trimmed.length === 0) {
throw new ValidationError('Area name is required.');
}
return trimmed;
}
/**
* Validates a UID parameter.
* @param {string} uid - The UID to validate
* @throws {ValidationError} - If validation fails
*/
function validateUid(uid) {
if (!isValidUid(uid)) {
throw new ValidationError('Invalid UID');
}
}
module.exports = {
validateName,
validateUid,
};