app2-api/modules/notification/notification.model.js
2019-10-31 13:45:18 +01:00

46 lines
1.2 KiB
JavaScript

module.exports = function (sequelize, DataTypes) {
const Notification = sequelize.define('Notification', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
date: {
type: DataTypes.DATE,
allowNull: false,
},
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;
};