app2-api/modules/notification/notification.model.js
2019-10-21 12:12:16 +02:00

42 lines
1.1 KiB
JavaScript

module.exports = function (sequelize, DataTypes) {
const Notification = sequelize.define('Notification', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
title: {
type: DataTypes.STRING,
allowNull: true,
},
body: {
type: DataTypes.STRING,
allowNull: true,
},
ttl: {
type: DataTypes.INTEGER,
allowNull: true,
},
priority: {
type: DataTypes.STRING,
allowNull: false,
default: 'default',
},
data: {
type: DataTypes.JSON,
allowNull: true,
},
}, {
tableName: 'notifications',
freezeTableName: true,
timestamps: true,
});
Notification.associate = function (models) {
Notification.User = Notification.belongsTo(models.User, { foreignKey: 'userId', as: "user" });
Notification.Details = Notification.hasMany(models.NotificationDetail, { foreignKey: 'notificationId', as: 'details' });
};
return Notification;
};