sending images through messages works

This commit is contained in:
jackiettran
2025-12-18 19:37:16 -05:00
parent 996e815d57
commit 4b4584bc0f
6 changed files with 52 additions and 22 deletions

View File

@@ -25,7 +25,7 @@ const Message = sequelize.define('Message', {
},
content: {
type: DataTypes.TEXT,
allowNull: false
allowNull: true
},
isRead: {
type: DataTypes.BOOLEAN,
@@ -36,7 +36,15 @@ const Message = sequelize.define('Message', {
allowNull: true
}
}, {
timestamps: true
timestamps: true,
validate: {
contentOrImage() {
const hasContent = this.content && this.content.trim().length > 0;
if (!hasContent && !this.imageFilename) {
throw new Error('Message must have content or an image');
}
}
}
});
module.exports = Message;