From f474092e92f43b228d130535f495d7c0dc43cc2c Mon Sep 17 00:00:00 2001 From: Wind-Explorer Date: Thu, 27 Jun 2024 11:03:16 +0800 Subject: [PATCH] Updated user model with uuid & pfp --- server/models/User.js | 22 +++++++++++++++++++--- server/routes/users.js | 15 ++++++--------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/server/models/User.js b/server/models/User.js index 55d3564..d71bef5 100644 --- a/server/models/User.js +++ b/server/models/User.js @@ -1,9 +1,12 @@ -module.exports = (sequelize, DataTypes) => { +const { DataTypes } = require("sequelize"); + +module.exports = (sequelize) => { const User = sequelize.define( "User", { id: { - type: DataTypes.STRING(36), + type: DataTypes.UUID, + defaultValue: DataTypes.UUIDV4, allowNull: false, primaryKey: true, }, @@ -18,23 +21,36 @@ module.exports = (sequelize, DataTypes) => { email: { type: DataTypes.STRING(69), allowNull: false, + validate: { + isEmail: true, + }, }, phoneNumber: { type: DataTypes.STRING(8), allowNull: false, + validate: { + len: [8, 8], + }, }, password: { type: DataTypes.STRING(100), allowNull: false, }, + profilePicture: { + type: DataTypes.TEXT, + allowNull: true, + }, isArchived: { - type: DataTypes.BOOLEAN(), + type: DataTypes.BOOLEAN, allowNull: false, + defaultValue: false, }, }, { tableName: "users", + timestamps: true, } ); + return User; }; diff --git a/server/routes/users.js b/server/routes/users.js index ee868b3..21a26ed 100644 --- a/server/routes/users.js +++ b/server/routes/users.js @@ -11,30 +11,28 @@ const { sign } = require("jsonwebtoken"); require("dotenv").config(); let validationSchema = yup.object({ - id: yup.string().trim().min(36).max(36).required(), firstName: yup.string().trim().min(1).max(100).required(), lastName: yup.string().trim().min(1).max(100).required(), - email: yup.string().trim().min(5).max(69).email().required(), + email: yup.string().trim().email().max(69).required(), phoneNumber: yup .string() .trim() - .matches(/^[0-9]+$/) - .length(8) + .matches(/^[0-9]{8}$/, "Must be exactly 8 digits") .required(), password: yup.string().trim().max(100).required(), + profilePicture: yup.string().trim().max(255), }); let optionalValidationSchema = yup.object({ - id: yup.string().trim().min(36).max(36).required(), firstName: yup.string().trim().min(1).max(100), lastName: yup.string().trim().min(1).max(100), - email: yup.string().trim().min(5).max(69).email(), + email: yup.string().trim().email().max(69), phoneNumber: yup .string() .trim() - .matches(/^[0-9]+$/) - .length(8), + .matches(/^[0-9]{8}$/, "Must be exactly 8 digits"), password: yup.string().trim().max(100), + profilePicture: yup.string().trim().max(255), }); router.post("/register", async (req, res) => { @@ -52,7 +50,6 @@ router.post("/register", async (req, res) => { return; } try { - data.id = uuidV4(); data.password = await argon2.hash(data.password); console.log("Validating schema...");