Colubrina/backend/models/chatassociations.js

62 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-06-05 22:58:18 +10:00
"use strict"
const { Model } = require("sequelize")
module.exports = (sequelize, DataTypes) => {
class ChatAssociation 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.
*/
// eslint-disable-next-line no-unused-vars
static associate(models) {
ChatAssociation.belongsTo(models.User, {
foreignKey: "userId",
as: "user"
})
ChatAssociation.belongsTo(models.Chat, {
foreignKey: "chatId",
as: "chat"
})
}
}
ChatAssociation.init(
{
chatId: {
type: DataTypes.BIGINT,
allowNull: false
},
userId: {
type: DataTypes.BIGINT,
allowNull: false
},
rank: {
type: DataTypes.ENUM(["member", "admin"]),
defaultValue: "member",
allowNull: false
},
lastRead: {
type: DataTypes.BIGINT,
defaultValue: null
},
createdAt: {
allowNull: false,
type: DataTypes.DATE
},
updatedAt: {
allowNull: false,
type: DataTypes.DATE
2022-08-06 19:22:21 +10:00
},
notifications: {
type: DataTypes.ENUM(["all", "none", "mentions"]),
defaultValue: "all",
allowNull: false
2022-06-05 22:58:18 +10:00
}
},
{
sequelize,
modelName: "ChatAssociation"
}
)
return ChatAssociation
}