2022-06-05 22:58:18 +10:00
|
|
|
"use strict"
|
|
|
|
const { Model } = require("sequelize")
|
|
|
|
module.exports = (sequelize, DataTypes) => {
|
|
|
|
class User extends Model {
|
|
|
|
/**
|
|
|
|
* Helper method for defining associations.
|
|
|
|
* This method is not a part of Sequelize lifecycle.
|
|
|
|
* The `models/index` file will call this method automatically.
|
|
|
|
*/
|
|
|
|
static associate(models) {
|
|
|
|
User.belongsTo(models.Theme, {
|
|
|
|
as: "themeObject",
|
|
|
|
foreignKey: "themeId"
|
|
|
|
})
|
|
|
|
User.hasMany(models.Friend, {
|
|
|
|
as: "friends",
|
|
|
|
foreignKey: "userId"
|
|
|
|
})
|
2022-07-29 01:12:29 +10:00
|
|
|
User.hasOne(models.Nickname, {
|
|
|
|
foreignKey: "friendId",
|
|
|
|
as: "nickname"
|
|
|
|
})
|
2022-06-05 22:58:18 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
User.init(
|
|
|
|
{
|
2022-07-29 19:04:37 +10:00
|
|
|
id: {
|
|
|
|
type: DataTypes.BIGINT,
|
|
|
|
primaryKey: true,
|
|
|
|
autoIncrement: true
|
|
|
|
},
|
2022-06-05 22:58:18 +10:00
|
|
|
username: {
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
allowNull: false,
|
|
|
|
unique: true,
|
|
|
|
validate: {
|
|
|
|
notNull: {
|
|
|
|
msg: "Username is required"
|
|
|
|
},
|
|
|
|
notEmpty: {
|
|
|
|
msg: "Username is required"
|
|
|
|
},
|
|
|
|
len: {
|
2022-07-31 14:56:43 +10:00
|
|
|
args: [2, 24],
|
|
|
|
msg: "Username must be between 2 and 24 characters"
|
2022-06-05 22:58:18 +10:00
|
|
|
},
|
|
|
|
regex: {
|
|
|
|
args: /^[a-z0-9_-]+$/i,
|
|
|
|
msg: "Username must be alphanumeric"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
theme: {
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
defaultValue: "dark"
|
|
|
|
},
|
|
|
|
themeId: {
|
|
|
|
type: DataTypes.BIGINT,
|
|
|
|
allowNull: false,
|
|
|
|
defaultValue: 1
|
|
|
|
},
|
|
|
|
accentColor: {
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
allowNull: true,
|
|
|
|
defaultValue: null
|
|
|
|
},
|
|
|
|
privacy: {
|
|
|
|
type: DataTypes.JSON,
|
|
|
|
defaultValue: {
|
|
|
|
communications: {
|
|
|
|
enabled: true,
|
|
|
|
outsideTenant: false,
|
|
|
|
directMessages: "friendsOnly",
|
|
|
|
friendRequests: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
allowNull: false,
|
|
|
|
defaultValue: ""
|
|
|
|
},
|
|
|
|
admin: {
|
|
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
|
|
defaultValue: false
|
|
|
|
},
|
|
|
|
totp: {
|
|
|
|
type: DataTypes.TEXT,
|
|
|
|
allowNull: true
|
|
|
|
},
|
|
|
|
totpEnabled: {
|
|
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
|
|
defaultValue: false
|
|
|
|
},
|
|
|
|
email: {
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
allowNull: true,
|
|
|
|
validate: {
|
|
|
|
isEmail: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
password: {
|
|
|
|
type: DataTypes.TEXT,
|
|
|
|
allowNull: true
|
|
|
|
},
|
|
|
|
font: {
|
|
|
|
type: DataTypes.STRING,
|
2022-07-29 19:04:37 +10:00
|
|
|
defaultValue: "Inter",
|
2022-06-05 22:58:18 +10:00
|
|
|
allowNull: false
|
|
|
|
},
|
|
|
|
status: {
|
|
|
|
type: DataTypes.ENUM([
|
|
|
|
"online",
|
|
|
|
"busy",
|
|
|
|
"away",
|
|
|
|
"offline",
|
|
|
|
"invisible"
|
|
|
|
]),
|
|
|
|
allowNull: false,
|
|
|
|
defaultValue: "offline"
|
|
|
|
},
|
|
|
|
storedStatus: {
|
|
|
|
type: DataTypes.ENUM(["online", "busy", "away", "invisible"]),
|
|
|
|
allowNull: false,
|
|
|
|
defaultValue: "online"
|
|
|
|
},
|
|
|
|
experiments: {
|
|
|
|
type: DataTypes.JSON,
|
|
|
|
allowNull: false,
|
|
|
|
defaultValue: []
|
|
|
|
},
|
|
|
|
avatar: {
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
allowNull: true
|
2022-07-29 01:12:29 +10:00
|
|
|
},
|
|
|
|
bot: {
|
|
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
|
|
defaultValue: false
|
2022-07-29 19:04:37 +10:00
|
|
|
},
|
|
|
|
lastSeenAt: {
|
|
|
|
type: DataTypes.DATE,
|
|
|
|
allowNull: true
|
2022-07-29 19:20:19 +10:00
|
|
|
},
|
|
|
|
banned: {
|
|
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
|
|
defaultValue: false
|
2022-07-31 14:56:43 +10:00
|
|
|
},
|
|
|
|
emailVerified: {
|
|
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
|
|
defaultValue: false
|
|
|
|
},
|
|
|
|
emailToken: {
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
allowNull: true
|
2023-01-30 17:16:38 +11:00
|
|
|
},
|
|
|
|
passwordResetToken: {
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
allowNull: true
|
|
|
|
},
|
|
|
|
passwordResetExpiry: {
|
|
|
|
type: DataTypes.DATE,
|
|
|
|
allowNull: true
|
2022-06-05 22:58:18 +10:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
sequelize,
|
|
|
|
modelName: "User"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
return User
|
|
|
|
}
|