Updated user model with uuid & pfp

This commit is contained in:
2024-06-27 11:03:16 +08:00
parent d8db68e411
commit f474092e92
2 changed files with 25 additions and 12 deletions

View File

@@ -1,9 +1,12 @@
module.exports = (sequelize, DataTypes) => { const { DataTypes } = require("sequelize");
module.exports = (sequelize) => {
const User = sequelize.define( const User = sequelize.define(
"User", "User",
{ {
id: { id: {
type: DataTypes.STRING(36), type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
allowNull: false, allowNull: false,
primaryKey: true, primaryKey: true,
}, },
@@ -18,23 +21,36 @@ module.exports = (sequelize, DataTypes) => {
email: { email: {
type: DataTypes.STRING(69), type: DataTypes.STRING(69),
allowNull: false, allowNull: false,
validate: {
isEmail: true,
},
}, },
phoneNumber: { phoneNumber: {
type: DataTypes.STRING(8), type: DataTypes.STRING(8),
allowNull: false, allowNull: false,
validate: {
len: [8, 8],
},
}, },
password: { password: {
type: DataTypes.STRING(100), type: DataTypes.STRING(100),
allowNull: false, allowNull: false,
}, },
profilePicture: {
type: DataTypes.TEXT,
allowNull: true,
},
isArchived: { isArchived: {
type: DataTypes.BOOLEAN(), type: DataTypes.BOOLEAN,
allowNull: false, allowNull: false,
defaultValue: false,
}, },
}, },
{ {
tableName: "users", tableName: "users",
timestamps: true,
} }
); );
return User; return User;
}; };

View File

@@ -11,30 +11,28 @@ const { sign } = require("jsonwebtoken");
require("dotenv").config(); require("dotenv").config();
let validationSchema = yup.object({ let validationSchema = yup.object({
id: yup.string().trim().min(36).max(36).required(),
firstName: yup.string().trim().min(1).max(100).required(), firstName: yup.string().trim().min(1).max(100).required(),
lastName: 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 phoneNumber: yup
.string() .string()
.trim() .trim()
.matches(/^[0-9]+$/) .matches(/^[0-9]{8}$/, "Must be exactly 8 digits")
.length(8)
.required(), .required(),
password: yup.string().trim().max(100).required(), password: yup.string().trim().max(100).required(),
profilePicture: yup.string().trim().max(255),
}); });
let optionalValidationSchema = yup.object({ let optionalValidationSchema = yup.object({
id: yup.string().trim().min(36).max(36).required(),
firstName: yup.string().trim().min(1).max(100), firstName: yup.string().trim().min(1).max(100),
lastName: 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 phoneNumber: yup
.string() .string()
.trim() .trim()
.matches(/^[0-9]+$/) .matches(/^[0-9]{8}$/, "Must be exactly 8 digits"),
.length(8),
password: yup.string().trim().max(100), password: yup.string().trim().max(100),
profilePicture: yup.string().trim().max(255),
}); });
router.post("/register", async (req, res) => { router.post("/register", async (req, res) => {
@@ -52,7 +50,6 @@ router.post("/register", async (req, res) => {
return; return;
} }
try { try {
data.id = uuidV4();
data.password = await argon2.hash(data.password); data.password = await argon2.hash(data.password);
console.log("Validating schema..."); console.log("Validating schema...");