summaryrefslogtreecommitdiff
path: root/lib/models
diff options
context:
space:
mode:
Diffstat (limited to 'lib/models')
-rw-r--r--lib/models/author.js43
-rw-r--r--lib/models/note.js8
-rw-r--r--lib/models/revision.js3
3 files changed, 54 insertions, 0 deletions
diff --git a/lib/models/author.js b/lib/models/author.js
new file mode 100644
index 00000000..0b0f149d
--- /dev/null
+++ b/lib/models/author.js
@@ -0,0 +1,43 @@
+"use strict";
+
+// external modules
+var Sequelize = require("sequelize");
+
+// core
+var logger = require("../logger.js");
+
+module.exports = function (sequelize, DataTypes) {
+ var Author = sequelize.define("Author", {
+ id: {
+ type: Sequelize.INTEGER,
+ primaryKey: true,
+ autoIncrement: true
+ },
+ color: {
+ type: DataTypes.STRING
+ }
+ }, {
+ indexes: [
+ {
+ unique: true,
+ fields: ['noteId', 'userId']
+ }
+ ],
+ classMethods: {
+ associate: function (models) {
+ Author.belongsTo(models.Note, {
+ foreignKey: "noteId",
+ as: "note",
+ constraints: false
+ });
+ Author.belongsTo(models.User, {
+ foreignKey: "userId",
+ as: "user",
+ constraints: false
+ });
+ }
+ }
+ });
+
+ return Author;
+}; \ No newline at end of file
diff --git a/lib/models/note.js b/lib/models/note.js
index f9a8ec61..5ee5c7de 100644
--- a/lib/models/note.js
+++ b/lib/models/note.js
@@ -51,6 +51,9 @@ module.exports = function (sequelize, DataTypes) {
content: {
type: DataTypes.TEXT
},
+ authorship: {
+ type: DataTypes.TEXT
+ },
lastchangeAt: {
type: DataTypes.DATE
},
@@ -74,6 +77,11 @@ module.exports = function (sequelize, DataTypes) {
foreignKey: "noteId",
constraints: false
});
+ Note.hasMany(models.Author, {
+ foreignKey: "noteId",
+ as: "authors",
+ constraints: false
+ });
},
checkFileExist: function (filePath) {
try {
diff --git a/lib/models/revision.js b/lib/models/revision.js
index bb89782f..f525ea55 100644
--- a/lib/models/revision.js
+++ b/lib/models/revision.js
@@ -30,6 +30,9 @@ module.exports = function (sequelize, DataTypes) {
},
length: {
type: DataTypes.INTEGER
+ },
+ authorship: {
+ type: DataTypes.TEXT
}
}, {
classMethods: {