Updated user model with uuid & pfp
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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...");
|
||||
|
||||
Reference in New Issue
Block a user