From b18529b50839bbfc420da44521996926e96bd294 Mon Sep 17 00:00:00 2001
From: Mathias Wagner <germannewsmaker@gmail.com>
Date: Sun, 26 Jun 2022 17:14:30 +0200
Subject: [PATCH] Created the user validation

---
 validations/user.js | 58 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
 create mode 100644 validations/user.js

diff --git a/validations/user.js b/validations/user.js
new file mode 100644
index 0000000..5819ed7
--- /dev/null
+++ b/validations/user.js
@@ -0,0 +1,58 @@
+const Joi = require('joi');
+
+const usernameRegex = "^(?:[a-zA-Z\\d]+(?:(?:\\.|-|_)[a-zA-Z\\d])*)+$";
+
+// The validation used when creating a new user
+module.exports.createUser = Joi.object({
+    username: Joi.string()
+        .regex(new RegExp(usernameRegex))
+        .min(5)
+        .max(15)
+        .required(),
+    email: Joi.string()
+        .email()
+        .max(50)
+        .required(),
+    password: Joi.string()
+        .min(8)
+        .max(256)
+        .required()
+});
+
+// The validation used when updating an existing user
+module.exports.updateUser = Joi.object({
+    username: Joi.string()
+        .regex(new RegExp(usernameRegex))
+        .min(5)
+        .max(15),
+    email: Joi.string()
+        .email()
+        .max(50),
+    password: Joi.string()
+        .min(8)
+        .max(256),
+    info: Joi.string()
+        .min(10)
+        .max(150)
+}).min(1);
+
+// The validation used when updating the user socials
+module.exports.updateSocials = Joi.object({
+    website: Joi.string()
+        .max(100)
+        .uri(),
+    github: Joi.string()
+        .max(100)
+        .uri(),
+    youtube: Joi.string()
+        .max(100)
+        .uri(),
+    twitter: Joi.string()
+        .max(100)
+        .uri(),
+    discord: Joi.string()
+        .regex(new RegExp("^.{3,32}#[0-9]{4}$")),
+    instagram: Joi.string()
+        .max(100)
+        .uri()
+}).min(1);
\ No newline at end of file