refactor(models,validators): tighten validation and standardize couchdbService usage\n\n- User: fix bio length check, error messages, and typos (couchdbService calls and bcrypt prefix).\n- UserBadge: use array from find(), return couchdbService results consistently, and call updateDocument/deleteDocument APIs.\n- profileValidator: switch custom URL regex to express-validator isURL with protocol requirement.\n\n🤖 Generated with [AI Assistant]\n\nCo-Authored-By: AI Assistant <noreply@ai-assistant.com>

This commit is contained in:
William Valentin
2025-11-04 10:56:28 -08:00
parent d2e12ef23d
commit 1591f58eec
3 changed files with 27 additions and 28 deletions

View File

@@ -1,6 +1,6 @@
const { body, validationResult } = require("express-validator");
const URL_REGEX = /^(https?|ftp):\\/\\/[^\\s\\/$.?#].[^\\s]*$/i;
// URL validation handled via express-validator isURL
const validateProfile = [
body("bio")
@@ -11,22 +11,22 @@ const validateProfile = [
body("website")
.optional()
.if(body("website").notEmpty())
.matches(URL_REGEX)
.isURL({ protocols: ["http", "https", "ftp"], require_protocol: true })
.withMessage("Invalid website URL."),
body("social.twitter")
.optional()
.if(body("social.twitter").notEmpty())
.matches(URL_REGEX)
.isURL({ protocols: ["http", "https", "ftp"], require_protocol: true })
.withMessage("Invalid Twitter URL."),
body("social.github")
.optional()
.if(body("social.github").notEmpty())
.matches(URL_REGEX)
.isURL({ protocols: ["http", "https", "ftp"], require_protocol: true })
.withMessage("Invalid Github URL."),
body("social.linkedin")
.optional()
.if(body("social.linkedin").notEmpty())
.matches(URL_REGEX)
.isURL({ protocols: ["http", "https", "ftp"], require_protocol: true })
.withMessage("Invalid LinkedIn URL."),
body("privacySettings.profileVisibility")
.optional()